def test_has_cells(self): """Test has_cells method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) self.assertTrue(num_mesh.has_type(CUBA.CELL))
def test_has_faces(self): """Test has_faces method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) self.assertTrue(num_mesh.has_type(CUBA.FACE))
def test_update_faces(self): """Test update_faces method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) with self.assertRaises(NotImplementedError): num_mesh.update(self.faces)
def test_update_edges(self): """Test update_edges method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) with self.assertRaises(NotImplementedError): num_mesh.update([Edge([self.puids, self.puids[3]])])
def test_iter_edges(self): """Test iter_edges method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) self.assertEqual(sum(1 for _ in num_mesh.iter(item_type=CUBA.EDGE)), num_mesh.count_of(CUBA.EDGE))
def test_add_cells(self): """Test add_cells method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) with self.assertRaises(NotImplementedError): num_mesh.add(self.cells)
def test_get_cell(self): """Test get_cell method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) cell = self.cells[0] cell_f = num_mesh.get(cell.uid) self.assertEqual(set(cell.points), set(cell_f.points))
def test_get_face(self): """Test get_face method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) face = self.faces[4] face_f = num_mesh.get(face.uid) self.assertEqual(face.points, face_f.points)
def test_get_edge(self): """Test get_edge method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) uid = num_mesh._numEdgeLabelToUuid[0] edge = num_mesh.get(uid) self.assertEqual(edge.uid, uid)
def test_iter_faces(self): """Test iter_faces method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) for face_f in num_mesh.iter(item_type=CUBA.FACE): face = self.mesh.get(face_f.uid) self.assertEqual(face.points, face_f.points)
def test_update_points(self): """Test update_points method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) points = self.points points[0].data[CUBA.VELOCITY] = (2, 1, 3) num_mesh.update(points) point_f = num_mesh.get(points[0].uid) self.assertIsInstance(point_f.data, DataContainer) self.assertEqual(points[0].data, point_f.data)
def test_iter_points(self): """Test iter_points method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) for point_f in num_mesh.iter(item_type=CUBA.POINT): point = self.mesh.get(point_f.uid) self.assertEqual(point.data[CUBA.VELOCITY], point_f.data[CUBA.VELOCITY]) self.assertEqual(point.data[CUBA.PRESSURE], point_f.data[CUBA.PRESSURE])
def test_get_point(self): """Test get_point method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) point = self.points[4] point_f = num_mesh.get(point.uid) self.assertEqual(point.coordinates, point_f.coordinates) self.assertEqual(point.data[CUBA.PRESSURE], point_f.data[CUBA.PRESSURE]) self.assertEqual(point.data[CUBA.VELOCITY], point_f.data[CUBA.VELOCITY])
def test_count_of(self): """Test count_of method """ num_mesh = NumerrinMesh('test_mesh', self.mesh, self.pool) item_type = CUBA.POINT self.assertEqual(num_mesh.count_of(item_type), self.mesh.count_of(item_type)) item_type = CUBA.EDGE self.assertEqual(num_mesh.count_of(item_type), 12) item_type = CUBA.FACE self.assertEqual(num_mesh.count_of(item_type), self.mesh.count_of(item_type)) item_type = CUBA.CELL self.assertEqual(num_mesh.count_of(item_type), self.mesh.count_of(item_type))
def test_generate_code(self): """Test generate_init_code and generate_code method """ CM = DataContainer() SP = DataContainer() SPExt = DataContainer() BC = DataContainer() CMExt = {} mesh_name = "Mesh" CM[CUBA.NAME] = mesh_name CMExt[CUBAExt.GE] = (CUBAExt.INCOMPRESSIBLE, CUBAExt.LAMINAR_MODEL) SP[CUBA.TIME_STEP] = 1 SP[CUBA.NUMBER_OF_TIME_STEPS] = 2 SP[CUBA.DENSITY] = 1.0 SP[CUBA.DYNAMIC_VISCOSITY] = 1.0 BC[CUBA.VELOCITY] = {'boundary0': ('fixedValue', (0.1, 0, 0))} BC[CUBA.PRESSURE] = {'boundary0': 'zeroGradient'} boundary_names = ['boundary0', 'boundary1', 'boundary2', 'boundary3'] corner_points = ((0.0, 0.0), (20.0e-3, 0.0), (20.0e-3, 1.0e-3), (0.0, 1.0e-3)) mesh_code = textwrap.dedent(""" pts={%f,%f;%f,%f;%f,%f;%f,%f} Quadmesh(pts,{%i,%i},{0,0,0,0},{1.0,1.0,-1.0,-1.0},mesh2d,domains2d) dvec[0:1]=0.0 dvec[2]=%f Extrude(mesh2d,domains2d,dvec,%i,0,0.0,%s,domains) omega->domains[0] %s->domains[6] %s->domains[4] %s=Union(domains[3],domains[5]) %s=Union(domains[1],domains[2]) """ % (corner_points[0][0], corner_points[0][1], corner_points[1][0], corner_points[1][1], corner_points[2][0], corner_points[2][1], corner_points[3][0], corner_points[3][1], 1, 1, 1.0, 1, mesh_name, mesh_name+boundary_names[0], mesh_name+boundary_names[1], mesh_name+boundary_names[2], mesh_name+boundary_names[3])) self.code.parse_string(mesh_code) self.code.execute(1) smesh, _, boundaries = self.pool.export_mesh('simmesh', mesh_name, boundary_names) nummesh = NumerrinMesh(mesh_name, smesh, self.pool) uidmap = nummesh._uuidToNumLabel boundary_faces = {} for boundary in boundaries: boundary_faces[boundary] = [] for fuid in boundaries[boundary]: boundary_faces[boundary].append(uidmap[fuid]) nummesh.pool.add_boundaries(mesh_name, boundaries, boundary_faces) nummesh._boundaries = boundaries for key in SP: self.pool.put_variable(numname[key], SP[key]) nummesh.init_point_variables(get_numerrin_solver(CMExt)) codestring = self.code.generate_init_code(CM, SP, SPExt, BC, CMExt) codestring += self.code.generate_code(CM, SP, SPExt, BC, CMExt, nummesh) self.code.parse_string(codestring) self.assertEqual(self.pool.variable_type(mesh_name), "Mesh") self.assertEqual(self.pool.variable_type(numname[CUBA.TIME_STEP]), "Integer") self.assertEqual(self.pool.variable_type(numname[CUBA.DENSITY]), "Real")
def test_generate_code(self): """Test generate_init_code and generate_code method """ CM = DataContainer() SP = DataContainer() SPExt = DataContainer() BC = DataContainer() CMExt = {} mesh_name = "Mesh" CM[CUBA.NAME] = mesh_name CMExt[CUBAExt.GE] = (CUBAExt.INCOMPRESSIBLE, CUBAExt.LAMINAR_MODEL) SP[CUBA.TIME_STEP] = 1 SP[CUBA.NUMBER_OF_TIME_STEPS] = 2 SP[CUBA.DENSITY] = 1.0 SP[CUBA.DYNAMIC_VISCOSITY] = 1.0 BC[CUBA.VELOCITY] = {'boundary0': ('fixedValue', (0.1, 0, 0))} BC[CUBA.PRESSURE] = {'boundary0': 'zeroGradient'} boundary_names = ['boundary0', 'boundary1', 'boundary2', 'boundary3'] corner_points = ((0.0, 0.0), (20.0e-3, 0.0), (20.0e-3, 1.0e-3), (0.0, 1.0e-3)) mesh_code = textwrap.dedent( """ pts={%f,%f;%f,%f;%f,%f;%f,%f} Quadmesh(pts,{%i,%i},{0,0,0,0},{1.0,1.0,-1.0,-1.0},mesh2d,domains2d) dvec[0:1]=0.0 dvec[2]=%f Extrude(mesh2d,domains2d,dvec,%i,0,0.0,%s,domains) omega->domains[0] %s->domains[6] %s->domains[4] %s=Union(domains[3],domains[5]) %s=Union(domains[1],domains[2]) """ % (corner_points[0][0], corner_points[0][1], corner_points[1][0], corner_points[1][1], corner_points[2][0], corner_points[2][1], corner_points[3][0], corner_points[3][1], 1, 1, 1.0, 1, mesh_name, mesh_name + boundary_names[0], mesh_name + boundary_names[1], mesh_name + boundary_names[2], mesh_name + boundary_names[3])) self.code.parse_string(mesh_code) self.code.execute(1) smesh, _, boundaries = self.pool.export_mesh('simmesh', mesh_name, boundary_names) nummesh = NumerrinMesh(mesh_name, smesh, self.pool) uidmap = nummesh._uuidToNumLabel boundary_faces = {} for boundary in boundaries: boundary_faces[boundary] = [] for fuid in boundaries[boundary]: boundary_faces[boundary].append(uidmap[fuid]) nummesh.pool.add_boundaries(mesh_name, boundaries, boundary_faces) nummesh._boundaries = boundaries for key in SP: self.pool.put_variable(numname[key], SP[key]) nummesh.init_point_variables(get_numerrin_solver(CMExt)) codestring = self.code.generate_init_code(CM, SP, SPExt, BC, CMExt) codestring += self.code.generate_code(CM, SP, SPExt, BC, CMExt, nummesh) self.code.parse_string(codestring) self.assertEqual(self.pool.variable_type(mesh_name), "Mesh") self.assertEqual(self.pool.variable_type(numname[CUBA.TIME_STEP]), "Integer") self.assertEqual(self.pool.variable_type(numname[CUBA.DENSITY]), "Real")