-
Notifications
You must be signed in to change notification settings - Fork 256
Python Script Tutorial: Reading ModelPart From Input File
The ModelPart represents an arbitrary part of the model to be simulated and stores the mesh and additional data for it. Most of the Kratos routines take a ModelPart as their argument. So always is necessary to create and fill a ModelPart. In this tutorial we will describe how to create and fill a model part from given input file.
First of all we need to create a python file with following code to import the Kratos:
import KratosMultiphysics
import KratosMultiphysics.FluidDynamicsApplication
To create a ModelPart, one has to call its constructor passing the ModelPart`s name as its argument:
structure_model_part = ModelPart("FluidPart")
You can print the fluid_model_part:
>>> print structure_model_part
StructurePart model part
Buffer Size : 1
Number of tables : 0
Current solution step index : 0
Mesh 0 :
Number of Nodes : 0
Number of Properties : 0
Number of Elements : 0
Number of Conditions : 0
It can be seen that the ModelPart is empty and has the buffer size equal to 1. This means that no history of the nodal solution steps variables will be saved.
The next step is to define the variables we want to store as historical variables in nodes of this ModelPart as follow:
structure_model_part.AddNodalSolutionStepVariable(DISPLACEMENT)
structure_model_part.AddNodalSolutionStepVariable(FORCE)
The input file of the Kratos has .mdpa (stand for ModelPart) and contains the properties, nodes, elements, conditions and initial values. A convenient way to create this file is to use the interface prepared for GiD pre and post processor. Here you can find more information about the input file. Here we assume that the example.mdpa input file is already created as follow:
example.mdpa:
Begin ModelPartData
// nothing here
End ModelPartData
Begin Properties 1
DENSITY 2700.000000
YOUNG_MODULUS 7000000.000000
POISSON_RATIO 0.300000
BODY_FORCE [3] (0.000000,0.000000,0.000000)
THICKNESS 1.000000
End Properties
Begin Nodes
1 0.0 0.0 0.0 //node number, coord x, cord y, coord z
2 1.0 0.0 0.0 //node number, coord x, cord y, coord z
3 1.0 1.0 0.0 //node number, coord x, cord y, coord z
4 0.0 1.0 0.0 //node number, coord x, cord y, coord z
End Nodes
Begin Elements TotalLagrangianElement2D3N
1 1 1 2 4 //the first column is the property
2 1 3 4 2
End Elements
Begin NodalData DISPLACEMENT_X //be careful, variables are case sensitive!
1 1 100.0 // pos1 is the node, pos2 (a 1) means that the DOF is fixed, then (position 3) we write the fixed displacement (in this case, temperature)
End NodalData
Begin NodalData DISPLACEMENT_Y
1 1 100.0
End NodalData
Begin NodalData FORCE_Y
3 0 5.0 //fixing it or not does not change anything since it is not a degree of freedom, it's just info that will be used by the condition
End NodalData
Begin Conditions PointLoadCondition2D1N
1 1 3 //pos1:condition ID ; pos2:cond Property ( = 1 in this case) ; pos3:node to apply the condition.
End Conditions
Begin SubModelPart BaseNodes // Note that this would be a sub sub modelpart
Begin SubModelPartNodes
1
2
End SubModelPartNodes
End SubModelPart
which represents the following 2D problem:
Elems.png
For reading the .mdpa file first we have to create a ModelPartIO object passing the input file path/name to its constructor:
model_part_io_structure = ModelPartIO("path/to/file/example")
the file name is used without the .mdpa extension!
Then use this io object to read the file and store the mesh and data in ModelPart:
model_part_io_structure.ReadModelPart(structure_model_part)
And printing again the ModelPart:
>>> print structure_model_part
StructurePart model part
Buffer Size : 1
Number of tables : 0
Current solution step index : 0
Mesh 0 :
Number of Nodes : 4
Number of Properties : 1
Number of Elements : 2
Number of Conditions : 1
If we need to store the values of the nodal solution step variables in previous time steps, we must modify the buffer size AFTER defining the historical variables:
structure_model_part.SetBufferSize(3)
This would store the values for two previous steps in addition to the current ones.
- 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