def __CreateSolver(self, external_model_part=None): """ Create the Solver (and create and import the ModelPart if it is not passed from outside) """ if external_model_part != None: # This is a temporary solution until the importing of the ModelPart # is removed from the solver (needed e.g. for Optimization) if (type(external_model_part) != KratosMultiphysics.ModelPart): raise Exception( "Input is expected to be provided as a Kratos ModelPart object" ) self.using_external_model_part = True else: self.using_external_model_part = False ## Get echo level and parallel type self.echo_level = self.ProjectParameters["problem_data"][ "echo_level"].GetInt() self.parallel_type = self.ProjectParameters["problem_data"][ "parallel_type"].GetString() ## Import parallel modules if needed if (self.parallel_type == "MPI"): import KratosMultiphysics.mpi as KratosMPI import KratosMultiphysics.MetisApplication as MetisApplication import KratosMultiphysics.TrilinosApplication as TrilinosApplication self.is_printing_rank = (KratosMPI.mpi.rank == 0) else: self.is_printing_rank = True ## Structure model part definition if self.using_external_model_part: self.main_model_part = external_model_part else: main_model_part_name = self.ProjectParameters["problem_data"][ "model_part_name"].GetString() self.main_model_part = KratosMultiphysics.ModelPart( main_model_part_name) self.main_model_part.ProcessInfo.SetValue( KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) ## Solver construction import python_solvers_wrapper_mesh_motion self.solver = python_solvers_wrapper_mesh_motion.CreateSolver( self.main_model_part, self.ProjectParameters) ## Adds the necessary variables to the model_part only if they don't exist self.solver.AddVariables() if not self.using_external_model_part: ## Read the model - note that SetBufferSize is done here self.solver.ReadModelPart() # TODO move to global instance
def __init__(self, model_part, custom_settings): # remove the ale_settings so we can use the navier stokes constructor navier_stokes_settings = custom_settings.Clone() navier_stokes_settings.RemoveValue("ale_settings") navier_stokes_settings["solver_type"].SetString("Monolithic") super(ALENavierStokesSolverVMSMonolithic, self).__init__(model_part, navier_stokes_settings) # create mesh motion solver custom_settings.AddEmptyValue("problem_data") custom_settings["problem_data"].AddEmptyValue("parallel_type") custom_settings["problem_data"]["parallel_type"].SetString("OpenMP") custom_settings.AddValue("solver_settings", custom_settings["ale_settings"]) custom_settings.RemoveValue("ale_settings") import python_solvers_wrapper_mesh_motion self.ale_solver = python_solvers_wrapper_mesh_motion.CreateSolver(self.main_model_part, custom_settings) print("::[ALENavierStokesSolverVMSMonolithic]:: Construction finished")
def __init__(self, model_part, custom_settings): # remove the ale_settings so we can use the navier stokes constructor navier_stokes_settings = custom_settings.Clone() navier_stokes_settings.RemoveValue("ale_settings") navier_stokes_settings["solver_type"].SetString("FractionalStep") super(ALETrilinosNavierStokesSolverFractionalStep, self).__init__(model_part, navier_stokes_settings) # create ale solver custom_settings.AddEmptyValue("problem_data") custom_settings["problem_data"].AddEmptyValue("parallel_type") custom_settings["problem_data"]["parallel_type"].SetString("MPI") custom_settings.AddValue("solver_settings", custom_settings["ale_settings"]) custom_settings.RemoveValue("ale_settings") import python_solvers_wrapper_mesh_motion self.ale_solver = python_solvers_wrapper_mesh_motion.CreateSolver( self.main_model_part, custom_settings) if KratosMPI.mpi.rank == 0: print( "::[ALETrilinosNavierStokesSolverFractionalStep]:: Construction finished" )
def _CreateSolver(self): """ Create the Solver (and create and import the ModelPart if it is not alread in the model) """ ## Solver construction import python_solvers_wrapper_mesh_motion return python_solvers_wrapper_mesh_motion.CreateSolver(self.model, self.project_parameters)
ProjectParameters["problem_data"]["model_part_name"].GetString()) main_model_part.ProcessInfo.SetValue( DOMAIN_SIZE, ProjectParameters["problem_data"]["domain_size"].GetInt()) ###TODO replace this "model" for real one once available Model = { ProjectParameters["problem_data"]["model_part_name"].GetString(): main_model_part } ## Solver construction #solver_module = __import__(ProjectParameters["solver_settings"]["solver_type"].GetString()) #solver = solver_module.CreateSolver(main_model_part, ProjectParameters["solver_settings"]) import python_solvers_wrapper_mesh_motion solver = python_solvers_wrapper_mesh_motion.CreateSolver( main_model_part, ProjectParameters) solver.AddVariables() ## Read the model - note that SetBufferSize is done here solver.ImportModelPart() ## Add AddDofs solver.AddDofs() ## Initialize GiD I/O from gid_output_process import GiDOutputProcess gid_output = GiDOutputProcess( solver.GetComputingModelPart(), ProjectParameters["problem_data"]["problem_name"].GetString(), ProjectParameters["output_configuration"])
def __init__(self, model, project_parameters): super(PartitionedFSIBaseSolver,self).__init__(model, project_parameters) # Initial tests start_time_structure = self.settings["structure_solver_settings"]["problem_data"]["start_time"].GetDouble() start_time_fluid = self.settings["fluid_solver_settings"]["problem_data"]["start_time"].GetDouble() end_time_structure = self.settings["structure_solver_settings"]["problem_data"]["end_time"].GetDouble() end_time_fluid = self.settings["fluid_solver_settings"]["problem_data"]["end_time"].GetDouble() if start_time_structure != start_time_fluid: raise Exception('Different initial time among subdomains.') if end_time_structure != end_time_fluid: raise Exception('Different final time among subdomains.') solver_settings = self.settings["fluid_solver_settings"]["solver_settings"] problem_data = self.settings["fluid_solver_settings"]["problem_data"] if solver_settings.Has("model_part_name"): self.fluid_model_part_name = solver_settings["model_part_name"].GetString() elif problem_data.Has("model_part_name"): self.fluid_model_part_name = problem_data["model_part_name"].GetString() # Backwards compatibility: copy the name to the solver section so that the fluid solver can read it solver_settings.AddEmptyValue("model_part_name") solver_settings["model_part_name"].SetString(self.fluid_model_part_name) # Backwards compatibility: copy the domain size to the solver section if not solver_settings.Has("domain_size"): solver_settings.AddEmptyValue("domain_size") solver_settings["domain_size"].SetInt(problem_data["domain_size"].GetInt()) # Time stepping checks (no sub-stepping between subdomains has been implemented yed) time_step_structure = self.settings["structure_solver_settings"]["problem_data"]["time_step"].GetDouble() # If automatic time stepping has been selected in the fluid domain, deactivate it and use the structure time step if (self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].GetBool()): self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["automatic_time_step"].SetBool(False) time_step_fluid = time_step_structure self._PrintWarningOnRankZero("::[PartitionedFSIBaseSolver]::", "Automatic fluid time stepping cannot be used. Setting structure time step as fluid time step.") else: time_step_fluid = self.settings["fluid_solver_settings"]["solver_settings"]["time_stepping"]["time_step"].GetDouble() if time_step_structure != time_step_fluid: raise Exception('Different time step among subdomains! No sub-stepping implemented yet.') self.time_step = time_step_fluid # Auxiliar variables coupling_solver_settings = self.settings["coupling_solver_settings"]["solver_settings"] self.max_nl_it = coupling_solver_settings["nl_max_it"].GetInt() self.nl_tol = coupling_solver_settings["nl_tol"].GetDouble() self.solve_mesh_at_each_iteration = coupling_solver_settings["solve_mesh_at_each_iteration"].GetBool() self.coupling_algorithm = coupling_solver_settings["coupling_scheme"].GetString() self.fluid_interface_submodelpart_name = coupling_solver_settings["fluid_interfaces_list"][0].GetString() self.structure_interface_submodelpart_name = coupling_solver_settings["structure_interfaces_list"][0].GetString() coupling_utility_parameters = coupling_solver_settings["coupling_strategy"] # Construct the structure solver structural_solver_settings = self.settings["structure_solver_settings"]["solver_settings"] if not structural_solver_settings.Has("time_stepping"): self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the time_step, this will be removed!") time_stepping_params = KratosMultiphysics.Parameters("{}") time_stepping_params.AddValue("time_step", self.settings["structure_solver_settings"]["problem_data"]["time_step"]) structural_solver_settings.AddValue("time_stepping", time_stepping_params) if not structural_solver_settings.Has("domain_size"): self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the domain_size, this will be removed!") structural_solver_settings.AddEmptyValue("domain_size") structural_solver_settings["domain_size"].SetInt(self.settings["structure_solver_settings"]["problem_data"]["domain_size"].GetInt()) if not structural_solver_settings.Has("model_part_name"): self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Using the old way to pass the model_part_name, this will be removed!") structural_solver_settings.AddEmptyValue("model_part_name") structural_solver_settings["model_part_name"].SetString(self.settings["structure_solver_settings"]["problem_data"]["model_part_name"].GetString()) self.structure_solver = python_solvers_wrapper_structural.CreateSolver(self.model, self.settings["structure_solver_settings"]) self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Structure solver construction finished.") # Construct the fluid solver self.fluid_solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.settings["fluid_solver_settings"]) self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Fluid solver construction finished.") # Construct the coupling partitioned strategy self.coupling_utility = convergence_accelerator_factory.CreateConvergenceAccelerator(coupling_utility_parameters) self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Coupling strategy construction finished.") # Construct the ALE mesh solver mesh_solver_settings = KratosMultiphysics.Parameters("{}") mesh_solver_settings.AddEmptyValue("problem_data") mesh_solver_settings.AddEmptyValue("solver_settings") parallel_type = KratosMultiphysics.Parameters('''{"parallel_type" : ""}''') parallel_type["parallel_type"].SetString(self.settings["fluid_solver_settings"]["problem_data"]["parallel_type"].GetString()) mesh_solver_type = KratosMultiphysics.Parameters('''{"solver_type" : ""}''') mesh_solver_type["solver_type"].SetString(self.settings["coupling_solver_settings"]["solver_settings"]["mesh_solver"].GetString()) mesh_solver_settings["problem_data"] = parallel_type mesh_solver_settings["solver_settings"] = mesh_solver_type #TODO: UPDATE TO MODEL ONCE MESH MOVING APPLICATION SUPPORTS IT self.mesh_solver = python_solvers_wrapper_mesh_motion.CreateSolver(self.fluid_solver.main_model_part, mesh_solver_settings) self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "ALE mesh solver construction finished.") self._PrintInfoOnRankZero("::[PartitionedFSIBaseSolver]::", "Partitioned FSI base solver construction finished.")