-
Notifications
You must be signed in to change notification settings - Fork 274
Python Script Tutorial: Reading ProjectParameters
The Kratos Parameters object is a container based on the well known JavaScript Object Notation (JSON) standard. Even though it can contain any type of key-value information, in Kratos it is used to contain configuration settings for solvers, processes or utilities.
In this tutorial, the use of the JSON format together with the Kratos Parameters class is reviewed using a standard Kratos simulation configuration file (ProjectParameters.json), in this case coming from the FluidDynamicsApplication, as example.
First of all we need to create a python file with following code to import the Kratos:
from KratosMultiphysics import *In this subsection we will try to parse the ProjectParameters.json file to construct the Kratos Parameters object. The ProjectParameters.json file reads as follows
{
"problem_data" : {
"problem_name" : "parameters_tutorial",
"model_part_name" : "MainModelPart",
"domain_size" : 2,
"parallel_type" : "OpenMP",
"echo_level" : 0,
"start_time" : 0.0,
"end_time" : 45
},
"output_configuration" : {
"result_file_configuration" : {
"gidpost_flags" : {
"GiDPostMode" : "GiD_PostBinary",
"WriteDeformedMeshFlag" : "WriteDeformed",
"WriteConditionsFlag" : "WriteConditions",
"MultiFileFlag" : "SingleFile"
},
"file_label" : "time",
"output_control_type" : "step",
"output_frequency" : 1,
"body_output" : true,
"node_output" : false,
"skin_output" : false,
"plane_output" : [],
"nodal_results" : ["VELOCITY","PRESSURE"],
"gauss_point_results" : []
},
"point_data_configuration" : []
},
"restart_options" : {
"SaveRestart" : "False",
"RestartFrequency" : 0,
"LoadRestart" : "False",
"Restart_Step" : 0
},
"solver_settings" : {
"solver_type" : "Monolithic",
"model_import_settings" : {
"input_type" : "mdpa",
"input_filename" : "parameters_tuto"
},
"echo_level" : 0,
"compute_reactions" : false,
"dynamic_tau" : 1.0,
"oss_switch" : 0,
"maximum_iterations" : 10,
"relative_velocity_tolerance" : 0.001,
"absolute_velocity_tolerance" : 1e-5,
"relative_pressure_tolerance" : 0.001,
"absolute_pressure_tolerance" : 1e-5,
"volume_model_part_name" : "Parts_Fluid",
"skin_parts" : ["AutomaticInlet2D_Inlet","Outlet2D_Outlet","NoSlip2D_No_Slip_Walls","NoSlip2D_No_Slip_Cylinder"],
"no_skin_parts" : [],
"time_stepping" : {
"automatic_time_step" : false,
"time_step" : 0.1
}
},
"initial_conditions_process_list" : [],
"boundary_conditions_process_list" : [{
"python_module" : "apply_inlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "AutomaticInlet2D_Inlet",
"variable_name" : "VELOCITY",
"modulus" : "6*y*(1-y)*sin(pi*t*0.5)",
"direction" : "automatic_inwards_normal",
"interval" : [0,1]
}
},{
"python_module" : "apply_inlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "AutomaticInlet2D_Inlet",
"variable_name" : "VELOCITY",
"modulus" : "6*y*(1-y)",
"direction" : "automatic_inwards_normal",
"interval" : [1,"End"]
}
},{
"python_module" : "apply_outlet_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "Outlet2D_Outlet",
"variable_name" : "PRESSURE",
"constrained" : true,
"value" : 0.0,
"hydrostatic_outlet" : false,
"h_top" : 0.0
}
},{
"python_module" : "apply_noslip_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "NoSlip2D_No_Slip_Walls"
}
},{
"python_module" : "apply_noslip_process",
"kratos_module" : "KratosMultiphysics.FluidDynamicsApplication",
"Parameters" : {
"model_part_name" : "NoSlip2D_No_Slip_Cylinder"
}
}],
"gravity" : [{
"python_module" : "assign_vector_by_direction_process",
"kratos_module" : "KratosMultiphysics",
"process_name" : "AssignVectorByDirectionProcess",
"Parameters" : {
"model_part_name" : "Parts_Fluid",
"variable_name" : "BODY_FORCE",
"modulus" : 0.0,
"constrained" : false,
"direction" : [0.0,-1.0,0.0]
}
}],
"auxiliar_process_list" : []
}
and can be parsed to construct a Kratos Parameters object with the next two lines of code
json_file = open("ProjectParameters.json",'r')
ProjectParameters = Parameters(json_file.read())- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API