Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fluid] Fine grained Python solvers #6575

Merged
merged 48 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
96e5fb4
Base solver
rubenzorrilla Mar 14, 2020
e2ab850
Working monolithic and FS solvers
rubenzorrilla Mar 14, 2020
d5035d1
Serial solvers working
rubenzorrilla Mar 15, 2020
ac17ab4
Remove old steady solver
rubenzorrilla Mar 15, 2020
2caacb2
Serial solvers clean up
rubenzorrilla Mar 16, 2020
889a4f2
MPI solvers (testing is pending)
rubenzorrilla Mar 16, 2020
aec2a26
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 18, 2020
17159d8
Adding missing Trilinos scheme
rubenzorrilla Mar 18, 2020
b98d832
Fix name mangling
rubenzorrilla Mar 19, 2020
3014ff8
Minor
rubenzorrilla Mar 19, 2020
e06ca98
Using AMGCL as default linear solver
rubenzorrilla Mar 19, 2020
7ff8119
Using self.__class__.__name__
rubenzorrilla Mar 19, 2020
11fc9ab
Adjoint solvers
rubenzorrilla Mar 20, 2020
aebc95d
Chimera solvers
rubenzorrilla Mar 20, 2020
bd58e39
Minor correction
rubenzorrilla Mar 20, 2020
255f2cc
Potential flow solvers
rubenzorrilla Mar 20, 2020
9e3900e
Using getters, main model part and adding missing initialize
marcnunezc Mar 20, 2020
6ba1b9c
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 20, 2020
a7152df
Adding @classmethod decorators to potential flow solvers
rubenzorrilla Mar 20, 2020
7f4ab1a
changes to chimera app to solve test failures
adityaghantasala Mar 20, 2020
060d974
add detailed optional output
adityaghantasala Mar 20, 2020
6400308
Merge branch 'fluid/fine-grained-initialize' of https://github.com/Kr…
adityaghantasala Mar 20, 2020
e69bc08
codecy spaces
adityaghantasala Mar 20, 2020
a82e8fe
Using computing_model_part and adapting test jsons
marcnunezc Mar 20, 2020
7f4d93e
Merge branch 'fluid/fine-grained-initialize' of https://github.com/Kr…
marcnunezc Mar 20, 2020
414db10
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 21, 2020
a8c6105
solution_scheme to scheme
rubenzorrilla Mar 21, 2020
96c1616
Update applications/FluidDynamicsApplication/python_scripts/fluid_sol…
rubenzorrilla Mar 21, 2020
8f06292
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 22, 2020
da89039
FM-ALE DOFs message
rubenzorrilla Mar 22, 2020
d1d5144
Follow style guide
rubenzorrilla Mar 22, 2020
78be497
More code review and Codacy
rubenzorrilla Mar 22, 2020
f0e3e1c
Update applications/FluidDynamicsApplication/python_scripts/trilinos_…
rubenzorrilla Mar 23, 2020
9dddf45
Update applications/FluidDynamicsApplication/python_scripts/trilinos_…
rubenzorrilla Mar 23, 2020
3b44eec
Update applications/FluidDynamicsApplication/python_scripts/trilinos_…
rubenzorrilla Mar 23, 2020
000dca5
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 23, 2020
d8be320
change mpi solver tolerance
sunethwarna Mar 23, 2020
726aefc
Merge branch 'fluid/fine-grained-initialize' of https://github.com/Kr…
sunethwarna Mar 23, 2020
95cf8c8
adding comment
sunethwarna Mar 23, 2020
017d37f
Check restart
rubenzorrilla Mar 23, 2020
110943b
Merge branch 'master' of https://github.com/KratosMultiphysics/Kratos…
adityaghantasala Mar 23, 2020
d59aeeb
Merge branch 'master' into fluid/fine-grained-initialize
rubenzorrilla Mar 27, 2020
b7b6858
@philbucher suggestions
rubenzorrilla Mar 27, 2020
d758736
Missing aux Darcy test solver change
rubenzorrilla Mar 27, 2020
6213eee
Merge branch 'master' into fluid/fine-grained-initialize
philbucher Mar 29, 2020
339612d
fixing NavierStokesAleFluidSolver
philbucher Mar 29, 2020
2f7b4ca
Potential flow style guide
rubenzorrilla Mar 30, 2020
f65a3ae
Merge branch 'fluid/fine-grained-initialize' of https://github.com/Kr…
rubenzorrilla Mar 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

@rubenzorrilla rubenzorrilla Mar 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adityaghantasala Just for me to know. Why do you need the main_model_part? It is because it contains both the background mesh and the patches?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly. I need to use the main_model_part because the constraints are added on this modelpart and computing_model_part does not know anything about them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmmm now I see. Do you think we should add them to the computing model part too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current impelementations, not necessary. But as I remember that computing modelpart is set to be removed in future no ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the structure. It is required to have it in the fluid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really required in FluidApp ? If not we can also try to remove it !

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discussed this many times with @jcotela, he said it is not possible to remove it
Not sure if this has changed


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