Exemple #1
0
    time = time + delta_time
    main_model_part.CloneTimeStep(time)

# Initialize GiD I/O
computing_model_part = solver.GetComputingModelPart()
output_settings = ProjectParameters["output_configuration"]
if parallel_type == "OpenMP":
    import poromechanics_cleaning_utility
    poromechanics_cleaning_utility.CleanPreviousFiles(
        problem_path)  # Clean previous post files
    from gid_output_process import GiDOutputProcess
    gid_output = GiDOutputProcess(computing_model_part, problem_name,
                                  output_settings)
else:
    from gid_output_process_mpi import GiDOutputProcessMPI
    gid_output = GiDOutputProcessMPI(computing_model_part, problem_name,
                                     output_settings)
gid_output.ExecuteInitialize()

# Initialize the solver
solver.Initialize()

# ExecuteBeforeSolutionLoop
for process in list_of_processes:
    process.ExecuteBeforeSolutionLoop()

## Set results when they are written in a single file
gid_output.ExecuteBeforeSolutionLoop()

# Initialize streamlines_output_utility
UseStreamlineUtility = False
if (use_streamline_utility == True and domain_size == 3):
Exemple #2
0
solver.ImportModelPart()

## Add AddDofs
solver.AddDofs()

## Initialize GiD  I/O
if (parallel_type == "OpenMP"):
    from gid_output_process import GiDOutputProcess
    gid_output = GiDOutputProcess(
        solver.GetComputingModelPart(),
        ProjectParameters["problem_data"]["problem_name"].GetString(),
        ProjectParameters["output_configuration"])
elif (parallel_type == "MPI"):
    from gid_output_process_mpi import GiDOutputProcessMPI
    gid_output = GiDOutputProcessMPI(
        solver.GetComputingModelPart(),
        ProjectParameters["problem_data"]["problem_name"].GetString(),
        ProjectParameters["output_configuration"])

gid_output.ExecuteInitialize()

##here all of the allocation of the strategies etc is done
solver.Initialize()

##TODO: replace MODEL for the Kratos one ASAP
## Get the list of the skin submodel parts in the object Model
for i in range(ProjectParameters["solver_settings"]["skin_parts"].size()):
    skin_part_name = ProjectParameters["solver_settings"]["skin_parts"][
        i].GetString()
    Model.update(
        {skin_part_name: main_model_part.GetSubModelPart(skin_part_name)})
solver.AddDofs()

## Initialize GiD  I/O
if (parallel_type == "OpenMP"):
    from gid_output_process import GiDOutputProcess
    gid_output_structure = GiDOutputProcess(solver.structure_solver.GetComputingModelPart(),
                                        ProjectParameters["structure_solver_settings"]["problem_data"]["problem_name"].GetString()+"_structure",
                                        ProjectParameters["structure_solver_settings"]["output_configuration"])
    gid_output_fluid = GiDOutputProcess(solver.fluid_solver.GetComputingModelPart(),
                                        ProjectParameters["fluid_solver_settings"]["problem_data"]["problem_name"].GetString()+"_fluid",
                                        ProjectParameters["fluid_solver_settings"]["output_configuration"])

elif (parallel_type == "MPI"):
    from gid_output_process_mpi import GiDOutputProcessMPI
    gid_output_structure = GiDOutputProcessMPI(solver.structure_solver.GetComputingModelPart(),
                                               ProjectParameters["structure_solver_settings"]["problem_data"]["problem_name"].GetString()+"_structure",
                                               ProjectParameters["structure_solver_settings"]["output_configuration"])

    gid_output_fluid = GiDOutputProcessMPI(solver.fluid_solver.GetComputingModelPart(),
                                           ProjectParameters["fluid_solver_settings"]["problem_data"]["problem_name"].GetString()+"_fluid",
                                           ProjectParameters["fluid_solver_settings"]["output_configuration"])

gid_output_structure.ExecuteInitialize()
gid_output_fluid.ExecuteInitialize()

## Creation of Kratos models
FluidModel = Model()
FluidModel.AddModelPart(fluid_main_model_part)
SolidModel = Model()
SolidModel.AddModelPart(structure_main_model_part)
computing_model_part = solver.GetComputingModelPart()

## Sets strategies, builders, linear solvers, schemes and solving info, and fills the buffer
solver.Initialize()
#solver.InitializeStrategy()
solver.SetEchoLevel(echo_level)

#### Output settings start ####

