class Kratos_Execute_Test: 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() def Solve(self): for process in self.list_of_processes: process.ExecuteBeforeSolutionLoop() # #Stepping and time settings (get from process info or solving info) # Delta time delta_time = self.ProjectParameters["problem_data"][ "time_step"].GetDouble() # Start step self.main_model_part.ProcessInfo[KratosMultiphysics.TIME_STEPS] = 0 # Start time time = self.ProjectParameters["problem_data"]["start_time"].GetDouble() # End time end_time = self.ProjectParameters["problem_data"][ "end_time"].GetDouble() # Solving the problem (time integration) while (time <= end_time): time = time + delta_time self.main_model_part.ProcessInfo[ KratosMultiphysics.TIME_STEPS] += 1 self.main_model_part.CloneTimeStep(time) for process in self.list_of_processes: process.ExecuteInitializeSolutionStep() if (self.output_post == True): self.gid_output.ExecuteInitializeSolutionStep() self.solver.Clear() self.solver.Solve() if (self.output_post == True): self.gid_output.ExecuteFinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteFinalizeSolutionStep() for process in self.list_of_processes: process.ExecuteBeforeOutputStep() if (self.output_post == True): if self.gid_output.IsOutputStep(): self.gid_output.PrintOutput() for process in self.list_of_processes: process.ExecuteAfterOutputStep() if (self.output_post == True): self.gid_output.ExecuteFinalize() for process in self.list_of_processes: process.ExecuteFinalize()
process.ExecuteFinalizeSolutionStep() # processes to be executed before witting the output for process in list_of_processes: process.ExecuteBeforeOutputStep() # write output results GiD: (frequency writing is controlled internally) if (gid_output.IsOutputStep()): gid_output.PrintOutput() # processes to be executed after witting the output for process in list_of_processes: process.ExecuteAfterOutputStep() # Ending the problem (time integration finished) gid_output.ExecuteFinalize() for process in list_of_processes: process.ExecuteFinalize() print("::[KSM Simulation]:: Analysis -END- ") print(" ") # Check solving information for any problem #~ solver.InfoCheck() # InfoCheck not implemented yet. #### END SOLUTION #### # Measure process time tfp = timer.clock() # Measure wall time
class ApplyEmbeddedSkinVisualizationProcess(KratosMultiphysics.Process): 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"]) def ExecuteInitialize(self): self.gid_output.ExecuteInitialize() self.EmbeddedSkinVisualizationProcess.ExecuteInitialize() def ExecuteBeforeSolutionLoop(self): self.EmbeddedSkinVisualizationProcess.ExecuteBeforeSolutionLoop() self.gid_output.ExecuteBeforeSolutionLoop() def ExecuteInitializeSolutionStep(self): # Set time in case the GiD process control output is time self.visualization_model_part.ProcessInfo[ KratosMultiphysics.TIME] = self.origin_model_part.ProcessInfo[ KratosMultiphysics.TIME] self.EmbeddedSkinVisualizationProcess.ExecuteInitializeSolutionStep() self.gid_output.ExecuteInitializeSolutionStep() def ExecuteFinalizeSolutionStep(self): self.EmbeddedSkinVisualizationProcess.ExecuteFinalizeSolutionStep() self.gid_output.ExecuteInitializeSolutionStep() def ExecuteBeforeOutputStep(self): self.EmbeddedSkinVisualizationProcess.ExecuteBeforeOutputStep() if (self.gid_output.IsOutputStep()): self.gid_output.PrintOutput() def ExecuteFinalize(self): self.EmbeddedSkinVisualizationProcess.ExecuteFinalize() self.gid_output.ExecuteFinalize()