-
Notifications
You must be signed in to change notification settings - Fork 247
Entities creation from scratch
Here we present the interface in order to create new entities in an empty model from Python.
We can create a node by doing. If we Try to create a new node with the same Id and different coordinates we would get an error.
main_model_part.CreateNewNode(1, 1.0,0.0,0.0)
#main_model_part.CreateNewNode(1, 0.0,0.0,0.0) # Here an error is thrown
However if we try to create a node with the same coordinates twice nothing is actually done (and no error is thrown)
main_model_part.CreateNewNode(1, 1.00,0.00,0.00)
print(main_model_part.NumberOfNodes()) # This still returns 1!!
We can now access the node as needed, for example:
print(main_model_part.GetNode(1).Id) # Gives 1
print(main_model_part.GetNode(1,0).X) # Gives 1.0
Nodes
can be created in every order
main_model_part.CreateNewNode(2000, 2.00,0.00,0.00)
main_model_part.CreateNewNode(2, 2.00,0.00,0.00)
We could then loop over all the nodes:
for node in main_model_part.Nodes:
print(node.Id, node.X, node.Y, node.Z)
Or eventually remove nodes one by one by doing:
main_model_part.RemoveNode(2000)
Let's now see what happens if we add a node to a submodelpart. Here the node will be both in root ModelPart
and "BC", but for example not in derived submodelparts from "BC" or root ModelPart
.
bc_model_part = main_model_part.GetSubModelPart("BC")
bc_model_part.CreateNewNode(3, 3.00,0.00,0.00)
Multiple nodes can be removed at once (and from all levels) by flagging them:
for node in main_model_part.Nodes:
if node.Id < 3:
node.Set(KratosMultiphysics.TO_ERASE,True)
main_model_part.RemoveNodesFromAllLevels(KratosMultiphysics.TO_ERASE)
One could call simply the function RemoveNodes
and remove them from the current level down.
Elements
and Conditions
can be created from the python interface by providing their connectivity as well as the Properties
to be employed in the creation. The string to be provided is the name by which the element is registered in Kratos. An error is thrown if i try to create an element with the same Id
main_model_part.AddProperties(KratosMultiphysics.Properties(1))
main_model_part.CreateNewElement("Element2D3N", 1, [1,2,3], main_model_part.GetProperties()[1])
#main_model_part.CreateNewElement("Element2D3N", 1, [1,2,3], main_model_part.GetProperties()[1])
An identical interface is provided for Conditions, as well as functions equivalent to the nodes for removing from one level or from all the levels.
The case of the constraints, like it requires the existance of DoF
we will create a new model part in order to avoid problems. This example will advance some methods that will be introduced in future sections, as AddNodalSolutionStepVariable
. The current interface for python works directly with nodes, it is not possible to manipulate DoF
manually.
mp = this_model.CreateModelPart("constraint_example")
mp.AddNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT)
mp.AddNodalSolutionStepVariable(KratosMultiphysics.REACTION)
mp.CreateNewNode(1, 0.00000, 0.00000, 0.00000)
mp.CreateNewNode(2, 0.00000, 1.00000, 0.00000)
KratosMultiphysics.VariableUtils().AddDof(KratosMultiphysics.DISPLACEMENT_X, KratosMultiphysics.REACTION_X, mp)
mp.CreateNewMasterSlaveConstraint("LinearMasterSlaveConstraint", 1, mp.Nodes[1], KratosMultiphysics.DISPLACEMENT_X, mp.Nodes[2], KratosMultiphysics.DISPLACEMENT_X, 1.0, 0)
- 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