problem_path = os.getcwd()
problem_name = ProjectParameters["problem_data"]["problem_name"].GetString()

# Initialize GiD  I/O (gid outputs, file_lists)
from gid_output_process_mpi import GiDOutputProcessMPI
output_settings = ProjectParameters["output_configuration"]
gid_output = GiDOutputProcessMPI(computing_model_part, problem_name,
                                 output_settings)

gid_output.ExecuteInitialize()

#### Output settings end ####

print(" ")
print("::[KSM Simulation]:: Analysis -START- ")

for process in list_of_processes:
    process.ExecuteBeforeSolutionLoop()

# writing a initial state results file or single file (if no restart)
if ((main_model_part.ProcessInfo).Has(KratosMultiphysics.IS_RESTARTED)):
    if (main_model_part.ProcessInfo[KratosMultiphysics.IS_RESTARTED] == False):
        gid_output.ExecuteBeforeSolutionLoop()
    def __init__(self, ProjectParameters):

        self.ProjectParameters = ProjectParameters

        self.echo_level = self.ProjectParameters["problem_data"][
            "echo_level"].GetInt()
        self.parallel_type = self.ProjectParameters["problem_data"][
            "parallel_type"].GetString()

        ## Import parallel modules if needed
        if (self.parallel_type == "MPI"):
            import KratosMultiphysics.mpi as mpi
            import KratosMultiphysics.MetisApplication as MetisApplication
            import KratosMultiphysics.TrilinosApplication as TrilinosApplication

        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())

        self.Model = {
            self.ProjectParameters["problem_data"]["model_part_name"].GetString(
            ):
            self.main_model_part
        }

        # Construct the solver (main setting methods are located in the solver_module)
        import python_solvers_wrapper_contact_structural
        self.solver = python_solvers_wrapper_contact_structural.CreateSolver(
            self.main_model_part, ProjectParameters)

        # Add variables (always before importing the model part) (it must be integrated in the ImportModelPart)
        # If we integrate it in the model part we cannot use combined solvers
        self.solver.AddVariables()

        # Read model_part (note: the buffer_size is set here) (restart can be read here)
        self.solver.ImportModelPart()

        # Add dofs (always after importing the model part) (it must be integrated in the ImportModelPart)
        # If we integrate it in the model part we cannot use combined solvers
        self.solver.AddDofs()

        # Build sub_model_parts or submeshes (rearrange parts for the application of custom processes)
        # #Get the list of the submodel part in the object Model
        for i in range(self.ProjectParameters["solver_settings"]
                       ["processes_sub_model_part_list"].size()):
            part_name = self.ProjectParameters["solver_settings"][
                "processes_sub_model_part_list"][i].GetString()
            self.Model.update(
                {part_name: self.main_model_part.GetSubModelPart(part_name)})

        # Obtain the list of the processes to be applied
        self.list_of_processes = process_factory.KratosProcessFactory(
            self.Model).ConstructListOfProcesses(
                self.ProjectParameters["constraints_process_list"])
        self.list_of_processes += process_factory.KratosProcessFactory(
            self.Model).ConstructListOfProcesses(
                self.ProjectParameters["loads_process_list"])
        if (ProjectParameters.Has("list_other_processes") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    self.ProjectParameters["list_other_processes"])
        if (ProjectParameters.Has("json_check_process") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    self.ProjectParameters["json_check_process"])
        if (ProjectParameters.Has("json_output_process") == True):
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    self.ProjectParameters["json_output_process"])
        if (
                ProjectParameters.Has("contact_process_list") == True
        ):  # NOTE: Always add the contact processes the last one (to avoid problems imposing displacements)
            self.list_of_processes += process_factory.KratosProcessFactory(
                self.Model).ConstructListOfProcesses(
                    self.ProjectParameters["contact_process_list"])

        for process in self.list_of_processes:
            process.ExecuteInitialize()

        # ### START SOLUTION ####

        self.computing_model_part = self.solver.GetComputingModelPart()
        self.solver.AddProcessesList(self.list_of_processes)

        # ### Output settings start ####
        self.problem_path = os.getcwd()
        self.problem_name = self.ProjectParameters["problem_data"][
            "problem_name"].GetString()

        # ### Output settings start ####
        self.output_post = ProjectParameters.Has("output_configuration")
        if (self.output_post == True):
            if (self.parallel_type == "OpenMP"):
                from gid_output_process import GiDOutputProcess
                output_settings = ProjectParameters["output_configuration"]
                self.gid_output = GiDOutputProcess(self.computing_model_part,
                                                   self.problem_name,
                                                   output_settings)
            elif (self.parallel_type == "MPI"):
                from gid_output_process_mpi import GiDOutputProcessMPI
                output_settings = ProjectParameters["output_configuration"]
                self.gid_output = GiDOutputProcessMPI(
                    self.computing_model_part, self.problem_name,
                    output_settings)
            self.gid_output.ExecuteInitialize()

        # Sets strategies, builders, linear solvers, schemes and solving info, and fills the buffer
        self.solver.Initialize()
        self.solver.SetEchoLevel(0)  # Avoid to print anything

        if (self.output_post == True):
            self.gid_output.ExecuteBeforeSolutionLoop()
