def __init__(self): self.mesh = generate_mesh( Cylinder(Point(0.0, 0.0, 10.0), Point(0.0, 0.0, 0.0), 16, 16), 32) self.time_step = 0.1 self.n_steps = 30 self.function_space = FunctionSpace(self.mesh, 'P', 2) self.dirichlet_bc = self._create_dirichlet_bc() self.rhs_function = Constant(5.0) self.vtk_file = File("../output/heat_problem/solution.pvd")
def getNormals(self): geoNormals = [Point() for i in range(self.getNoFaces())] if self._nDim == 2: for i in range(self.getNoFaces()): v = self._points[self._faces[i][1]]-self._points[self._faces[i][0]] geoNormals[i] = Point(v[1],-v[0]) elif self._nDim == 3: geoNormals = [ (self._points[face[1]]-self._points[face[0]]).cross(self._points[face[2]]-self._points[face[0]]) for face in self._faces ] else: print("Invalid dimension!") exit(1) return geoNormals
def testMarkSquare(self): geo = Geometry( # Points used for face elements (Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point( 0.0, 1.0)), # Face elements ((0, 1), (1, 2), (2, 3), (3, 0))) mesh = Mesh("triangle.7.nml.gz") faceSubdomains = markBoundariesOfMesh(mesh, geo) self.assertTrue(isinstance(faceSubdomains, MeshFunction), "faceSubdomains is not a MeshFunction")
def construct_mesh(self, nx0, nx1, nx2, nt, res, project_path): """ :param nx0, nx1, nx2: mesh-sizes wrt to X, Y, Z directions :param res: mesh resolution if defined with mesh_generator function :param project_path: path of the project to load the mesh :return: mesh:discretization of the domain """ # --------------------------------------------------------------------------------------------------------------# if self.domain == "unit-domain": if self.dim == 2: # Create mesh on the unit square mesh = UnitSquareMesh(nx0, nt) elif self.dim == 3: # Create mesh on the unit cube mesh = UnitCubeMesh(nx0, nx1, nt) elif self.domain == "10byT-domain": if self.dim == 2: # Create mesh on the unit square point_1 = Point(0.0, 0.0) point_2 = Point(10.0, self.T) mesh = RectangleMesh(point_1, point_2, nx0, nt, 'left') elif self.domain == "long-rectangle-domain": if self.dim == 2: point_1 = Point(0.0, 0.0) point_2 = Point(1.0, 3.0) mesh = RectangleMesh(point_1, point_2, nx0, nt, 'left') elif self.domain == "rectangular-domain-1x2": if self.dim == 2: point_1 = Point(0.0, 0.0) point_2 = Point(1.0, 2.0) mesh = RectangleMesh(point_1, point_2, nx0, nt, 'left') return mesh
def construct_mesh(self, nx0, nx1, nx2, res, project_path): """ :param nx0, nx1, nx2: mesh-sizes wrt to X, Y, Z directions :param res: mesh resolution if defined with mesh_generator function :param project_path: path of the project to load the mesh :return: mesh:discretization of the domain """ if self.domain == "unit-domain": if self.dim == 1: # Create mesh on the unit interval mesh = UnitIntervalMesh(nx0) elif self.dim == 2: # Create mesh on the unit square mesh = UnitSquareMesh(nx0, nx1) elif self.dim == 3: # Create mesh on the unit cube mesh = UnitCubeMesh(nx0, nx1, nx2) elif self.domain == "l-shape-domain": if self.dim == 2: #data_path = '/data/%dd/test-%d/' % (self.dim, test_num) # file_name = 'l-shape-3d-mmg3d.xml' # file_name = 'l-shape-diam-2sqrt2-33-vertices.xml' #file_name = 'l-shape-3.xml' # file_name = 'l-shape-15-verts.xml' # file_name = 'l-shape-adapt.xml' # file_name = 'l-shape-3d-twice-refined.xml' # file_name = 'l-shape-3d-once-refined.xml' # plot(mesh, interactive=True) # Load mesh from the xml-file #mesh = Mesh(project_path + data_path + file_name) #plot(mesh) # ''' #res = 4 big_square = Rectangle(Point(-1.0, -1.0), Point(1.0, 1.0)) small_square = Rectangle(Point(0.0, -1.0), Point(1.0, 0.0)) mesh = generate_mesh(big_square - small_square, res) #plot(mesh) # ''' elif dim == 3: mesh = generate_mesh( Box(Point(0, 0, 0), Point(1, 1, 1)) + Box(Point(0, 0, 0), Point(-1, 1, 1)) + Box(Point(0, 0, 0), Point(-1, -1, 1)), res) elif self.domain == "pi-shape-domain": data_path = '/data/%dd/test-%d/' % (self.dim, test_num) file_name = 'pi-shape-2.xml' # Load mesh from the xml-file mesh = Mesh(project_path + data_path + file_name) plot(mesh, interactive=True) elif self.domain == "circle-domain": mesh = generate_mesh(Circle(dolfin.Point(0, 0), 1), res) print "num", mesh.num_cells() return mesh
def construct_mesh(self, nx0, nx1, nx2, res, project_path): """ :param nx0, nx1, nx2: mesh-sizes wrt to X, Y, Z directions :param res: mesh resolution if defined with mesh_generator function :param project_path: path of the project to load the mesh :return: mesh:discretization of the domain """ # --------------------------------------------------------------------------------------------------------------# if self.domain == "unit-domain": if self.dim == 1: # Create mesh on the unit interval mesh = UnitIntervalMesh(nx0) elif self.dim == 2: # Create mesh on the unit square mesh = UnitSquareMesh(nx0, nx1) elif self.dim == 3: # Create mesh on the unit cube mesh = UnitCubeMesh(nx0, nx1, nx2) # --------------------------------------------------------------------------------------------------------------# elif self.domain == "circle-domain": # Define the 'resolution' of the mesh res = 4 # Define the radius of the circle rad = 2.0 # Create the circle geometry circle = Circle(Point(0.0, 0.0), rad) # Generate the mesh based on the geometry and the resolution of the mesh mesh = generate_mesh(circle, res) # --------------------------------------------------------------------------------------------------------------# elif self.domain == "l-shape-domain": # Define the data path depending on the problem parameters file_path = '/data/%dd/test-%d/' % (self.dim, test_num) # 2d l-shaped domain mesh file_name = 'l-shape-diam-2sqrt2-33-vertices.xml' # 3d l-shaped domain mesh # file_name = 'l-shape-3d-twice-refined.xml' # file_name = 'l-shape-3d-once-refined.xml' # file_name = 'l-shape-3d-three-refined.xml' # Load mesh from the xml-file mesh = Mesh(project_path + file_path + file_name) # --------------------------------------------------------------------------------------------------------------# elif self.domain == "ring-domain": # Define the 'resolution' of the mesh res = 4 # Define the radius of the circle big_rad = 1.0 small_rad = 0.5 # Create the circle geometry big_circle = Circle(Point(0.0, 0.0), big_rad) small_circle = Circle(Point(0.0, 0.0), small_rad) # Generate the mesh based on the geometry and the resolution of the mesh mesh = generate_mesh(big_circle - small_circle, res) return mesh
def inside(self, x, on_boundary): return near( geoNormals[i].dot(Point(x)-geo._points[geoBndPoints[i]]), 0.0 ) and on_boundary
def _create_mesh(self): return generate_mesh( Cylinder(Point(0.0, 0.0, 0.0), Point(0.0, 0.0, self.H), self.R, self.R), 100)
def _create_mesh(self): L = 0.2 R = 1.0 self.mesh = generate_mesh( Cylinder(Point(0.0, 0.0, L), Point(0.0, 0.0, 0.0), R, R), 64) File("../output/elasticity/mesh.xml") << self.mesh
''' Created on 3 de ago de 2017 @author: weslley ''' from dolfin.cpp.mesh import Point from demos.meshes.geometry import Geometry geo = Geometry( # Points used for face elements (Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)), # Face elements ((0, 1), (1, 2), (2, 3), (3, 0))) ## Face markers #facesMarkers = ( # 1, # 2, # 3, # 4 #)