Skip to content

Commit

Permalink
Merge pull request #6575 from KratosMultiphysics/fluid/fine-grained-i…
Browse files Browse the repository at this point in the history
…nitialize

[Fluid] Fine grained Python solvers
  • Loading branch information
rubenzorrilla authored Mar 31, 2020
2 parents e69d5fc + f65a3ae commit d578593
Show file tree
Hide file tree
Showing 29 changed files with 1,303 additions and 1,478 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class NavierStokesSolverFractionalStepForChimera(NavierStokesSolverFractionalSte
def __init__(self, model, custom_settings):
[self.chimera_settings, self.chimera_internal_parts, custom_settings] = chimera_setup_utils.SeparateAndValidateChimeraSettings(custom_settings)
super(NavierStokesSolverFractionalStepForChimera,self).__init__(model,custom_settings)
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera", "Construction of NavierStokesSolverFractionalStepForChimera finished.")
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Construction of NavierStokesSolverFractionalStepForChimera finished.")

def AddVariables(self):
super(NavierStokesSolverFractionalStepForChimera,self).AddVariables()
Expand All @@ -31,9 +31,7 @@ def AddVariables(self):
self.main_model_part.AddNodalSolutionStepVariable(KratosChimera.ROTATION_MESH_DISPLACEMENT)
self.main_model_part.AddNodalSolutionStepVariable(KratosChimera.ROTATION_MESH_VELOCITY)


KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera", "Fluid solver variables added correctly.")

KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Fluid chimera solver variables added correctly.")

def ImportModelPart(self):
if(self.settings["model_import_settings"]["input_type"].GetString() == "chimera"):
Expand All @@ -45,63 +43,25 @@ def ImportModelPart(self):
material_file_name = self.settings["material_import_settings"]["materials_filename"].GetString()
import KratosMultiphysics.ChimeraApplication.chimera_modelpart_import as chim_mp_imp
chim_mp_imp.ImportChimeraModelparts(self.main_model_part, chimera_mp_import_settings, material_file=material_file_name, parallel_type="OpenMP")
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera", " Import of all chimera modelparts completed.")
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, " Import of all chimera modelparts completed.")
else:# we can use the default implementation in the base class
super(NavierStokesSolverFractionalStepForChimera,self).ImportModelPart()

def Initialize(self):
self.chimera_process = chimera_setup_utils.GetApplyChimeraProcess(self.model, self.chimera_settings, self.settings)
self.computing_model_part =self.main_model_part
# If needed, create the estimate time step utility
if (self.settings["time_stepping"]["automatic_time_step"].GetBool()):
self.EstimateDeltaTimeUtility = self._get_automatic_time_stepping_utility()

#TODO: next part would be much cleaner if we passed directly the parameters to the c++
if self.settings["consider_periodic_conditions"] == True:
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera Periodic conditions are not implemented in this case .")
raise NotImplementedError
else:
self.solver_settings = KratosChimera.FractionalStepSettings(self.computing_model_part,
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE],
self.settings["time_order"].GetInt(),
self.settings["use_slip_conditions"].GetBool(),
self.settings["move_mesh_flag"].GetBool(),
self.settings["reform_dofs_at_each_step"].GetBool())

self.solver_settings.SetEchoLevel(self.settings["echo_level"].GetInt())

self.solver_settings.SetStrategy(KratosCFD.StrategyLabel.Velocity,
self.velocity_linear_solver,
self.settings["velocity_tolerance"].GetDouble(),
self.settings["maximum_velocity_iterations"].GetInt())

self.solver_settings.SetStrategy(KratosCFD.StrategyLabel.Pressure,
self.pressure_linear_solver,
self.settings["pressure_tolerance"].GetDouble(),
self.settings["maximum_pressure_iterations"].GetInt())


if self.settings["consider_periodic_conditions"].GetBool() == True:
self.solver = KratosCFD.FSStrategy(self.computing_model_part,
self.solver_settings,
self.settings["predictor_corrector"].GetBool(),
KratosCFD.PATCH_INDEX)
else:
self.solver = KratosChimera.FSStrategyForChimera(self.computing_model_part,
self.solver_settings,
self.settings["predictor_corrector"].GetBool())

self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DYNAMIC_TAU, self.settings["dynamic_tau"].GetDouble())
self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.OSS_SWITCH, self.settings["oss_switch"].GetInt())
# Call the base solver to create the solution strategy
super(NavierStokesSolverFractionalStepForChimera,self).Initialize()

(self.solver).Initialize()

self.solver.Check()

KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera", "Solver initialization finished.")

chimera_setup_utils.SetChimeraInternalPartsFlag(self.model, self.chimera_internal_parts)
# Chimera utilities initialization
self.chimera_process = chimera_setup_utils.GetApplyChimeraProcess(
self.model,
self.chimera_settings,
self.settings)
chimera_setup_utils.SetChimeraInternalPartsFlag(
self.model,
self.chimera_internal_parts)

def GetComputingModelPart(self):
return self.main_model_part

