def Initialize(self): print("::[Meshing Contact Domain]:: -START-") self.domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] self.mesh_id = 0 # Set MeshingParameters self.SetMeshingParameters() # Create contact domain model_part if( not self.main_model_part.HasSubModelPart(self.settings["model_part_name"].GetString()) ): self.main_model_part.CreateSubModelPart(self.settings["model_part_name"].GetString()) contact_model_part_names = self.settings["contact_sub_model_part_list"] self.contact_parts = KratosContact.StringVector() for i in range(contact_model_part_names.size()): self.contact_parts.PushBack(contact_model_part_names[i].GetString()) # transforms list to a std vector self.build_contact_model_part = KratosContact.BuildContactModelPart(self.main_model_part, self.MeshingParameters, self.contact_parts, self.echo_level) self.build_contact_model_part.Execute() # Meshing Stratety self.MeshingStrategy.Initialize(self.MeshingParameters, self.domain_size) print("::[Meshing Contact Domain]:: -END- ")
def RemeshDomains(self): if (self.echo_level > 0): print("::[Meshing_Process]:: CONTACT SEARCH...( call:", self.counter, ")") meshing_options = KratosMultiphysics.Flags() self.model_meshing = KratosContact.ContactModelMeshing( self.main_model_part, meshing_options, self.echo_level) self.model_meshing.ExecuteInitialize() for domain in self.meshing_domains: domain.ExecuteMeshing() self.model_meshing.ExecuteFinalize() if (self.echo_level > 1): print("") print(self.main_model_part) self.counter += 1 # schedule next meshing if (self.meshing_frequency > 0.0): # note: if == 0 always active if (self.meshing_control_is_time): time = self.main_model_part.ProcessInfo[ KratosMultiphysics.TIME] while (self.next_meshing <= time): self.next_meshing += self.meshing_frequency else: while (self.next_meshing <= self.step_count): self.next_meshing += self.meshing_frequency
def SetPreMeshingProcesses(self): # The order set is the order of execution: # clear contact conditions clear_contact_conditions= KratosContact.ClearContactConditions(self.model_part, self.echo_level) self.mesher.SetPreMeshingProcess(clear_contact_conditions)
def Initialize(self, dimension): self.dimension = dimension # set mesh modeler if(self.dimension == 2): self.mesher = KratosContact.ContactDomain2DModeler() elif(self.dimension == 3): self.mesher = KratosContact.ContactDomain3DModeler() self.mesher.SetEchoLevel(self.echo_level) self.mesher.SetMeshingParameters(self.MeshingParameters) self.SetPreMeshingProcesses() self.SetPostMeshingProcesses() self.mesher.Initialize()
def SetPostMeshingProcesses(self): # The order set is the order of execution: #select mesh elements select_mesh_elements = KratosPfemBase.SelectMeshElements( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) # build contact conditions build_contact_conditions = KratosContact.BuildContactConditions( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(build_contact_conditions)
def SetPostMeshingProcesses(self): # The order set is the order of execution: #print GiD mesh output for checking purposes print_output_mesh = KratosPfem.PrintOutputMeshProcess(self.model_part, self.MeshingParameters, "output", self.echo_level) self.mesher.SetPostMeshingProcess(print_output_mesh) #select mesh elements select_mesh_elements = KratosPfem.SelectMeshElements(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) # build contact conditions build_contact_conditions= KratosContact.BuildContactConditions(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(build_contact_conditions)
def Initialize(self): contact_model_part_names = self.settings["contact_bodies_list"] if contact_model_part_names.size(): self.contact_parts = [] for i in range(contact_model_part_names.size()): self.contact_parts.append( contact_model_part_names[i].GetString()) model_part = self.model[self.contact_parts[0]] else: print(self._class_prefix() + " ERROR, contact model parts not supplied ") self.main_model_part = model_part.GetRootModelPart() self.dimension = self.main_model_part.ProcessInfo[ KratosMultiphysics.SPACE_DIMENSION] # Create contact search strategy meshing_module = __import__( self.settings["meshing_strategy"]["python_module"].GetString()) self.MeshingStrategy = meshing_module.CreateMeshingStrategy( self.main_model_part, self.settings["meshing_strategy"]) # Set MeshingParameters self.SetMeshingParameters() # Create contact domain model_part if not self.main_model_part.HasSubModelPart( self.settings["model_part_name"].GetString()): self.main_model_part.CreateSubModelPart( self.settings["model_part_name"].GetString()) self.build_contact_model_part = KratosContact.BuildContactModelPart( self.main_model_part, self.MeshingParameters, self.contact_parts, self.echo_level) self.build_contact_model_part.Execute() # Meshing Stratety self.MeshingStrategy.Initialize(self.MeshingParameters, self.dimension) print(self._class_prefix() + " (" + self.settings["model_part_name"].GetString() + ") Ready")
def SearchContact(self): if self.echo_level > 0: print(self._class_prefix() + " [ Contact Search (call:", str(self.counter) + ") ]") self.wall_contact_model = KratosContact.ClearPointContactConditions( self.main_model_part, self.echo_level) self.wall_contact_model.ExecuteInitialize() # serial for wall in self.parametric_walls: wall.ExecuteSearch() # parallel (not working pickling instances not enabled) # walls_number = len(self.parametric_walls) # if(walls_number>8): # walls_number = 8 # pool = Pool(walls_number) # pool.map(self.ExecuteSearch,self.parametric_walls) # pool.close() # pool.joint() self.wall_contact_model.ExecuteFinalize() self.counter += 1 # schedule next search if (self.search_frequency > 0.0): # note: if == 0 always active if (self.search_control_is_time): time = self.main_model_part.ProcessInfo[ KratosMultiphysics.TIME] while (self.next_search <= time): self.next_search += self.search_frequency else: while self.next_search <= self.step_count: self.next_search += self.search_frequency
def SearchContact(self): if (self.echo_level > 0): print("::[Walls_Process]:: CONTACT SEARCH...( call:", self.counter, ")") self.wall_contact_model = KratosContact.ClearPointContactConditions( self.main_model_part, self.echo_level) self.wall_contact_model.ExecuteInitialize() #serial for wall in self.parametric_walls: wall.ExecuteSearch() #parallel (not working pickling instances not enabled) #walls_number = len(self.parametric_walls) #if(walls_number>8): # walls_number = 8 #pool = Pool(walls_number) #pool.map(self.ExecuteSearch,self.parametric_walls) #pool.close() #pool.joint() self.wall_contact_model.ExecuteFinalize() self.counter += 1 # schedule next search if (self.search_frequency > 0.0): # note: if == 0 always active if (self.search_control_is_time): while (self.next_search <= time): self.next_search += self.search_frequency else: while self.next_search <= self.step_count: self.next_search += self.search_frequency
def __init__(self, main_model_part, custom_settings): self.main_model_part = main_model_part ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "python_module" : "rigid_body", "model_part_name" : "RigidBodyDomain", "rigid_body_settings":{ "rigid_body_element_type": "TranslatoryRigidElement3D1N", "fixed_body": true, "compute_body_parameters": false, "rigid_body_model_part_name": "RigidBodyDomain", "rigid_body_parameters":{ "center_of_gravity": [0.0 ,0.0, 0.0], "mass":0.0, "main_inertias": [0.0, 0.0, 0.0], "main_axes": [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] } } } """) ## new node and rigid body element inside the same mesh : boundary conditions also applied ## this node and elements must be considered in the computing model part ## new contact conditions must be already assembled ## if exist a movement from a point different from CG a link condition must be used ##overwrite the default settings with user-provided parameters self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) # construct rigid body // it will contain the array of nodes, array of elements, and the array of conditions self.rigid_body_model_part = self.main_model_part.GetSubModelPart(self.settings["model_part_name"].GetString()) self.rigid_body_model_part.Set(KratosMultiphysics.RIGID) for node in self.rigid_body_model_part.Nodes: node.Set(KratosMultiphysics.RIGID,True) for node in self.rigid_body_model_part.Conditions: node.Set(KratosMultiphysics.ACTIVE,False) #check for the bounding box of a compound wall box_settings = KratosMultiphysics.Parameters(""" { "parameters_list":[{ "upper_point": [0.0, 0.0, 0.0], "lower_point": [0.0, 0.0, 0.0], "convexity": 1 }], "velocity" : [0.0, 0.0, 0.0] } """) box_parameters = box_settings["parameters_list"][0] upper_point = self.GetUpperPoint(self.rigid_body_model_part) counter = 0 for i in upper_point: box_parameters["upper_point"][counter].SetDouble(i) counter+=1 lower_point = self.GetLowerPoint(self.rigid_body_model_part) counter = 0 for i in lower_point: box_parameters["lower_point"][counter].SetDouble(i) counter+=1 self.bounding_box = KratosPfem.SpatialBoundingBox(box_settings) # construct rigid element // must pass an array of nodes to the element, create a node (CG) and a rigid element set them in the model_part, set the node CG as the reference node of the wall_bounding_box, BLOCKED, set in the wall_model_part for imposed movements processes. creation_utility = KratosContact.RigidBodyCreationUtility() creation_utility.CreateRigidBodyElement(self.main_model_part, self.bounding_box, self.settings["rigid_body_settings"]) print("::[Rigid_Body]:: -BUILT-")
def __init__(self, main_model_part, custom_settings): self.main_model_part = main_model_part ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "python_module": "parametric_wall", "model_part_name" : "WallDomain", "rigid_body_settings":{ "rigid_body_element_type": "TranslatoryRigidElement3D1N", "fixed_body": true, "compute_body_parameters": false, "rigid_body_model_part_name": "RigidBodyDomain", "rigid_body_parameters":{ "center_of_gravity": [0.0 ,0.0, 0.0], "mass":0.0, "main_inertias": [0.0, 0.0, 0.0], "main_axes": [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] } }, "bounding_box_settings":{ "kratos_module": "KratosMultiphysics.ContactMechanicsApplication", "bounding_box_type": "SpatialBoundingBox", "bounding_box_parameters":{ "parameters_list":[], "velocity" : [0.0, 0.0, 0.0], "plane_size": 1.0 } }, "contact_search_settings":{ "kratos_module": "KratosMultiphysics.ContactMechanicsApplication", "contatct_search_type": "ParametricWallContactSearch", "contact_parameters":{ "contact_condition_type": "PointContactCondition2D1N", "friction_law_type": "FrictionLaw", "variables_of_properties":{ "FRICTION_ACTIVE": false, "MU_STATIC": 0.3, "MU_DYNAMIC": 0.2, "PENALTY_PARAMETER": 1000, "TANGENTIAL_PENALTY_RATIO": 0.1, "TAU_STAB": 1 } } } } """) ## new node and rigid body element inside the same mesh : boundary conditions also applied ## this node and elements must be considered in the computing model part ## new contact conditions must be already assembled ## if exist a movement from a point different from CG a link condition must be used ##overwrite the default settings with user-provided parameters self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) # construct rigid wall // it will contain the array of nodes, array of elements, and the array of conditions self.wall_model_part = self.main_model_part.GetSubModelPart( self.settings["model_part_name"].GetString()) self.wall_model_part.Set(KratosMultiphysics.RIGID) for node in self.wall_model_part.Nodes: node.Set(KratosMultiphysics.RIGID, True) node.Set(KratosMultiphysics.BOUNDARY, False) for node in self.wall_model_part.Conditions: node.Set(KratosMultiphysics.ACTIVE, False) box_module = self.settings["bounding_box_settings"][ "kratos_module"].GetString() box_type_name = self.settings["bounding_box_settings"][ "bounding_box_type"].GetString() #import module if not previously imported module = __import__(box_module) module_name = (box_module.split("."))[-1] BoundingBox = getattr(getattr(module, module_name), box_type_name) #check for the bounding box of a compound wall box_settings = self.settings["bounding_box_settings"][ "bounding_box_parameters"] self.wall_bounding_box = BoundingBox( self.settings["bounding_box_settings"]["bounding_box_parameters"]) if (self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] == False): # contruct parametric wall mesh self.CreateBoundingBoxMesh(self.wall_bounding_box, self.wall_model_part) # construct rigid element // must pass an array of nodes to the element, create a node (CG) and a rigid element set them in the model_part, set the node CG as the reference node of the wall_bounding_box, BLOCKED, set in the wall_model_part for imposed movements processes. creation_utility = KratosContact.RigidBodyCreationUtility() creation_utility.CreateRigidBodyElement( self.main_model_part, self.wall_bounding_box, self.settings["rigid_body_settings"]) # create a contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.main_model_part.CreateSubModelPart( self.contact_model_part_name) self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) else: # next must be tested: self.rigid_body_model_part_name = self.settings[ "rigid_body_settings"]["rigid_body_model_part_name"].GetString( ) self.rigid_body_model_part = self.main_model_part.GetSubModelPart( self.rigid_body_model_part_name) #RigidBodyCenter = self.rigid_body_model_part.GetNode(self.rigid_body_model_part.NumberOfNodes()-1) for node in self.rigid_body_model_part.GetNodes(): RigidBodyCenter = node self.wall_bounding_box.SetRigidBodyCenter(RigidBodyCenter) # get contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) #construct the search strategy search_module = self.settings["contact_search_settings"][ "kratos_module"].GetString() search_type_name = self.settings["contact_search_settings"][ "contact_search_type"].GetString() #import module if not previously imported smodule = __import__(search_module) smodule_name = (search_module.split("."))[-1] SearchProcess = getattr(getattr(smodule, smodule_name), search_type_name) print("::[Parametric_Wall]:: Contact Model Part", self.contact_model_part_name) self.SearchStrategy = SearchProcess( self.main_model_part, self.contact_model_part_name, self.wall_bounding_box, self.settings["contact_search_settings"]["contact_parameters"]) print("::[Parametric_Wall]:: -BUILT-")
def BuildParametricWall(self): # construct rigid wall // it will contain the array of nodes, array of elements, and the array of conditions self.wall_model_part = self.main_model_part.GetSubModelPart( self.settings["model_part_name"].GetString()) self.wall_model_part.Set(KratosMultiphysics.RIGID) for node in self.wall_model_part.Nodes: node.Set(KratosMultiphysics.RIGID, True) node.Set(KratosMultiphysics.BOUNDARY, False) for node in self.wall_model_part.Conditions: node.Set(KratosMultiphysics.ACTIVE, False) box_module = self.settings["bounding_box_settings"][ "kratos_module"].GetString() box_type_name = self.settings["bounding_box_settings"][ "bounding_box_type"].GetString() #import module if not previously imported module = __import__(box_module) module_name = (box_module.split("."))[-1] BoundingBox = getattr(getattr(module, module_name), box_type_name) #check for the bounding box of a compound wall box_settings = self.settings["bounding_box_settings"][ "bounding_box_parameters"] self.wall_bounding_box = BoundingBox( self.settings["bounding_box_settings"]["bounding_box_parameters"]) if (self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] == False): # contruct parametric wall mesh self.CreateBoundingBoxMesh(self.wall_bounding_box, self.wall_model_part) # construct rigid element // must pass an array of nodes to the element, create a node (CG) and a rigid element set them in the model_part, set the node CG as the reference node of the wall_bounding_box, BLOCKED, set in the wall_model_part for imposed movements processes. creation_utility = KratosContact.RigidBodyCreationUtility() creation_utility.CreateRigidBodyElement( self.main_model_part, self.wall_bounding_box, self.settings["rigid_body_settings"]) # create a contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.main_model_part.CreateSubModelPart( self.contact_model_part_name) self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) else: # next must be tested: self.rigid_body_model_part_name = self.settings[ "rigid_body_settings"]["rigid_body_model_part_name"].GetString( ) self.rigid_body_model_part = self.main_model_part.GetSubModelPart( self.rigid_body_model_part_name) #RigidBodyCenter = self.rigid_body_model_part.GetNode(self.rigid_body_model_part.NumberOfNodes()-1) for node in self.rigid_body_model_part.GetNodes(): RigidBodyCenter = node self.wall_bounding_box.SetRigidBodyCenter(RigidBodyCenter) # get contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) #construct the search strategy search_module = self.settings["contact_search_settings"][ "kratos_module"].GetString() search_type_name = self.settings["contact_search_settings"][ "contact_search_type"].GetString() #import module if not previously imported smodule = __import__(search_module) smodule_name = (search_module.split("."))[-1] SearchProcess = getattr(getattr(smodule, smodule_name), search_type_name) print("::[Parametric_Wall]:: Contact Model Part", self.contact_model_part_name) self.SearchStrategy = SearchProcess( self.main_model_part, self.contact_model_part_name, self.wall_bounding_box, self.settings["contact_search_settings"]["contact_parameters"]) print("::[Parametric_Wall]:: -BUILT-")
def GetModelManager(self): meshing_options = KratosMultiphysics.Flags() return KratosContact.ContactModelStructure(self.main_model_part, meshing_options, self.echo_level)
def BuildParametricWall(self): # construct rigid wall // it will contain the array of nodes, array of elements, and the array of conditions self.wall_model_part = self.main_model_part.GetSubModelPart( self.settings["model_part_name"].GetString()) self.wall_model_part.Set(KratosMultiphysics.RIGID) for node in self.wall_model_part.Nodes: node.Set(KratosMultiphysics.RIGID, True) node.Set(KratosMultiphysics.BOUNDARY, False) for node in self.wall_model_part.Conditions: node.Set(KratosMultiphysics.ACTIVE, False) box_module = self.settings["bounding_box_settings"][ "kratos_module"].GetString() box_type_name = self.settings["bounding_box_settings"][ "bounding_box_type"].GetString() # import module if not previously imported module = __import__(box_module) module_name = (box_module.split("."))[-1] BoundingBox = getattr(getattr(module, module_name), box_type_name) # check for the bounding box of a compound wall box_settings = self.settings["bounding_box_settings"][ "bounding_box_parameters"] self.wall_bounding_box = BoundingBox( self.settings["bounding_box_settings"]["bounding_box_parameters"]) if (self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] == False): # contruct parametric wall mesh self.CreateBoundingBoxMesh(self.wall_bounding_box, self.wall_model_part) # construct rigid element // must pass an array of nodes to the element, create a node (CG) and a rigid element set them in the model_part, set the node CG as the reference node of the wall_bounding_box, BLOCKED, set in the wall_model_part for imposed movements processes. creation_utility = KratosContact.RigidBodyCreationUtility() creation_utility.CreateRigidBody(self.wall_model_part, self.wall_bounding_box, self.settings["body_settings"]) # create a contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.main_model_part.CreateSubModelPart( self.contact_model_part_name) self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) else: # next must be tested: self.body_model_part_name = self.settings[ "model_part_name"].GetString() self.body_model_part = self.main_model_part.GetSubModelPart( self.body_model_part_name) #RigidBodyCenter = self.rigid_body_model_part.GetNode(self.rigid_body_model_part.NumberOfNodes()-1) for node in self.body_model_part.GetNodes(): RigidBodyCenter = node break self.wall_bounding_box.SetRigidBodyCenter(RigidBodyCenter) # get contact model part self.contact_model_part_name = "contact_" + self.settings[ "model_part_name"].GetString() #can not be a child of wall_model_part due to process imposed variables self.contact_wall_model_part = self.main_model_part.GetSubModelPart( self.contact_model_part_name) #construct the search strategy search_module = self.settings["contact_search_settings"][ "kratos_module"].GetString() search_type_name = self.settings["contact_search_settings"][ "contact_search_type"].GetString() #import module if not previously imported smodule = __import__(search_module) smodule_name = (search_module.split("."))[-1] SearchProcess = getattr(getattr(smodule, smodule_name), search_type_name) print(self._class_prefix() + " Contact Part (" + self.contact_model_part_name + ")") self.SearchStrategy = SearchProcess( self.main_model_part, self.contact_model_part_name, self.wall_bounding_box, self.settings["contact_search_settings"]["contact_parameters"]) # set friction law to properties: prop_id = len( self.main_model_part.Properties) - 1 # stored in last property # print(" Number of Properties", prop_id) prop = self.main_model_part.Properties[prop_id] friction_law_name = self.settings["contact_search_settings"][ "contact_parameters"]["friction_law_type"].GetString() # print(" Friction law name ", friction_law_name) material_law = search_module + "." + friction_law_name + "()" FrictionLaw = eval(material_law) # print(" FrictionLaw ", FrictionLaw) FrictionLaw.AddToProperties(KratosContact.FRICTION_LAW, FrictionLaw.Clone(), prop) print(self._class_prefix() + " Ready")