-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from matekelemen/struct-mech/truss-snap-through
[StructMech] Update the Truss Snap-Through Example
- Loading branch information
Showing
6 changed files
with
265 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 52 additions & 164 deletions
216
structural_mechanics/validation/truss_snap_through/source/MainKratos.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
112 changes: 0 additions & 112 deletions
112
structural_mechanics/validation/truss_snap_through/source/ProjectParameters.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.