def __init__(self, name, mesh, verbose=False): """Create a Domain. Parameters ---------- name : str Object name. mesh : Mesh A mesh defining the domain. """ geom_els = {} for ig, desc in enumerate(mesh.descs): gel = GeometryElement(desc) # Create geometry elements of dimension - 1. gel.create_surface_facet() geom_els[desc] = gel interps = {} for gel in geom_els.itervalues(): key = gel.get_interpolation_name() gel.interp = interps.setdefault(key, fea.Interpolant(key, gel)) gel = gel.surface_facet if gel is not None: key = gel.get_interpolation_name() gel.interp = interps.setdefault(key, fea.Interpolant(key, gel)) Struct.__init__(self, name=name, mesh=mesh, geom_els=geom_els, geom_interps=interps) self.mat_ids_to_i_gs = {} for ig, mat_id in enumerate(mesh.mat_ids): self.mat_ids_to_i_gs[mat_id[0]] = ig self.setup_groups() self.fix_element_orientation() self.reset_regions() self.clear_surface_groups() from sfepy.fem.geometry_element import create_geometry_elements from sfepy.fem.extmods.cmesh import CMesh self.cmesh = CMesh.from_mesh(mesh) gels = create_geometry_elements() self.cmesh.set_local_entities(gels) self.cmesh.setup_entities() self.shape.tdim = self.cmesh.tdim
def test_cmesh_counts(self): from sfepy.fem import Mesh from sfepy.fem.geometry_element import create_geometry_elements from sfepy.fem.extmods.cmesh import CMesh, get_cmem_usage gels = create_geometry_elements() ok = True for filename in self.filename_meshes: basename = os.path.basename(filename) enum, esizes = expected[basename] self.report('mesh: %s' % basename) mesh = Mesh.from_file(filename) cmesh = CMesh.from_mesh(mesh) cmesh.set_local_entities(gels) cmesh.setup_entities() self.report('dim:', cmesh.dim) self.report('n_cell: %d, n_face: %d, n_edge: %d, n_vertex: %d' % tuple(cmesh.num)) _ok = (enum == cmesh.num).all() if not _ok: self.report('%s == %s failed!' % (enum, cmesh.num)) ok = ok and _ok dim = cmesh.dim for ir in range(dim + 1): for ic in range(dim + 1): cmesh.setup_connectivity(ir, ic) mem_usage1 = get_cmem_usage()[0] if (ir == dim) and (ic == 0): continue cmesh.free_connectivity(ir, ic) mem_usage2 = get_cmem_usage()[0] cmesh.setup_connectivity(ir, ic) mem_usage3 = get_cmem_usage()[0] conn = cmesh.get_conn(ir, ic) self.report('(%d, %d) : (%d, %d)' % (ir, ic, conn.num, conn.n_incident)) sizes = nm.array([conn.num, conn.n_incident]) _ok = (esizes[ir, ic] == sizes).all() if not _ok: self.report('%s == %s failed!' % (esizes, sizes)) ok = ok and _ok _ok1 = mem_usage3 == mem_usage1 _ok2 = mem_usage3 > mem_usage2 if not (_ok1 and _ok2): self.report('unexpected memory usage! (%s)' % (mem_usage1, mem_usage2, mem_usage3)) ok = ok and (_ok1 and _ok2) return ok