Skip to content

Commit

Permalink
Revert "Compatibilty problems (WIP)"
Browse files Browse the repository at this point in the history
This reverts commit 73e6c64.
  • Loading branch information
loumalouomega committed May 28, 2018
1 parent 73e6c64 commit 79c071a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ class FluidDynamicsAnalysis(AnalysisStage):
def __init__(self,model,parameters):
# Create the ModelPart
# Note that this in temporary and will be done through the model in the future
main_model_part_name = parameters["problem_data"]["model_part_name"].GetString()
if model.HasModelPart(main_model_part_name):
self.main_model_part = model[main_model_part_name]
else:
self.main_model_part = KratosMultiphysics.ModelPart(main_model_part_name)
self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
parameters["problem_data"]["domain_size"].GetInt())
model.AddModelPart(self.main_model_part)
model_part_name = parameters["problem_data"]["model_part_name"].GetString()
self.main_model_part = Kratos.ModelPart(model_part_name)
self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
parameters["problem_data"]["domain_size"].GetInt())

super(FluidDynamicsAnalysis,self).__init__(model,parameters)

Expand All @@ -33,7 +29,7 @@ def __init__(self,model,parameters):

def _CreateSolver(self):
import python_solvers_wrapper_fluid
return python_solvers_wrapper_fluid.CreateSolver(self.model, self.project_parameters)
return python_solvers_wrapper_fluid.CreateSolver(self.main_model_part, self.project_parameters)

def Initialize(self):
# This function is temporary until restart saving is handled through process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@
# Import applications
import KratosMultiphysics.FluidDynamicsApplication as KratosCFD

# Importing the base class
from python_solver import PythonSolver
def CreateSolver(main_model_part, custom_settings):
return NavierStokesBaseSolver(main_model_part, custom_settings)

def CreateSolver(model, custom_settings):
return NavierStokesBaseSolver(model, custom_settings)
class NavierStokesBaseSolver(object):

class NavierStokesBaseSolver(PythonSolver):

def __init__(self, model, custom_settings):
super(NavierStokesBaseSolver, self).__init__(model, custom_settings)
def __init__(self, main_model_part, custom_settings):
## Set the element and condition names for the replace settings
self.element_name = None
self.condition_name = None
Expand All @@ -43,15 +39,15 @@ def ImportModelPart(self):
self._set_buffer_size()

if self._IsPrintingRank():
KratosMultiphysics.Logger.PrintInfo("::[NavierStokesBaseSolver]:: ", "Model reading finished.")
KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Model reading finished.")

def ExportModelPart(self):
## Model part writing
name_out_file = self.settings["model_import_settings"]["input_filename"].GetString()+".out"
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("NavierStokesBaseSolver", "Model export finished.")

def AddDofs(self):
KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.VELOCITY_X, KratosMultiphysics.REACTION_X,self.main_model_part)
Expand All @@ -60,27 +56,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.")

def ReadModelPart(self):
"""This function reads the ModelPart
"""
self._ImportModelPart(self.main_model_part, self.settings["model_import_settings"])

def PrepareModelPart(self):
if not self.is_restarted():
## Replace default elements and conditions
self._replace_elements_and_conditions()
## Executes the check and prepare model process
self._execute_check_and_prepare()
## Set buffer size
self._set_buffer_size()

# This will be removed once the Model is fully supported!
if not self.model.HasModelPart(self.main_model_part.Name):
self.model.AddModelPart(self.main_model_part)

KratosMultiphysics.Logger.PrintInfo("::[NavierStokesBaseSolver]:: ", "ModelPart prepared for Solver.")
KratosMultiphysics.Logger.PrintInfo("NavierStokesBaseSolver", "Fluid solver DOFs added correctly.")

def AdaptMesh(self):
pass
Expand Down Expand Up @@ -142,7 +118,7 @@ def SolveSolutionStep(self):
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 += "corresponding to time " + str(self.main_model_part.ProcessInfo[KratosMultiphysics.TIME]) + "\n"
KratosMultiphysics.Logger.PrintWarning("::[NavierStokesBaseSolver]:: ",msg)
KratosMultiphysics.Logger.PrintWarning("NavierStokesBaseSolver",msg)

def FinalizeSolutionStep(self):
if self._TimeBufferIsInitialized():
Expand All @@ -154,21 +130,6 @@ def Solve(self):
self.SolveSolutionStep()
self.FinalizeSolutionStep()

def is_restarted(self):
# this function avoids the long call to ProcessInfo and is also safer
# in case the detection of a restart is changed later
return self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED]

def print_on_rank_zero(self, *args):
# This function will be overridden in the trilinos-solvers
KratosMultiphysics.Logger.PrintInfo(" ".join(map(str,args)))

def print_warning_on_rank_zero(self, *args):
# This function will be overridden in the trilinos-solvers
KratosMultiphysics.Logger.PrintWarning(" ".join(map(str,args)))

#### Private functions ####

