def _SetUpListOfProcesses(self): ''' Read the definition of initial and boundary conditions for the problem and initialize the processes that will manage them. Also initialize any additional processes present in the problem (such as those used to calculate additional results). ''' from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) # The list of processes will contain a list with each individual process already constructed (boundary conditions, initial conditions and gravity) # Note 1: gravity is constructed first. Outlet process might need its information. # Note 2: initial conditions are constructed before BCs. Otherwise, they may overwrite the BCs information. self.list_of_processes = factory.ConstructListOfProcesses( self.project_parameters["gravity"]) self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["initial_conditions_process_list"]) self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["boundary_conditions_process_list"]) self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["auxiliar_process_list"]) #TODO this should be generic # initialize GiD I/O self.output = self._SetUpGiDOutput() if self.output is not None: self.list_of_processes += [ self.output, ]
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of Processes This method is TEMPORARY to not break existing code It will be removed in the future """ list_of_processes = super()._CreateProcesses(parameter_name, initialization_order) if parameter_name == "processes": processes_block_names = ["recursive_remeshing_process"] if len(list_of_processes ) == 0: # Processes are given in the old format KM.Logger.PrintWarning( "AdaptativeRemeshingStructuralMechanicsAnalysis", "Using the old way to create the processes, this will be removed!" ) from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) for process_name in processes_block_names: if self.project_parameters.Has(process_name): list_of_processes += factory.ConstructListOfProcesses( self.project_parameters[process_name]) else: # Processes are given in the new format for process_name in processes_block_names: if self.project_parameters.Has(process_name): raise Exception( "Mixing of process initialization is not allowed!") elif parameter_name == "output_processes": pass # Already added else: raise NameError("wrong parameter name") return list_of_processes
def SetUpProcesses(self): ''' Read the definition of initial and boundary conditions for the problem and initialize the processes that will manage them. Also initialize any additional processes present in the problem (such as those used to calculate additional results). ''' from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) # "list_of_processes" contains all the processes already constructed (boundary conditions, initial conditions and gravity) # Note 1: bathymetry is firstly constructed. Initial conditions might need its information. # Note 2: initial conditions are constructed before BCs. Otherwise, they may overwrite the BCs information. self.list_of_processes = factory.ConstructListOfProcesses( self.ProjectParameters["bathymetry_process_list"]) self.list_of_processes += factory.ConstructListOfProcesses( self.ProjectParameters["initial_conditions_process_list"]) self.list_of_processes += factory.ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"])
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of Processes This method is TEMPORARY to not break existing code It will be removed in the future """ list_of_processes = super(AdjointFluidAnalysis, self)._CreateProcesses(parameter_name, initialization_order) # The list of processes will contain a list with each individual process already constructed (boundary conditions, initial conditions and gravity) # Note 1: gravity is constructed first. Outlet process might need its information. # Note 2: initial conditions are constructed before BCs. Otherwise, they may overwrite the BCs information. if parameter_name == "processes": processes_block_names = ["gravity", "initial_conditions_process_list", "boundary_conditions_process_list", "auxiliar_process_list"] if len(list_of_processes) == 0: # Processes are given in the old format Kratos.Logger.PrintInfo(self.__class__.__name__, "Using the old way to create the processes, this will be removed!") from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): list_of_processes += factory.ConstructListOfProcesses(self.project_parameters[process_name]) else: # Processes are given in the new format for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): raise Exception("Mixing of process initialization is not alowed!") elif parameter_name == "output_processes": if self.project_parameters.Has("output_configuration"): #KratosMultiphysics.Logger.PrintInfo("FluidDynamicsAnalysis", "Using the old way to create the gid-output, this will be removed!") gid_output= self._SetUpGiDOutput() list_of_processes += [gid_output,] else: raise NameError("wrong parameter name") return list_of_processes
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of Processes This method is TEMPORARY to not break existing code It will be removed in the future """ list_of_processes = super(FluidTransportAnalysis, self)._CreateProcesses(parameter_name, initialization_order) if parameter_name == "processes": processes_block_names = ["constraints_process_list", "loads_process_list","auxiliar_process_list"] if len(list_of_processes) == 0: # Processes are given in the old format KratosMultiphysics.Logger.PrintInfo(self._GetSimulationName(), "Using the old way to create the processes, this will be removed!") from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): list_of_processes += factory.ConstructListOfProcesses(self.project_parameters[process_name]) else: # Processes are given in the new format for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): raise Exception("Mixing of process initialization is not alowed!") elif parameter_name == "output_processes": if self.project_parameters.Has("output_configuration"): gid_output= self._SetUpGiDOutput() list_of_processes += [gid_output,] else: raise NameError("wrong parameter name") return list_of_processes
def _SetUpListOfProcesses(self): """ Set up the list of processes """ from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) self.list_of_processes = factory.ConstructListOfProcesses(self.project_parameters["constraints_process_list"]) self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["loads_process_list"]) if (self.project_parameters.Has("list_other_processes") is True): self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["list_other_processes"]) if (self.project_parameters.Has("json_output_process") is True): self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["json_output_process"]) # Processes for tests if (self.project_parameters.Has("json_check_process") is True): self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["json_check_process"]) if (self.project_parameters.Has("check_analytic_results_process") is True): self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["check_analytic_results_process"]) if (self.project_parameters.Has("contact_process_list") is True): self.list_of_processes += factory.ConstructListOfProcesses(self.project_parameters["contact_process_list"]) #TODO this should be generic # initialize GiD I/O self._SetUpGiDOutput() if self.have_output: self.list_of_processes += [self.output,] if self.is_printing_rank and self.echo_level > 1: count = 0 for process in self.list_of_processes: count += 1
def _SetUpListOfProcesses(self): ''' Read the definition of initial and boundary conditions for the problem and initialize the processes that will manage them. Also initialize any additional processes present in the problem (such as those used to calculate additional results). ''' from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) self.list_of_processes = factory.ConstructListOfProcesses( self.project_parameters["initial_conditions_process_list"] ) self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["boundary_conditions_process_list"] ) self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["gravity"] ) if self.project_parameters.Has("list_other_processes"): self.list_of_processes += factory.ConstructListOfProcesses( self.project_parameters["list_other_processes"] ) #TODO this should be generic # initialize GiD I/O self.output = self._SetUpGiDOutput() if self.output is not None: self.list_of_processes += [self.output,]
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of Processes""" list_of_processes = super(ParticleMechanicsAnalysis, self)._CreateProcesses( parameter_name, initialization_order) if parameter_name == "processes": processes_block_names = [ "constraints_process_list", "loads_process_list", "list_other_processes", "gravity" ] if len(list_of_processes ) == 0: # Processes are given in the old format info_msg = "Using the old way to create the processes, this will be removed!\n" info_msg += "Refer to \"https://github.com/KratosMultiphysics/Kratos/wiki/Common-" info_msg += "Python-Interface-of-Applications-for-Users#analysisstage-usage\" " info_msg += "for a description of the new format" KratosMultiphysics.Logger.PrintWarning( "ParticleMechanicsAnalysis", info_msg) from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): list_of_processes += factory.ConstructListOfProcesses( self.project_parameters[process_name]) else: # Processes are given in the new format for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): raise Exception( "Mixing of process initialization is not allowed!") elif parameter_name == "output_processes": if self.project_parameters.Has("grid_output_configuration" ) or self.project_parameters.Has( "body_output_configuration"): info_msg = "Using the old way to create the gid-output for grid, this will be removed!\n" info_msg += "Refer to \"https://github.com/KratosMultiphysics/Kratos/wiki/Common-" info_msg += "Python-Interface-of-Applications-for-Users#analysisstage-usage\" " info_msg += "for a description of the new format" KratosMultiphysics.Logger.PrintInfo( "ParticleMechanicsAnalysis", info_msg) if self.project_parameters.Has("grid_output_configuration"): grid_gid_output = self._SetUpGiDOutput("grid_output") list_of_processes += [ grid_gid_output, ] if self.project_parameters.Has("body_output_configuration"): mp_gid_output = self._SetUpGiDOutput("body_output") list_of_processes += [ mp_gid_output, ] else: raise NameError("wrong parameter name") return list_of_processes
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of processes Format: "processes" : { initial_processes : [ { proces_specific_params }, { proces_specific_params } ], boundary_processes : [ { proces_specific_params }, { proces_specific_params } ] } The order of intialization can be specified by setting it in "initialization_order" if e.g. the "boundary_processes" should be constructed before the "initial_processes", then initialization_order should be a list containing ["boundary_processes", "initial_processes"] see the functions _GetOrderOfProcessesInitialization and _GetOrderOfOutputProcessesInitialization """ list_of_processes = [] from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) if self.project_parameters.Has(parameter_name): processes_params = self.project_parameters[parameter_name] # first initialize the processes that depend on the order for processes_names in initialization_order: if processes_params.Has(processes_names): list_of_processes += factory.ConstructListOfProcesses( processes_params[processes_names]) # then initialize the processes that don't depend on the order for name, value in processes_params.items(): if not name in initialization_order: list_of_processes += factory.ConstructListOfProcesses( value ) # Does this work? or should it be processes[name] return list_of_processes
def _CreateProcesses(self, parameter_name, initialization_order): """Create a list of Processes This method is TEMPORARY to not break existing code It will be removed in the future """ list_of_processes = super(PotentialFlowAnalysis, self)._CreateProcesses( parameter_name, initialization_order) if parameter_name == "processes": processes_block_names = [ "initial_conditions_process_list", "boundary_conditions_process_list", "auxiliar_process_list" ] if len(list_of_processes ) == 0: # Processes are given in the old format info_msg = "Using the old way to create the processes, this will be removed!\n" info_msg += "Refer to \"https://github.com/KratosMultiphysics/Kratos/wiki/Common-" info_msg += "Python-Interface-of-Applications-for-Users#analysisstage-usage\" " info_msg += "for a description of the new format" KratosMultiphysics.Logger.PrintWarning("PotentialFlowAnalysis", info_msg) from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): list_of_processes += factory.ConstructListOfProcesses( self.project_parameters[process_name]) else: # Processes are given in the new format for process_name in processes_block_names: if (self.project_parameters.Has(process_name) is True): raise Exception( "Mixing of process initialization is not alowed!") elif parameter_name == "output_processes": if self.project_parameters.Has("output_configuration"): info_msg = "Using the old way to create the gid-output, this will be removed!\n" info_msg += "Refer to \"https://github.com/KratosMultiphysics/Kratos/wiki/Common-" info_msg += "Python-Interface-of-Applications-for-Users#analysisstage-usage\" " info_msg += "for a description of the new format" KratosMultiphysics.Logger.PrintWarning("PotentialFlowAnalysis", info_msg) gid_output = self._SetUpGiDOutput() list_of_processes += [ gid_output, ] else: raise NameError("wrong parameter name") return list_of_processes
def UpdateSolverAndProcesses(self, solver, list_of_processes, list_of_output_processes): ## Finalize old solver and processes # Finalize list_of_processes and list_of_output_processes (included in list_of_processes) for process in list_of_processes: process.ExecuteFinalize() solver.Finalize() solver.Clear() # Save old .post.list file all_list_filename = str(self.problem_name) + "_all.post.lst" all_list_file = open(all_list_filename, 'a') partial_list_filename = str(self.problem_name) + ".post.lst" with open(partial_list_filename) as partial_list_file: next(partial_list_file) for line in partial_list_file: all_list_file.write(line) all_list_file.close() ## Create new solver and processes # Parsing the parameters with open("ProjectParameters.json", 'r') as parameter_file: parameters = KratosMultiphysics.Parameters(parameter_file.read()) # Update parameters with the new model part name new_model_part_name = str(self.original_model_part_name) + '_' + str( self.model_part_number) parameters["solver_settings"]["model_part_name"].SetString( new_model_part_name) if parameters.Has("processes"): for name, value in parameters["processes"].items(): value = self.UpdateModelPartNames(value) if parameters.Has("output_processes"): for name, value in parameters["output_processes"].items(): value = self.UpdateModelPartNames(value) # Create new solver (and new_model_part) solver_module = __import__( parameters["solver_settings"]["solver_type"].GetString()) new_solver = solver_module.CreateSolver(self.model, parameters["solver_settings"]) new_solver.AddVariables() new_solver.ImportModelPart() new_solver.PrepareModelPart() new_solver.AddDofs() # Create new_list_of_processes new_list_of_processes = [] new_list_of_output_processes = [] from process_factory import KratosProcessFactory factory = KratosProcessFactory(self.model) if parameters.Has("processes"): processes_params = parameters["processes"] # first initialize the processes that depend on the order for processes_names in self.order_processes_initialization: if processes_params.Has(processes_names): new_list_of_processes += factory.ConstructListOfProcesses( processes_params[processes_names]) # then initialize the processes that don't depend on the order for name, value in processes_params.items(): if not name in self.order_processes_initialization: new_list_of_processes += factory.ConstructListOfProcesses( value) order_output_processes_initialization = [] if parameters.Has("output_processes"): processes_params = parameters["output_processes"] # first initialize the processes that depend on the order for processes_names in order_output_processes_initialization: if processes_params.Has(processes_names): new_list_of_output_processes += factory.ConstructListOfProcesses( processes_params[processes_names]) # then initialize the processes that don't depend on the order for name, value in processes_params.items(): if not name in order_output_processes_initialization: new_list_of_output_processes += factory.ConstructListOfProcesses( value) new_list_of_processes.extend(new_list_of_output_processes) # Initialize processes and solver for process in new_list_of_processes: process.ExecuteInitialize() new_solver.Initialize() new_solver.Check() for process in new_list_of_processes: process.Check() for process in new_list_of_processes: process.ExecuteBeforeSolutionLoop() ## Mapping between old and new model parts old_model_part_name = str( self.original_model_part_name) + '_' + str(self.model_part_number - 1) old_main_model_part = self.model.GetModelPart(old_model_part_name) new_model_part = self.model.GetModelPart(new_model_part_name) new_model_part.ProcessInfo.SetValue( KratosMultiphysics.TIME, old_main_model_part.ProcessInfo[KratosMultiphysics.TIME]) new_model_part.ProcessInfo.SetValue( KratosMultiphysics.STEP, old_main_model_part.ProcessInfo[KratosMultiphysics.STEP]) self.PropagationUtility.MappingModelParts(self.FracturesData, old_main_model_part, new_model_part, self.move_mesh_flag) # Set ARC_LENGTH_LAMBDA and ARC_LENGTH_RADIUS_FACTOR and update loads if parameters["solver_settings"]["strategy_type"].GetString( ) == "arc_length": new_model_part.ProcessInfo.SetValue( KratosPoro.ARC_LENGTH_LAMBDA, old_main_model_part.ProcessInfo[KratosPoro.ARC_LENGTH_LAMBDA]) new_model_part.ProcessInfo.SetValue( KratosPoro.ARC_LENGTH_RADIUS_FACTOR, old_main_model_part.ProcessInfo[ KratosPoro.ARC_LENGTH_RADIUS_FACTOR]) new_solver._UpdateLoads() ## Delete old model_part and replace solver and processes self.model.DeleteModelPart(old_model_part_name) solver = new_solver list_of_processes = new_list_of_processes list_of_output_processes = new_list_of_output_processes # Check new mesh # IsConverged = new_solver._CheckConvergence() return solver, list_of_processes, list_of_output_processes