def SetPostMeshingProcesses(self): # The order set is the order of execution: print( "::[fluid_post_refining_modeler]:: -START SetPostMeshingProcesses-" ) #select mesh elements #generate_particles = KratosPfemBase.GenerateNewNodes(self.main_model_part, self.MeshingParameters, self.mesh_id, self.echo_level) #self.mesher.SetPostMeshingProcess(generate_particles) #select mesh elements #select_mesh_elements = KratosPfemBase.SelectMeshElements(self.main_model_part, self.MeshingParameters, self.echo_level) #self.mesher.SetPostMeshingProcess(select_mesh_elements) select_mesh_elements = KratosPfemFluid.SelectMeshElementsForFluids( self.main_model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) #rebuild elements #rebuild_mesh_elements = KratosPfemBase.BuildMeshElements(self.main_model_part, self.MeshingParameters, self.mesh_id, self.echo_level) rebuild_mesh_elements = KratosPfemBase.BuildMeshElements( self.main_model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_elements) #rebuild boundary rebuild_mesh_boundary = KratosPfemBase.ReconstructMeshBoundary( self.main_model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_boundary)
def SetPostMeshingProcesses(self): # The order set is the order of execution: print( "::[fluid_pre_refining_modeler]:: -START SetPostMeshingProcesses-") refining_parameters = self.MeshingParameters.GetRefiningParameters() refining_options = refining_parameters.GetRefiningOptions() #select mesh elements select_mesh_elements = KratosPfemFluid.SelectMeshElementsForFluids( self.model_part, self.MeshingParameters, self.echo_level) #select_mesh_elements = KratosPfemBase.SelectMeshElements(self.main_model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) #rebuild elements #rebuild_mesh_elements = KratosPfemBase.BuildMeshElements(self.main_model_part, self.MeshingParameters, self.mesh_id, self.echo_level) #self.mesher.SetPostMeshingProcess(rebuild_mesh_elements) if (refining_options.Is( KratosPfemBase.ModelerUtilities.REFINE_ADD_NODES)): select_refine_elements = KratosPfemBase.SetElementsToRefineOnSize( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_refine_elements) #rebuild elements #rebuild_mesh_elements = KratosPfemBase.BuildMeshElements(self.model_part, self.MeshingParameters, self.mesh_id, self.echo_level) rebuild_mesh_elements = KratosPfemBase.BuildMeshElements( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_elements) #rebuild boundary rebuild_mesh_boundary = KratosPfemBase.BuildMeshBoundary( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_boundary)
def Initialize(self,meshing_parameters,domain_size): print("::[Meshing Strategy]:: -START-") #parameters self.mesh_id = meshing_parameters.GetMeshId() #meshing parameters self.MeshingParameters = meshing_parameters meshing_options = KratosMultiphysics.Flags() meshing_options.Set(KratosPfemBase.ModelerUtilities.REMESH, self.settings["remesh"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.REFINE, self.settings["refine"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.RECONNECT, self.settings["reconnect"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.TRANSFER, self.settings["transfer"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.CONSTRAINED, self.settings["constrained"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.MESH_SMOOTHING, self.settings["mesh_smoothing"].GetBool()) meshing_options.Set(KratosPfemBase.ModelerUtilities.VARIABLES_SMOOTHING, self.settings["variables_smoothing"].GetBool()) self.MeshingParameters.SetOptions(meshing_options) self.MeshingParameters.SetReferenceElement(self.settings["reference_element_type"].GetString()) self.MeshingParameters.SetReferenceCondition(self.settings["reference_condition_type"].GetString()) #set variables to global transfer self.MeshDataTransfer = KratosPfemBase.MeshDataTransferUtilities() self.TransferParameters = KratosPfemBase.TransferParameters() self.global_transfer = False if( self.settings["variables_smoothing"].GetBool() == True ): self.global_transfer = True transfer_variables = self.settings["elemental_variables_to_smooth"] #for variable in transfer_variables: # self.TransferParameters.SetVariable( KratosMultiphysics.KratosGlobals.GetVariable( variable.GetString() ) ) for i in range(0, transfer_variables.size() ): self.TransferParameters.SetVariable(KratosMultiphysics.KratosGlobals.GetVariable(transfer_variables[i].GetString())) #mesh modelers for the current strategy self.mesh_modelers = [] #configure meshers: self.SetMeshModelers(); self.model_part = self.main_model_part if( self.main_model_part.Name != self.MeshingParameters.GetSubModelPartName() ): self.model_part = self.main_model_part.GetSubModelPart(self.MeshingParameters.GetSubModelPartName()) for mesher in self.mesh_modelers: mesher.SetEchoLevel(self.echo_level) mesher.Initialize(domain_size) self.number_of_nodes = 0 self.number_of_elements = 0 self.number_of_conditions = 0 print("::[Meshing Strategy]:: -END-")
def SetPostMeshingProcesses(self): #nothing to do: only reconnection #select mesh elements #select_mesh_elements = KratosPfemBase.SelectMeshElements(self.main_model_part, self.MeshingParameters, self.echo_level) #self.mesher.SetPostMeshingProcess(select_mesh_elements) #rebuild elements rebuild_mesh_elements = KratosPfemBase.BuildMeshElements( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_elements) #rebuild boundary rebuild_mesh_boundary = KratosPfemBase.ReconstructMeshBoundary( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_boundary)
def SetMeshingParameters(self): # Create MeshingParameters self.MeshingParameters = KratosPfemBase.MeshingParameters() self.MeshingParameters.Initialize() self.MeshingParameters.SetMeshId(self.settings["mesh_id"].GetInt()) self.MeshingParameters.SetSubModelPartName( self.settings["model_part_name"].GetString()) if (self.active_remeshing): self.MeshingParameters.SetAlphaParameter( self.settings["alpha_shape"].GetDouble()) self.MeshingParameters.SetOffsetFactor( self.settings["offset_factor"].GetDouble()) self.SetInfoParameters() self.SetTransferParameters() self.SetRefiningParameters() self.MeshingParameters.SetInfoParameters(self.InfoParameters) self.MeshingParameters.SetTransferParameters( self.TransferParameters) self.MeshingParameters.SetRefiningParameters( self.RefiningParameters)
def RemeshFluidDomains(self): if (self.remesh_domains_active): # if(self.contact_search): # self.ContactTransfer() if (self.echo_level > 1): print("::[Remesh_fluid_domains_process]:: MESH DOMAIN...", self.counter) meshing_options = KratosMultiphysics.Flags() self.modeler_utils = KratosPfemBase.ModelerUtilities() meshing_options.Set(self.modeler_utils.KEEP_ISOLATED_NODES, True) #self.model_meshing = KratosPfemBase.ModelMeshing(self.main_model_part, meshing_options, self.echo_level) self.model_meshing = KratosPfemFluid.ModelMeshingForFluids( self.main_model_part, meshing_options, self.echo_level) self.model_meshing.ExecuteInitialize() id = 0 for domain in self.meshing_domains: domain.ExecuteMeshing() self.remesh_executed = True id += 1 self.model_meshing.ExecuteFinalize() self.counter += 1
def BuildMeshModelersNEW(self, meshing_domains ): if(self.remesh_domains): self.modeler_active = True # set mesing domains self.meshing_domains = meshing_domains # set modeler utilities self.modeler_utils = KratosPfemBase.ModelerUtilities() # set transfer utilities self.transfer_utils = KratosPfemBase.MeshDataTransferUtilities() # set the domain labels to mesh modeler self.modeler_utils.SetDomainLabels(self.model_part)
def SetPreMeshingProcesses(self): # The order set is the order of execution: # process to refine elements / refine boundary refine_mesh_elements = KratosPfemBase.SetElementNodesToRefineOnThreshold(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(refine_mesh_elements) # process to refine boundary / contact boundary refine_mesh_boundary = RefineMeshBoundary(self.model_part, self.RefiningParameters, self.echo_level) self.mesher.SetPreMeshingProcess(refine_mesh_boundary) # process to remove nodes / remove boundary remove_mesh_nodes = KratosPfemBase.RemoveMeshNodes(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(remove_mesh_nodes)
def Initialize(self, domain_size): self.domain_size = domain_size # set mesh modeler if(self.domain_size == 2): self.mesher = KratosPfemBase.TriangularMesh2DModeler() elif(self.domain_size == 3): self.mesher = KratosPfemBase.TetrahedralMesh3DModeler() 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: refining_parameters = self.MeshingParameters.GetRefiningParameters() refining_options = refining_parameters.GetRefiningOptions() #select mesh elements select_mesh_elements = KratosPfemBase.SelectMeshElements( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) if (refining_options.Is( KratosPfemBase.ModelerUtilities.REFINE_ADD_NODES)): select_refine_elements = KratosPfemBase.SetElementsToRefineOnSize( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_refine_elements)
def SetPostMeshingProcesses(self): # The order set is the order of execution: #print GiD mesh output for checking purposes print_output_mesh = KratosPfemBase.PrintOutputMeshProcess( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(print_output_mesh) #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 SetRefiningParameters(self): #no refine in the contact domain # Create RefiningParameters self.RefiningParameters = KratosPfemBase.RefiningParameters() self.RefiningParameters.Initialize() # parameters self.RefiningParameters.SetAlphaParameter( self.settings["alpha_shape"].GetDouble())
def SetPreMeshingProcesses(self): # process to refine elements /refine boundary refine_mesh_elements = KratosPfemBase.SetElementNodesToRefineOnThreshold( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(refine_mesh_elements) refine_edge_elements = KratosPfemBase.SetElementEdgesToRefine( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(refine_edge_elements) refine_mesh_boundary = KratosPfemBase.RefineMeshBoundary( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(refine_mesh_boundary) # process to remove nodes / remove boundary remove_mesh_nodes = KratosPfemBase.RemoveMeshNodes( self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPreMeshingProcess(remove_mesh_nodes)
def SetPostMeshingProcesses(self): # The order set is the order of execution: #generate new particles generate_particles = KratosPfemBase.GenerateNewNodes(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(generate_particles) #select mesh elements select_mesh_elements = KratosPfemBase.SelectMeshElements(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(select_mesh_elements) #rebuild elements rebuild_mesh_elements = KratosPfemBase.BuildMeshElements(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_elements) #rebuild boundary rebuild_mesh_boundary = KratosPfemBase.BuildMeshBoundary(self.model_part, self.MeshingParameters, self.echo_level) self.mesher.SetPostMeshingProcess(rebuild_mesh_boundary)
def SetTransferParameters(self): # Create TransferParameters self.TransferParameters = KratosPfemBase.TransferParameters() transfer_variables = self.settings["elemental_variables_to_transfer"] #for variable in transfer_variables: # self.TransferParameters.SetVariable( KratosMultiphysics.KratosGlobals.GetVariable( variable.GetString() ) ) for i in range(0, transfer_variables.size()): self.TransferParameters.SetVariable( KratosMultiphysics.KratosGlobals.GetVariable( transfer_variables[i].GetString()))
def BuildMeshBoundaryForFluids(self): # set building options: mesh_id = 0 # define building utility model_part_name = self.settings["model_part_name"].GetString() skin_build = KratosPfemBase.BuildModelPartBoundary( self.main_model_part, model_part_name, self.echo_level) # execute building: skin_build.Execute()
def Check(self): # set modeler utilities self.modeler_utils = KratosPfemBase.ModelerUtilities() # set the domain labels to mesh modeler critical_mesh_size = self.settings["refining_parameters"][ "critical_size"].GetDouble() critical_radius = self.modeler_utils.CheckCriticalRadius( self.main_model_part, critical_mesh_size, self.mesh_id) print(" CriticalRadius ", critical_radius)
def ComputeBoundaryNormals(self): # define calculation utility # normals_calculation = BoundaryNormalsCalculation() normals_calculation = KratosPfemBase.BoundaryNormalsCalculation() # execute calculation: #(scaled normals) normals_calculation.CalculateWeightedBoundaryNormals(self.model_part, self.echo_level) #(unit normals) # normals_calculation.CalculateUnitBoundaryNormals(model_part, self.echo_level) print("::[Modeler_Utility]:: Boundary Normals computed ")
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 SearchElementNeighbours(self): # set search options: number_of_avg_elems = 10 mesh_id = 0 # define search utility elemental_neighbour_search = KratosPfemBase.ElementalNeighboursSearch(self.model_part, self.domain_size, self.echo_level, number_of_avg_elems, mesh_id) # execute search: elemental_neighbour_search.Execute() print("::[Modeler_Utility]:: Elemental Search executed ")
def ComputeBoundaryNormals(self, model_part, echo_level): # define calculation utility normals_calculation = KratosPfemBase.BoundaryNormalsCalculation() # execute calculation: #(scaled normals) normals_calculation.CalculateWeightedBoundaryNormals( model_part, echo_level) #(unit normals) # normals_calculation.CalculateUnitBoundaryNormals(model_part, self.echo_level) if (echo_level > 0): print("::[Domain_Utilities]:: Boundary Normals computed ")
def SearchNodeNeighbours(self): # set search options: number_of_avg_elems = 10 number_of_avg_nodes = 10 mesh_id = 0 # define search utility nodal_neighbour_search = KratosPfemBase.NodalNeighboursSearch(self.model_part, self.echo_level, number_of_avg_elems, number_of_avg_nodes, mesh_id) # execute search: nodal_neighbour_search.Execute() print("::[Modeler_Utility]:: Nodal Search executed ")
def BuildMeshBoundary(self): print("::[Modeler_Utility]:: Build Mesh Boundary ") # set building options: mesh_id = 0 # define building utility # skin_build = BuildMeshBoundary(self.model_part, self.domain_size, self.echo_level, mesh_id) skin_build = KratosPfemBase.BuildMeshBoundary(self.model_part, mesh_id, self.echo_level) #skin_build = KratosPfemFluid.BuildMeshBoundaryForFluids(self.model_part, mesh_id, self.echo_level) # execute building: skin_build.Execute() print("::[Modeler_Utility]:: Mesh Boundary Build executed ")
def ComputeAverageMeshParameters(self): ModelerUtils = KratosPfemBase.ModelerUtilities() self.domain_volume = ModelerUtils.ComputeModelPartVolume( self.main_model_part) self.element_mean_volume = 0 number_of_elements = self.main_model_part.NumberOfElements() nodes_for_element = self.main_model_part.ProcessInfo[ KratosMultiphysics.DOMAIN_SIZE] + 1 if (number_of_elements != 0): self.element_mean_volume = self.domain_volume / float( number_of_elements * nodes_for_element) self.RefiningParameters.SetMeanVolume(self.element_mean_volume)
def BuildModelPartBoundary(self, model_part, echo_level): mesh_id = 0 print("::[Domain_Utilities]:: Build Mesh Boundary ") # set building options: # define building utility skin_build = KratosPfemBase.BuildModelPartBoundary( model_part, model_part.Name, echo_level) # execute building: skin_build.Execute() if (echo_level > 0): print("::[Domain_Utilities]:: Mesh Boundary Build executed ")
def SearchElementNeighbours(self, model_part, echo_level): mesh_id = 0 domain_size = model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] # set search options: number_of_avg_elems = 10 # define search utility elemental_neighbour_search = KratosPfemBase.ElementalNeighboursSearch( model_part, domain_size, echo_level, number_of_avg_elems, mesh_id) # execute search: elemental_neighbour_search.Execute() if (echo_level > 0): print("::[Domain_Utilities]:: Elemental Search executed ")
def RemeshDomains(self): if (self.echo_level > 0): print("::[Meshing_Process]:: MESHING DOMAIN...( call:", self.counter, ")") meshing_options = KratosMultiphysics.Flags() self.model_meshing = KratosPfemBase.ModelMeshing( self.main_model_part, meshing_options, self.echo_level) self.model_meshing.ExecuteInitialize() #serial for domain in self.meshing_domains: domain.ExecuteMeshing() #parallel (not working pickling instances not enabled) #domains_number = len(self.meshing_domains) #if(domains_number>8): # domains_number = 8 #pool = Pool(domains_number) #pool.map(self.ExecuteMeshing,self.meshing_domains) #pool.close() #pool.joint() # self.model_meshing.ExecuteFinalize() self.counter += 1 self.main_model_part.ProcessInfo[ KratosPfemBase.MESHING_STEP_PERFORMED] = True # 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 InitializeDomains(self): # initialize the modeler if (self.echo_level > 1): print("::[Remesh_Fluid_Domains]:: Initialize Domains ") import domain_utilities domain_utils = domain_utilities.DomainUtilities() # find node neighbours domain_utils.SearchNodeNeighbours(self.main_model_part, self.echo_level) # find element neighbours domain_utils.SearchElementNeighbours(self.main_model_part, self.echo_level) # set neighbour search performed self.neighbour_search_performed = True # set modeler utilities self.modeler_utils = KratosPfemBase.ModelerUtilities() # set the domain labels to conditions self.modeler_utils.SetModelPartNameToConditions(self.main_model_part) # find skin and boundary normals if (self.restart == False): self.BuildMeshBoundaryForFluids() #domain_utils.ConstructModelPartBoundary(self.main_model_part, self.echo_level) # search nodal h if (self.neighbour_search_performed): domain_utils.SearchNodalH(self.main_model_part, self.echo_level) # set the domain labels to nodes self.modeler_utils.SetModelPartNameToNodes(self.main_model_part) self.main_model_part.ProcessInfo.SetValue( KratosPfemBase.INITIALIZED_DOMAINS, True) if (self.echo_level > 1): print(self.main_model_part)
def InitializeDomains(self, model_part, echo_level): if (model_part.ProcessInfo[KratosPfemBase.INITIALIZED_DOMAINS] == False ): # initialize the modeler print("::[Domain_Utilities]:: Initialize", model_part.Name) # find node neighbours self.SearchNodeNeighbours(model_part, echo_level) # find element neighbours self.SearchElementNeighbours(model_part, echo_level) # set modeler utilities modeler_utils = KratosPfemBase.ModelerUtilities() # set the domain labels to conditions modeler_utils.SetModelPartNameToConditions(model_part) # find skin and boundary normals if (model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] == False): # build boundary of a volumetric body domain self.BuildModelPartBoundary(model_part, echo_level) # search nodal h self.SearchNodalH(model_part, echo_level) # set the domain labels to nodes modeler_utils.SetModelPartNameToNodes(model_part) model_part.ProcessInfo.SetValue(KratosPfemBase.INITIALIZED_DOMAINS, True) print("::[Domain_Utilities]:: Resultant ModelPart") print(model_part)
def RemeshDomainsNEW(self): if(self.remesh_domains): # if(self.contact_search): # self.ContactTransfer() if( self.echo_level > 0 ): print("::[Modeler_Utility]:: MESH DOMAIN...", self.counter) meshing_options = KratosMultiphysics.Flags() self.modeler_utils = KratosPfemBase.ModelerUtilities() meshing_options.Set(self.modeler_utils.KEEP_ISOLATED_NODES, True) #self.model_meshing = KratosPfemBase.ModelMeshing(self.model_part, meshing_options, self.echo_level) self.model_meshing = KratosPfemFluid.ModelMeshingForFluids(self.model_part, meshing_options, self.echo_level) self.model_meshing.ExecuteInitialize() print("::[Modeler_Utility]:: BEFORE LOOP", self.counter) id = 0 for domain in self.meshing_domains: print("::[Modeler_Utility]:: IN THE LOOP") domain.ExecuteMeshing(); self.remesh_executed = True id+=1 self.model_meshing.ExecuteFinalize() self.counter += 1