Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StructMech] Update the Truss Snap-Through Example #141

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions structural_mechanics/validation/truss_snap_through/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ By incrementally increasing the load and solving for the residual to be zero the

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

_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:


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

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



Expand Down
216 changes: 52 additions & 164 deletions structural_mechanics/validation/truss_snap_through/source/MainKratos.py
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()

This file was deleted.

Loading
Loading