def test_SameEntitiesInDifferentSMPs(self): nodes = {1: [[0.0, 0.0, 0.0],{}], 2: [[5.0, 0.0, 0.0],{}], 3: [[5.0, 1.0, 0.0],{}]} entity_1 = global_utils.GeometricEntity(23, 102, [1,2]) entity_2 = global_utils.GeometricEntity(24, 102, [2,3]) geom_entities = {102 : [entity_1, entity_2]} smp_dict_1 = {'smp_name': 'domain_1'} smp_dict_2 = {'smp_name': 'domain_2'} smp_mesh ={'write_smp': 1, 'entity_creation': {102: {'Element': {'TrussElement': '15'}}}} main_mp = kratos_utils.MainModelPart() main_mp.AddMesh(smp_dict_1, smp_mesh, nodes, geom_entities) main_mp.AddMesh(smp_dict_2, smp_mesh, nodes, geom_entities) main_mp.WriteMesh("my_file") print(main_mp.NumberOfNodes()) print(main_mp.NumberOfElements()) print(main_mp.NumberOfConditions())
def setUp(self): self.nodes = {1: [[0.0, 0.0, 0.0],{}], 2: [[5.0, 0.0, 0.0],{}], 3: [[5.0, 1.0, 0.0],{}], 4: [[0.0, 1.0, 0.0],{}], 5: [[0.2, 0.0, 0.0],{}], 6: [[0.4, 0.0, 0.0],{}], 7: [[1.0, 1.0, 0.0],{}], 8: [[0.2, 1.0, 0.0],{}], 9: [[0.4, 1.0, 0.0],{}]} entity_1 = global_utils.GeometricEntity(23, 102, [1,2]) entity_2 = global_utils.GeometricEntity(24, 102, [2,3]) entity_3 = global_utils.GeometricEntity(25, 102, [3,4]) entity_4 = global_utils.GeometricEntity(27, 102, [4,1]) entity_5 = global_utils.GeometricEntity(29, 204, [4,1,5,6]) entity_6 = global_utils.GeometricEntity(28, 204, [4,1,2,3]) self.geom_entities = {102 : [entity_1, entity_2, entity_3, entity_4], 204 : [entity_5, entity_6]} self.elements = { 'ShellThinElement3D4N' : [kratos_utils.Element(entity_5, 'ShellThinElement3D4N', '2'), kratos_utils.Element(entity_6, 'ShellThinElement3D4N', '2')], 'TrussElement' : [kratos_utils.Element(entity_1, 'TrussElement', '4'), kratos_utils.Element(entity_2, 'TrussElement', '4'), kratos_utils.Element(entity_3, 'TrussElement', '4'), kratos_utils.Element(entity_4, 'TrussElement', '4')], 'UpdatedLagrangianElement2D4N' : [kratos_utils.Element(entity_5, 'UpdatedLagrangianElement2D4N', '15'), kratos_utils.Element(entity_6, 'UpdatedLagrangianElement2D4N', '15')] } #why is this kratos_utils.Elements ???? self.conditions = { 'SurfaceCondition2D4N' : [kratos_utils.Element(entity_5, 'SurfaceCondition2D4N', '5'), kratos_utils.Element(entity_6, 'SurfaceCondition2D4N', '5')], 'LineLoadCondition2D2N' : [kratos_utils.Element(entity_1, 'LineLoadCondition2D2N', '0'), kratos_utils.Element(entity_2, 'LineLoadCondition2D2N', '0'), kratos_utils.Element(entity_3, 'LineLoadCondition2D2N', '0'), kratos_utils.Element(entity_4, 'LineLoadCondition2D2N', '0')] } self.smp1_dict = {'smp_name': 'domain_custom', 'smp_file_name': 'domain', 'smp_file_path': '/Examples/Structure/Test_1_2D.salome/dat-files/domain.dat'} self.smp1_mesh_dict = {'write_smp': 1, 'entity_creation': {204: {'Element': {'UpdatedLagrangianElement2D4N': '15', 'ShellThinElement3D4N' : '2'}, 'Condition' : {'SurfaceCondition2D4N' : '5'}}, 102: {'Element' : {'TrussElement' : '4'}, 'Condition': {'LineLoadCondition2D2N': '0'}}}} self.serialized_smp1 = {'domain_custom': {'nodes_read': self.nodes, 'submodelpart_information': self.smp1_dict, 'geom_entities_read': [[29, 204, [4, 1, 5, 6]], [28, 204, [4, 1, 2, 3]], [23, 102, [1, 2]], [24, 102, [2, 3]], [25, 102, [3, 4]], [27, 102, [4, 1]]], 'mesh_information': self.smp1_mesh_dict}} self.mp_dict={'domain_custom': self.smp1_mesh_dict} self.serialized_mp={'domain_custom': {'submodelpart_information': {'smp_name': 'domain_custom', 'smp_file_name': 'domain', 'smp_file_path': '/Examples/Structure/Test_1_2D.salome/dat-files/domain.dat'}, 'mesh_information': {'write_smp': 1, 'entity_creation': {204: {'Element': {'UpdatedLagrangianElement2D4N': '15', 'ShellThinElement3D4N': '2'}, 'Condition': {'SurfaceCondition2D4N': '5'}}, 102: {'Element': {'TrussElement': '4'}, 'Condition': {'LineLoadCondition2D2N': '0'}}}}, 'nodes_read': {1: [[0.0, 0.0, 0.0], {}], 2: [[5.0, 0.0, 0.0], {}], 3: [[5.0, 1.0, 0.0], {}], 4: [[0.0, 1.0, 0.0], {}], 5: [[0.2, 0.0, 0.0], {}], 6: [[0.4, 0.0, 0.0], {}], 7: [[1.0, 1.0, 0.0], {}], 8: [[0.2, 1.0, 0.0], {}], 9: [[0.4, 1.0, 0.0], {}]}, 'geom_entities_read': [[23, 102, [1, 2], {}], [24, 102, [2, 3], {}], [25, 102, [3, 4], {}], [27, 102, [4, 1], {}], [29, 204, [4, 1, 5, 6], {}], [28, 204, [4, 1, 2, 3], {}]]}}
def __CreateGeometricEntitiesFromNodes(self, nodes): """This function creates objects of type "GeometricEntity" from Nodes. This is needed for point-based entities in Kratos, e.g. PointLoadCondition, NodalConcentratedElement """ geom_entities = [] for node_id, node_data in nodes.items(): nodal_data = node_data[1] if type(nodal_data) != dict: raise Exception( "wrong datatype for nodal_data, type received: " + str(type(nodal_data))) geom_entities.append( global_utils.GeometricEntity(-1, global_utils.NODE_IDENTIFIER, [node_id], nodal_data)) return geom_entities
def _execute_entity_tests(self, class2test): orig_entity = global_utils.GeometricEntity(125, 203, [1,2], {"NodalData" : 123}) obj2test = class2test( origin_entity=orig_entity, name="SomeName", property_ID=5) self._test_GetID(obj2test) self._test_SetID(obj2test) self._test___eq__(obj2test,class2test) self._test_SetIsAdded(obj2test) self._test_IsAddedAlready(obj2test) self._test_ResetWritingInfo(obj2test) self._test___str__(obj2test,class2test) # self._test_GetWriteLineNode(class2test) # self._test_GetWriteLineGeomEntity(class2test) self._test_HasEntityData(obj2test) self._test_GetEntityData(obj2test) self._test_GetNodeList(obj2test)
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)
def _test___eq__(self,obj2test,class2test): other_entity = global_utils.GeometricEntity(125, 203, [1,2], {"NodalData" : 123}) other_obj = class2test( origin_entity=other_entity, name="SomeName", property_ID=5) self.assertTrue(obj2test.__eq__(other_obj))