-
Notifications
You must be signed in to change notification settings - Fork 245
Nodes and Nodal Data
In this tutorial the access to the nodes stored in a ModelPart
and their nodal data will be described. More information about nodes and nodal data can be found here.
First of all we need to create a python file with following code to import the Kratos, create a ModelPart
and read it from input as described in the here :
import KratosMultiphysics
import KratosMultiphysics.StructuralMechanicsApplication
this_model = KratosMultiphysics.Model()
structural_model_part = this_model.CreateModelPart("StructuralPart", 3)
structural_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT)
structural_model_part.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION)
structural_model_part_io = KratosMultiphysics.ModelPartIO("KratosWorkshop2019_high_rise_building_CSM")
structural_model_part_io.ReadModelPart(structural_model_part)
The nodes stored in the ModelPart can be accessed using the Nodes parameter:
model_part_nodes = structural_model_part.Nodes
Having access to the nodes make iteration over all nodes very easy. For example to print all nodes in the model part:
for node in model_part_nodes:
print(node)
Here is a loop over all of the nodes in a model part, which prints the ID for all of the nodes:
for node in model_part_nodes:
print(node.Id)
The coordinates can be accessed by X,Y,Z parameters of the node:
node_x = node.X
node_y = node.Y
node_z = node.Z
Or we can extend the previous example writing also the coordinates of all the nodes in the ModelPart:
for node in model_part_nodes:
print(node.Id, node.X, node.Y, node.Z)
This access is very useful in order to classify the nodes due to their position. For example we can extend the previous loop to write node information exclusively on the nodes with positive X
for node in model_part_nodes:
if(node.X > 0.0): # Printing the ID of all of the nodes with positive X
print(node.Id, node.X, node.Y)
The Python interface provides full access to the nodal database. The access to the historical variables is given by GetSolutionStepValue
and SetSolutionStepValue
passing the variable you want:
node_displacement = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT) # node's displacement at the current time step
We can write the displacements of all the nodes:
for node in model_part_nodes:
node_displacement = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT) # node's displacement at the current time step
print(node_displacement)
you can also get a value for n time step ago, where n is the buffer size:
node_previous_displacement = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT, 1) # node's displacement at 1 time step ago
node_earlier_displacement = node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT, 2) # node's displacement at 2 time step ago
For getting the previous time step displacements of all the nodes:
for node in model_part_nodes:
print(node.GetSolutionStepValue(KratosMultiphysics.DISPLACEMENT, 1)) # node's displacement at 1 time step ago
To set the historical value for a variable in a node we can use the SetSolutionStepValue
. To make an example let's assume that we want to set the variable DISPLACEMENT_X
to the value of 1.0e-6 on the nodes in our ModelPart
. This is obtained immediately by typing
for node in model_part_nodes:
node.SetSolutionStepValue(KratosMultiphysics.DISPLACEMENT_X,0,1.0e-6)
To set the non-historical value for a variable in a node we can use the SetValue
. Later this can be accessed with GetValue
. For example:
for node in model_part_nodes:
node.SetValue(KratosMultiphysics.TEMPERATURE,100.0)
print(node.GetValue(KratosMultiphysics.TEMPERATURE))
- 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