Exemple #1
0
def create_toy_mesh():

    box = mshr.Box(dolfin.Point(-3, -1, -0.5), dolfin.Point(3, 1, 0.5))

    c1 = mshr.Cylinder(dolfin.Point(0, 0, -2), dolfin.Point(0, 0, 2), 0.6, 0.6)
    b1 = mshr.Box(dolfin.Point(-2.5, -0.5, -2), dolfin.Point(-1.5, 0.5, 2))

    # "triangle"
    t1 = mshr.Polygon([
        dolfin.Point(2.5, -0.5, 0),
        dolfin.Point(2.5, 0.5, 0),
        dolfin.Point(1.5, -0.5, 0),
    ])
    g3d = mshr.Extrude2D(t1, -2)
    g3d = mshr.CSGTranslation(g3d, dolfin.Point(0, 0, 1))

    m = mshr.generate_mesh(box - c1 - b1 - g3d, 40, "cgal")

    return m.coordinates(), m.cells()
Exemple #2
0
import mshr
import dolfin as dlf

radius = 0.5
height = 10.0
circ = mshr.Circle(dlf.Point(), radius, 100)
domain = mshr.Extrude2D(circ, height)

mesh = mshr.generate_mesh(domain, 200)
dlf.File('cylinder-mesh.xml.gz') << mesh
dlf.File('cylinder-mesh.pvd') << mesh

# Region IDs
ALL_ELSE = 0
INLET = 1
OUTLET = 2
NOSLIP = 3


class Boundary(dlf.SubDomain):
    def inside(self, x, on_boundary):
        return on_boundary


class Inlet(dlf.SubDomain):
    def inside(self, x, on_boundary):
        return abs(x[2]) < dlf.DOLFIN_EPS \
            and on_boundary


class Outlet(dlf.SubDomain):
Exemple #3
0
# Copyright (C) 2015 Benjamin Kehlet
#
# This file is part of mshr.
#
# mshr is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# mshr is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with mshr.  If not, see <http://www.gnu.org/licenses/>.

# This demo illustrates how a 2D geometry can be extruded to 3D.

from dolfin import *
import mshr

g2d = mshr.Circle(Point(0, 0), 1.2) + mshr.Circle(Point(0, 1.2), 1.2)

# Any simple 2D geometry can be extruded to 3D
g3d = mshr.Extrude2D(g2d, .2)  # The z "thickness"

m = mshr.generate_mesh(g3d, 15)
plot(m, interactive=True)