Пример #1
0
 def _set_boundary_flags(self):
     bmesh = fa.BoundaryMesh(self.mesh, "exterior", True)
     bmesh_coos = bmesh.coordinates()
     boundary_flags = np.zeros(self.num_vertices)
     for i in range(self.num_vertices):
         for bcoo in bmesh_coos:
             if np.linalg.norm(bcoo - self.coo_dof[i]) < 1e-8:
                 boundary_flags[i] = 1
     # print(boundary_flags.sum())
     self.boundary_flags = boundary_flags
Пример #2
0
    def generate_holes(self):

        fname = os.path.join(self.fem_solution_storage_dir, 'holes.txt')
        if self.use_available_hole_data and os.path.exists(fname):
            print('Found a file containing the hole data')
            self.hole_coordinates = np.loadtxt(fname)
            return

        boundary = fe.BoundaryMesh(self.mesh, 'exterior')
        bbtree = fe.BoundingBoxTree()
        bbtree.build(boundary)

        np.random.seed(123)

        N = self.n_holes

        if not self.enforce_radius_of_holes:
            self.hole_radius = np.sqrt(self.hole_fractional_volume *\
                    self.mesh_volume / np.pi / N)

        print('Hole radius:', self.hole_radius)
        gap = 0.15
        max_n_tries = 1e7
        counter = 0
        L = []

        while len(L) < N and counter < max_n_tries:

            counter += 1
            x = np.random.rand() * 8 - 4
            y = np.random.rand() * 4.8 - 2.4
            p = np.array([x, y])
            p_fenics = fe.Point(p)
            _, distance_to_boundary = bbtree.compute_closest_entity(p_fenics)

            rejected = False

            if distance_to_boundary < self.hole_radius + gap:
                continue

            for c in L:
                if np.linalg.norm(c - p) < 2 * self.hole_radius + gap:
                    rejected = True
                    break

            if not rejected:
                L.append(p)

        self.hole_coordinates = np.array(L)
        fname = os.path.join(self.fem_solution_storage_dir, 'holes.txt')
        np.savetxt(fname, L)

        print('Found', N, 'circles in', counter, 'trials')
Пример #3
0
        for key, value in _Faces.items():
            _Faces[key] = list(map(int, value))
        for key, value in _groups.items():
            _groups[key] = list(map(int, value))
        return _groups, _Faces


ImportedMesh = MeshImport("./UserFiles/myMesh.unv")
ImportedMesh.UNVtoXMLConverter()
Edges, Faces = ImportedMesh.MeshGroups()

mesh = fn.Mesh("./UserFiles/mesh.xml")

V = fn.FunctionSpace(mesh, 'CG', 1)
# Create subdomains
BoundaryEdges = fn.BoundaryMesh(mesh, 'exterior').entity_map(1).array()
BoundaryNodes = fn.BoundaryMesh(mesh, 'exterior').entity_map(0).array()
boundaries = fn.MeshFunction('size_t', mesh, dim=1)
boundaries.set_all(0)
interior = {}
idx = 1
for key, nodes in Edges.items():
    if all(item in BoundaryNodes for item in nodes):
        for node in nodes:
            ver = fn.Vertex(mesh, node)
            for edge in fn.edges(ver):
                if edge.index() in BoundaryEdges:
                    entity = edge.entities(0)
                    if all(item in nodes for item in entity):
                        boundaries[edge.index()] = idx
        idx += 1