def InitializeSolutionStep(self):
self.chimera_process.ExecuteInitializeSolutionStep()
Expand All @@ -110,4 +70,53 @@ def InitializeSolutionStep(self):
def FinalizeSolutionStep(self):
super(NavierStokesSolverFractionalStepForChimera,self).FinalizeSolutionStep()
## Depending on the setting this will clear the created constraints
self.chimera_process.ExecuteFinalizeSolutionStep()
self.chimera_process.ExecuteFinalizeSolutionStep()

def _CreateSolutionStrategy(self):
computing_model_part = self.GetComputingModelPart()
domain_size = computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]

# Create the pressure and velocity linear solvers
# Note that linear_solvers is a tuple. The first item is the pressure
# linear solver. The second item is the velocity linear solver.
linear_solvers = self._GetLinearSolver()

# Create the fractional step settings instance
# TODO: next part would be much cleaner if we passed directly the parameters to the c++
if self.settings["consider_periodic_conditions"].GetBool():
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStepForChimera Periodic conditions are not implemented in this case .")
raise NotImplementedError
else:
fractional_step_settings = KratosChimera.FractionalStepSettings(
computing_model_part,
domain_size,
self.settings["time_order"].GetInt(),
self.settings["use_slip_conditions"].GetBool(),
self.settings["move_mesh_flag"].GetBool(),
self.settings["reform_dofs_at_each_step"].GetBool())

# Set the strategy echo level
fractional_step_settings.SetEchoLevel(self.settings["echo_level"].GetInt())

# Set the velocity and pressure fractional step strategy settings
fractional_step_settings.SetStrategy(KratosCFD.StrategyLabel.Pressure,
linear_solvers[0],
self.settings["pressure_tolerance"].GetDouble(),
self.settings["maximum_pressure_iterations"].GetInt())

fractional_step_settings.SetStrategy(KratosCFD.StrategyLabel.Velocity,
linear_solvers[1],
self.settings["velocity_tolerance"].GetDouble(),
self.settings["maximum_velocity_iterations"].GetInt())

# Create the fractional step strategy
if self.settings["consider_periodic_conditions"].GetBool() == True:
KratosMultiphysics.Logger.PrintInfo("FSStrategyForChimera Periodic conditions are not implemented in this case .")
raise NotImplementedError
else:
solution_strategy = KratosChimera.FSStrategyForChimera(
computing_model_part,
fractional_step_settings,
self.settings["predictor_corrector"].GetBool())

return solution_strategy
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import KratosMultiphysics
import KratosMultiphysics.ChimeraApplication as KratosChimera
from KratosMultiphysics.ChimeraApplication import chimera_setup_utils
# Import applications
import KratosMultiphysics.FluidDynamicsApplication as KratosCFD

# Import base class file
from KratosMultiphysics.FluidDynamicsApplication.navier_stokes_solver_vmsmonolithic import NavierStokesSolverMonolithic
Expand All @@ -17,7 +15,7 @@ class NavierStokesSolverMonolithicChimera(NavierStokesSolverMonolithic):
def __init__(self, model, custom_settings):
[self.chimera_settings, self.chimera_internal_parts, custom_settings] = chimera_setup_utils.SeparateAndValidateChimeraSettings(custom_settings)
super(NavierStokesSolverMonolithicChimera,self).__init__(model,custom_settings)
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicChimera", "Construction of NavierStokesSolverMonolithic finished.")
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Construction of NavierStokesSolverMonolithicChimera finished.")

def AddVariables(self):
super(NavierStokesSolverMonolithicChimera,self).AddVariables()
Expand All @@ -28,7 +26,7 @@ def AddVariables(self):
self.main_model_part.AddNodalSolutionStepVariable(KratosChimera.ROTATION_MESH_DISPLACEMENT)
self.main_model_part.AddNodalSolutionStepVariable(KratosChimera.ROTATION_MESH_VELOCITY)

KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicChimera", "Fluid solver variables added correctly.")
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, "Fluid chimera solver variables added correctly.")

def ImportModelPart(self):
if(self.settings["model_import_settings"]["input_type"].GetString() == "chimera"):
Expand All @@ -40,106 +38,40 @@ def ImportModelPart(self):
material_file_name = self.settings["material_import_settings"]["materials_filename"].GetString()
import KratosMultiphysics.ChimeraApplication.chimera_modelpart_import as chim_mp_imp
chim_mp_imp.ImportChimeraModelparts(self.main_model_part, chimera_mp_import_settings, material_file=material_file_name, parallel_type="OpenMP")
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicChimera", " Import of all chimera modelparts completed.")
KratosMultiphysics.Logger.PrintInfo(self.__class__.__name__, " Import of all chimera modelparts completed.")
else:# we can use the default implementation in the base class
super(NavierStokesSolverMonolithicChimera,self).ImportModelPart()

def Initialize(self):
self.chimera_process = chimera_setup_utils.GetApplyChimeraProcess(self.model, self.chimera_settings, self.settings)
self.computing_model_part = self.main_model_part
# If needed, create the estimate time step utility
if (self.settings["time_stepping"]["automatic_time_step"].GetBool()):
self.EstimateDeltaTimeUtility = self._get_automatic_time_stepping_utility()
# Call the base solver to create the solution strategy
super(NavierStokesSolverMonolithicChimera,self).Initialize()

