From 9a1ec9479c4955651794c5eec89f8ba3a3e12e1c Mon Sep 17 00:00:00 2001 From: jcotela Date: Wed, 30 May 2018 17:03:13 +0200 Subject: [PATCH 01/27] Deriving fluid solvers from PythonSolver. --- .../navier_stokes_base_solver.py | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py index d3489571c142..39399223e973 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py @@ -3,6 +3,7 @@ # Importing the Kratos Library import KratosMultiphysics +from python_sovler import PythonSolver # Check that applications were imported in the main script KratosMultiphysics.CheckRegisteredApplications("FluidDynamicsApplication") @@ -13,20 +14,36 @@ def CreateSolver(main_model_part, custom_settings): return NavierStokesBaseSolver(main_model_part, custom_settings) -class NavierStokesBaseSolver(object): +class NavierStokesBaseSolver(PythonSolver): + + def __init__(self, model, custom_settings): + super(NavierStokesBaseSolver,self).__init___(model, custom_settings) + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True - def __init__(self, main_model_part, custom_settings): ## Set the element and condition names for the replace settings + ## These should be defined in derived classes self.element_name = None self.condition_name = None self.min_buffer_size = 3 - self.step = 0 - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True + if self.settings.Has("model_part_name"): + model_part_name = self.settings["model_part_name"].GetString() + if self.model.HasModelPart(model_part_name): + self.main_model_part = self.model.GetModelPart(model_part_name) + else: + self.main_model_part = ModelPart(model_part_name) + self.model.AddModelPart(self.main_model_part) + else: + message = "".join( + "\"model_part_name\" not found in solver settings\n." + "Please validate input parameters before calling the NavierStokesBaseSolver base class constructor." + ) + raise Exception(message) def AddVariables(self): - raise Exception("Trying to add Navier-Stokes base solver variables. Implement the AddVariables() method in the specific derived solver.") + raise Exception("Trying to call NavierStokesBaseSolver.AddVariables(). Implement the AddVariables() method in the specific derived solver.") def ImportModelPart(self): ## Read model part From 2182cc71ae2e215f8ebef1e0f50e887f144a5e62 Mon Sep 17 00:00:00 2001 From: jcotela Date: Wed, 30 May 2018 17:50:50 +0200 Subject: [PATCH 02/27] Adapting the fluid base solver to match the PythonSolver structure. --- .../navier_stokes_base_solver.py | 161 +++++++++--------- 1 file changed, 83 insertions(+), 78 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py index 39399223e973..5a8b52156007 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py @@ -28,23 +28,26 @@ def __init__(self, model, custom_settings): self.condition_name = None self.min_buffer_size = 3 - if self.settings.Has("model_part_name"): - model_part_name = self.settings["model_part_name"].GetString() - if self.model.HasModelPart(model_part_name): - self.main_model_part = self.model.GetModelPart(model_part_name) - else: - self.main_model_part = ModelPart(model_part_name) - self.model.AddModelPart(self.main_model_part) + # Either retrieve the model part from the model or create a new one + model_part_name = self.settings["model_part_name"].GetString() + if self.model.HasModelPart(model_part_name): + self.main_model_part = self.model.GetModelPart(model_part_name) else: - message = "".join( - "\"model_part_name\" not found in solver settings\n." - "Please validate input parameters before calling the NavierStokesBaseSolver base class constructor." - ) - raise Exception(message) + self.main_model_part = ModelPart(model_part_name) + self.model.AddModelPart(self.main_model_part) def AddVariables(self): raise Exception("Trying to call NavierStokesBaseSolver.AddVariables(). Implement the AddVariables() method in the specific derived solver.") + def AddDofs(self): + KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_X, KratosMultiphysics.REACTION_X,self.main_model_part) + KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_Y, KratosMultiphysics.REACTION_Y,self.main_model_part) + KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_Z, KratosMultiphysics.REACTION_Z,self.main_model_part) + KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.PRESSURE, KratosMultiphysics.REACTION_WATER_PRESSURE,self.main_model_part) + + if self._IsPrintingRank(): + KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Fluid solver DOFs added correctly.") + def ImportModelPart(self): ## Read model part self._model_part_reading() @@ -53,7 +56,7 @@ def ImportModelPart(self): ## Executes the check and prepare model process self._execute_check_and_prepare() ## Set buffer size - self._set_buffer_size() + self.main_model_part.SetBufferSize(self.min_buffer_size) if self._IsPrintingRank(): KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Model reading finished.") @@ -66,52 +69,12 @@ def ExportModelPart(self): if self._IsPrintingRank(): KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Model export finished.") - def AddDofs(self): - KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_X, KratosMultiphysics.REACTION_X,self.main_model_part) - KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_Y, KratosMultiphysics.REACTION_Y,self.main_model_part) - KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_Z, KratosMultiphysics.REACTION_Z,self.main_model_part) - KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.PRESSURE, KratosMultiphysics.REACTION_WATER_PRESSURE,self.main_model_part) - - if self._IsPrintingRank(): - KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Fluid solver DOFs added correctly.") - - def AdaptMesh(self): - pass - - def GetComputingModelPart(self): - return self.main_model_part.GetSubModelPart("fluid_computational_model_part") - - def GetOutputVariables(self): - pass - - def ComputeDeltaTime(self): - # Automatic time step computation according to user defined CFL number - if (self.settings["time_stepping"]["automatic_time_step"].GetBool()): - delta_time = self.EstimateDeltaTimeUtility.EstimateDt() - # User-defined delta time - else: - delta_time = self.settings["time_stepping"]["time_step"].GetDouble() - - return delta_time - def GetMinimumBufferSize(self): return self.min_buffer_size def Initialize(self): raise Exception("Calling the Navier-Stokes base solver. Please implement the custom Initialize() method of your solver.") - def SaveRestart(self): - pass #one should write the restart file here - - def Clear(self): - (self.solver).Clear() - - def Check(self): - (self.solver).Check() - - def SetEchoLevel(self, level): - (self.solver).SetEchoLevel(level) - def AdvanceInTime(self, current_time): dt = self.ComputeDeltaTime() new_time = current_time + dt @@ -141,38 +104,54 @@ def FinalizeSolutionStep(self): if self._TimeBufferIsInitialized(): (self.solver).FinalizeSolutionStep() + def Check(self): + (self.solver).Check() + + def Clear(self): + (self.solver).Clear() + def Solve(self): + message = "".join( + "Calling NavierStokesBaseSolver.Solve() method, which is deprecated\n", + "Please call the individual methods instead:\n", + "solver.InitializeSolutionStep()\n", + "solver.Predict()\n", + "solver.SolveSolutionStep()\n", + "solver.FinalizeSolutionStep()\n" + ) + KratosMultiphysics.Logger.PrintWarning("NavierStokesBaseSolver",message) self.InitializeSolutionStep() self.Predict() self.SolveSolutionStep() self.FinalizeSolutionStep() - def _model_part_reading(self): - ## Model part reading - if(self.settings["model_import_settings"]["input_type"].GetString() == "mdpa"): - ## Here it would be the place to import restart data if required - KratosMultiphysics.ModelPartIO(self.settings["model_import_settings"]["input_filename"].GetString()).ReadModelPart(self.main_model_part) + def GetComputingModelPart(self): + return self.main_model_part.GetSubModelPart("fluid_computational_model_part") - if(self.settings["reorder"].GetBool()): - tmp = KratosMultiphysics.Parameters("{}") - KratosMultiphysics.ReorderAndOptimizeModelPartProcess(self.main_model_part, tmp).Execute() + ## Fluid-specific additions (?) + + def AdaptMesh(self): + pass + + def GetOutputVariables(self): + pass + + def ComputeDeltaTime(self): + # Automatic time step computation according to user defined CFL number + if (self.settings["time_stepping"]["automatic_time_step"].GetBool()): + delta_time = self.EstimateDeltaTimeUtility.EstimateDt() + # User-defined delta time else: - raise Exception("Other input options are not implemented yet.") + delta_time = self.settings["time_stepping"]["time_step"].GetDouble() - def _execute_check_and_prepare(self): - ## Check that the input read has the shape we like - prepare_model_part_settings = KratosMultiphysics.Parameters("{}") - prepare_model_part_settings.AddValue("volume_model_part_name",self.settings["volume_model_part_name"]) - prepare_model_part_settings.AddValue("skin_parts",self.settings["skin_parts"]) + return delta_time - import check_and_prepare_model_process_fluid - check_and_prepare_model_process_fluid.CheckAndPrepareModelProcess(self.main_model_part, prepare_model_part_settings).Execute() + def SaveRestart(self): + pass #one should write the restart file here - def _set_buffer_size(self): - current_buffer_size = self.main_model_part.GetBufferSize() - if self.min_buffer_size > current_buffer_size: - self.main_model_part.SetBufferSize(self.min_buffer_size) + def SetEchoLevel(self, level): + (self.solver).SetEchoLevel(level) def _get_automatic_time_stepping_utility(self): if (self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2): @@ -184,6 +163,30 @@ def _get_automatic_time_stepping_utility(self): return EstimateDeltaTimeUtility + ## The following are required by derived classes + + def _TimeBufferIsInitialized(self): + # We always have one extra old step (step 0, read from input) + return self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] + 1 >= self.GetMinimumBufferSize() + + def _IsPrintingRank(self): + return self._is_printing_rank + + def _GetDefaultSettings(self): + raise Exception("Please define the default solver settings in the derived solver class") + + def _model_part_reading(self): + ## Model part reading + if(self.settings["model_import_settings"]["input_type"].GetString() == "mdpa"): + ## Here it would be the place to import restart data if required + KratosMultiphysics.ModelPartIO(self.settings["model_import_settings"]["input_filename"].GetString()).ReadModelPart(self.main_model_part) + + if(self.settings["reorder"].GetBool()): + tmp = KratosMultiphysics.Parameters("{}") + KratosMultiphysics.ReorderAndOptimizeModelPartProcess(self.main_model_part, tmp).Execute() + else: + raise Exception("Other input options are not implemented yet.") + def _replace_elements_and_conditions(self): ## Get number of nodes and domain size elem_num_nodes = self._get_element_num_nodes() @@ -242,9 +245,11 @@ def _get_condition_num_nodes(self): condition_num_nodes = self.main_model_part.GetCommunicator().MaxAll(condition_num_nodes) return condition_num_nodes - def _IsPrintingRank(self): - return self._is_printing_rank + def _execute_check_and_prepare(self): + ## Check that the input read has the shape we like + prepare_model_part_settings = KratosMultiphysics.Parameters("{}") + prepare_model_part_settings.AddValue("volume_model_part_name",self.settings["volume_model_part_name"]) + prepare_model_part_settings.AddValue("skin_parts",self.settings["skin_parts"]) - def _TimeBufferIsInitialized(self): - # We always have one extra old step (step 0, read from input) - return self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] + 1 >= self.GetMinimumBufferSize() + import check_and_prepare_model_process_fluid + check_and_prepare_model_process_fluid.CheckAndPrepareModelProcess(self.main_model_part, prepare_model_part_settings).Execute() \ No newline at end of file From fdcd7c9cb66fde000bed6b6a144c85af780ec728 Mon Sep 17 00:00:00 2001 From: jcotela Date: Wed, 30 May 2018 18:14:35 +0200 Subject: [PATCH 03/27] Separating Import and Prepare model part methods. --- .../navier_stokes_base_solver.py | 18 ++++-------------- .../navier_stokes_solver_vmsmonolithic.py | 1 + 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py index 5a8b52156007..ed270cee2335 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py @@ -49,8 +49,10 @@ def AddDofs(self): KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Fluid solver DOFs added correctly.") def ImportModelPart(self): - ## Read model part - self._model_part_reading() + # we can use the default implementation in the base class + self._ImportModelPart() + + def PrepareModelPart(self): ## Replace default elements and conditions self._replace_elements_and_conditions() ## Executes the check and prepare model process @@ -175,18 +177,6 @@ def _IsPrintingRank(self): def _GetDefaultSettings(self): raise Exception("Please define the default solver settings in the derived solver class") - def _model_part_reading(self): - ## Model part reading - if(self.settings["model_import_settings"]["input_type"].GetString() == "mdpa"): - ## Here it would be the place to import restart data if required - KratosMultiphysics.ModelPartIO(self.settings["model_import_settings"]["input_filename"].GetString()).ReadModelPart(self.main_model_part) - - if(self.settings["reorder"].GetBool()): - tmp = KratosMultiphysics.Parameters("{}") - KratosMultiphysics.ReorderAndOptimizeModelPartProcess(self.main_model_part, tmp).Execute() - else: - raise Exception("Other input options are not implemented yet.") - def _replace_elements_and_conditions(self): ## Get number of nodes and domain size elem_num_nodes = self._get_element_num_nodes() diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 700e608fd9f6..9d03bf54ece5 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -118,6 +118,7 @@ def __init__(self, main_model_part, custom_settings): default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "navier_stokes_solver_vmsmonolithic", + "model_part_name": "FluidModelPart", "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" From 288cd08acd1ee4e2241c240ba288eebf566e167a Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 11:36:23 +0200 Subject: [PATCH 04/27] Renaming base class and updating method names to match guidelines. --- ..._stokes_base_solver.py => fluid_solver.py} | 97 ++++++++----------- 1 file changed, 41 insertions(+), 56 deletions(-) rename applications/FluidDynamicsApplication/python_scripts/{navier_stokes_base_solver.py => fluid_solver.py} (82%) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py similarity index 82% rename from applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py rename to applications/FluidDynamicsApplication/python_scripts/fluid_solver.py index ed270cee2335..9d8c2a1fd07a 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_base_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py @@ -12,12 +12,12 @@ import KratosMultiphysics.FluidDynamicsApplication as KratosCFD def CreateSolver(main_model_part, custom_settings): - return NavierStokesBaseSolver(main_model_part, custom_settings) + return FluidSolver(main_model_part, custom_settings) -class NavierStokesBaseSolver(PythonSolver): +class FluidSolver(PythonSolver): def __init__(self, model, custom_settings): - super(NavierStokesBaseSolver,self).__init___(model, custom_settings) + super(FluidSolver,self).__init___(model, custom_settings) # There is only a single rank in OpenMP, we always print self._is_printing_rank = True @@ -37,7 +37,7 @@ def __init__(self, model, custom_settings): self.model.AddModelPart(self.main_model_part) def AddVariables(self): - raise Exception("Trying to call NavierStokesBaseSolver.AddVariables(). Implement the AddVariables() method in the specific derived solver.") + raise Exception("Trying to call FluidSolver.AddVariables(). Implement the AddVariables() method in the specific derived solver.") def AddDofs(self): KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_X, KratosMultiphysics.REACTION_X,self.main_model_part) @@ -46,7 +46,7 @@ def AddDofs(self): KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.PRESSURE, KratosMultiphysics.REACTION_WATER_PRESSURE,self.main_model_part) if self._IsPrintingRank(): - KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Fluid solver DOFs added correctly.") + KratosMultiphysics.Logger.PrintInfo("FluidSolver", "Fluid solver DOFs added correctly.") def ImportModelPart(self): # we can use the default implementation in the base class @@ -54,14 +54,14 @@ def ImportModelPart(self): def PrepareModelPart(self): ## Replace default elements and conditions - self._replace_elements_and_conditions() + self.ReplaceElementsAndConditions() ## Executes the check and prepare model process - self._execute_check_and_prepare() + self._ExecuteCheckAndPrepare() ## Set buffer size self.main_model_part.SetBufferSize(self.min_buffer_size) if self._IsPrintingRank(): - KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Model reading finished.") + KratosMultiphysics.Logger.PrintInfo("FluidSolver", "Model reading finished.") def ExportModelPart(self): ## Model part writing @@ -69,13 +69,13 @@ def ExportModelPart(self): KratosMultiphysics.ModelPartIO(name_out_file, KratosMultiphysics.IO.WRITE).WriteModelPart(self.main_model_part) if self._IsPrintingRank(): - KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Model export finished.") + KratosMultiphysics.Logger.PrintInfo("FluidSolver", "Model export finished.") def GetMinimumBufferSize(self): return self.min_buffer_size def Initialize(self): - raise Exception("Calling the Navier-Stokes base solver. Please implement the custom Initialize() method of your solver.") + raise Exception("Calling FluidSolver.Initialize() base method. Please implement a custom Initialize() method for your solver.") def AdvanceInTime(self, current_time): dt = self.ComputeDeltaTime() @@ -98,9 +98,9 @@ def SolveSolutionStep(self): if self._TimeBufferIsInitialized(): is_converged = self.solver.SolveSolutionStep() if not is_converged and self._IsPrintingRank(): - msg = "Navier-Stokes solver did not converge for iteration " + str(self.main_model_part.ProcessInfo[KratosMultiphysics.STEP]) + "\n" + msg = "Fluid solver did not converge for iteration " + str(self.main_model_part.ProcessInfo[KratosMultiphysics.STEP]) + "\n" msg += "corresponding to time " + str(self.main_model_part.ProcessInfo[KratosMultiphysics.TIME]) + "\n" - KratosMultiphysics.Logger.PrintWarning("NavierStokesBaseSolver",msg) + KratosMultiphysics.Logger.PrintWarning("FluidSolver",msg) def FinalizeSolutionStep(self): if self._TimeBufferIsInitialized(): @@ -114,14 +114,14 @@ def Clear(self): def Solve(self): message = "".join( - "Calling NavierStokesBaseSolver.Solve() method, which is deprecated\n", + "Calling FluidSolver.Solve() method, which is deprecated\n", "Please call the individual methods instead:\n", "solver.InitializeSolutionStep()\n", "solver.Predict()\n", "solver.SolveSolutionStep()\n", "solver.FinalizeSolutionStep()\n" ) - KratosMultiphysics.Logger.PrintWarning("NavierStokesBaseSolver",message) + KratosMultiphysics.Logger.PrintWarning("FluidSolver",message) self.InitializeSolutionStep() self.Predict() self.SolveSolutionStep() @@ -130,41 +130,6 @@ def Solve(self): def GetComputingModelPart(self): return self.main_model_part.GetSubModelPart("fluid_computational_model_part") - ## Fluid-specific additions (?) - - def AdaptMesh(self): - pass - - def GetOutputVariables(self): - pass - - def ComputeDeltaTime(self): - # Automatic time step computation according to user defined CFL number - if (self.settings["time_stepping"]["automatic_time_step"].GetBool()): - delta_time = self.EstimateDeltaTimeUtility.EstimateDt() - # User-defined delta time - else: - delta_time = self.settings["time_stepping"]["time_step"].GetDouble() - - return delta_time - - def SaveRestart(self): - pass #one should write the restart file here - - - def SetEchoLevel(self, level): - (self.solver).SetEchoLevel(level) - - def _get_automatic_time_stepping_utility(self): - if (self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2): - EstimateDeltaTimeUtility = KratosCFD.EstimateDtUtility2D(self.computing_model_part, - self.settings["time_stepping"]) - else: - EstimateDeltaTimeUtility = KratosCFD.EstimateDtUtility3D(self.computing_model_part, - self.settings["time_stepping"]) - - return EstimateDeltaTimeUtility - ## The following are required by derived classes def _TimeBufferIsInitialized(self): @@ -177,10 +142,10 @@ def _IsPrintingRank(self): def _GetDefaultSettings(self): raise Exception("Please define the default solver settings in the derived solver class") - def _replace_elements_and_conditions(self): + def _ReplaceElementsAndConditions(self): ## Get number of nodes and domain size - elem_num_nodes = self._get_element_num_nodes() - cond_num_nodes = self._get_condition_num_nodes() + elem_num_nodes = self._GetElementNumNodes() + cond_num_nodes = self._GetConditionNumNodes() domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] ## If there are no elements and/or conditions, default to triangles/tetra meshes to avoid breaking the ReplaceElementsAndConditionsProcess @@ -211,7 +176,7 @@ def _replace_elements_and_conditions(self): ## Call the replace elements and conditions process KratosMultiphysics.ReplaceElementsAndConditionsProcess(self.main_model_part, self.settings["element_replace_settings"]).Execute() - def _get_element_num_nodes(self): + def _GetElementNumNodes(self): if self.main_model_part.NumberOfElements() != 0: if sys.version_info[0] >= 3: # python3 syntax element_num_nodes = len(self.main_model_part.Elements.__iter__().__next__().GetNodes()) @@ -223,7 +188,7 @@ def _get_element_num_nodes(self): element_num_nodes = self.main_model_part.GetCommunicator().MaxAll(element_num_nodes) return element_num_nodes - def _get_condition_num_nodes(self): + def _GetConditionNumNodes(self): if self.main_model_part.NumberOfConditions() != 0: if sys.version_info[0] >= 3: # python3 syntax condition_num_nodes = len(self.main_model_part.Conditions.__iter__().__next__().GetNodes()) @@ -235,11 +200,31 @@ def _get_condition_num_nodes(self): condition_num_nodes = self.main_model_part.GetCommunicator().MaxAll(condition_num_nodes) return condition_num_nodes - def _execute_check_and_prepare(self): + def _ExecuteCheckAndPrepare(self): ## Check that the input read has the shape we like prepare_model_part_settings = KratosMultiphysics.Parameters("{}") prepare_model_part_settings.AddValue("volume_model_part_name",self.settings["volume_model_part_name"]) prepare_model_part_settings.AddValue("skin_parts",self.settings["skin_parts"]) import check_and_prepare_model_process_fluid - check_and_prepare_model_process_fluid.CheckAndPrepareModelProcess(self.main_model_part, prepare_model_part_settings).Execute() \ No newline at end of file + check_and_prepare_model_process_fluid.CheckAndPrepareModelProcess(self.main_model_part, prepare_model_part_settings).Execute() + + def _ComputeDeltaTime(self): + # Automatic time step computation according to user defined CFL number + if (self.settings["time_stepping"]["automatic_time_step"].GetBool()): + delta_time = self.EstimateDeltaTimeUtility.EstimateDt() + # User-defined delta time + else: + delta_time = self.settings["time_stepping"]["time_step"].GetDouble() + + return delta_time + + def _GetAutomaticTimeSteppingUtility(self): + if (self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2): + EstimateDeltaTimeUtility = KratosCFD.EstimateDtUtility2D(self.computing_model_part, + self.settings["time_stepping"]) + else: + EstimateDeltaTimeUtility = KratosCFD.EstimateDtUtility3D(self.computing_model_part, + self.settings["time_stepping"]) + + return EstimateDeltaTimeUtility \ No newline at end of file From 283a43d3754f7d46b0e009511c23c77f94138a9e Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 11:45:53 +0200 Subject: [PATCH 05/27] Adding _ValidateSettings method to check parameters. --- .../FluidDynamicsApplication/python_scripts/fluid_solver.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py index 9d8c2a1fd07a..03471eacc611 100755 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py @@ -19,6 +19,8 @@ class FluidSolver(PythonSolver): def __init__(self, model, custom_settings): super(FluidSolver,self).__init___(model, custom_settings) + self._ValidateSettings() + # There is only a single rank in OpenMP, we always print self._is_printing_rank = True @@ -130,7 +132,7 @@ def Solve(self): def GetComputingModelPart(self): return self.main_model_part.GetSubModelPart("fluid_computational_model_part") - ## The following are required by derived classes + ## FluidSolver specific methods. def _TimeBufferIsInitialized(self): # We always have one extra old step (step 0, read from input) @@ -139,7 +141,7 @@ def _TimeBufferIsInitialized(self): def _IsPrintingRank(self): return self._is_printing_rank - def _GetDefaultSettings(self): + def _ValidateSettings(self): raise Exception("Please define the default solver settings in the derived solver class") def _ReplaceElementsAndConditions(self): From 5f4610047ef632ffa43104f9bfe028a85e2e263c Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 11:46:01 +0200 Subject: [PATCH 06/27] First attempt at derivation. --- .../navier_stokes_solver_vmsmonolithic.py | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 9d03bf54ece5..369649902012 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -10,7 +10,7 @@ import KratosMultiphysics.FluidDynamicsApplication as KratosCFD # Import base class file -import navier_stokes_base_solver +from fluid_solver import FluidSolver class StabilizedFormulation(object): """Helper class to define stabilization-dependent parameters.""" @@ -104,15 +104,9 @@ def _SetUpFIC(self,settings): def CreateSolver(main_model_part, custom_settings): return NavierStokesSolverMonolithic(main_model_part, custom_settings) -class NavierStokesSolverMonolithic(navier_stokes_base_solver.NavierStokesBaseSolver): +class NavierStokesSolverMonolithic(FluidSolver): - def __init__(self, main_model_part, custom_settings): - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part + def _ValidateSettings(self): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" @@ -157,31 +151,36 @@ def __init__(self, main_model_part, custom_settings): }""") ## Backwards compatibility -- deprecation warnings - if custom_settings.Has("oss_switch"): + if self.settings.Has("oss_switch"): msg = "Input JSON data contains deprecated setting \'oss_switch\' (int).\n" msg += "Please define \'stabilization/formulation\' (set it to \'vms\')\n" msg += "and set \'stabilization/use_orthogonal_subscales\' (bool) instead." KratosMultiphysics.Logger.PrintWarning("NavierStokesVMSMonolithicSolver",msg) - if not custom_settings.Has("stabilization"): - custom_settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) - custom_settings["stabilization"].AddEmptyValue("use_orthogonal_subscales") - custom_settings["stabilization"]["use_orthogonal_subscales"].SetBool(bool(custom_settings["oss_switch"].GetInt())) - custom_settings.RemoveValue("oss_switch") - if custom_settings.Has("dynamic_tau"): + if not self.settings.Has("stabilization"): + self.settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) + self.settings["stabilization"].AddEmptyValue("use_orthogonal_subscales") + self.settings["stabilization"]["use_orthogonal_subscales"].SetBool(bool(self.settings["oss_switch"].GetInt())) + self.settings.RemoveValue("oss_switch") + if self.settings.Has("dynamic_tau"): msg = "Input JSON data contains deprecated setting \'dynamic_tau\' (float).\n" msg += "Please define \'stabilization/formulation\' (set it to \'vms\') and \n" msg += "set \'stabilization/dynamic_tau\' (float) instead." KratosMultiphysics.Logger.PrintWarning("NavierStokesVMSMonolithicSolver",msg) - if not custom_settings.Has("stabilization"): - custom_settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) - custom_settings["stabilization"].AddEmptyValue("dynamic_tau") - custom_settings["stabilization"]["dynamic_tau"].SetDouble(custom_settings["dynamic_tau"].GetDouble()) - custom_settings.RemoveValue("dynamic_tau") - - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings + if not self.settings.Has("stabilization"): + self.settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) + self.settings["stabilization"].AddEmptyValue("dynamic_tau") + self.settings["stabilization"]["dynamic_tau"].SetDouble(self.settings["dynamic_tau"].GetDouble()) + self.settings.RemoveValue("dynamic_tau") + self.settings.ValidateAndAssignDefaults(default_settings) + + def __init__(self, main_model_part, custom_settings): + super(NavierStokesSolverMonolithic,self).__init__(main_model_part,custom_settings) + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True + self.stabilization = StabilizedFormulation(self.settings["stabilization"]) self.element_name = self.stabilization.element_name self.condition_name = self.stabilization.condition_name From c74aea5edae090f7989511c90c0e65a6757d6c05 Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 11:57:58 +0200 Subject: [PATCH 07/27] Updating python solvers wrapper for the fluid. --- .../python_scripts/python_solvers_wrapper_fluid.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/python_solvers_wrapper_fluid.py b/applications/FluidDynamicsApplication/python_scripts/python_solvers_wrapper_fluid.py index 500b2b5a4793..d2f8eab7869d 100644 --- a/applications/FluidDynamicsApplication/python_scripts/python_solvers_wrapper_fluid.py +++ b/applications/FluidDynamicsApplication/python_scripts/python_solvers_wrapper_fluid.py @@ -2,10 +2,10 @@ import KratosMultiphysics -def CreateSolver(main_model_part, custom_settings): +def CreateSolver(model, custom_settings): - if (type(main_model_part) != KratosMultiphysics.ModelPart): - raise Exception("input is expected to be provided as a Kratos ModelPart object") + if (type(model) != KratosMultiphysics.Model): + raise Exception("input is expected to be provided as a Kratos Model object") if (type(custom_settings) != KratosMultiphysics.Parameters): raise Exception("input is expected to be provided as a Kratos Parameters object") @@ -46,13 +46,13 @@ def CreateSolver(main_model_part, custom_settings): elif (solver_type == "EmbeddedAusas"): solver_module_name = "trilinos_navier_stokes_embedded_ausas_solver" - + else: raise Exception("the requested solver type is not in the python solvers wrapper") else: raise Exception("parallelism is neither OpenMP nor MPI") solver_module = __import__(solver_module_name) - solver = solver_module.CreateSolver(main_model_part, custom_settings["solver_settings"]) + solver = solver_module.CreateSolver(model, custom_settings["solver_settings"]) return solver From 8a9cf4d4c435c33c98a3010f1dc3ceb29075bd68 Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 15:34:40 +0200 Subject: [PATCH 08/27] Making monolithic solver test run (assorted typos and bugfixes), --- .../python_scripts/fluid_dynamics_analysis.py | 23 ++++++++++++------- .../python_scripts/fluid_solver.py | 23 +++++++++++-------- .../navier_stokes_solver_vmsmonolithic.py | 11 +++++---- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py b/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py index 089c173ea2f8..15fdd15cae27 100644 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py @@ -27,30 +27,37 @@ def __init__(self,model,parameters): else: self.is_printing_rank = True - ## Create model part and solver (but don't initialize them yet) - model_part_name = self.project_parameters["problem_data"]["model_part_name"].GetString() - self.main_model_part = Kratos.ModelPart(model_part_name) + # Deprecation warnings + solver_settings = self.project_parameters["solver_settings"] + if not solver_settings.Has("domain_size"): + Kratos.Logger.PrintInfo("FluidDynamicsAnalysis", "Using the old way to pass the domain_size, this will be removed!") + solver_settings.AddEmptyValue("domain_size") + solver_settings["domain_size"].SetInt(self.project_parameters["problem_data"]["domain_size"].GetInt()) + + if not solver_settings.Has("model_part_name"): + Kratos.Logger.PrintInfo("FluidDynamicsAnalysis", "Using the old way to pass the model_part_name, this will be removed!") + solver_settings.AddEmptyValue("model_part_name") + solver_settings["model_part_name"].SetString(self.project_parameters["problem_data"]["model_part_name"].GetString()) import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.project_parameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(model, self.project_parameters) def Initialize(self): ''' Construct and initialize all classes and tools used in the simulation loop. ''' - domain_size = self.project_parameters["problem_data"]["domain_size"].GetInt() - self.main_model_part.ProcessInfo.SetValue(Kratos.DOMAIN_SIZE, domain_size) self._SetUpRestart() if self.load_restart: + self.main_model_part = self.model.CreateModelPart(self.project_parameters["solver_settings"]["model_part_name"].GetString()) self.restart_utility.LoadRestart() else: self.solver.AddVariables() self.solver.ImportModelPart() + self.solver.PrepareModelPart() self.solver.AddDofs() - - self.model.AddModelPart(self.main_model_part) + self.main_model_part = self.model.GetModelPart(self.project_parameters["solver_settings"]["model_part_name"].GetString()) # this should let eventual derived stages modify the model after reading. self.ModifyInitialProperties() diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py index 03471eacc611..e2a258d3a382 100755 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py @@ -3,7 +3,7 @@ # Importing the Kratos Library import KratosMultiphysics -from python_sovler import PythonSolver +from python_solver import PythonSolver # Check that applications were imported in the main script KratosMultiphysics.CheckRegisteredApplications("FluidDynamicsApplication") @@ -11,13 +11,13 @@ # Import applications import KratosMultiphysics.FluidDynamicsApplication as KratosCFD -def CreateSolver(main_model_part, custom_settings): - return FluidSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return FluidSolver(model, custom_settings) class FluidSolver(PythonSolver): def __init__(self, model, custom_settings): - super(FluidSolver,self).__init___(model, custom_settings) + super(FluidSolver,self).__init__(model, custom_settings) self._ValidateSettings() @@ -35,8 +35,10 @@ def __init__(self, model, custom_settings): if self.model.HasModelPart(model_part_name): self.main_model_part = self.model.GetModelPart(model_part_name) else: - self.main_model_part = ModelPart(model_part_name) - self.model.AddModelPart(self.main_model_part) + self.main_model_part = KratosMultiphysics.ModelPart(model_part_name) + + domain_size = self.settings["domain_size"].GetInt() + self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, domain_size) def AddVariables(self): raise Exception("Trying to call FluidSolver.AddVariables(). Implement the AddVariables() method in the specific derived solver.") @@ -52,16 +54,19 @@ def AddDofs(self): def ImportModelPart(self): # we can use the default implementation in the base class - self._ImportModelPart() + self._ImportModelPart(self.main_model_part,self.settings["model_import_settings"]) def PrepareModelPart(self): ## Replace default elements and conditions - self.ReplaceElementsAndConditions() + self._ReplaceElementsAndConditions() ## Executes the check and prepare model process self._ExecuteCheckAndPrepare() ## Set buffer size self.main_model_part.SetBufferSize(self.min_buffer_size) + if not self.model.HasModelPart(self.settings["model_part_name"].GetString()): + self.model.AddModelPart(self.main_model_part) + if self._IsPrintingRank(): KratosMultiphysics.Logger.PrintInfo("FluidSolver", "Model reading finished.") @@ -80,7 +85,7 @@ def Initialize(self): raise Exception("Calling FluidSolver.Initialize() base method. Please implement a custom Initialize() method for your solver.") def AdvanceInTime(self, current_time): - dt = self.ComputeDeltaTime() + dt = self._ComputeDeltaTime() new_time = current_time + dt self.main_model_part.CloneTimeStep(new_time) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 369649902012..38f656695022 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -101,8 +101,8 @@ def _SetUpFIC(self,settings): self.process_data[KratosCFD.FIC_BETA] = settings["beta"].GetDouble() -def CreateSolver(main_model_part, custom_settings): - return NavierStokesSolverMonolithic(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesSolverMonolithic(model, custom_settings) class NavierStokesSolverMonolithic(FluidSolver): @@ -113,6 +113,7 @@ def _ValidateSettings(self): { "solver_type": "navier_stokes_solver_vmsmonolithic", "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -136,7 +137,7 @@ def _ValidateSettings(self): "skin_parts": [""], "no_skin_parts":[""], "time_stepping" : { - "automatic_time_step" : true, + "automatic_time_step" : false, "CFL_number" : 1, "minimum_delta_time" : 1e-4, "maximum_delta_time" : 0.01 @@ -175,8 +176,8 @@ def _ValidateSettings(self): self.settings.ValidateAndAssignDefaults(default_settings) - def __init__(self, main_model_part, custom_settings): - super(NavierStokesSolverMonolithic,self).__init__(main_model_part,custom_settings) + def __init__(self, model, custom_settings): + super(NavierStokesSolverMonolithic,self).__init__(model,custom_settings) # There is only a single rank in OpenMP, we always print self._is_printing_rank = True From 62d2b76a46c59aa2e44364b3d45f88f7abfbf96d Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 16:08:00 +0200 Subject: [PATCH 09/27] Updating Fractional Step solvers. --- .../navier_stokes_solver_fractionalstep.py | 38 +++++++-------- ...nos_navier_stokes_solver_fractionalstep.py | 48 +++++++++---------- 2 files changed, 41 insertions(+), 45 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py index 6f2885013bc7..5923c09b50e2 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py @@ -10,29 +10,20 @@ import KratosMultiphysics.FluidDynamicsApplication as KratosCFD # Import base class file -import navier_stokes_base_solver +from fluid_solver import FluidSolver -def CreateSolver(main_model_part, custom_settings): - return NavierStokesSolverFractionalStep(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesSolverFractionalStep(model, custom_settings) -class NavierStokesSolverFractionalStep(navier_stokes_base_solver.NavierStokesBaseSolver): - - def __init__(self, main_model_part, custom_settings): - - self.element_name = "FractionalStep" - self.condition_name = "WallCondition" - self.min_buffer_size = 3 - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part +class NavierStokesSolverFractionalStep(FluidSolver): + def _ValidateSettings(self): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "FractionalStep", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -79,7 +70,7 @@ def __init__(self, main_model_part, custom_settings): "skin_parts":[""], "no_skin_parts":[""], "time_stepping" : { - "automatic_time_step" : true, + "automatic_time_step" : false, "CFL_number" : 1, "minimum_delta_time" : 1e-4, "maximum_delta_time" : 0.01 @@ -89,10 +80,19 @@ def __init__(self, main_model_part, custom_settings): "reorder": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings + ## Validate input settings self.settings.ValidateAndAssignDefaults(default_settings) + def __init__(self, model, custom_settings): + super(NavierStokesSolverFractionalStep,self).__init__(model,custom_settings) + + self.element_name = "FractionalStep" + self.condition_name = "WallCondition" + self.min_buffer_size = 3 + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True + ## Construct the linear solvers import linear_solver_factory self.pressure_linear_solver = linear_solver_factory.ConstructSolver(self.settings["pressure_linear_solver_settings"]) diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py index 29da7065f7df..d2e0be3f7ca8 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py @@ -14,27 +14,20 @@ # Import base class file import navier_stokes_solver_fractionalstep +import trilinos_import_model_part_utility -def CreateSolver(main_model_part, custom_settings): - return TrilinosNavierStokesSolverFractionalStep(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return TrilinosNavierStokesSolverFractionalStep(model, custom_settings) class TrilinosNavierStokesSolverFractionalStep(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep): - def __init__(self, main_model_part, custom_settings): - - self.element_name = "FractionalStep" - self.condition_name = "WallCondition" - self.min_buffer_size = 3 - - self._is_printing_rank = (KratosMPI.mpi.rank == 0) - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - + def _ValidateSettings(self): ## Default settings string in Json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "FractionalStep", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -82,10 +75,17 @@ def __init__(self, main_model_part, custom_settings): "use_slip_conditions": true }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) + def __init__(self, model, custom_settings): + super(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep,self).__init__(model,custom_settings) + + self.element_name = "FractionalStep" + self.condition_name = "WallCondition" + self.min_buffer_size = 3 + + self._is_printing_rank = (KratosMPI.mpi.rank == 0) + ## Construct the linear solvers import trilinos_linear_solver_factory self.pressure_linear_solver = trilinos_linear_solver_factory.ConstructSolver(self.settings["pressure_linear_solver_settings"]) @@ -114,25 +114,21 @@ def AddVariables(self): def ImportModelPart(self): ## Construct the Trilinos import model part utility - import trilinos_import_model_part_utility - TrilinosModelPartImporter = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) + self.trilinos_model_part_importer = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) ## Execute the Metis partitioning and reading - TrilinosModelPartImporter.ExecutePartitioningAndReading() - ## Replace default elements and conditions - super(TrilinosNavierStokesSolverFractionalStep, self)._replace_elements_and_conditions() - ## Executes the check and prepare model process - super(TrilinosNavierStokesSolverFractionalStep, self)._execute_check_and_prepare() - ## Call the base class set buffer size - super(TrilinosNavierStokesSolverFractionalStep, self)._set_buffer_size() + self.trilinos_model_part_importer.ExecutePartitioningAndReading() ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY super(TrilinosNavierStokesSolverFractionalStep, self)._set_physical_properties() - ## Construct Trilinos the communicators - TrilinosModelPartImporter.CreateCommunicators() if self._IsPrintingRank(): #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED KratosMultiphysics.Logger.PrintInfo("TrilinosNavierStokesSolverFractionalStep","MPI model reading finished.") + def PrepareModelPart(self): + super(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep,self).PrepareModelPart() + ## Construct Trilinos the communicators + self.trilinos_model_part_importer.CreateCommunicators() + def AddDofs(self): ## Base class DOFs addition From 81bbb15d1847a7a0c15c61b2e4ab6faccd747e3c Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 16:54:35 +0200 Subject: [PATCH 10/27] Fixing issue with restart initialization order. --- .../python_scripts/fluid_dynamics_analysis.py | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py b/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py index 15fdd15cae27..d7c035536261 100644 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_dynamics_analysis.py @@ -42,6 +42,8 @@ def __init__(self,model,parameters): import python_solvers_wrapper_fluid self.solver = python_solvers_wrapper_fluid.CreateSolver(model, self.project_parameters) + self.__restart_utility = None + def Initialize(self): ''' Construct and initialize all classes and tools used in the simulation loop. @@ -50,8 +52,8 @@ def Initialize(self): self._SetUpRestart() if self.load_restart: - self.main_model_part = self.model.CreateModelPart(self.project_parameters["solver_settings"]["model_part_name"].GetString()) - self.restart_utility.LoadRestart() + restart_utility = self._GetRestartUtility() + restart_utility.LoadRestart() else: self.solver.AddVariables() self.solver.ImportModelPart() @@ -90,7 +92,8 @@ def OutputSolutionStep(self): process.ExecuteAfterOutputStep() if self.save_restart: - self.restart_utility.SaveRestart() + restart_utility = self._GetRestartUtility() + restart_utility.SaveRestart() def _SetUpListOfProcesses(self): ''' @@ -164,17 +167,29 @@ def _SetUpRestart(self): restart_settings.RemoveValue("save_restart") restart_settings.AddValue("input_filename", self.project_parameters["problem_data"]["problem_name"]) restart_settings.AddValue("echo_level", self.project_parameters["problem_data"]["echo_level"]) + else: + self.load_restart = False + self.save_restart = False + + def _GetRestartUtility(self): + if self.__restart_utility is not None: + return self.__restart_utility + else: if self.parallel_type == "OpenMP": from restart_utility import RestartUtility as Restart elif self.parallel_type == "MPI": from trilinos_restart_utility import TrilinosRestartUtility as Restart - self.restart_utility = Restart(self.main_model_part, - self.project_parameters["restart_settings"]) - else: - self.load_restart = False - self.save_restart = False + model_part_name = self.project_parameters["solver_settings"]["model_part_name"].GetString() + if self.model.HasModelPart(model_part_name): + model_part = self.model.GetModelPart(model_part_name) + else: + model_part = self.model.CreateModelPart(model_part_name) + + self.__restart_utility = Restart(model_part, + self.project_parameters["restart_settings"]) + if __name__ == '__main__': from sys import argv From 44a1e37a8428d5dd3491756115f3dec461f3f7ef Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 16:55:58 +0200 Subject: [PATCH 11/27] Porting trilinos monolithic solver + changes in trilinos FS solver. --- ...nos_navier_stokes_solver_fractionalstep.py | 5 +- ...inos_navier_stokes_solver_vmsmonolithic.py | 55 +++++++++---------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py index d2e0be3f7ca8..7038e4b2ab80 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py @@ -66,7 +66,7 @@ def _ValidateSettings(self): "skin_parts":[""], "no_skin_parts":[""], "time_stepping": { - "automatic_time_step" : true, + "automatic_time_step" : false, "CFL_number" : 1, "minimum_delta_time" : 1e-4, "maximum_delta_time" : 0.01 @@ -78,6 +78,7 @@ def _ValidateSettings(self): self.settings.ValidateAndAssignDefaults(default_settings) def __init__(self, model, custom_settings): + # Note: deliberately calling the constructor of the base python solver (the parent of my parent) super(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep,self).__init__(model,custom_settings) self.element_name = "FractionalStep" @@ -125,7 +126,7 @@ def ImportModelPart(self): KratosMultiphysics.Logger.PrintInfo("TrilinosNavierStokesSolverFractionalStep","MPI model reading finished.") def PrepareModelPart(self): - super(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep,self).PrepareModelPart() + super(TrilinosNavierStokesSolverFractionalStep,self).PrepareModelPart() ## Construct Trilinos the communicators self.trilinos_model_part_importer.CreateCommunicators() diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py index e9fa6445131b..ef22776e1337 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py @@ -14,27 +14,19 @@ # Import base class file import navier_stokes_solver_vmsmonolithic +import trilinos_import_model_part_utility -def CreateSolver(main_model_part, custom_settings): - return TrilinosNavierStokesSolverMonolithic(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return TrilinosNavierStokesSolverMonolithic(model, custom_settings) class TrilinosNavierStokesSolverMonolithic(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic): - def __init__(self, main_model_part, custom_settings): - - self.element_name = "VMS" - self.condition_name = "MonolithicWallCondition" - self.min_buffer_size = 2 - - self._is_printing_rank = (KratosMPI.mpi.rank == 0) - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - - ## Default settings string in json format + def _ValidateSettings(self):## Default settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "trilinos_navier_stokes_solver_vmsmonolithic", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -64,7 +56,7 @@ def __init__(self, main_model_part, custom_settings): "skin_parts": [""], "no_skin_parts":[""], "time_stepping": { - "automatic_time_step" : true, + "automatic_time_step" : false, "CFL_number" : 1, "minimum_delta_time" : 1e-4, "maximum_delta_time" : 0.01 @@ -78,10 +70,19 @@ def __init__(self, main_model_part, custom_settings): "turbulence_model": "None" }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) + + def __init__(self, model, custom_settings): + # Note: deliberately calling the constructor of the base python solver (the parent of my parent) + super(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic, self).__init__(model,custom_settings) + + self.element_name = "VMS" + self.condition_name = "MonolithicWallCondition" + self.min_buffer_size = 2 + + self._is_printing_rank = (KratosMPI.mpi.rank == 0) + ## Construct the linear solver import trilinos_linear_solver_factory self.trilinos_linear_solver = trilinos_linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"]) @@ -103,28 +104,22 @@ def AddVariables(self): #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED KratosMultiphysics.Logger.Print("Variables for the VMS fluid Trilinos solver added correctly in each processor.") - def ImportModelPart(self): ## Construct the Trilinos import model part utility - import trilinos_import_model_part_utility - TrilinosModelPartImporter = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) + self.trilinos_model_part_importer = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) ## Execute the Metis partitioning and reading - TrilinosModelPartImporter.ExecutePartitioningAndReading() - ## Replace default elements and conditions - super(TrilinosNavierStokesSolverMonolithic, self)._replace_elements_and_conditions() - ## Executes the check and prepare model process - super(TrilinosNavierStokesSolverMonolithic, self)._execute_check_and_prepare() - ## Call the base class set buffer size - super(TrilinosNavierStokesSolverMonolithic, self)._set_buffer_size() + self.trilinos_model_part_importer.ExecutePartitioningAndReading() ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY super(TrilinosNavierStokesSolverMonolithic, self)._set_physical_properties() - ## Construct Trilinos the communicators - TrilinosModelPartImporter.CreateCommunicators() if self._IsPrintingRank(): #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED - KratosMultiphysics.Logger.Print("MPI model reading finished.") + KratosMultiphysics.Logger.PrintInfo("TrilinosNavierStokesSolverFractionalStep","MPI model reading finished.") + def PrepareModelPart(self): + super(TrilinosNavierStokesSolverMonolithic,self).PrepareModelPart() + ## Construct Trilinos the communicators + self.trilinos_model_part_importer.CreateCommunicators() def AddDofs(self): ## Base class DOFs addition From a92464416716beb1dd02ab84a92d994085e7a6b7 Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 17:06:22 +0200 Subject: [PATCH 12/27] Deriving the compressible solver from FluidSolver. --- .../navier_stokes_compressible_solver.py | 72 ++++++++++--------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py index c33704930fbc..2c3171e40d5e 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py @@ -7,29 +7,20 @@ KratosMultiphysics.CheckForPreviousImport() ## Import base class file -import navier_stokes_base_solver +from fluid_solver import FluidSolver -def CreateSolver(main_model_part, custom_settings): - return NavierStokesCompressibleSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesCompressibleSolver(model, custom_settings) -class NavierStokesCompressibleSolver(navier_stokes_base_solver.NavierStokesBaseSolver): - - def __init__(self, main_model_part, custom_settings): - - self.element_name = "CompressibleNavierStokes" - self.condition_name = "Condition" - self.min_buffer_size = 3 - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part +class NavierStokesCompressibleSolver(FluidSolver): + def _ValidateSettings(self): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { - "solver_type": "embedded_solver_from_defaults", + "solver_type": "compressible_solver_from_defaults", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "two_element_test" @@ -70,6 +61,17 @@ def __init__(self, main_model_part, custom_settings): self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) + + def __init__(self, model, custom_settings): + super(NavierStokesCompressibleSolver,self).__init__(model,custom_settings) + + self.element_name = "CompressibleNavierStokes" + self.condition_name = "Condition" + self.min_buffer_size = 3 + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True + ## Construct the linear solver import linear_solver_factory self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"]) @@ -81,15 +83,15 @@ def __init__(self, main_model_part, custom_settings): def AddVariables(self): - + self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.MOMENTUM) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DENSITY) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.TOTAL_ENERGY) - + self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.CONDUCTIVITY) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.SPECIFIC_HEAT) self.main_model_part.AddNodalSolutionStepVariable(KratosFluid.HEAT_CAPACITY_RATIO) - + self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.IS_STRUCTURE) ## ? self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.BODY_FORCE) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NODAL_H) ## ? @@ -97,7 +99,7 @@ def AddVariables(self): self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION) #for momentum self.main_model_part.AddNodalSolutionStepVariable(KratosFluid.REACTION_DENSITY) #for momentum self.main_model_part.AddNodalSolutionStepVariable(KratosFluid.REACTION_ENERGY) #for momentum - + self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.FLAG_VARIABLE) ## ? self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.NORMAL) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.Y_WALL) ## ? @@ -105,13 +107,13 @@ def AddVariables(self): self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.KINEMATIC_VISCOSITY) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DYNAMIC_VISCOSITY) - # Post-process + # Post-process self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.VELOCITY) self.main_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.PRESSURE) self.main_model_part.AddNodalSolutionStepVariable(KratosFluid.MACH) #for momentum print("Monolithic compressible fluid solver variables added correctly") - + def AddDofs(self): KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.MOMENTUM_X, KratosMultiphysics.REACTION_X, self.main_model_part) KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.MOMENTUM_Y, KratosMultiphysics.REACTION_Y, self.main_model_part) @@ -130,23 +132,23 @@ def Initialize(self): # Creating the solution strategy self.conv_criteria = KratosMultiphysics.ResidualCriteria(self.settings["relative_tolerance"].GetDouble(), self.settings["absolute_tolerance"].GetDouble()) - + #(self.conv_criteria).SetEchoLevel(self.settings["echo_level"].GetInt() (self.conv_criteria).SetEchoLevel(3) self.bdf_process = KratosMultiphysics.ComputeBDFCoefficientsProcess(self.computing_model_part, self.settings["time_order"].GetInt()) - + domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] rotation_utility = KratosFluid.CompressibleElementRotationUtility(domain_size,KratosMultiphysics.IS_STRUCTURE) time_scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticSchemeSlip(rotation_utility) #time_scheme = KratosMultiphysics.ResidualBasedIncrementalUpdateStaticScheme() # DOFs (4,5) - + builder_and_solver = KratosMultiphysics.ResidualBasedBlockBuilderAndSolver(self.linear_solver) - + self.solver = KratosMultiphysics.ResidualBasedNewtonRaphsonStrategy(self.computing_model_part, time_scheme, @@ -157,22 +159,22 @@ def Initialize(self): 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.solver).SetEchoLevel(1) (self.solver).Initialize() - - + + (self.solver).Check() - + # self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DYNAMIC_TAU, self.settings["dynamic_tau"].GetDouble()) # REMEMBER TO CHECK MY STAB CONSTANTS print ("Monolithic compressible solver initialization finished.") - + def InitializeSolutionStep(self): (self.bdf_process).Execute() @@ -183,6 +185,8 @@ def Solve(self): (self.bdf_process).Execute() (self.solver).Solve() + def PrepareModelPart(self): + self._ExecuteAfterReading() def _ExecuteAfterReading(self): ## Replace element and conditions @@ -195,12 +199,12 @@ def _ExecuteAfterReading(self): import check_and_prepare_model_process_fluid check_and_prepare_model_process_fluid.CheckAndPrepareModelProcess(self.main_model_part, prepare_model_part_settings).Execute() - + #def _SetCompressibleElementReplaceSettings(self): #domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] #self.settings.AddEmptyValue("element_replace_settings") - + #if(domain_size == 3): #self.settings["element_replace_settings"] = KratosMultiphysics.Parameters(""" #{ From 7373be5570f5822ad5499e01888acecd943f6f8a Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 17:07:55 +0200 Subject: [PATCH 13/27] Fixing last commit. --- .../python_scripts/navier_stokes_compressible_solver.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py index 2c3171e40d5e..dd48ffd8b75b 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py @@ -57,8 +57,6 @@ def _ValidateSettings(self): "reorder": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings self.settings.ValidateAndAssignDefaults(default_settings) @@ -186,6 +184,7 @@ def Solve(self): (self.solver).Solve() def PrepareModelPart(self): + super(NavierStokesCompressibleSolver,self).PrepareModelPart() self._ExecuteAfterReading() def _ExecuteAfterReading(self): From e1bb5b619a35efe9f360588883c655a985aa6b8d Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 28 May 2018 16:03:35 +0200 Subject: [PATCH 14/27] Bugfix: non-threadsafe access to processinfo in vms. --- applications/FluidDynamicsApplication/custom_elements/vms.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/FluidDynamicsApplication/custom_elements/vms.h b/applications/FluidDynamicsApplication/custom_elements/vms.h index 53d71ccdcfae..818af4bea16d 100644 --- a/applications/FluidDynamicsApplication/custom_elements/vms.h +++ b/applications/FluidDynamicsApplication/custom_elements/vms.h @@ -301,7 +301,8 @@ class VMS : public Element this->AddMomentumRHS(rRightHandSideVector, Density, N, Area); // For OSS: Add projection of residuals to RHS - if (rCurrentProcessInfo[OSS_SWITCH] == 1) + const ProcessInfo& r_const_process_info = rCurrentProcessInfo; + if (r_const_process_info[OSS_SWITCH] == 1) { array_1d AdvVel; this->GetAdvectiveVel(AdvVel, N); @@ -353,7 +354,8 @@ class VMS : public Element These terms are not used in OSS, as they belong to the finite element space and cancel out with their projections. */ - if (rCurrentProcessInfo[OSS_SWITCH] != 1) + const ProcessInfo& r_const_process_info = rCurrentProcessInfo; + if (r_const_process_info[OSS_SWITCH] != 1) { double ElemSize = this->ElementSize(Area); double Viscosity = this->EffectiveViscosity(Density,N,DN_DX,ElemSize,rCurrentProcessInfo); From 4364dc5aebcf77065d99ed2a7a35973684b5a36d Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 17:55:27 +0200 Subject: [PATCH 15/27] Solving initialization order issue with _ValidateSettings. --- .../python_scripts/fluid_solver.py | 9 ++++-- .../navier_stokes_compressible_solver.py | 5 ++-- .../navier_stokes_solver_fractionalstep.py | 6 ++-- .../navier_stokes_solver_vmsmonolithic.py | 29 ++++++++++--------- ...nos_navier_stokes_solver_fractionalstep.py | 5 ++-- ...inos_navier_stokes_solver_vmsmonolithic.py | 6 ++-- 6 files changed, 34 insertions(+), 26 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py index e2a258d3a382..23d4d1c0c2fc 100755 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py @@ -17,9 +17,9 @@ def CreateSolver(model, custom_settings): class FluidSolver(PythonSolver): def __init__(self, model, custom_settings): - super(FluidSolver,self).__init__(model, custom_settings) + settings = self._ValidateSettings(custom_settings) - self._ValidateSettings() + super(FluidSolver,self).__init__(model, settings) # There is only a single rank in OpenMP, we always print self._is_printing_rank = True @@ -146,9 +146,12 @@ def _TimeBufferIsInitialized(self): def _IsPrintingRank(self): return self._is_printing_rank - def _ValidateSettings(self): + def _ValidateSettings(self, settings): raise Exception("Please define the default solver settings in the derived solver class") + settings.ValidateAndAssignDefaults(KratosMultiphysics.Parameters(r'{}')) + return settings + def _ReplaceElementsAndConditions(self): ## Get number of nodes and domain size elem_num_nodes = self._GetElementNumNodes() diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py index dd48ffd8b75b..e716702fe9a5 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_compressible_solver.py @@ -14,7 +14,7 @@ def CreateSolver(model, custom_settings): class NavierStokesCompressibleSolver(FluidSolver): - def _ValidateSettings(self): + def _ValidateSettings(self,settings): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { @@ -57,7 +57,8 @@ def _ValidateSettings(self): "reorder": false }""") - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings def __init__(self, model, custom_settings): diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py index 5923c09b50e2..d60609b431b5 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py @@ -17,7 +17,7 @@ def CreateSolver(model, custom_settings): class NavierStokesSolverFractionalStep(FluidSolver): - def _ValidateSettings(self): + def _ValidateSettings(self, settings): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { @@ -80,8 +80,8 @@ def _ValidateSettings(self): "reorder": false }""") - ## Validate input settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings def __init__(self, model, custom_settings): super(NavierStokesSolverFractionalStep,self).__init__(model,custom_settings) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 38f656695022..7207b66b13f0 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -106,7 +106,7 @@ def CreateSolver(model, custom_settings): class NavierStokesSolverMonolithic(FluidSolver): - def _ValidateSettings(self): + def _ValidateSettings(self, settings): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" @@ -152,28 +152,29 @@ def _ValidateSettings(self): }""") ## Backwards compatibility -- deprecation warnings - if self.settings.Has("oss_switch"): + if settings.Has("oss_switch"): msg = "Input JSON data contains deprecated setting \'oss_switch\' (int).\n" msg += "Please define \'stabilization/formulation\' (set it to \'vms\')\n" msg += "and set \'stabilization/use_orthogonal_subscales\' (bool) instead." KratosMultiphysics.Logger.PrintWarning("NavierStokesVMSMonolithicSolver",msg) - if not self.settings.Has("stabilization"): - self.settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) - self.settings["stabilization"].AddEmptyValue("use_orthogonal_subscales") - self.settings["stabilization"]["use_orthogonal_subscales"].SetBool(bool(self.settings["oss_switch"].GetInt())) - self.settings.RemoveValue("oss_switch") - if self.settings.Has("dynamic_tau"): + if not settings.Has("stabilization"): + settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) + settings["stabilization"].AddEmptyValue("use_orthogonal_subscales") + settings["stabilization"]["use_orthogonal_subscales"].SetBool(bool(settings["oss_switch"].GetInt())) + settings.RemoveValue("oss_switch") + if settings.Has("dynamic_tau"): msg = "Input JSON data contains deprecated setting \'dynamic_tau\' (float).\n" msg += "Please define \'stabilization/formulation\' (set it to \'vms\') and \n" msg += "set \'stabilization/dynamic_tau\' (float) instead." KratosMultiphysics.Logger.PrintWarning("NavierStokesVMSMonolithicSolver",msg) - if not self.settings.Has("stabilization"): - self.settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) - self.settings["stabilization"].AddEmptyValue("dynamic_tau") - self.settings["stabilization"]["dynamic_tau"].SetDouble(self.settings["dynamic_tau"].GetDouble()) - self.settings.RemoveValue("dynamic_tau") + if not settings.Has("stabilization"): + settings.AddValue("stabilization",KratosMultiphysics.Parameters(r'{"formulation":"vms"}')) + settings["stabilization"].AddEmptyValue("dynamic_tau") + settings["stabilization"]["dynamic_tau"].SetDouble(settings["dynamic_tau"].GetDouble()) + settings.RemoveValue("dynamic_tau") - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings def __init__(self, model, custom_settings): diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py index 7038e4b2ab80..d28539588fac 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py @@ -21,7 +21,7 @@ def CreateSolver(model, custom_settings): class TrilinosNavierStokesSolverFractionalStep(navier_stokes_solver_fractionalstep.NavierStokesSolverFractionalStep): - def _ValidateSettings(self): + def _ValidateSettings(self,settings): ## Default settings string in Json format default_settings = KratosMultiphysics.Parameters(""" { @@ -75,7 +75,8 @@ def _ValidateSettings(self): "use_slip_conditions": true }""") - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings def __init__(self, model, custom_settings): # Note: deliberately calling the constructor of the base python solver (the parent of my parent) diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py index ef22776e1337..5aed2ed22f96 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py @@ -21,7 +21,8 @@ def CreateSolver(model, custom_settings): class TrilinosNavierStokesSolverMonolithic(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic): - def _ValidateSettings(self):## Default settings string in json format + def _ValidateSettings(self, settings): + ## Default settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "trilinos_navier_stokes_solver_vmsmonolithic", @@ -70,7 +71,8 @@ def _ValidateSettings(self):## Default settings string in json format "turbulence_model": "None" }""") - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings def __init__(self, model, custom_settings): From ad0cb37399158fc822e96dec2ce3302c272f0cff Mon Sep 17 00:00:00 2001 From: jcotela Date: Fri, 1 Jun 2018 20:35:21 +0200 Subject: [PATCH 16/27] WIP: Ongoing work on the embedded solver (and fixing its tests). --- .../navier_stokes_embedded_solver.py | 42 +++++++++--------- .../ManufacturedSolutionTestParameters.json | 3 +- .../tests/manufactured_solution_test.py | 43 +++++++------------ 3 files changed, 39 insertions(+), 49 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py index 5e08f15e7e15..69ab786cac13 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py @@ -10,29 +10,20 @@ import KratosMultiphysics.FluidDynamicsApplication as KratosCFD # Import base class file -import navier_stokes_base_solver +from fluid_solver import FluidSolver -def CreateSolver(main_model_part, custom_settings): - return NavierStokesEmbeddedMonolithicSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesEmbeddedMonolithicSolver(model, custom_settings) -class NavierStokesEmbeddedMonolithicSolver(navier_stokes_base_solver.NavierStokesBaseSolver): - - def __init__(self, main_model_part, custom_settings): - - self.element_name = "EmbeddedNavierStokes" - self.condition_name = "NavierStokesWallCondition" - self.min_buffer_size = 3 - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part +class NavierStokesEmbeddedMonolithicSolver(FluidSolver): + def _ValidateSettings(self, settings): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "embedded_solver_from_defaults", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -68,9 +59,18 @@ def __init__(self, main_model_part, custom_settings): "reorder": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings + + def __init__(self, model, custom_settings): + super(NavierStokesEmbeddedMonolithicSolver,self).__init__(model,custom_settings) + + self.element_name = "EmbeddedNavierStokes" + self.condition_name = "NavierStokesWallCondition" + self.min_buffer_size = 3 + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True # TODO: Remove this once we finish the new implementations if (self.settings["solver_type"].GetString() == "EmbeddedDevelopment"): @@ -114,6 +114,9 @@ def AddVariables(self): def ImportModelPart(self): super(NavierStokesEmbeddedMonolithicSolver, self).ImportModelPart() + def PrepareModelPart(self): + super(NavierStokesEmbeddedMonolithicSolver, self).PrepareModelPart() + ## Sets DENSITY, DYNAMIC_VISCOSITY and SOUND_VELOCITY self._set_physical_properties() ## Sets the constitutive law @@ -121,7 +124,6 @@ def ImportModelPart(self): ## Setting the nodal distance self._set_distance_function() - def Initialize(self): self.computing_model_part = self.GetComputingModelPart() diff --git a/applications/FluidDynamicsApplication/tests/ManufacturedSolutionTest/ManufacturedSolutionTestParameters.json b/applications/FluidDynamicsApplication/tests/ManufacturedSolutionTest/ManufacturedSolutionTestParameters.json index 2e080d1da9b7..3df7cbcc2e88 100644 --- a/applications/FluidDynamicsApplication/tests/ManufacturedSolutionTest/ManufacturedSolutionTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/ManufacturedSolutionTest/ManufacturedSolutionTestParameters.json @@ -2,7 +2,6 @@ "problem_data" : { "problem_name" : "manufactured_solution", "model_part_name" : "MainModelPart", - "domain_size" : 2, "parallel_type" : "OpenMP", "echo_level" : 0, "start_step" : 0.0, @@ -35,6 +34,8 @@ "Restart_Step" : 0 }, "solver_settings" : { + "model_part_name" : "MainModelPart", + "domain_size" : 2, "solver_type" : "Embedded", "model_import_settings" : { "input_type" : "mdpa", diff --git a/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py b/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py index 0870b0767c93..33082c29d024 100644 --- a/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py +++ b/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py @@ -30,9 +30,7 @@ def __exit__(self, type, value, traceback): @KratosUnittest.skipUnless(have_external_solvers, "Missing required application: ExternalSolversApplication") class ManufacturedSolutionTest(KratosUnittest.TestCase): def testManufacturedSolution(self): - self.setUp() self.runTest() - self.tearDown() def setUp(self): self.print_output = False @@ -84,6 +82,10 @@ def runTest(self): den *= 2 # Compute average convergence slopes + print(err_p[0]) + print(err_p[-1]) + print(h[0]) + print(h[-1]) average_slope_pressure = (math.log(err_p[0])-math.log(err_p[-1]))/(math.log(h[0])-math.log(h[-1])) average_slope_velocity = (math.log(err_v[0])-math.log(err_v[-1]))/(math.log(h[0])-math.log(h[-1])) @@ -142,10 +144,11 @@ class ManufacturedSolutionProblem: def __init__(self, ProjectParameters, input_file_name, print_output, problem_type, analytical_solution_type): self.problem_type = problem_type - self.print_output = print_output + self.print_output = True #print_output self.input_file_name = input_file_name self.ProjectParameters = ProjectParameters self.analytical_solution_type = analytical_solution_type + self.model = KratosMultiphysics.Model() def SetFluidProblem(self): @@ -157,21 +160,17 @@ def SetFluidProblem(self): self.ProjectParameters["problem_data"]["problem_name"].SetString(self.input_file_name) self.ProjectParameters["solver_settings"]["model_import_settings"]["input_filename"].SetString(self.input_file_name) - ## Fluid model part definition - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - ###TODO replace this "model" for real one once available - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} - ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() + + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) ## Add AddDofs self.solver.AddDofs() @@ -185,14 +184,6 @@ def SetFluidProblem(self): self.gid_output.ExecuteInitialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - for i in range(self.ProjectParameters["solver_settings"]["no_skin_parts"].size()): - no_skin_part_name = self.ProjectParameters["solver_settings"]["no_skin_parts"][i].GetString() - Model.update({no_skin_part_name: self.main_model_part.GetSubModelPart(no_skin_part_name)}) - ## Solver initialization self.solver.Initialize() @@ -217,18 +208,13 @@ def SolveFluidProblem(self): time = 0.0 step = 0 - out = 0.0 if (self.print_output): self.gid_output.ExecuteBeforeSolutionLoop() while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) if (self.print_output): self.gid_output.ExecuteInitializeSolutionStep() @@ -245,7 +231,10 @@ def SolveFluidProblem(self): self.SetManufacturedSolutionValues(False) # Set the analytical solution in the two first steps else: if (self.problem_type != "analytical_solution"): - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() if (self.print_output): self.gid_output.ExecuteFinalizeSolutionStep() @@ -253,8 +242,6 @@ def SolveFluidProblem(self): if self.gid_output.IsOutputStep(): self.gid_output.PrintOutput() - out = out + Dt - if (self.print_output): self.gid_output.ExecuteFinalize() From d6f47855a657773fe10befa119b5e48184ed959a Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 14:10:22 +0200 Subject: [PATCH 17/27] Updating manufactured solution test (it works now). --- .../tests/manufactured_solution_test.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py b/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py index 33082c29d024..0f635307f2d6 100644 --- a/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py +++ b/applications/FluidDynamicsApplication/tests/manufactured_solution_test.py @@ -82,10 +82,6 @@ def runTest(self): den *= 2 # Compute average convergence slopes - print(err_p[0]) - print(err_p[-1]) - print(h[0]) - print(h[-1]) average_slope_pressure = (math.log(err_p[0])-math.log(err_p[-1]))/(math.log(h[0])-math.log(h[-1])) average_slope_velocity = (math.log(err_v[0])-math.log(err_v[-1]))/(math.log(h[0])-math.log(h[-1])) @@ -144,7 +140,7 @@ class ManufacturedSolutionProblem: def __init__(self, ProjectParameters, input_file_name, print_output, problem_type, analytical_solution_type): self.problem_type = problem_type - self.print_output = True #print_output + self.print_output = print_output self.input_file_name = input_file_name self.ProjectParameters = ProjectParameters self.analytical_solution_type = analytical_solution_type @@ -207,7 +203,6 @@ def SolveFluidProblem(self): end_time = self.ProjectParameters["problem_data"]["end_time"].GetDouble() time = 0.0 - step = 0 if (self.print_output): self.gid_output.ExecuteBeforeSolutionLoop() @@ -227,7 +222,7 @@ def SolveFluidProblem(self): self.SetManufacturedSolutionValues(fix=True, set_only_boundaries=True) self.SetManufacturedSolutionSourceValues() - if (step < 3): + if (self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] < 3): self.SetManufacturedSolutionValues(False) # Set the analytical solution in the two first steps else: if (self.problem_type != "analytical_solution"): From 32b6f35d27c5a51783b7f418053562af1424c215 Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 14:34:02 +0200 Subject: [PATCH 18/27] Updating embedded ausas solver. --- .../navier_stokes_embedded_ausas_solver.py | 42 +++++++------------ 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py index 9801e1c2d63b..97e29e5a6d89 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py @@ -12,27 +12,18 @@ # Import base class file import navier_stokes_embedded_solver -def CreateSolver(main_model_part, custom_settings): - return NavierStokesEmbeddedAusasMonolithicSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesEmbeddedAusasMonolithicSolver(model, custom_settings) class NavierStokesEmbeddedAusasMonolithicSolver(navier_stokes_embedded_solver.NavierStokesEmbeddedMonolithicSolver): - def __init__(self, main_model_part, custom_settings): + def _ValidateSettings(self, settings): - self.element_name = "EmbeddedAusasNavierStokes" - self.condition_name = "EmbeddedAusasNavierStokesWallCondition" - self.min_buffer_size = 3 - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - - ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "EmbeddedAusas", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -68,18 +59,16 @@ def __init__(self, main_model_part, custom_settings): "reorder": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings + + def __init__(self, model, custom_settings): - ## Construct the linear solver - import linear_solver_factory - self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"]) + super(NavierStokesEmbeddedAusasMonolithicSolver,self).__init__(model,custom_settings) - ## Set the distance reading filename - # TODO: remove the manual "distance_file_name" set as soon as the problem type one has been tested. - if (self.settings["distance_reading_settings"]["import_mode"].GetString() == "from_GiD_file"): - self.settings["distance_reading_settings"]["distance_file_name"].SetString(self.settings["model_import_settings"]["input_filename"].GetString()+".post.res") + self.element_name = "EmbeddedAusasNavierStokes" + self.condition_name = "EmbeddedAusasNavierStokesWallCondition" + self.min_buffer_size = 3 KratosMultiphysics.Logger.PrintInfo("NavierStokesEmbeddedAusasMonolithicSolver", "Construction of NavierStokesEmbeddedAusasMonolithicSolver finished.") @@ -102,7 +91,8 @@ def Initialize(self): def InitializeSolutionStep(self): (self.bdf_process).Execute() (self.find_nodal_neighbours_process).Execute() - (self.solver).InitializeSolutionStep() + if self._TimeBufferIsInitialized(): + (self.solver).InitializeSolutionStep() def Solve(self): @@ -110,5 +100,5 @@ def Solve(self): (self.find_nodal_neighbours_process).Execute() # Note that the first two time steps are dropped to fill the BDF buffer - if (self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] >= 2): + if self._TimeBufferIsInitialized(): (self.solver).Solve() From 7f6ffcdca459b8b2644b8382a681318cdbd46e4f Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 14:44:44 +0200 Subject: [PATCH 19/27] All tests in queue \"all\" pass now. --- ...tificialCompressibilityTestParameters.json | 2 ++ .../EmbeddedAusasCouette2DTestParameters.json | 2 ++ .../EmbeddedCouette2DTestParameters.json | 2 ++ ...dedDevelopmentCouette2DTestParameters.json | 2 ++ .../EmbeddedAusasCouette3DTestParameters.json | 2 ++ .../EmbeddedCouette3DTestParameters.json | 2 ++ ...dedDevelopmentCouette3DTestParameters.json | 2 ++ ...mbeddedCouetteImposed2DTestParameters.json | 2 ++ ...mbeddedCouetteImposed3DTestParameters.json | 2 ++ .../EmbeddedReservoir2DTest_parameters.json | 2 ++ .../EmbeddedReservoir3DTest_parameters.json | 2 ++ ...vierStokesWallConditionTestParameters.json | 2 ++ .../tests/artificial_compressibility_test.py | 35 +++++++----------- .../tests/embedded_couette_imposed_test.py | 35 +++++++----------- .../tests/embedded_couette_test.py | 35 +++++++----------- .../tests/embedded_reservoir_test.py | 36 +++++++------------ .../navier_stokes_wall_condition_test.py | 35 +++++++----------- 17 files changed, 84 insertions(+), 116 deletions(-) diff --git a/applications/FluidDynamicsApplication/tests/ArtificialCompressibilityTest/ArtificialCompressibilityTestParameters.json b/applications/FluidDynamicsApplication/tests/ArtificialCompressibilityTest/ArtificialCompressibilityTestParameters.json index dac6f4924434..f6c23f302ea6 100644 --- a/applications/FluidDynamicsApplication/tests/ArtificialCompressibilityTest/ArtificialCompressibilityTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/ArtificialCompressibilityTest/ArtificialCompressibilityTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "cavity_compressibility" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedAusasCouette2DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedAusasCouette2DTestParameters.json index 0b065755def5..01f3ff9cc4e3 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedAusasCouette2DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedAusasCouette2DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "EmbeddedAusas", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_2D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedCouette2DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedCouette2DTestParameters.json index 38f12a9f1a64..1b14045b5f03 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedCouette2DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedCouette2DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_2D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedDevelopmentCouette2DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedDevelopmentCouette2DTestParameters.json index 73c69138f654..e0eb99a5b4e2 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedDevelopmentCouette2DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette2DTest/EmbeddedDevelopmentCouette2DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "EmbeddedDevelopment", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_2D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedAusasCouette3DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedAusasCouette3DTestParameters.json index 5bce8f5ec27f..9a752e50a142 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedAusasCouette3DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedAusasCouette3DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "EmbeddedAusas", + "model_part_name" : "MainModelPart", + "domain_size" : 3, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_3D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedCouette3DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedCouette3DTestParameters.json index 807b7d7b32e1..b7b64b9c0ef1 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedCouette3DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedCouette3DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 3, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_3D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedDevelopmentCouette3DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedDevelopmentCouette3DTestParameters.json index f139638abfce..a7a903680198 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedDevelopmentCouette3DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouette3DTest/EmbeddedDevelopmentCouette3DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "EmbeddedDevelopment", + "model_part_name" : "MainModelPart", + "domain_size" : 3, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_3D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed2DTest/EmbeddedCouetteImposed2DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed2DTest/EmbeddedCouetteImposed2DTestParameters.json index 32975577f40f..2687c033d6be 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed2DTest/EmbeddedCouetteImposed2DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed2DTest/EmbeddedCouetteImposed2DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_imposed_2D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed3DTest/EmbeddedCouetteImposed3DTestParameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed3DTest/EmbeddedCouetteImposed3DTestParameters.json index 088021879fe7..755d3d0910cd 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed3DTest/EmbeddedCouetteImposed3DTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedCouetteImposed3DTest/EmbeddedCouetteImposed3DTestParameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 3, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "couette_imposed_3D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir2DTest_parameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir2DTest_parameters.json index f1bec0735415..186bad773fb1 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir2DTest_parameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir2DTest_parameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "reservoir_2D" diff --git a/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir3DTest_parameters.json b/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir3DTest_parameters.json index e8423dd70642..646b73e71a14 100644 --- a/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir3DTest_parameters.json +++ b/applications/FluidDynamicsApplication/tests/EmbeddedReservoirTest/EmbeddedReservoir3DTest_parameters.json @@ -35,6 +35,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 3, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "reservoir_3D" diff --git a/applications/FluidDynamicsApplication/tests/NavierStokesWallConditionTest/NavierStokesWallConditionTestParameters.json b/applications/FluidDynamicsApplication/tests/NavierStokesWallConditionTest/NavierStokesWallConditionTestParameters.json index 6cfe09d1c14c..28cceda5d06d 100644 --- a/applications/FluidDynamicsApplication/tests/NavierStokesWallConditionTest/NavierStokesWallConditionTestParameters.json +++ b/applications/FluidDynamicsApplication/tests/NavierStokesWallConditionTest/NavierStokesWallConditionTestParameters.json @@ -36,6 +36,8 @@ }, "solver_settings" : { "solver_type" : "Embedded", + "model_part_name" : "MainModelPart", + "domain_size" : 2, "model_import_settings" : { "input_type" : "mdpa", "input_filename" : "test_wall_condition" diff --git a/applications/FluidDynamicsApplication/tests/artificial_compressibility_test.py b/applications/FluidDynamicsApplication/tests/artificial_compressibility_test.py index 35a544ea272f..13b9327b7213 100644 --- a/applications/FluidDynamicsApplication/tests/artificial_compressibility_test.py +++ b/applications/FluidDynamicsApplication/tests/artificial_compressibility_test.py @@ -51,19 +51,17 @@ def setUpProblem(self): with open(self.settings, 'r') as parameter_file: self.ProjectParameters = KratosMultiphysics.Parameters(parameter_file.read()) - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} + self.model = KratosMultiphysics.Model() ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() ## Add AddDofs self.solver.AddDofs() @@ -71,25 +69,17 @@ def setUpProblem(self): ## Solver initialization self.solver.Initialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - - ## Get the gravity submodel part in the object Model - for i in range(self.ProjectParameters["gravity"].size()): - gravity_part_name = self.ProjectParameters["gravity"][i]["Parameters"]["model_part_name"].GetString() - Model.update({gravity_part_name: self.main_model_part.GetSubModelPart(gravity_part_name)}) - ## Processes construction import process_factory - self.list_of_processes = process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) - self.list_of_processes += process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + self.list_of_processes = process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) + self.list_of_processes += process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) ## Processes initialization for process in self.list_of_processes: process.ExecuteInitialize() + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) + def runTest(self): with WorkFolderScope(self.work_folder): if (self.print_output): @@ -115,16 +105,15 @@ def runTest(self): while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() diff --git a/applications/FluidDynamicsApplication/tests/embedded_couette_imposed_test.py b/applications/FluidDynamicsApplication/tests/embedded_couette_imposed_test.py index 429f39b0b392..5c10b4fba6aa 100644 --- a/applications/FluidDynamicsApplication/tests/embedded_couette_imposed_test.py +++ b/applications/FluidDynamicsApplication/tests/embedded_couette_imposed_test.py @@ -70,19 +70,17 @@ def setUpProblem(self): with open(self.settings, 'r') as parameter_file: self.ProjectParameters = KratosMultiphysics.Parameters(parameter_file.read()) - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} + self.model = KratosMultiphysics.Model() ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() ## Add AddDofs self.solver.AddDofs() @@ -90,25 +88,17 @@ def setUpProblem(self): ## Solver initialization self.solver.Initialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - - ## Get the gravity submodel part in the object Model - for i in range(self.ProjectParameters["gravity"].size()): - gravity_part_name = self.ProjectParameters["gravity"][i]["Parameters"]["model_part_name"].GetString() - Model.update({gravity_part_name: self.main_model_part.GetSubModelPart(gravity_part_name)}) - ## Processes construction import process_factory - self.list_of_processes = process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) - self.list_of_processes += process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + self.list_of_processes = process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) + self.list_of_processes += process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) ## Processes initialization for process in self.list_of_processes: process.ExecuteInitialize() + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) + def setUpDistanceField(self): # Set the distance function domain_size = self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] @@ -207,17 +197,16 @@ def runTest(self): while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() diff --git a/applications/FluidDynamicsApplication/tests/embedded_couette_test.py b/applications/FluidDynamicsApplication/tests/embedded_couette_test.py index 6524e08b6419..e47d2ea2db2e 100644 --- a/applications/FluidDynamicsApplication/tests/embedded_couette_test.py +++ b/applications/FluidDynamicsApplication/tests/embedded_couette_test.py @@ -140,19 +140,17 @@ def setUpProblem(self): with open(self.settings, 'r') as parameter_file: self.ProjectParameters = KratosMultiphysics.Parameters(parameter_file.read()) - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} + self.model = KratosMultiphysics.Model() ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() ## Add AddDofs self.solver.AddDofs() @@ -160,20 +158,12 @@ def setUpProblem(self): ## Solver initialization self.solver.Initialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - - ## Get the gravity submodel part in the object Model - for i in range(self.ProjectParameters["gravity"].size()): - gravity_part_name = self.ProjectParameters["gravity"][i]["Parameters"]["model_part_name"].GetString() - Model.update({gravity_part_name: self.main_model_part.GetSubModelPart(gravity_part_name)}) - ## Processes construction import process_factory - self.list_of_processes = process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) - self.list_of_processes += process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + self.list_of_processes = process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) + self.list_of_processes += process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) ## Processes initialization for process in self.list_of_processes: @@ -277,16 +267,15 @@ def runTest(self): while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() diff --git a/applications/FluidDynamicsApplication/tests/embedded_reservoir_test.py b/applications/FluidDynamicsApplication/tests/embedded_reservoir_test.py index 2b6f9ec4e15a..757be3b6ed67 100644 --- a/applications/FluidDynamicsApplication/tests/embedded_reservoir_test.py +++ b/applications/FluidDynamicsApplication/tests/embedded_reservoir_test.py @@ -82,19 +82,17 @@ def setUpProblem(self): with open(self.settings, 'r') as parameter_file: self.ProjectParameters = KratosMultiphysics.Parameters(parameter_file.read()) - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} + self.model = KratosMultiphysics.Model() ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() ## Add AddDofs self.solver.AddDofs() @@ -102,25 +100,17 @@ def setUpProblem(self): ## Solver initialization self.solver.Initialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - - ## Get the gravity submodel part in the object Model - for i in range(self.ProjectParameters["gravity"].size()): - gravity_part_name = self.ProjectParameters["gravity"][i]["Parameters"]["model_part_name"].GetString() - Model.update({gravity_part_name: self.main_model_part.GetSubModelPart(gravity_part_name)}) - ## Processes construction import process_factory - self.list_of_processes = process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) - self.list_of_processes += process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + self.list_of_processes = process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) + self.list_of_processes += process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) ## Processes initialization for process in self.list_of_processes: process.ExecuteInitialize() + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) + def setUpDistanceField(self): # Set the distance function if (self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 2): @@ -170,17 +160,15 @@ def runTest(self): while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() - if(step >= 3): - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() diff --git a/applications/FluidDynamicsApplication/tests/navier_stokes_wall_condition_test.py b/applications/FluidDynamicsApplication/tests/navier_stokes_wall_condition_test.py index 41d7f22fb81f..2898fe001fd1 100644 --- a/applications/FluidDynamicsApplication/tests/navier_stokes_wall_condition_test.py +++ b/applications/FluidDynamicsApplication/tests/navier_stokes_wall_condition_test.py @@ -50,19 +50,17 @@ def setUpProblem(self): with open(self.settings, 'r') as parameter_file: self.ProjectParameters = KratosMultiphysics.Parameters(parameter_file.read()) - self.main_model_part = KratosMultiphysics.ModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) - self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE, self.ProjectParameters["problem_data"]["domain_size"].GetInt()) - - Model = {self.ProjectParameters["problem_data"]["model_part_name"].GetString() : self.main_model_part} + self.model = KratosMultiphysics.Model() ## Solver construction import python_solvers_wrapper_fluid - self.solver = python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.ProjectParameters) + self.solver = python_solvers_wrapper_fluid.CreateSolver(self.model, self.ProjectParameters) self.solver.AddVariables() ## Read the model - note that SetBufferSize is done here self.solver.ImportModelPart() + self.solver.PrepareModelPart() ## Add AddDofs self.solver.AddDofs() @@ -70,25 +68,17 @@ def setUpProblem(self): ## Solver initialization self.solver.Initialize() - ## Get the list of the skin submodel parts in the object Model - for i in range(self.ProjectParameters["solver_settings"]["skin_parts"].size()): - skin_part_name = self.ProjectParameters["solver_settings"]["skin_parts"][i].GetString() - Model.update({skin_part_name: self.main_model_part.GetSubModelPart(skin_part_name)}) - - ## Get the gravity submodel part in the object Model - for i in range(self.ProjectParameters["gravity"].size()): - gravity_part_name = self.ProjectParameters["gravity"][i]["Parameters"]["model_part_name"].GetString() - Model.update({gravity_part_name: self.main_model_part.GetSubModelPart(gravity_part_name)}) - ## Processes construction import process_factory - self.list_of_processes = process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) - self.list_of_processes += process_factory.KratosProcessFactory(Model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) + self.list_of_processes = process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["gravity"] ) + self.list_of_processes += process_factory.KratosProcessFactory(self.model).ConstructListOfProcesses( self.ProjectParameters["boundary_conditions_process_list"] ) ## Processes initialization for process in self.list_of_processes: process.ExecuteInitialize() + self.main_model_part = self.model.GetModelPart(self.ProjectParameters["problem_data"]["model_part_name"].GetString()) + def runTest(self): with WorkFolderScope(self.work_folder): if (self.print_output): @@ -114,16 +104,15 @@ def runTest(self): while(time <= end_time): - Dt = self.solver.ComputeDeltaTime() - step += 1 - time += Dt - self.main_model_part.CloneTimeStep(time) - self.main_model_part.ProcessInfo[KratosMultiphysics.STEP] = step + time = self.solver.AdvanceInTime(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() - self.solver.Solve() + self.solver.InitializeSolutionStep() + self.solver.Predict() + self.solver.SolveSolutionStep() + self.solver.FinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() From b96b4b47e97d47e14f4adaf7e07d24a20c139b8c Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 15:35:56 +0200 Subject: [PATCH 20/27] Porting FM-ALE solver and changing a few solver defaults. --- .../navier_stokes_embedded_ausas_solver.py | 2 +- .../navier_stokes_embedded_fm_ale_solver.py | 51 +++++++++---------- .../navier_stokes_embedded_solver.py | 2 +- .../navier_stokes_solver_vmsmonolithic.py | 2 +- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py index 97e29e5a6d89..201a70e7816b 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py @@ -43,7 +43,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_NS_Solver" + "solver_type" : "AMGCL_Solver" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py index c87ee0e0b649..d7e63b20a09a 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py @@ -14,28 +14,18 @@ # Import base class file import navier_stokes_embedded_solver -def CreateSolver(main_model_part, structure_model_part, custom_settings): - return NavierStokesEmbeddedFMALEMonolithicSolver(main_model_part, structure_model_part, custom_settings) +def CreateSolver(model, structure_model_part, custom_settings): + return NavierStokesEmbeddedFMALEMonolithicSolver(model, custom_settings) class NavierStokesEmbeddedFMALEMonolithicSolver(navier_stokes_embedded_solver.NavierStokesEmbeddedMonolithicSolver): - def __init__(self, main_model_part, structure_model_part, custom_settings): - - self.element_name = "EmbeddedNavierStokes" - self.condition_name = "NavierStokesWallCondition" - self.min_buffer_size = 3 - - # There is only a single rank in OpenMP, we always print - self._is_printing_rank = True - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - self.structure_model_part = structure_model_part - - ##settings string in json format + def _ValidateSettings(self, settings): default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "embedded_solver_from_defaults", + "model_part_name": "FluidModelPart", + "structure_model_part_name": "StructureModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -55,7 +45,7 @@ def __init__(self, main_model_part, structure_model_part, custom_settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings": { - "solver_type": "AMGCL_NS_Solver" + "solver_type": "AMGCL_Solver" }, "volume_model_part_name": "volume_model_part", "skin_parts": [""], @@ -74,18 +64,25 @@ def __init__(self, main_model_part, structure_model_part, custom_settings): } }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings - ## Construct the linear solver - import linear_solver_factory - self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"]) + def __init__(self, model, custom_settings): + super(NavierStokesEmbeddedFMALEMonolithicSolver,self).__init__(model,custom_settings) - ## Set the distance reading filename - # TODO: remove the manual "distance_file_name" set as soon as the problem type one has been tested. - if (self.settings["distance_reading_settings"]["import_mode"].GetString() == "from_GiD_file"): - self.settings["distance_reading_settings"]["distance_file_name"].SetString(self.settings["model_import_settings"]["input_filename"].GetString()+".post.res") + self.element_name = "EmbeddedNavierStokes" + self.condition_name = "NavierStokesWallCondition" + self.min_buffer_size = 3 + + # There is only a single rank in OpenMP, we always print + self._is_printing_rank = True + + # Retrieve the structural model part using json input + structure_model_part_name = self.settings["model_part_name"].GetString() + if self.model.HasModelPart(structure_model_part_name): + self.structure_model_part = self.model.GetModelPart(structure_model_part_name) + else: + raise Exception("Structural model part {0} not found in model".format(structure_model_part_name)) ## Set the FM-ALE framework self.fm_ale_step_frequency = self.settings["fm_ale_settings"]["fm_ale_step_frequency"].GetInt() diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py index 69ab786cac13..3caebe9169ad 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py @@ -43,7 +43,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_NS_Solver" + "solver_type" : "AMGCL_Solver" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 7207b66b13f0..3010fba36379 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -131,7 +131,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_NS_Solver" + "solver_type" : "AMGCL_Solver" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], From f8c0b86726fcc2731a6871f26d980c1c5519c97e Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 16:14:39 +0200 Subject: [PATCH 21/27] Physical property assignment now in PrepareModelPart for all solvers. --- .../python_scripts/navier_stokes_solver_fractionalstep.py | 7 ++----- .../python_scripts/navier_stokes_solver_vmsmonolithic.py | 7 ++----- .../trilinos_navier_stokes_solver_fractionalstep.py | 2 -- .../trilinos_navier_stokes_solver_vmsmonolithic.py | 4 +--- 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py index d60609b431b5..5b0de77ad824 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_fractionalstep.py @@ -132,12 +132,9 @@ def AddVariables(self): KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverFractionalStep", "Fluid solver variables added correctly.") - def ImportModelPart(self): - super(NavierStokesSolverFractionalStep, self).ImportModelPart() - - ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY + def PrepareModelPart(self): self._set_physical_properties() - + super(NavierStokesSolverFractionalStep, self).PrepareModelPart() def Initialize(self): self.computing_model_part = self.GetComputingModelPart() diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 3010fba36379..74f841023546 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -232,12 +232,9 @@ def AddVariables(self): KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithic", "Fluid solver variables added correctly.") - def ImportModelPart(self): - super(NavierStokesSolverMonolithic, self).ImportModelPart() - - ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY + def PrepareModelPart(self): self._set_physical_properties() - + super(NavierStokesSolverMonolithic, self).PrepareModelPart() def Initialize(self): diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py index d28539588fac..1c20e209373e 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_fractionalstep.py @@ -119,8 +119,6 @@ def ImportModelPart(self): self.trilinos_model_part_importer = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) ## Execute the Metis partitioning and reading self.trilinos_model_part_importer.ExecutePartitioningAndReading() - ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY - super(TrilinosNavierStokesSolverFractionalStep, self)._set_physical_properties() if self._IsPrintingRank(): #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py index 5aed2ed22f96..d4fc35a56e10 100755 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_solver_vmsmonolithic.py @@ -111,12 +111,10 @@ def ImportModelPart(self): self.trilinos_model_part_importer = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) ## Execute the Metis partitioning and reading self.trilinos_model_part_importer.ExecutePartitioningAndReading() - ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY - super(TrilinosNavierStokesSolverMonolithic, self)._set_physical_properties() if self._IsPrintingRank(): #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED - KratosMultiphysics.Logger.PrintInfo("TrilinosNavierStokesSolverFractionalStep","MPI model reading finished.") + KratosMultiphysics.Logger.PrintInfo("TrilinosNavierStokesSolverMonolithic","MPI model reading finished.") def PrepareModelPart(self): super(TrilinosNavierStokesSolverMonolithic,self).PrepareModelPart() From 126e75999a99ab47e7b3a67a112278e2777f33a3 Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 16:15:12 +0200 Subject: [PATCH 22/27] Updating steady navier stokes solver to new format. --- .../steady_navier_stokes_solver_vmsmonolithic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/steady_navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/steady_navier_stokes_solver_vmsmonolithic.py index a8917b90f1ac..f8c489bbade3 100644 --- a/applications/FluidDynamicsApplication/python_scripts/steady_navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/steady_navier_stokes_solver_vmsmonolithic.py @@ -9,13 +9,13 @@ ## Import base class file import navier_stokes_solver_vmsmonolithic -def CreateSolver(main_model_part, custom_settings): - return SteadyNavierStokesSolver_VMSMonolithic(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return SteadyNavierStokesSolver_VMSMonolithic(model, custom_settings) class SteadyNavierStokesSolver_VMSMonolithic(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic): - def __init__(self, main_model_part, custom_settings): - + def __init__(self, model, custom_settings): + # parse and strip parameters that do not exist in base class. we need to remove # extra parameters so base class doesn't throw an error. alternatively a single solver script # could be used and the scheme type could be passed in json parameters. @@ -26,7 +26,7 @@ def __init__(self, main_model_part, custom_settings): base_settings.RemoveValue("pressure_relaxation_factor") # call base class constructor with remaining parameters - super().__init__(main_model_part, base_settings) + super().__init__(model, base_settings) if self.settings["consider_periodic_conditions"].GetBool() == True: raise ValueError("consider_periodic_conditions not supported yet.") @@ -50,7 +50,7 @@ def Initialize(self): 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()) self.time_scheme = KratosCFD.ResidualBasedSimpleSteadyScheme(self.velocity_relaxation_factor, self.pressure_relaxation_factor, self.computing_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE]) From 7dec61cdd03ad3314b9dff2e50e8a9721f245a9a Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 16:24:50 +0200 Subject: [PATCH 23/27] Updating trilinos embedded solvers. --- ...nos_navier_stokes_embedded_ausas_solver.py | 33 ++++----- .../trilinos_navier_stokes_embedded_solver.py | 68 ++++++++----------- 2 files changed, 43 insertions(+), 58 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_ausas_solver.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_ausas_solver.py index 07d0184edbef..2d71056b21ce 100644 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_ausas_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_ausas_solver.py @@ -13,26 +13,18 @@ # Import base class file import trilinos_navier_stokes_embedded_solver -def CreateSolver(main_model_part, custom_settings): - return NavierStokesMPIEmbeddedAusasMonolithicSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesMPIEmbeddedAusasMonolithicSolver(model, custom_settings) class NavierStokesMPIEmbeddedAusasMonolithicSolver(trilinos_navier_stokes_embedded_solver.NavierStokesMPIEmbeddedMonolithicSolver): - def __init__(self, main_model_part, custom_settings): - - self.element_name = "EmbeddedAusasNavierStokes" - self.condition_name = "EmbeddedAusasNavierStokesWallCondition" - self.min_buffer_size = 3 - - self._is_printing_rank = (KratosMPI.mpi.rank == 0) - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - + def _ValidateSettings(self, settings): ##settings string in json format default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "EmbeddedAusas", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -74,13 +66,16 @@ def __init__(self, main_model_part, custom_settings): "move_mesh_flag": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings + + def __init__(self, model, custom_settings): + + super(NavierStokesMPIEmbeddedAusasMonolithicSolver,self).__init__(model,custom_settings) - ## Construct the linear solver - import trilinos_linear_solver_factory - self.trilinos_linear_solver = trilinos_linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"]) + self.element_name = "EmbeddedAusasNavierStokes" + self.condition_name = "EmbeddedAusasNavierStokesWallCondition" + self.min_buffer_size = 3 ## Set the distance reading filename # TODO: remove the manual "distance_file_name" set as soon as the problem type one has been tested. diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py index c17139e09b5c..815bf91882a7 100644 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py @@ -14,27 +14,19 @@ # Import serial monolithic embedded solver import navier_stokes_embedded_solver +import trilinos_import_model_part_utility -def CreateSolver(main_model_part, custom_settings): - return NavierStokesMPIEmbeddedMonolithicSolver(main_model_part, custom_settings) +def CreateSolver(model, custom_settings): + return NavierStokesMPIEmbeddedMonolithicSolver(model, custom_settings) class NavierStokesMPIEmbeddedMonolithicSolver(navier_stokes_embedded_solver.NavierStokesEmbeddedMonolithicSolver): - def __init__(self, main_model_part, custom_settings): - self.element_name = "EmbeddedNavierStokes" - self.condition_name = "NavierStokesWallCondition" - self.min_buffer_size = 3 - - self._is_printing_rank = (KratosMPI.mpi.rank == 0) - - #TODO: shall obtain the compute_model_part from the MODEL once the object is implemented - self.main_model_part = main_model_part - - ## Default settings string in json format - default_settings = KratosMultiphysics.Parameters(""" + def _ValidateSettings(self, settings):default_settings = KratosMultiphysics.Parameters(""" { "solver_type": "Embedded", + "model_part_name": "FluidModelPart", + "domain_size": 2, "model_import_settings": { "input_type": "mdpa", "input_filename": "unknown_name" @@ -76,9 +68,18 @@ def __init__(self, main_model_part, custom_settings): "move_mesh_flag": false }""") - ## Overwrite the default settings with user-provided parameters - self.settings = custom_settings - self.settings.ValidateAndAssignDefaults(default_settings) + settings.ValidateAndAssignDefaults(default_settings) + return settings + + def __init__(self, model, custom_settings): + # Note: deliberately calling the constructor of the base python solver (the parent of my parent) + super(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic, self).__init__(model,custom_settings) + + self.element_name = "EmbeddedNavierStokes" + self.condition_name = "NavierStokesWallCondition" + self.min_buffer_size = 3 + + self._is_printing_rank = (KratosMPI.mpi.rank == 0) # TODO: Remove this once we finish the new implementations if (self.settings["solver_type"].GetString() == "EmbeddedDevelopment"): @@ -102,32 +103,21 @@ def AddVariables(self): if self._IsPrintingRank(): KratosMultiphysics.Logger.PrintInfo("NavierStokesMPIEmbeddedMonolithicSolver","Variables for the Trilinos monolithic embedded fluid solver added correctly.") - def ImportModelPart(self): - - # Construct the Trilinos import model part utility - import trilinos_import_model_part_utility - TrilinosModelPartImporter = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) - # Execute the Metis partitioning and reading - TrilinosModelPartImporter.ExecutePartitioningAndReading() - # Replace default elements and conditions - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._replace_elements_and_conditions() - # Executes the check and prepare model process - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._execute_check_and_prepare() - # Call the base class set buffer size - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._set_buffer_size() - # Sets DENSITY, DYNAMIC_VISCOSITY and SOUND_VELOCITY - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._set_physical_properties() - # Sets the constitutive law - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._set_constitutive_law() - # Sets the nodal distance - super(NavierStokesMPIEmbeddedMonolithicSolver, self)._set_distance_function() - # Construct the Trilinos communicators - TrilinosModelPartImporter.CreateCommunicators() + ## Construct the Trilinos import model part utility + self.trilinos_model_part_importer = trilinos_import_model_part_utility.TrilinosImportModelPartUtility(self.main_model_part, self.settings) + ## Execute the Metis partitioning and reading + self.trilinos_model_part_importer.ExecutePartitioningAndReading() + ## Sets DENSITY, VISCOSITY and SOUND_VELOCITY if self._IsPrintingRank(): - KratosMultiphysics.Logger.PrintInfo("NavierStokesMPIEmbeddedMonolithicSolver","Trilinos import model part performed correctly.") + #TODO: CHANGE THIS ONCE THE MPI LOGGER IS IMPLEMENTED + KratosMultiphysics.Logger.PrintInfo("NavierStokesMPIEmbeddedMonolithicSolver","MPI model reading finished.") + def PrepareModelPart(self): + super(NavierStokesMPIEmbeddedMonolithicSolver,self).PrepareModelPart() + ## Construct Trilinos the communicators + self.trilinos_model_part_importer.CreateCommunicators() def AddDofs(self): From 1dc5f570308a6a88b9124e422a21ec86497a8738 Mon Sep 17 00:00:00 2001 From: jcotela Date: Mon, 4 Jun 2018 16:45:43 +0200 Subject: [PATCH 24/27] Fixing a few typos. --- .../python_scripts/navier_stokes_embedded_ausas_solver.py | 2 +- .../python_scripts/navier_stokes_embedded_fm_ale_solver.py | 2 +- .../python_scripts/navier_stokes_embedded_solver.py | 2 +- .../python_scripts/navier_stokes_solver_vmsmonolithic.py | 2 +- .../trilinos_navier_stokes_embedded_solver.py | 7 ++++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py index 201a70e7816b..6c805c359959 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_ausas_solver.py @@ -43,7 +43,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_Solver" + "solver_type" : "AMGCL" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py index d7e63b20a09a..4945f5634384 100644 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_fm_ale_solver.py @@ -45,7 +45,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings": { - "solver_type": "AMGCL_Solver" + "solver_type": "AMGCL" }, "volume_model_part_name": "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py index 3caebe9169ad..c7e502be0153 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_embedded_solver.py @@ -43,7 +43,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_Solver" + "solver_type" : "AMGCL" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index 74f841023546..b61bc72be7a2 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -131,7 +131,7 @@ def _ValidateSettings(self, settings): "relative_pressure_tolerance": 1e-3, "absolute_pressure_tolerance": 1e-5, "linear_solver_settings" : { - "solver_type" : "AMGCL_Solver" + "solver_type" : "AMGCL" }, "volume_model_part_name" : "volume_model_part", "skin_parts": [""], diff --git a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py index 815bf91882a7..bc74fb10f9cb 100644 --- a/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/trilinos_navier_stokes_embedded_solver.py @@ -22,8 +22,9 @@ def CreateSolver(model, custom_settings): class NavierStokesMPIEmbeddedMonolithicSolver(navier_stokes_embedded_solver.NavierStokesEmbeddedMonolithicSolver): - def _ValidateSettings(self, settings):default_settings = KratosMultiphysics.Parameters(""" - { + def _ValidateSettings(self, settings): + + default_settings = KratosMultiphysics.Parameters("""{ "solver_type": "Embedded", "model_part_name": "FluidModelPart", "domain_size": 2, @@ -73,7 +74,7 @@ def _ValidateSettings(self, settings):default_settings = KratosMultiphysics.Para def __init__(self, model, custom_settings): # Note: deliberately calling the constructor of the base python solver (the parent of my parent) - super(navier_stokes_solver_vmsmonolithic.NavierStokesSolverMonolithic, self).__init__(model,custom_settings) + super(navier_stokes_embedded_solver.NavierStokesEmbeddedMonolithicSolver, self).__init__(model,custom_settings) self.element_name = "EmbeddedNavierStokes" self.condition_name = "NavierStokesWallCondition" From 9abc76d12560529369a04d072fec9cddff77f6c0 Mon Sep 17 00:00:00 2001 From: jcotela Date: Tue, 5 Jun 2018 10:36:34 +0200 Subject: [PATCH 25/27] Removing debug print. --- .../python_scripts/navier_stokes_solver_vmsmonolithic.py | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py index b61bc72be7a2..b434072b9d1f 100755 --- a/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py +++ b/applications/FluidDynamicsApplication/python_scripts/navier_stokes_solver_vmsmonolithic.py @@ -34,7 +34,6 @@ def __init__(self,settings): raise RuntimeError("Argument \'formulation\' not found in stabilization settings.") def SetProcessInfo(self,model_part): - print(self.process_data) for variable,value in self.process_data.items(): model_part.ProcessInfo[variable] = value From 66ba1e8caf8dda2a5273079860a765698a7cd445 Mon Sep 17 00:00:00 2001 From: jcotela Date: Tue, 5 Jun 2018 10:56:53 +0200 Subject: [PATCH 26/27] Editing error message. --- .../python_scripts/fluid_solver.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py index 23d4d1c0c2fc..cc98e903b124 100755 --- a/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py +++ b/applications/FluidDynamicsApplication/python_scripts/fluid_solver.py @@ -147,10 +147,10 @@ def _IsPrintingRank(self): return self._is_printing_rank def _ValidateSettings(self, settings): - raise Exception("Please define the default solver settings in the derived solver class") - - settings.ValidateAndAssignDefaults(KratosMultiphysics.Parameters(r'{}')) - return settings + raise Exception("Please define the _ValidateSettings() method in your derived solver class to validate the Kratos::Parameters configuration.") + # Suggested implementation: + #settings.ValidateAndAssignDefaults(KratosMultiphysics.Parameters(r'{}')) + #return settings def _ReplaceElementsAndConditions(self): ## Get number of nodes and domain size From 9ec96392a13363e14f90ea615f45fa14ea6f3d1c Mon Sep 17 00:00:00 2001 From: jcotela Date: Tue, 5 Jun 2018 11:35:59 +0200 Subject: [PATCH 27/27] Removing an unreachable check (impossible condition) and some prints. --- .../check_and_prepare_model_process_fluid.py | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/applications/FluidDynamicsApplication/python_scripts/check_and_prepare_model_process_fluid.py b/applications/FluidDynamicsApplication/python_scripts/check_and_prepare_model_process_fluid.py index f9ca706df9ae..4cd7e42ff466 100644 --- a/applications/FluidDynamicsApplication/python_scripts/check_and_prepare_model_process_fluid.py +++ b/applications/FluidDynamicsApplication/python_scripts/check_and_prepare_model_process_fluid.py @@ -1,5 +1,5 @@ -import KratosMultiphysics -import KratosMultiphysics.FluidDynamicsApplication +import KratosMultiphysics +import KratosMultiphysics.FluidDynamicsApplication def Factory(settings, Model): if(type(settings) != KratosMultiphysics.Parameters): @@ -10,52 +10,45 @@ def Factory(settings, Model): class CheckAndPrepareModelProcess(KratosMultiphysics.Process): def __init__(self, main_model_part, Parameters ): self.main_model_part = main_model_part - + self.volume_model_part_name = Parameters["volume_model_part_name"].GetString() self.skin_name_list = Parameters["skin_parts"] - - + + #self.volume_model_part_name = Parameters["volume_model_part_name"].GetString() #self.list_of_inlets = Parameters["list_of_inlets"] #self.list_of_slip = Parameters["list_of_inlets"] #self.list_of_inlets = Parameters["list_of_inlets"] - - + + def Execute(self): self.volume_model_part = self.main_model_part.GetSubModelPart(self.volume_model_part_name) - + skin_parts = [] for i in range(self.skin_name_list.size()): skin_parts.append(self.main_model_part.GetSubModelPart(self.skin_name_list[i].GetString())) - + #construct a model part which contains both the skin and the volume #temporarily we call it "fluid_computational_model_part" self.main_model_part.CreateSubModelPart("fluid_computational_model_part") fluid_computational_model_part= self.main_model_part.GetSubModelPart("fluid_computational_model_part") fluid_computational_model_part.ProcessInfo = self.main_model_part.ProcessInfo - - print("adding nodes and elements to fluid_computational_model_part") + for node in self.volume_model_part.Nodes: fluid_computational_model_part.AddNode(node,0) for elem in self.volume_model_part.Elements: fluid_computational_model_part.AddElement(elem,0) - + #do some gymnastics to have this done fast. - create an ordered list to be added list_of_ids = set() for part in skin_parts: for cond in part.Conditions: list_of_ids.add(cond.Id) - + fluid_computational_model_part.AddConditions(list(list_of_ids)) - - print(fluid_computational_model_part) - - if(self.main_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE] == 3 and self.main_model_part.GetCommunicator().TotalProcesses() == 0 ): - #verify that the skin is correct (no gaps and overlaps) - KratosMultiphysics.CheckSkinProcess(fluid_computational_model_part , KratosMultiphysics.Flags()).Execute() #verify the orientation of the skin throw_errors = False KratosMultiphysics.TetrahedralMeshOrientationCheck(fluid_computational_model_part,throw_errors).Execute() - +