How to work with Groups (Meshes)
What is a Group?
A Group is a subset of entities of the domain. In numerical simulation, they are useful to identify parts of the domain that have different data associated to them. For instance, the nodes belonging to a fluid inlet can belong to a group, the nodes where we want to plot some result can belong to a different group, the elements that belong to a rigid body can belong to a different group, etc... As a big difference with Layers, which conform a partition of the domain, the Groups can overlap, in such a way that a node can belong to different groups. This is the reason why Groups know what entities they contain, while the entities not necessarily know what Groups they belong to.
How to use Groups in Kratos? The Meshes
The keyword that Kratos uses for Group is Mesh. A Mesh is a subset of a Model Part which can contain simultaneously Nodes, Elements, Conditions and Shared Data.
The main features of the Mesh are the following:
- It contains pointers to the entities included (not copies of the entities)
- It has an interface accessible from C++ and Python for the most usual operations.
- The Nodes are iterable. The Elements and the Conditions are iterable, too.
- It features a container (Mesh Data) which can store variables of any kind, as many as wanted
Important Note: All the entities of the Model Part are saved by default in Mesh 0, so when the Model Part loops over all its entities, it actually loops over the entities of Mesh 0. All the other meshes point to entities that are already included in Mesh 0. Care must be taken when adding an newly created entity to a Mesh. It must be added to Mesh 0 as well if we want the ModelPart to be aware of the inclusion of the new entity. A safe way to create a new node is to use the function ModelPart.CreateNewNode(...).
How to create Meshes?
The easiest option is to write it in the input file (.mdpa file). The syntax is the following (the next example would be added after the rest of the information of the .mdpa file):
Begin Mesh 2 // just an example, the Id has been chosen to be 2 Begin MeshData IDENTIFIER Custom_Name // just an example YOUNG_MODULUS 1.0e9 // just an example EULER_ANGLES  (0.0,0.0,0.0) // just an example End MeshData Begin MeshNodes 3 5 7 End MeshNodes Begin MeshElements 10 12 End MeshElements Begin MeshConditions 6 7 End MeshConditions End Mesh
Using the Groups / Meshes to do fast loops
The Mesh allows fast iteration over the entities included in the Mesh. For instance, if we want to loop over the nodes of a Mesh to sum a certain nodal variable called VARIABLE, we can do the following (Python code):
for node in model_part.GetMesh(mesh_number).Nodes: total_value += node.GetSolutionStepValue(VARIABLE)
Sometimes we will have to loop over all meshes. Then we can use this (Python code):
for mesh_number in range(1, model_part.NumberOfMeshes()): if(model_part.GetMesh(mesh_number)[INTEGRATE_VARIABLE_OPTION]): //Conditional jump based on information inside Mesh Data for node in model_part.GetMesh(mesh_number).Nodes: total_value += node.GetSolutionStepValue(VARIABLE)
(Note that Mesh 0 is skipped because it gives no additional information versus the whole Model Part.)
How to add entities to a Mesh
(to be written)
If the .mdpa file includes the definition of Mesh 1 and Mesh 3 (skipping Mesh 2), Mesh 2 is still created, but it is empty.