def test_compare_mesh_datasets_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test") point_list = create_particles_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = DataContainer() mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) reference.add_points(point_list) reference.add_edges(edge_list) reference.add_faces(face_list) reference.add_cells(cell_list) mesh.data = data reference.data = data # this should pass without problems compare_mesh_datasets(mesh, reference, testcase=self)
def test_compare_mesh_datasets_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test") point_list = create_points_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = DataContainer() mesh.add(point_list) mesh.add(edge_list) mesh.add(face_list) mesh.add(cell_list) reference.add(point_list) reference.add(edge_list) reference.add(face_list) reference.add(cell_list) mesh.data = data reference.data = data # this should pass without problems compare_mesh_datasets(mesh, reference, testcase=self)
def read_modelpart_as_mesh(self, filename): """ Reads a Kratos formated modelpart from DEM """ model_part = KRTS.ModelPart("Fluid") model_part.AddNodalSolutionStepVariable(KRTS.RADIUS) model_part.AddNodalSolutionStepVariable(KRTSDEM.PARTICLE_DENSITY) model_part.AddNodalSolutionStepVariable(KRTS.VELOCITY) model_part_io_fluid = KRTS.ModelPartIO(filename) model_part_io_fluid.ReadModelPart(model_part) smp_meshes = [] smp_conditions = [] smp_materials = [] dem_fem_pe = api.Cfd() dem_fem_pe.data[CUBA.DATA_SET] = [] for i in xrange(1, model_part.NumberOfMeshes()): mesh_name = 'solid_' + str(i) mesh = SMesh(name=mesh_name) # Export mesh data to Simphony self.exportKratosNodes(model_part, mesh, i) self.exportKratosElements(model_part, mesh, i) self.exportKratosConditions(model_part, mesh, i) properties = model_part.GetProperties(0)[i] # Fill the boundary condition for the mesh condition = self.convertBc(properties, mesh_name) # Fill the material for the mesh material = self.convertMaterial(properties, mesh_name) # Save the relations meshData = mesh.data meshData[CUBA.CONDITION] = condition.name meshData[CUBA.MATERIAL] = material.name mesh.data = meshData # Pack the return objects smp_meshes.append(mesh) smp_conditions.append(condition) smp_materials.append(material) # Add to the pe? dem_fem_pe.data[CUBA.DATA_SET].append(mesh.name) return { 'datasets': smp_meshes, 'conditions': smp_conditions, 'materials': smp_materials, 'pe': dem_fem_pe, }
def test_compare_mesh_datasets_not_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test_ref") point_list = create_particles_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = create_data_container() mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) reference.add_points(point_list) reference.add_edges(edge_list) reference.add_faces(face_list) reference.add_cells(cell_list) mesh.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_points = create_points_with_id() mesh = Mesh(name=reference.name) mesh.add_points(test_points) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_edges = create_edges() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(test_edges) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_faces = create_faces() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(test_faces) mesh.add_cells(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_cells = create_cells() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(test_cells) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_data = DataContainer() mesh = Mesh(name=reference.name) mesh.add_points(point_list) mesh.add_edges(edge_list) mesh.add_faces(face_list) mesh.add_cells(cell_list) mesh.data = test_data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self)
def test_compare_mesh_datasets_not_equal(self): # given mesh = Mesh(name="test") reference = Mesh(name="test_ref") point_list = create_points_with_id() edge_list = create_edges() face_list = create_faces() cell_list = create_cells() data = create_data_container() mesh.add(point_list) mesh.add(edge_list) mesh.add(face_list) mesh.add(cell_list) reference.add(point_list) reference.add(edge_list) reference.add(face_list) reference.add(cell_list) mesh.data = data reference.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_points = create_points_with_id() mesh = Mesh(name=reference.name) mesh.add(test_points) mesh.add(edge_list) mesh.add(face_list) mesh.add(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_edges = create_edges() mesh = Mesh(name=reference.name) mesh.add(point_list) mesh.add(test_edges) mesh.add(face_list) mesh.add(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_faces = create_faces() mesh = Mesh(name=reference.name) mesh.add(point_list) mesh.add(edge_list) mesh.add(test_faces) mesh.add(cell_list) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_cells = create_cells() mesh = Mesh(name=reference.name) mesh.add(point_list) mesh.add(edge_list) mesh.add(face_list) mesh.add(test_cells) mesh.data = data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self) # given test_data = DataContainer() mesh = Mesh(name=reference.name) mesh.add(point_list) mesh.add(edge_list) mesh.add(face_list) mesh.add(cell_list) mesh.data = test_data # when/then with self.assertRaises(AssertionError): compare_mesh_datasets(mesh, reference, testcase=self)
def read_modelpart(self, filename): """ Reads a Kratos formated modelpart for KratosCFD wrapper This functions translates each of the modelpart meshes to one simphony mesh. Properties in the modelpart related to boundary conditions are stored in simphony conditions and referenced in CUBA.CONDITION inside the mesh. Properties in the modelpart not relared to boundary conditions are stored in simphony as materials and referenced in CUBA.MATERIAL inside the mesh. """ model_part = KRTS.ModelPart("FluidPart") self.addNodalVariablesToModelpart(model_part) model_part_io_fluid = KRTS.ModelPartIO(filename) model_part_io_fluid.ReadModelPart(model_part) smp_meshes = [] smp_conditions = [] smp_materials = [] cfd_pe = api.Cfd() cfd_pe.data[CUBA.DATA_SET] = [] for i in xrange(1, model_part.NumberOfMeshes()): mesh_name = 'fluid_' + str(i) mesh = SMesh(name=mesh_name) # Export mesh data to Simphony self.exportKratosNodes(model_part, mesh, i) self.exportKratosElements(model_part, mesh, i) self.exportKratosConditions(model_part, mesh, i) properties = model_part.GetProperties(0)[i] # Fill the boundary condition for the mesh condition = self._convertBc(properties, mesh_name) # Fill the material for the mesh material = self._convertMaterial(properties, mesh_name) # Save the relations meshData = mesh.data meshData[CUBA.CONDITION] = condition.name meshData[CUBA.MATERIAL] = material.name mesh.data = meshData # Pack the return objects smp_meshes.append(mesh) smp_conditions.append(condition) smp_materials.append(material) # Add to the pe? cfd_pe.data[CUBA.DATA_SET].append(mesh.name) return { 'datasets': smp_meshes, 'conditions': smp_conditions, 'materials': smp_materials, 'pe': cfd_pe, }