# Creating the solution strategy
self.conv_criteria = KratosCFD.VelPrCriteria(self.settings["relative_velocity_tolerance"].GetDouble(),
self.settings["absolute_velocity_tolerance"].GetDouble(),
self.settings["relative_pressure_tolerance"].GetDouble(),
self.settings["absolute_pressure_tolerance"].GetDouble())

(self.conv_criteria).SetEchoLevel(self.settings["echo_level"].GetInt())

# Creating the time integration scheme
if (self.element_integrates_in_time):
# "Fake" scheme for those cases in where the element manages the time integration
# It is required to perform the nodal update once the current time step is solved
self.time_scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticSchemeSlip(
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE],
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]+1)
# In case the BDF2 scheme is used inside the element, the BDF time discretization utility is required to update the BDF coefficients
if (self.settings["time_scheme"].GetString() == "bdf2"):
time_order = 2
self.time_discretization = KratosMultiphysics.TimeDiscretization.BDF(time_order)
else:
err_msg = "Requested elemental time scheme \"" + self.settings["time_scheme"].GetString()+ "\" is not available.\n"
err_msg += "Available options are: \"bdf2\""
raise Exception(err_msg)
else:
if not hasattr(self, "_turbulence_model_solver"):
# Bossak time integration scheme
if self.settings["time_scheme"].GetString() == "bossak":
if self.settings["consider_periodic_conditions"].GetBool() == True:
self.time_scheme = KratosCFD.ResidualBasedPredictorCorrectorVelocityBossakSchemeTurbulent(
self.settings["alpha"].GetDouble(),
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE],
KratosCFD.PATCH_INDEX)
else:
self.time_scheme = KratosCFD.ResidualBasedPredictorCorrectorVelocityBossakSchemeTurbulent(
self.settings["alpha"].GetDouble(),
self.settings["move_mesh_strategy"].GetInt(),
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE])
# BDF2 time integration scheme
elif self.settings["time_scheme"].GetString() == "bdf2":
self.time_scheme = KratosCFD.GearScheme()
# Time scheme for steady state fluid solver
elif self.settings["time_scheme"].GetString() == "steady":
self.time_scheme = KratosCFD.ResidualBasedSimpleSteadyScheme(
self.settings["velocity_relaxation"].GetDouble(),
self.settings["pressure_relaxation"].GetDouble(),
self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE])
else:
err_msg = "Requested time scheme " + self.settings["time_scheme"].GetString() + " is not available.\n"
err_msg += "Available options are: \"bossak\", \"bdf2\" and \"steady\""
raise Exception(err_msg)
else:
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicForChimera turbulent solver is not possible.")
raise NotImplementedError

if self.settings["consider_periodic_conditions"].GetBool() == True:
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicForChimera Periodic conditions are not implemented in this case .")
raise NotImplementedError
else:
builder_and_solver = KratosChimera.ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera(self.linear_solver)

self.solver = KratosMultiphysics.ResidualBasedNewtonRaphsonStrategy(self.computing_model_part,
self.time_scheme,
self.linear_solver,
self.conv_criteria,
builder_and_solver,
self.settings["maximum_iterations"].GetInt(),
self.settings["compute_reactions"].GetBool(),
self.settings["reform_dofs_at_each_step"].GetBool(),
self.settings["move_mesh_flag"].GetBool())

(self.solver).SetEchoLevel(self.settings["echo_level"].GetInt())

self.formulation.SetProcessInfo(self.computing_model_part)

(self.solver).Initialize()

self.solver.Check()

KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicChimera", "Solver initialization finished.")

chimera_setup_utils.SetChimeraInternalPartsFlag(self.model, self.chimera_internal_parts)
# Chimera utilities initialization
self.chimera_process = chimera_setup_utils.GetApplyChimeraProcess(
self.model,
self.chimera_settings,
self.settings)
chimera_setup_utils.SetChimeraInternalPartsFlag(
self.model,
self.chimera_internal_parts)

def GetComputingModelPart(self):
return self.main_model_part

def InitializeSolutionStep(self):
self.chimera_process.ExecuteInitializeSolutionStep()
super(NavierStokesSolverMonolithicChimera,self).InitializeSolutionStep()


def FinalizeSolutionStep(self):
super(NavierStokesSolverMonolithicChimera,self).FinalizeSolutionStep()
## Depending on the setting this will clear the created constraints
self.chimera_process.ExecuteFinalizeSolutionStep()

def _CreateBuilderAndSolver(self):
linear_solver = self._GetLinearSolver()
if self.settings["consider_periodic_conditions"].GetBool():
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithicForChimera Periodic conditions are not implemented in this case .")
raise NotImplementedError
else:
builder_and_solver = KratosChimera.ResidualBasedBlockBuilderAndSolverWithConstraintsForChimera(linear_solver)
return builder_and_solver
Loading

0 comments on commit d578593

Please sign in to comment.