示例#1
0
    def test_DoubleSerializing(self):
        smp_generic = kratos_utils.MeshSubmodelPart()

        self._fill_smp(smp_generic) # Must not throw!

        serialized_smp = smp_generic.Serialize()

        obj2test = kratos_utils.MeshSubmodelPart()

        obj2test.Deserialize("domain_custom", serialized_smp["domain_custom"])

        self._test_smp_for_correctness(obj2test)
示例#2
0
    def _test_Serialize(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with self.assertRaises(RuntimeError): # Throws bcs the obj2test is not properly initialized!
            obj2test.Serialize()

        self._fill_smp(obj2test) # Must not throw!

        serialized_smp = obj2test.Serialize()

        self.assertDictEqual(self.serialized_smp, serialized_smp)
示例#3
0
    def test_ValidateMeshDict(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        # these are the default values
        default_mesh_dict = {
            "entity_creation" : {},
            "write_smp"       : True
        }

        dict2validate = {}
        obj2test.__ValidateMeshDict(dict2validate)

        self.assertDictEqual(default_mesh_dict, dict2validate)
示例#4
0
    def test_ValidateSMPInfoDict(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        # these are the default values
        default_smp_info_dict = {
            "smp_name"      : "PLEASE_SPECIFY_SUBMODELPART_NAME",
            "smp_file_name" : "",
            "smp_file_path" : ""
        }

        dict2validate = {}
        obj2test.__ValidateSMPInfoDict(dict2validate)

        self.assertDictEqual(default_smp_info_dict, dict2validate)
示例#5
0
    def _test_WriteMeshInfo(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with open(self.test_file, "w") as test_file:
            with self.assertRaisesRegex(RuntimeError,"MeshSubmodelPart is not properly initialized!"):
                obj2test.WriteMeshInfo(test_file)

        self._fill_smp(obj2test)
        obj2test.Assemble()

        with open(self.test_file, "w") as test_file:
            obj2test.WriteMeshInfo(test_file)

        self.assertTrue(filecmp.cmp(self.write_mesh_info_ref_file, self.test_file))
示例#6
0
    def test_Update(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        smp_dict_new = {'smp_file_name': 'dirichlet', 'smp_name': 'dirichlet_name', 'smp_file_path': '/Examples/Structure/Test_1_2D.salome/dat-files/dirichlet.dat'}
        mesh_dict_new = {'entity_creation': {204: {'Element': {'TotalLagrangianElement2D4N': '15'}}, 102: {'Condition': {'Condition2D2N': '0'}}}, 'write_smp': 1}

        with self.assertRaises(RuntimeError): # Throws bcs the obj2test is not properly initialized!
            obj2test.Update(smp_dict_new, mesh_dict_new)

        self._fill_smp(obj2test) # Must not throw!

        obj2test.Update(smp_dict_new, mesh_dict_new)

        self.assertDictEqual(smp_dict_new, obj2test.GetInfoDict())
        self.assertDictEqual(mesh_dict_new, obj2test.GetMeshInfoDict())
示例#7
0
    def test_CreateGeometricEntitiesFromNodes(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        geom_entities_from_nodes = obj2test.__CreateGeometricEntitiesFromNodes(self.nodes)

        reference_geom_entities = [
            global_utils.GeometricEntity(-1, 101, [1]),
            global_utils.GeometricEntity(-1, 101, [2]),
            global_utils.GeometricEntity(-1, 101, [3]),
            global_utils.GeometricEntity(-1, 101, [4]),
            global_utils.GeometricEntity(-1, 101, [5]),
            global_utils.GeometricEntity(-1, 101, [6])
        ]

        self.assertEqual(len(geom_entities_from_nodes), len(reference_geom_entities))

        for created_entitiy, ref_entity in zip(geom_entities_from_nodes, reference_geom_entities):
            self.assertEqual(created_entitiy, ref_entity)
示例#8
0
    def test_WriteMesh(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with open(self.test_file, "w") as test_file:
            with self.assertRaisesRegex(RuntimeError,"MeshSubmodelPart is not properly initialized!"):
                obj2test.WriteMesh(test_file)

        self._fill_smp(obj2test)
        obj2test.Assemble()

        nodes, elements, conditions = obj2test.GetMesh()

        # Hackish way to assign new IDs, bcs Elements and Conditions throw if the didn't get assigned a new ID!
        index = 1
        for elem_name in sorted(elements.keys()):
            new_elems = elements[elem_name]
            for i in range(len(new_elems)):
                new_elems[i].new_ID = index
                index +=1

        index = 1
        for elem_name in sorted(conditions.keys()):
            new_conds = conditions[elem_name]
            for i in range(len(new_conds)):
                new_conds[i].new_ID = index
                index +=1

        with open(self.test_file, "w") as test_file:
            obj2test.WriteMesh(test_file, readable_mdpa=True)

        self.assertTrue(filecmp.cmp(self.write_mesh_readable_ref_file, self.test_file))

        with open(self.test_file, "w") as test_file:
            obj2test.WriteMesh(test_file)

        self.assertTrue(filecmp.cmp(self.write_mesh_ref_file, self.test_file))
示例#9
0
 def test_CheckIsProperlyInitialized(self):
     obj2test = kratos_utils.MeshSubmodelPart()
     with self.assertRaisesRegex(RuntimeError,"MeshSubmodelPart is not properly initialized!"):
         obj2test.__CheckIsProperlyInitialized()
示例#10
0
 def test_CheckIsAssembled(self):
     obj2test = kratos_utils.MeshSubmodelPart()
     obj2test.is_properly_initialized = True
     with self.assertRaisesRegex(RuntimeError,"MeshSubmodelPart was not assembled!"):
         obj2test.__CheckIsAssembled()
示例#11
0
    def test_GetFilePath(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        self.assertEqual(obj2test.GetFilePath(), "")
示例#12
0
    def test_NumberOfConditions(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with self.assertRaises(RuntimeError): # Throws bcs the obj2test is not properly initialized!
            obj2test.NumberOfConditions()
示例#13
0
    def test_GetMeshInfoDict(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with self.assertRaises(RuntimeError): # Throws bcs the obj2test is not properly initialized!
            obj2test.GetMeshInfoDict()
示例#14
0
    def test_GetGeomEntites(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with self.assertRaises(AttributeError): # Throws bcs the obj2test is not properly initialized!
            obj2test.GetGeomEntites()
示例#15
0
    def test_FillWithEntities(self):
        obj2test = kratos_utils.MeshSubmodelPart()
        self._fill_smp(obj2test) # Must not throw!

        self._test_smp_for_correctness(obj2test)
示例#16
0
    def test_Assemble(self):
        obj2test = kratos_utils.MeshSubmodelPart()

        with self.assertRaisesRegex(RuntimeError,"MeshSubmodelPart is not properly initialized!"): # Throws bcs the obj2test is not properly initialized!
            obj2test.Assemble()