Skip to content

Commit c7773d0

Browse files
authored
Merge pull request #141 from matekelemen/struct-mech/truss-snap-through
[StructMech] Update the Truss Snap-Through Example
2 parents 94720b3 + cc094a0 commit c7773d0

File tree

6 files changed

+265
-297
lines changed

6 files changed

+265
-297
lines changed

structural_mechanics/validation/truss_snap_through/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ By incrementally increasing the load and solving for the residual to be zero the
2424

2525
<img src="data/LoadCont.PNG" width="500">
2626

27-
_Non-linear snap through: Load-control_
27+
_Non-linear snap through: Load-control_ `python3 MainKratos.py ProjectParametersLoadControl.json`
2828

2929
Whereas both limit points can be found by incrementally increasing the displacement and solving for the residual to be zero:
3030

3131

3232
<img src="data/DispCont.PNG" width="500">
3333

34-
_Non-linear snap through: Displacement-control_
34+
_Non-linear snap through: Displacement-control_ `python3 MainKratos.py ProjectParametersDisplacementControl.json`
3535

3636

3737

Lines changed: 52 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,52 @@
1-
2-
from KratosMultiphysics import *
3-
from KratosMultiphysics.LinearSolversApplication import *
4-
from KratosMultiphysics.StructuralMechanicsApplication import *
5-
6-
## Import define_output
7-
parameter_file = open("ProjectParameters.json",'r')
8-
ProjectParameters = Parameters( parameter_file.read())
9-
10-
## Get echo level and parallel type
11-
echo_level = ProjectParameters["problem_data"]["echo_level"].GetInt()
12-
parallel_type = ProjectParameters["problem_data"]["parallel_type"].GetString()
13-
14-
## Import parallel modules if needed
15-
if (parallel_type == "MPI"):
16-
from KratosMultiphysics.mpi import *
17-
from KratosMultiphysics.MetisApplication import *
18-
from KratosMultiphysics.TrilinosApplication import *
19-
20-
21-
22-
def ApplyLoad(initial_value, model_part, time):
23-
for node in model_part.Nodes:
24-
factor = 1
25-
value = initial_value * factor * time
26-
node.SetSolutionStepValue(POINT_LOAD_Y,0,value)
27-
28-
29-
## Structure model part definition
30-
main_model_part = ModelPart(ProjectParameters["problem_data"]["model_part_name"].GetString())
31-
main_model_part.ProcessInfo.SetValue(DOMAIN_SIZE, ProjectParameters["problem_data"]["domain_size"].GetInt())
32-
33-
## Solver construction
34-
import python_solvers_wrapper_structural
35-
solver = python_solvers_wrapper_structural.CreateSolver(main_model_part, ProjectParameters)
36-
37-
solver.AddVariables()
38-
39-
## Read the model - note that SetBufferSize is done here
40-
solver.ImportModelPart()
41-
42-
## Add AddDofs
43-
solver.AddDofs()
44-
45-
## Initialize GiD I/O
46-
output_post = ProjectParameters.Has("output_configuration")
47-
if (output_post == True):
48-
if (parallel_type == "OpenMP"):
49-
from KratosMultiphysics.gid_output_process import GiDOutputProcess
50-
gid_output = GiDOutputProcess(solver.GetComputingModelPart(),
51-
ProjectParameters["problem_data"]["problem_name"].GetString() ,
52-
ProjectParameters["output_configuration"])
53-
elif (parallel_type == "MPI"):
54-
from gid_output_process_mpi import GiDOutputProcessMPI
55-
gid_output = GiDOutputProcessMPI(solver.GetComputingModelPart(),
56-
ProjectParameters["problem_data"]["problem_name"].GetString() ,
57-
ProjectParameters["output_configuration"])
58-
59-
gid_output.ExecuteInitialize()
60-
61-
## Creation of the Kratos model (build sub_model_parts or submeshes)
62-
StructureModel = {ProjectParameters["problem_data"]["model_part_name"].GetString(): main_model_part}
63-
64-
## Get the list of the sub_model_parts in where the processes are to be applied
65-
for i in range(ProjectParameters["solver_settings"]["processes_sub_model_part_list"].size()):
66-
part_name = ProjectParameters["solver_settings"]["processes_sub_model_part_list"][i].GetString()
67-
StructureModel.update({part_name: main_model_part.GetSubModelPart(part_name)})
68-
69-
## Print model_part and properties
70-
if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 1):
71-
print("")
72-
print(main_model_part)
73-
for properties in main_model_part.Properties:
74-
print(properties)
75-
76-
## Processes construction
77-
import process_factory
78-
list_of_processes = process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["constraints_process_list"])
79-
list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["loads_process_list"])
80-
if (ProjectParameters.Has("list_other_processes") == True):
81-
list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["list_other_processes"])
82-
if (ProjectParameters.Has("json_output_process") == True):
83-
list_of_processes += process_factory.KratosProcessFactory(StructureModel).ConstructListOfProcesses(ProjectParameters["json_output_process"])
84-
85-
if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 1):
86-
for process in list_of_processes:
87-
print(process)
88-
89-
## Processes initialization
90-
for process in list_of_processes:
91-
process.ExecuteInitialize()
92-
93-
## Solver initialization
94-
solver.Initialize()
95-
solver.SetEchoLevel(echo_level)
96-
97-
if (output_post == True):
98-
gid_output.ExecuteBeforeSolutionLoop()
99-
100-
for process in list_of_processes:
101-
process.ExecuteBeforeSolutionLoop()
102-
103-
## Writing the full ProjectParameters file before solving
104-
if ((parallel_type == "OpenMP") or (mpi.rank == 0)) and (echo_level > 0):
105-
f = open("ProjectParametersOutput.json", 'w')
106-
f.write(ProjectParameters.PrettyPrintJsonString())
107-
f.close()
108-
109-
## Stepping and time settings
110-
delta_time = ProjectParameters["problem_data"]["time_step"].GetDouble()
111-
start_time = ProjectParameters["problem_data"]["start_time"].GetDouble()
112-
end_time = ProjectParameters["problem_data"]["end_time"].GetDouble()
113-
114-
time = start_time
115-
main_model_part.ProcessInfo[TIME_STEPS] = 0
116-
117-
# Solving the problem (time integration)
118-
while(time <= end_time):
119-
120-
time = time + delta_time
121-
main_model_part.ProcessInfo[TIME_STEPS] += 1
122-
main_model_part.CloneTimeStep(time)
123-
124-
if (parallel_type == "OpenMP") or (mpi.rank == 0):
125-
print("")
126-
print("STEP = ", main_model_part.ProcessInfo[TIME_STEPS])
127-
print("TIME = ", time)
128-
129-
for process in list_of_processes:
130-
process.ExecuteInitializeSolutionStep()
131-
132-
if (output_post == True):
133-
gid_output.ExecuteInitializeSolutionStep()
134-
135-
ApplyLoad(-37000000, main_model_part.GetSubModelPart("PointLoad3D_neumann"), time)
136-
137-
solver.Solve()
138-
139-
140-
for process in list_of_processes:
141-
process.ExecuteFinalizeSolutionStep()
142-
143-
if (output_post == True):
144-
gid_output.ExecuteFinalizeSolutionStep()
145-
146-
for process in list_of_processes:
147-
process.ExecuteBeforeOutputStep()
148-
149-
if (output_post == True) and (gid_output.IsOutputStep()):
150-
gid_output.PrintOutput()
151-
152-
for process in list_of_processes:
153-
process.ExecuteAfterOutputStep()
154-
155-
for process in list_of_processes:
156-
process.ExecuteFinalize()
157-
158-
if (output_post == True):
159-
gid_output.ExecuteFinalize()
160-
161-
if (parallel_type == "OpenMP") or (mpi.rank == 0):
162-
print(" ")
163-
print("::[KSM Simulation]:: Analysis -END- ")
164-
print(" ")
1+
if __name__ == "__main__":
2+
3+
# --- STD Imports ---
4+
import sys
5+
import argparse
6+
import pathlib
7+
8+
# --- Kratos Imports ---
9+
import KratosMultiphysics
10+
from KratosMultiphysics.analysis_stage import AnalysisStage
11+
from KratosMultiphysics.StructuralMechanicsApplication.structural_mechanics_analysis import StructuralMechanicsAnalysis
12+
13+
try:
14+
import KratosMultiphysics.LinearSolversApplication
15+
except ImportError as exception:
16+
print(str(exception), file = sys.stderr)
17+
print("This example requires the LinearSolversApplication", file = sys.stderr)
18+
exit(1)
19+
20+
try:
21+
import KratosMultiphysics.StructuralMechanicsApplication
22+
except ImportError as exception:
23+
print(str(exception), file = sys.stderr)
24+
print("This example requires the StructuralMechanicsApplication", file = sys.stderr)
25+
exit(1)
26+
27+
try:
28+
import KratosMultiphysics.ConstitutiveLawsApplication
29+
except ImportError as exception:
30+
print(str(exception), file = sys.stderr)
31+
print("This example requires the ConstitutiveLawsApplication", file = sys.stderr)
32+
exit(1)
33+
34+
# Parse input arguments
35+
parser: argparse.ArgumentParser = argparse.ArgumentParser("TrussSnapThrough")
36+
parser.add_argument("json_input",
37+
type = pathlib.Path,
38+
choices = [pathlib.Path("ProjectParametersLoadControl.json"),
39+
pathlib.Path("ProjectParametersDisplacementControl.json")],
40+
default = pathlib.Path("ProjectParametersLoadControl.json"),
41+
nargs = "?")
42+
arguments = parser.parse_args()
43+
44+
# Read settings.
45+
parameters: KratosMultiphysics.Parameters
46+
with open(arguments.json_input, 'r') as file:
47+
parameters = KratosMultiphysics.Parameters(file.read())
48+
49+
# Run the example.
50+
model = KratosMultiphysics.Model()
51+
analysis: AnalysisStage = StructuralMechanicsAnalysis(model, parameters)
52+
analysis.Run()

structural_mechanics/validation/truss_snap_through/source/ProjectParameters.json

Lines changed: 0 additions & 112 deletions
This file was deleted.

0 commit comments

Comments
 (0)