Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Management of Cartesian Meshes

This page describes the management of Cartesian meshes in Arcane.

Note
For now, Arcane does not automatically handle the recalculation of structuring information when the mesh changes. You must explicitly call Arcane::ICartesianMesh::computeDirections() to perform this recalculation.

Initialization

To have information about a Cartesian mesh, it is necessary to have an instance of the Arcane::ICartesianMesh class. To retrieve such an instance, you must use the Arcane::ICartesianMesh::getReference() method:

Arcane::IMesh* mesh = ...;
static ICartesianMesh * getReference(const MeshHandleOrMesh &mesh, bool create=true)
Retrieves or creates the reference associated with mesh.
Warning
Once the instance is created and before you can use it, it is necessary to calculate the direction information via the Arcane::ICartesianMesh::computeDirections() method. This call should only be made once if the mesh does not change, for example, during code initialization.
cartesian_mesh->computeDirections();
virtual void computeDirections()=0
Calculates information for directional access.

Using Directional Information

Once this is done, it is possible to get information about the entities for a given direction. The possible directions are provided by the #eMeshDirection type. It is also possible to use an integer to specify the direction, where 0 corresponds to the X direction, 1 to the Y direction, and 2 to the Z direction. For readability reasons, it is recommended to use the enumerated type if possible. For example, to retrieve information about cells in the Y direction:

using namespace Arcane;
Arcane::CellDirectionMng cell_dm(cartesian_mesh->cellDirection(1));
Info about the cells in a specific X, Y, or Z direction of a structured mesh.
virtual CellDirectionMng cellDirection(eMeshDirection dir)=0
List of cells in direction dir.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
@ MD_DirY
Y Direction.
Warning
The objects managing entities by direction are temporary objects that should not be retained, particularly from one iteration to the next or when the mesh changes.

Once a direction is retrieved, it is possible to iterate over all entities in that direction and, for cells for example, to get the cell before and after:

using namespace Arcane;
ENUMERATE_(Cell, icell, cell_dm.allCells()){
Arcane::Cell cell = *icell;
Arcane::DirCell dir_cell(cell_dm[icell]); // Directional info for cell
Arcane::Cell prev_cell = dir_cell.previous(); // Cell before
Arcane::Cell next_cell = dir_cell.next(); // Cell after.
}
#define ENUMERATE_(type, name, group)
Generic enumerator for an entity group.
Cell of a mesh.
Definition Item.h:1300
Cell before and after a cell along a direction.

For boundary cells, it is possible that prev_cell or next_cell is null. This can be tested using the Arcane::Cell::null() method.

Retrieving nodes in a direction is done in the same way.

using namespace Arcane;
ENUMERATE_(Node, inode, node_dm.allNodes()){
Arcane::Node node = *inode;
Arcane::DirNode dir_node(node_dm[inode]); // Directional info for node
Arcane::Node prev_cell = dir_node.previous(); // Node before
Arcane::Node next_cell = dir_node.next(); // Node after
}
Node before and after a node following a direction.
virtual NodeDirectionMng nodeDirection(eMeshDirection dir)=0
List of nodes in direction dir.
Info about nodes in a specific direction X, Y, or Z of a structured mesh.
Node of a mesh.
Definition Item.h:598
@ MD_DirX
X Direction.

For faces, the writing is similar, but instead of retrieving the face before and after the current face, you can retrieve the cell before and after:

using namespace Arcane;
ENUMERATE_(Face, iface, face_dm.allFaces()){
Arcane::Face face = *iface;
Arcane::DirFace dir_face(face_dm[iface]);
Arcane::Cell prev_cell = dir_face.previousCell(); // Cell before the face
Arcane::Cell next_cell = dir_face.nextCell(); // Cell after the face
}
Info on the cell before and after a face along a direction.
Info on the faces of a specific direction X, Y, or Z of a structured mesh.
Face of a cell.
Definition Item.h:1032
virtual FaceDirectionMng faceDirection(eMeshDirection dir)=0
List of faces in direction dir.

Finally, for cells, it is possible to retrieve directional information about the nodes of a cell following a direction, via the Arcane::DirCellNode class.

using namespace Arcane;
ENUMERATE_(Cell, icell, cell_dm.allCells()){
Arcane::Cell cell = *icell;
Arcane::DirCellNode cn(cell_dm.cellNode(cell));
Arcane::Node next_left = cn.nextLeft(); // Node to the left towards the next cell.
Arcane::Node next_right = cn.nextRight(); // Node to the right towards the next cell.
Arcane::Node prev_right = cn.previousRight(); // Node to the right towards the previous cell.
Arcane::Node prev_left = cn.previousLeft(); // Node to the left towards the previous cell.
}
Cell with directional node information.