def _model_part_reading(self):
## Model part reading
if(self.settings["model_import_settings"]["input_type"].GetString() == "mdpa"):
Expand All @@ -190,6 +151,7 @@ def _execute_check_and_prepare(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 _set_buffer_size(self):
current_buffer_size = self.main_model_part.GetBufferSize()
if self.min_buffer_size > current_buffer_size:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,22 @@ def _SetUpFIC(self,settings):

self.process_data[KratosCFD.FIC_BETA] = settings["beta"].GetDouble()

def CreateSolver(model, custom_settings):
return NavierStokesSolverMonolithic(model, custom_settings)
def CreateSolver(main_model_part, custom_settings):
return NavierStokesSolverMonolithic(main_model_part, custom_settings)

class NavierStokesSolverMonolithic(navier_stokes_base_solver.NavierStokesBaseSolver):

def __init__(self, model, custom_settings):
super(NavierStokesSolverMonolithic, self).__init__(model, custom_settings)

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

##settings string in json format
default_settings = KratosMultiphysics.Parameters("""
{
"model_part_name" : "PLEASE_SPECIFY_NAME",
"solver_type": "navier_stokes_solver_vmsmonolithic",
"model_import_settings": {
"input_type": "mdpa",
Expand Down Expand Up @@ -180,20 +181,6 @@ def __init__(self, model, custom_settings):
self.settings = custom_settings
self.settings.ValidateAndAssignDefaults(default_settings)

model_part_name = self.settings["model_part_name"].GetString()

# This will be changed once the Model is fully supported!
if self.model.HasModelPart(model_part_name):
self.main_model_part = self.model[model_part_name]
else:
self.main_model_part = KratosMultiphysics.ModelPart(model_part_name)

# Set if the analysis is restarted
if self.settings["model_import_settings"]["input_type"].GetString() == "rest":
self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] = True
else:
self.main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] = False

self.stabilization = StabilizedFormulation(self.settings["stabilization"])
self.element_name = self.stabilization.element_name
self.condition_name = self.stabilization.condition_name
Expand All @@ -213,7 +200,8 @@ def __init__(self, model, custom_settings):
import linear_solver_factory
self.linear_solver = linear_solver_factory.ConstructSolver(self.settings["linear_solver_settings"])

self.print_on_rank_zero("::[NavierStokesSolverMonolithic]:: ", "Construction of NavierStokesSolverMonolithic finished.")
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithic", "Construction of NavierStokesSolverMonolithic finished.")


def AddVariables(self):
## Add base class variables
Expand All @@ -239,7 +227,7 @@ def AddVariables(self):
if self.settings["consider_periodic_conditions"].GetBool() == True:
self.main_model_part.AddNodalSolutionStepVariable(KratosCFD.PATCH_INDEX)

self.print_on_rank_zero("::[NavierStokesSolverMonolithic]:: ", "Fluid solver variables added correctly.")
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithic", "Fluid solver variables added correctly.")


def ImportModelPart(self):
Expand Down Expand Up @@ -308,7 +296,7 @@ def Initialize(self):

self.solver.Check()

self.print_on_rank_zero("::[NavierStokesSolverMonolithic]:: ", "Solver initialization finished.")
KratosMultiphysics.Logger.PrintInfo("NavierStokesSolverMonolithic", "Solver initialization finished.")


def _set_physical_properties(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import KratosMultiphysics

def CreateSolver(model, custom_settings):
def CreateSolver(main_model_part, custom_settings):

if (type(model) != KratosMultiphysics.Model):
raise Exception("input is expected to be provided as a Kratos Model object")
if (type(main_model_part) != KratosMultiphysics.ModelPart):
raise Exception("input is expected to be provided as a Kratos ModelPart object")

if (type(custom_settings) != KratosMultiphysics.Parameters):
raise Exception("input is expected to be provided as a Kratos Parameters object")

parallelism = custom_settings["problem_data"]["parallel_type"].GetString()
solver_type = custom_settings["solver_settings"]["solver_type"].GetString()

custom_settings["solver_settings"].AddValue("model_part_name", custom_settings["problem_data"]["model_part_name"])

# Solvers for OpenMP parallelism
if (parallelism == "OpenMP"):
if (solver_type == "Monolithic"):
Expand Down Expand Up @@ -55,6 +53,6 @@ def CreateSolver(model, custom_settings):
raise Exception("parallelism is neither OpenMP nor MPI")

solver_module = __import__(solver_module_name)
solver = solver_module.CreateSolver(model, custom_settings["solver_settings"])
solver = solver_module.CreateSolver(main_model_part, custom_settings["solver_settings"])

return solver
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def __init__(self, model, project_parameters):
self.main_model_part = KratosMultiphysics.ModelPart(main_model_part_name)
self.main_model_part.ProcessInfo.SetValue(KratosMultiphysics.DOMAIN_SIZE,
project_parameters["problem_data"]["domain_size"].GetInt())
model.AddModelPart(self.main_model_part)

super(StructuralMechanicsAnalysis, self).__init__(model, project_parameters)

Expand All @@ -65,7 +64,7 @@ def _CreateSolver(self):
""" Create the Solver (and create and import the ModelPart if it is not alread in the model) """
## Solver construction
import python_solvers_wrapper_structural
return python_solvers_wrapper_structural.CreateSolver(self.model, self.project_parameters)
return python_solvers_wrapper_structural.CreateSolver(self.main_model_part, self.project_parameters)

def _CreateProcesses(self, parameter_name, initialization_order):
"""Create a list of Processes
Expand Down

0 comments on commit 79c071a

Please sign in to comment.