Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Examples of using Cartesian meshes

Example of using IGridMeshPartitioner

// file_name is the name of the unstructured mesh file
Arcane::String file_name = options()->unstructuredMeshFile();
info() << "UnstructuredMeshFileName=" << file_name;
Arcane::ISubDomain* sd = subDomain();
Arcane::ICartesianMesh* cartesian_mesh = m_cartesian_mesh;
Arcane::IMesh* current_mesh = cartesian_mesh->mesh();
Arcane::IParallelMng* pm = current_mesh->parallelMng();
Arcane::MeshReaderMng reader_mng(sd);
Arcane::IMesh* new_mesh = reader_mng.readMesh("UnstructuredMesh2", file_name, pm);
info() << "MESH=" << new_mesh;
// Creation of the partitioning service
auto partitioner_ref = sbuilder.createReference("SimpleGridMeshPartitioner", new_mesh);
Arcane::IGridMeshPartitioner* partitioner = partitioner_ref.get();
// Positions the coordinates of our subdomain in the grid
Int32 sd_x = cartesian_mesh->cellDirection(MD_DirX).subDomainOffset();
Int32 sd_y = cartesian_mesh->cellDirection(MD_DirY).subDomainOffset();
Int32 sd_z = cartesian_mesh->cellDirection(MD_DirZ).subDomainOffset();
partitioner->setPartIndex(sd_x, sd_y, sd_z);
// Positions the bounding box of our subdomain.
// To do this, iterate only over our nodes and take the min and max coordinates
Real min_value = -max_value;
Arcane::Real3 min_box(max_value, max_value, max_value);
Arcane::Real3 max_box(min_value, min_value, min_value);
VariableNodeReal3& nodes_coord = current_mesh->nodesCoordinates();
ENUMERATE_ (Cell, icell, current_mesh->ownCells()) {
Cell cell{ *icell };
for (Node node : cell.nodes()) {
Real3 coord = nodes_coord[node];
min_box = math::min(min_box, coord);
max_box = math::max(max_box, coord);
}
}
partitioner->setBoundingBox(min_box, max_box);
// Applies the partitioning
partitioner->applyMeshPartitioning(new_mesh);