Similarly, it is also possible to know the face in front of and behind the cell in a given direction (this also works in 3D):

using namespace Arcane;
ENUMERATE_(Cell, icell, cell_dm.allCells()){
Arcane::Cell cell = *icell;
Arcane::DirCellFace cf(cell_dm.cellFace(cell));
Arcane::Face next_left = cf.next(); // Face connected to the next cell.
Arcane::Face prev_right = cf.previous(); // Face connected to the previous cell.
}
Cell with directional face information.

To iterate over all directions of a mesh, you can loop as follows:

using namespace Arcane;
Integer nb_dir = mesh->dimension();
for( Integer idir=0; idir<nb_dir; ++idir){
CellDirectionMng cdm(cartesian_mesh->cellDirection(idir));
ENUMERATE_(Cell, icell, cdm.allCells()){
...
}
}
Int32 Integer
Type representing an integer.

It is possible to know the global number of cells in a given direction via Arcane::CellDirectionMng::globalNbCell(). Similarly, assuming that the subdomain decomposition can be represented as a grid, it is possible to know the numbering in this grid via Arcane::CellDirectionMng::subDomainOffset(). This numbering starts at 0.

It is also possible to know the number of own cells of the subdomain in a given direction via Arcane::CellDirectionMng::ownNbCell(). It is also possible to know the offset in the grid of the first own cell via Arcane::CellDirectionMng::ownCellOffset().

Warning
This information is only accessible if the mesh was generated via the specific Cartesian generator. In particular, it is not accessible if the mesh comes from a file. For more information, refer to the description of these methods.

Using Cartesian Connectivities

In 2D, it is possible to access the cells around a node and the nodes of the cell without going through directional connectivities. This is done via the Arcane::CartesianConnectivity object returned by calling Arcane::ICartesianMesh::connectivity(). For example:

CartesianConnectivity cc = cartesian_mesh->connectivity();
ENUMERATE_NODE (inode, allNodes()) {
Node n = *inode;
Cell c1 = cc.upperLeft(n); // Top-left cell
Cell c2 = cc.upperRight(n); // Top-right cell
Cell c3 = cc.lowerRight(n); // Bottom-right cell
Cell c4 = cc.lowerLeft(n); // Bottom-left cell
info(6) << " C1=" << ItemPrinter(c1) << " C2=" << ItemPrinter(c2)
<< " C3=" << ItemPrinter(c3) << " C4=" << ItemPrinter(c4);
}

And similarly for cells:

using namespace Arcane;
ENUMERATE_(Cell, icell, allCells()){
Arcane::Cell c = *icell;
Arcane::Node n1 = cc.upperLeft(c); // Node upper left
Arcane::Node n2 = cc.upperRight(c); // Node upper right
Arcane::Node n3 = cc.lowerRight(c); // Node lower right
Arcane::Node n4 = cc.lowerLeft(c); // Node lower left
}
Connectivity information of a Cartesian mesh.
Cell lowerRight(Node n) const
Cell bottom right of node n.
Cell upperLeft(Node n) const
Cell top left of node n.
Cell lowerLeft(Node n) const
Cell bottom left of node n.
Cell upperRight(Node n) const
Cell top right of node n.
virtual CartesianConnectivity connectivity()=0
Connectivity information.

These connectivities are also accessible in 3D. The nomenclature is the same as for 2D connectivities. The prefix topZ is used for the nodes above the same following the Z direction. For those below, there is no prefix, and therefore the method name is the same as in 2D. This potentially allows the use of the same code in 2D and 3D.

using namespace Arcane;
ENUMERATE_(Cell, icell, allCells()){
Arcane::Cell c = *icell;
Arcane::Node n1 = cc.upperLeft(c); // Node below in Z, upper left
Arcane::Node n2 = cc.upperRight(c); // Node below in Z, upper right
Arcane::Node n3 = cc.lowerRight(c); // Node below in Z, lower right
Arcane::Node n4 = cc.lowerLeft(c); // Node below in Z, lower left
Arcane::Node n5 = cc.topZUpperLeft(c); // Node above in Z, upper left
Arcane::Node n6 = cc.topZUpperRight(c); // Node above in Z, upper right
Arcane::Node n7 = cc.topZLowerRight(c); // Node above in Z, lower right
Arcane::Node n8 = cc.topZLowerLeft(c); // Node above in Z, lower left
}
Cell topZUpperRight(Node n) const
In 3D, cell top right of node n.
Cell topZLowerRight(Node n) const
In 3D, cell bottom right of node n.
Cell topZLowerLeft(Node n) const
In 3D, cell bottom left of node n.
Cell topZUpperLeft(Node n) const
In 3D, cell top left of node n.