diff --git a/structural_mechanics/validation/truss_snap_through/README.md b/structural_mechanics/validation/truss_snap_through/README.md index 2c32bf88..3e13711d 100644 --- a/structural_mechanics/validation/truss_snap_through/README.md +++ b/structural_mechanics/validation/truss_snap_through/README.md @@ -24,14 +24,14 @@ By incrementally increasing the load and solving for the residual to be zero the -_Non-linear snap through: Load-control_ +_Non-linear snap through: Load-control_ `python3 MainKratos.py ProjectParametersLoadControl.json` Whereas both limit points can be found by incrementally increasing the displacement and solving for the residual to be zero: -_Non-linear snap through: Displacement-control_ +_Non-linear snap through: Displacement-control_ `python3 MainKratos.py ProjectParametersDisplacementControl.json` diff --git a/structural_mechanics/validation/truss_snap_through/source/MainKratos.py b/structural_mechanics/validation/truss_snap_through/source/MainKratos.py index 784d1a5b..32580ca8 100755 --- a/structural_mechanics/validation/truss_snap_through/source/MainKratos.py +++ b/structural_mechanics/validation/truss_snap_through/source/MainKratos.py @@ -1,164 +1,52 @@ - -from KratosMultiphysics import * -from KratosMultiphysics.LinearSolversApplication import * -from KratosMultiphysics.StructuralMechanicsApplication import * - -## Import define_output -parameter_file = open("ProjectParameters.json",'r') -ProjectParameters = Parameters( parameter_file.read()) - -## Get echo level and parallel type -echo_level = ProjectParameters["problem_data"]["echo_level"].GetInt() -parallel_type = ProjectParameters["problem_data"]["parallel_type"].GetString() - -## Import parallel modules if needed -if (parallel_type == "MPI"): - from KratosMultiphysics.mpi import * - from KratosMultiphysics.MetisApplication import * - from KratosMultiphysics.TrilinosApplication import * - - - -def ApplyLoad(initial_value, model_part, time): - for node in model_part.Nodes: - factor = 1 - value = initial_value * factor * time - node.SetSolutionStepValue(POINT_LOAD_Y,0,value) - - -## Structure model part definition -main_model_part = ModelPart(ProjectParameters["problem_data"]["model_part_name"].GetString()) -main_model_part.ProcessInfo.SetValue(DOMAIN_SIZE, ProjectParameters["problem_data"]["domain_size"].GetInt()) - -## Solver construction -import python_solvers_wrapper_structural -solver = python_solvers_wrapper_structural.CreateSolver(main_model_part, ProjectParameters) - -solver.AddVariables() - -## Read the model - note that SetBufferSize is done here -solver.ImportModelPart() - -## Add AddDofs -solver.AddDofs() - -## Initialize GiD I/O -output_post = ProjectParameters.Has("output_configuration") -if (output_post == True): - if (parallel_type == "OpenMP"): - from KratosMultiphysics.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() - -## Creation of the Kratos model (build sub_model_parts or submeshes) -StructureModel = {ProjectParameters["problem_data"]["model_part_name"].GetString(): main_model_part} - -## Get the list of the sub_model_parts in where the processes are to be applied -for i in range(ProjectParameters["solver_settings"]["processes_sub_model_part_list"].size()): - part_name = ProjectParameters["solver_settings"]["processes_sub_model_part_list"][i].GetString() - StructureModel.update({part_name: main_model_part.GetSubModelPart(part_name)}) - -## Print model_part and properties -if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 1): - print("") - print(main_model_part) - for properties in main_model_part.Properties: - print(properties) - -## Processes construction -import process_factory -list_of_processes = process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["constraints_process_list"]) -list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["loads_process_list"]) -if (ProjectParameters.Has("list_other_processes") == True): - list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["list_other_processes"]) -if (ProjectParameters.Has("json_output_process") == True): - list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["json_output_process"]) - -if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 1): - for process in list_of_processes: - print(process) - -## Processes initialization -for process in list_of_processes: - process.ExecuteInitialize() - -## Solver initialization -solver.Initialize() -solver.SetEchoLevel(echo_level) - -if (output_post == True): - gid_output.ExecuteBeforeSolutionLoop() - -for process in list_of_processes: - process.ExecuteBeforeSolutionLoop() - -## Writing the full ProjectParameters file before solving -if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 0): - f = open("ProjectParametersOutput.json", 'w') - f.write(ProjectParameters.PrettyPrintJsonString()) - f.close() - -## Stepping and time settings -delta_time = ProjectParameters["problem_data"]["time_step"].GetDouble() -start_time = ProjectParameters["problem_data"]["start_time"].GetDouble() -end_time = ProjectParameters["problem_data"]["end_time"].GetDouble() - -time = start_time -main_model_part.ProcessInfo[TIME_STEPS] = 0 - -# Solving the problem (time integration) -while(time <= end_time): - - time = time + delta_time - main_model_part.ProcessInfo[TIME_STEPS] += 1 - main_model_part.CloneTimeStep(time) - - if (parallel_type == "OpenMP") or (mpi.rank == 0): - print("") - print("STEP = ", main_model_part.ProcessInfo[TIME_STEPS]) - print("TIME = ", time) - - for process in list_of_processes: - process.ExecuteInitializeSolutionStep() - - if (output_post == True): - gid_output.ExecuteInitializeSolutionStep() - - ApplyLoad(-37000000, main_model_part.GetSubModelPart("PointLoad3D_neumann"), time) - - solver.Solve() - - - for process in list_of_processes: - process.ExecuteFinalizeSolutionStep() - - if (output_post == True): - gid_output.ExecuteFinalizeSolutionStep() - - for process in list_of_processes: - process.ExecuteBeforeOutputStep() - - if (output_post == True) and (gid_output.IsOutputStep()): - gid_output.PrintOutput() - - for process in list_of_processes: - process.ExecuteAfterOutputStep() - -for process in list_of_processes: - process.ExecuteFinalize() - -if (output_post == True): - gid_output.ExecuteFinalize() - -if (parallel_type == "OpenMP") or (mpi.rank == 0): - print(" ") - print("::[KSM Simulation]:: Analysis -END- ") - print(" ") +if __name__ == "__main__": + + # --- STD Imports --- + import sys + import argparse + import pathlib + + # --- Kratos Imports --- + import KratosMultiphysics + from KratosMultiphysics.analysis_stage import AnalysisStage + from KratosMultiphysics.StructuralMechanicsApplication.structural_mechanics_analysis import StructuralMechanicsAnalysis + + try: + import KratosMultiphysics.LinearSolversApplication + except ImportError as exception: + print(str(exception), file = sys.stderr) + print("This example requires the LinearSolversApplication", file = sys.stderr) + exit(1) + + try: + import KratosMultiphysics.StructuralMechanicsApplication + except ImportError as exception: + print(str(exception), file = sys.stderr) + print("This example requires the StructuralMechanicsApplication", file = sys.stderr) + exit(1) + + try: + import KratosMultiphysics.ConstitutiveLawsApplication + except ImportError as exception: + print(str(exception), file = sys.stderr) + print("This example requires the ConstitutiveLawsApplication", file = sys.stderr) + exit(1) + + # Parse input arguments + parser: argparse.ArgumentParser = argparse.ArgumentParser("TrussSnapThrough") + parser.add_argument("json_input", + type = pathlib.Path, + choices = [pathlib.Path("ProjectParametersLoadControl.json"), + pathlib.Path("ProjectParametersDisplacementControl.json")], + default = pathlib.Path("ProjectParametersLoadControl.json"), + nargs = "?") + arguments = parser.parse_args() + + # Read settings. + parameters: KratosMultiphysics.Parameters + with open(arguments.json_input, 'r') as file: + parameters = KratosMultiphysics.Parameters(file.read()) + + # Run the example. + model = KratosMultiphysics.Model() + analysis: AnalysisStage = StructuralMechanicsAnalysis(model, parameters) + analysis.Run() diff --git a/structural_mechanics/validation/truss_snap_through/source/ProjectParameters.json b/structural_mechanics/validation/truss_snap_through/source/ProjectParameters.json deleted file mode 100755 index e3e4b82a..00000000 --- a/structural_mechanics/validation/truss_snap_through/source/ProjectParameters.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "problem_data" : { - "problem_name" : "SnapThrough", - "model_part_name" : "Structure", - "domain_size" : 3, - "parallel_type" : "OpenMP", - "time_step" : 0.001, - "start_time" : 0.0, - "end_time" : 1.20, - "echo_level" : 0 - }, - "solver_settings" : { - "solver_type" : "Static", - "echo_level" : 1, - "analysis_type" : "non_linear", - "model_import_settings" : { - "input_type" : "mdpa", - "input_filename" : "SnapThrough" - }, - "material_import_settings" : { - "materials_filename" : "StructuralMaterials.json" - }, - "line_search" : false, - "convergence_criterion" : "residual_criterion", - "displacement_relative_tolerance" : 1e-9, - "displacement_absolute_tolerance" : 1e-9, - "residual_relative_tolerance" : 0.0001, - "residual_absolute_tolerance" : 1e-9, - "max_iteration" : 1000, - "linear_solver_settings" : { - "solver_type" : "Super_LU", - "scaling" : false, - "verbosity" : 0 - }, - "problem_domain_sub_model_part_list" : ["Parts_structure"], - "processes_sub_model_part_list" : ["DISPLACEMENT_dirichletXYZ","DISPLACEMENT_dirichletXZ","PointLoad3D_neumann"], - "rotation_dofs" : true - }, - "constraints_process_list" : [{ - "python_module" : "assign_vector_variable_process", - "kratos_module" : "KratosMultiphysics", - "help" : "This process fixes the selected components of a given vector variable", - "process_name" : "AssignVectorVariableProcess", - "Parameters" : { - "mesh_id" : 0, - "model_part_name" : "DISPLACEMENT_dirichletXYZ", - "variable_name" : "DISPLACEMENT", - "value" : [0.0,0.0,0.0], - "interval" : [0.0,"End"] - } - },{ - "python_module" : "assign_vector_variable_process", - "kratos_module" : "KratosMultiphysics", - "help" : "This process fixes the selected components of a given vector variable", - "process_name" : "AssignVectorVariableProcess", - "Parameters" : { - "mesh_id" : 0, - "model_part_name" : "DISPLACEMENT_dirichletXZ", - "variable_name" : "DISPLACEMENT", - "value" : [0.0,null,0.0], - "interval" : [0.0,"End"] - } - }], - "loads_process_list" : [{ - "python_module" : "assign_vector_by_direction_to_condition_process", - "kratos_module" : "KratosMultiphysics", - "help" : "This process sets a vector variable value over a condition", - "check" : "DirectorVectorNonZero direction", - "process_name" : "AssignModulusAndDirectionToConditionsProcess", - "Parameters" : { - "mesh_id" : 0, - "model_part_name" : "PointLoad3D_neumann", - "variable_name" : "POINT_LOAD", - "modulus" : 0, - "direction" : [0,-1,0], - "interval" : [0.0,"End"] - } - }], - "output_configuration" : { - "result_file_configuration" : { - "gidpost_flags" : { - "GiDPostMode" : "GiD_PostBinary", - "WriteDeformedMeshFlag" : "WriteDeformed", - "WriteConditionsFlag" : "WriteConditions", - "MultiFileFlag" : "SingleFile" - }, - "file_label" : "step", - "output_control_type" : "step", - "output_interval" : 1.0, - "body_output" : true, - "node_output" : false, - "skin_output" : false, - "plane_output" : [], - "nodal_results" : ["DISPLACEMENT","REACTION","ROTATION","POINT_LOAD"], - "gauss_point_results" : [] - }, - "point_data_configuration" : [] - }, - "restart_options" : { - "SaveRestart" : false, - "RestartFrequency" : 0, - "LoadRestart" : false, - "Restart_Step" : 0 - }, - "constraints_data" : { - "incremental_load" : false, - "incremental_displacement" : false - }, - "material_import_settings" : { - "materials_filename" : "StructuralMaterials.json" - } -} diff --git a/structural_mechanics/validation/truss_snap_through/source/ProjectParametersDisplacementControl.json b/structural_mechanics/validation/truss_snap_through/source/ProjectParametersDisplacementControl.json new file mode 100755 index 00000000..f4a570fe --- /dev/null +++ b/structural_mechanics/validation/truss_snap_through/source/ProjectParametersDisplacementControl.json @@ -0,0 +1,89 @@ +{ + "problem_data": { + "problem_name": "SnapThroughDisplacementControl", + "parallel_type": "OpenMP", + "echo_level": 0, + "start_time": 0.0, + "end_time": 2.2 + }, + "solver_settings": { + "solver_type": "Static", + "echo_level": 1, + "analysis_type": "non_linear", + "time_stepping" : { + "time_step": 5e-3 + }, + "domain_size" : 3, + "model_part_name" : "Structure", + "model_import_settings": { + "input_type": "mdpa", + "input_filename": "SnapThrough" + }, + "material_import_settings": { + "materials_filename": "StructuralMaterials.json" + }, + "compute_reactions": true, + "line_search": false, + "convergence_criterion": "residual_criterion", + "displacement_relative_tolerance": 1e-9, + "displacement_absolute_tolerance": 1e-9, + "residual_relative_tolerance": 1e-4, + "residual_absolute_tolerance": 1e-9, + "max_iteration": 1e3, + "linear_solver_settings": { + "solver_type": "LinearSolversApplication.sparse_lu", + "scaling": false, + "verbosity": 0 + }, + "rotation_dofs": true + }, + "processes" : { + "constraints_process_list": [ + { + "python_module": "assign_vector_variable_process", + "kratos_module": "KratosMultiphysics", + "help": "This process fixes the selected components of a given vector variable", + "process_name": "AssignVectorVariableProcess", + "Parameters": { + "model_part_name": "Structure.DISPLACEMENT_dirichletXYZ", + "variable_name": "DISPLACEMENT", + "value": [0.0, 0.0, 0.0], + "constrained" : [true, true, true], + "interval": [0.0, "End"] + } + }, + { + "python_module": "assign_vector_variable_process", + "kratos_module": "KratosMultiphysics", + "help": "This process fixes the selected components of a given vector variable", + "process_name": "AssignVectorVariableProcess", + "Parameters": { + "model_part_name": "Structure.DISPLACEMENT_dirichletXZ", + "variable_name": "DISPLACEMENT", + "value": [0.0, "-t", 0.0], + "constrained" : [true, true, true], + "interval": [0.0, "End"] + } + } + ] + }, + "output_processes" : { + "vtk_output" : [{ + "python_module" : "vtk_output_process", + "kratos_module" : "KratosMultiphysics", + "process_name" : "VtkOutputProcess", + "help" : "This process writes postprocessing files for Paraview", + "Parameters" : { + "model_part_name" : "Structure", + "output_control_type" : "step", + "output_interval" : 1, + "file_format" : "binary", + "output_precision" : 7, + "output_sub_model_parts" : false, + "output_path" : "vtk_output_displacement_control", + "save_output_files_in_folder" : true, + "nodal_solution_step_data_variables" : ["DISPLACEMENT", "REACTION", "ROTATION", "POINT_LOAD"] + } + }] + } +} \ No newline at end of file diff --git a/structural_mechanics/validation/truss_snap_through/source/ProjectParametersLoadControl.json b/structural_mechanics/validation/truss_snap_through/source/ProjectParametersLoadControl.json new file mode 100755 index 00000000..8175f510 --- /dev/null +++ b/structural_mechanics/validation/truss_snap_through/source/ProjectParametersLoadControl.json @@ -0,0 +1,105 @@ +{ + "problem_data": { + "problem_name": "SnapThroughLoadControl", + "parallel_type": "OpenMP", + "echo_level": 0, + "start_time": 0.0, + "end_time": 1.20 + }, + "solver_settings": { + "solver_type": "Static", + "echo_level": 1, + "analysis_type": "non_linear", + "time_stepping" : { + "time_step": 1e-3 + }, + "domain_size" : 3, + "model_part_name" : "Structure", + "model_import_settings": { + "input_type": "mdpa", + "input_filename": "SnapThrough" + }, + "material_import_settings": { + "materials_filename": "StructuralMaterials.json" + }, + "compute_reactions": true, + "line_search": false, + "convergence_criterion": "residual_criterion", + "displacement_relative_tolerance": 1e-9, + "displacement_absolute_tolerance": 1e-9, + "residual_relative_tolerance": 1e-4, + "residual_absolute_tolerance": 1e-9, + "max_iteration": 1e3, + "linear_solver_settings": { + "solver_type": "LinearSolversApplication.sparse_lu", + "scaling": false, + "verbosity": 0 + }, + "rotation_dofs": true + }, + "processes" : { + "constraints_process_list": [ + { + "python_module": "assign_vector_variable_process", + "kratos_module": "KratosMultiphysics", + "help": "This process fixes the selected components of a given vector variable", + "process_name": "AssignVectorVariableProcess", + "Parameters": { + "model_part_name": "Structure.DISPLACEMENT_dirichletXYZ", + "variable_name": "DISPLACEMENT", + "value": [0.0, 0.0, 0.0], + "constrained" : [true, true, true], + "interval": [0.0, "End"] + } + }, + { + "python_module": "assign_vector_variable_process", + "kratos_module": "KratosMultiphysics", + "help": "This process fixes the selected components of a given vector variable", + "process_name": "AssignVectorVariableProcess", + "Parameters": { + "model_part_name": "Structure.DISPLACEMENT_dirichletXZ", + "variable_name": "DISPLACEMENT", + "value": [0.0, null, 0.0], + "constrained" : [true, false, true], + "interval": [0.0, "End"] + } + } + ], + "loads_process_list": [ + { + "python_module": "assign_vector_by_direction_to_condition_process", + "kratos_module": "KratosMultiphysics", + "help": "This process sets a vector variable value over a condition", + "check": "DirectorVectorNonZero direction", + "process_name": "AssignModulusAndDirectionToConditionsProcess", + "Parameters": { + "model_part_name": "Structure.PointLoad3D_neumann", + "variable_name": "POINT_LOAD", + "modulus": "3.7e7 * t", + "direction": [0, -1, 0], + "interval": [0.0, "End"] + } + } + ] + }, + "output_processes" : { + "vtk_output" : [{ + "python_module" : "vtk_output_process", + "kratos_module" : "KratosMultiphysics", + "process_name" : "VtkOutputProcess", + "help" : "This process writes postprocessing files for Paraview", + "Parameters" : { + "model_part_name" : "Structure", + "output_control_type" : "step", + "output_interval" : 1, + "file_format" : "binary", + "output_precision" : 7, + "output_sub_model_parts" : false, + "output_path" : "vtk_output_load_control", + "save_output_files_in_folder" : true, + "nodal_solution_step_data_variables" : ["DISPLACEMENT", "REACTION", "ROTATION", "POINT_LOAD"] + } + }] + } +} \ No newline at end of file diff --git a/structural_mechanics/validation/truss_snap_through/source/StructuralMaterials.json b/structural_mechanics/validation/truss_snap_through/source/StructuralMaterials.json index fec37015..4e86c74f 100644 --- a/structural_mechanics/validation/truss_snap_through/source/StructuralMaterials.json +++ b/structural_mechanics/validation/truss_snap_through/source/StructuralMaterials.json @@ -1,21 +1,19 @@ { - "properties" : [{ - "model_part_name" : "Parts_structure", - "properties_id" : 1, - "Material" : { - "constitutive_law" : { - "name" : "KratosMultiphysics.StructuralMechanicsApplication.LinearElasticPlaneStress2DLaw" - }, - "Variables" : { - "DENSITY" : 7850.0, - "YOUNG_MODULUS" : 210000000000.0, - "KratosMultiphysics.StructuralMechanicsApplication.CROSS_AREA" : 0.01, - "KratosMultiphysics.StructuralMechanicsApplication.TRUSS_PRESTRESS_PK2" : 0.00 - }, - "Tables" : {} + "properties": [ + { + "model_part_name" : "Structure.Parts_structure", + "properties_id" : 1, + "Material" : { + "constitutive_law" : { + "name" : "TrussConstitutiveLaw" + }, + "Variables" : { + "DENSITY": 7.85e3, + "YOUNG_MODULUS": 2.1e11, + "CROSS_AREA" : 1e-2, + "TRUSS_PRESTRESS_PK2" : 0 + } + } } - }] -} - - - + ] +} \ No newline at end of file