-
Notifications
You must be signed in to change notification settings - Fork 245
ModelPart and SubModelPart
Here we introduce the basics to create and access to model parts and submodelparts.
First of all we need to create a python file with following code to import the KratosMultiphysics
.
import KratosMultiphysics
Then we need to create the Model
, which will be the resposible to manage the different ModelPart
s that we will create.
this_model = KratosMultiphysics.Model()
Now we can create a ModelPart
. The ModelPart
is the object containing Element
, Conditions
, Nodes
and Properties
. For now we create the Main model part, which will store the successive submodelparts.
main_model_part = this_model.CreateModelPart("Main")
We can create a new model part with a certain buffer size using the following (we need to delete the model part to avoid errors):
this_model.DeleteModelPart("Main")
main_model_part = this_model.CreateModelPart("Main", 2)
We can now execute different operations with the Model
:
print(this_model.HasModelPart("Main")) # It will return True
print(this_model.GetModelPartNames()) # It will return ['Main']
main_model_part_again = this_model.GetModelPart("Main") # Getting again
Let's output what is there:
print(main_model_part)
-Main- model part
Buffer Size : 2
Number of tables : 0
Number of sub model parts : 0
Current solution step index : 0
Mesh 0 :
Number of Nodes : 0
Number of Properties : 0
Number of Elements : 0
Number of Conditions : 0
Number of Constraints : 0
Some other operations we can do are:
print(main_model_part.NumberOfNodes()) # It will return 0
print(main_model_part.NumberOfElements()) # It will return 0
print(main_model_part.NumberOfConditions()) # It will return 0
print(main_model_part.NumberOfMasterSlaveConstraints()) # It will return 0
print(main_model_part.NumberOfProperties()) # It will return 0
print(main_model_part.NumberOfMeshes()) # It will return 1
print(main_model_part.GetBufferSize()) # It will return 2
main_model_part.SetBufferSize(3) # Set the buffer size to 3 instead of 2
A fundamental feature is that it can also hierarchically contain SubModelParts intended as other ModelParts
which belong to the same parent. This relation can be repeated recursively, so that each "root" ModelPart
can actually own a tree of SubModelParts. We can create a submodelpart with the following:
bc_model_part = main_model_part.CreateSubModelPart("BC")
Let's output what is there:
print(main_model_part)
-Main- model part
Buffer Size : 3
Number of tables : 0
Number of sub model parts : 1
Current solution step index : 0
Mesh 0 :
Number of Nodes : 0
Number of Properties : 0
Number of Elements : 0
Number of Conditions : 0
Number of Constraints : 0
-BC- model part
Number of tables : 0
Number of sub model parts : 0
Mesh 0 :
Number of Nodes : 0
Number of Properties : 0
Number of Elements : 0
Number of Conditions : 0
Number of Constraints : 0
Now we can do several operations with this:
print(main_model_part.HasSubModelPart("BC")) #returns True
print(main_model_part.NumberOfSubModelParts()) #returns 1
print(main_model_part.GetSubModelPart("BC").Name) #returns the name --> BC
The parent-son relation is such that anything that belongs to a given SubModelPart also belongs to the parent ModelPart.
This implies that the ultimate owner of any Node
, Element
, etc, will be the root ModelPart
. The consistency of the tree is ensured by the ModelPart
API, which provides the tools needed for creating or removing anything any of the contained objects.
- 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