Exemple #6
0
    def __init__(self, Model, settings):

        KratosMultiphysics.Process.__init__(self)

        default_parameters = KratosMultiphysics.Parameters("""
        {
            "parallel_type"                       : "OpenMP",
            "model_part_name"                     : "origin_model_part",
            "visualization_model_part_name"       : "origin_model_part_visualization",
            "shape_functions"                     : "standard",
            "reform_model_part_at_each_time_step" : false,
            "visualization_variables"             : ["VELOCITY","PRESSURE"],
            "output_configuration"                : {
                "result_file_configuration" : {
                    "gidpost_flags" : {
                        "GiDPostMode"           : "GiD_PostBinary",
                        "WriteDeformedMeshFlag" : "WriteDeformed",
                        "WriteConditionsFlag"   : "WriteConditions",
                        "MultiFileFlag"         : "SingleFile"
                    },
                    "file_label"          : "time",
                    "output_control_type" : "time",
                    "output_frequency"    : 0.1,
                    "body_output"         : true,
                    "node_output"         : false,
                    "skin_output"         : false,
                    "nodal_results"       : []
                },
                "point_data_configuration"  : []
            }
        } """)

        settings.ValidateAndAssignDefaults(default_parameters)

        # Get the origin model part
        self.origin_model_part = Model[settings["model_part_name"].GetString()]

        # Set up the visualization model part
        visualization_buffer_size = 1
        self.visualization_model_part = Model.CreateModelPart(
            settings["visualization_model_part_name"].GetString(),
            visualization_buffer_size)
        self.visualization_model_part.ProcessInfo.SetValue(
            KratosMultiphysics.DOMAIN_SIZE,
            self.origin_model_part.ProcessInfo[KratosMultiphysics.DOMAIN_SIZE])

        # Check that the nodal results array is empty
        if (settings["output_configuration"]["result_file_configuration"]
            ["nodal_results"].size() != 0):
            error_msg = "The nodal_results field in output_configuration is not empty.\n Add the variables in the visualization_variables field instead."
            raise Exception(error_msg)

        # Add the visualization model part variables to the visualization model part.
        # Add them to the nodal_results GiD output process list as well.
        for i_var in range(0, settings["visualization_variables"].size()):
            variable_name = settings["visualization_variables"][
                i_var].GetString()
            settings["output_configuration"]["result_file_configuration"][
                "nodal_results"].Append(variable_name)
            self.visualization_model_part.AddNodalSolutionStepVariable(
                KratosMultiphysics.KratosGlobals.GetVariable(variable_name))

        # Set an auxilar Kratos Parameters object to build the skin visualization process
        aux_params = KratosMultiphysics.Parameters("""{}""")
        aux_params.AddValue("shape_functions", settings["shape_functions"])
        aux_params.AddValue("visualization_variables",
                            settings["visualization_variables"])
        aux_params.AddValue("reform_model_part_at_each_time_step",
                            settings["reform_model_part_at_each_time_step"])

        self.EmbeddedSkinVisualizationProcess = KratosFluid.EmbeddedSkinVisualizationProcess(
            self.origin_model_part, self.visualization_model_part, aux_params)

        # Set the output variables and build the GiD output process
        if (settings["parallel_type"].GetString() == "OpenMP"):
            from gid_output_process import GiDOutputProcess
            self.gid_output = GiDOutputProcess(
                self.visualization_model_part,
                settings["visualization_model_part_name"].GetString(),
                settings["output_configuration"])
        elif (settings["parallel_type"].GetString() == "MPI"):
            from gid_output_process_mpi import GiDOutputProcessMPI
            self.gid_output = GiDOutputProcessMPI(
                self.visualization_model_part,
                settings["visualization_model_part_name"].GetString(),
                settings["output_configuration"])