14#include "arcane/cartesianmesh/internal/CartesianMeshPatch.h"
16#include "arcane/core/IMesh.h"
17#include "arcane/core/ItemPrinter.h"
19#include "arcane/cartesianmesh/ICartesianMesh.h"
20#include "arcane/cartesianmesh/CartesianConnectivity.h"
38, m_amr_patch_index(patch_index)
41 Integer nb_dir = cmesh->mesh()->dimension();
42 for (Integer i = 0; i < nb_dir; ++i) {
44 m_cell_directions[i]._internalInit(cmesh, dir, patch_index);
45 m_face_directions[i]._internalInit(cmesh, dir, patch_index);
46 m_node_directions[i]._internalInit(cmesh, dir, patch_index);
54CartesianMeshPatch(ICartesianMesh* cmesh, Integer patch_index)
55: CartesianMeshPatch(cmesh, patch_index, {})
65 for (Integer i = 0; i < 3; ++i) {
66 m_cell_directions[i]._internalDestroy();
67 m_face_directions[i]._internalDestroy();
68 m_node_directions[i]._internalDestroy();
82 return cellDirection(MD_DirX).allCells();
91 return cellDirection(MD_DirX).inPatchCells();
100 return cellDirection(MD_DirX).overlapCells();
110void CartesianMeshPatch::
111_computeNodeCellInformations2D(Cell cell0, Real3 cell0_coord, VariableNodeReal3& nodes_coord)
113 using Int8 = std::int8_t;
114 Int8 nodes_indirection_i[CellDirectionMng::MAX_NB_NODE];
115 ArrayView<Int8> nodes_indirection(CellDirectionMng::MAX_NB_NODE, nodes_indirection_i);
116 Int32 nb_node = cell0.nbNode();
118 ARCANE_FATAL(
"Number of nodes should be '4' (v={0})", nb_node);
120 Real3 cell_coord = cell0_coord;
121 bool is_2d = m_mesh->mesh()->dimension() == 2;
123 ARCANE_FATAL(
"Invalid call. This mesh is not a 2D mesh");
126 nodes_indirection.fill(-1);
127 for (Int8 i = 0; i < i8_nb_node; ++i) {
128 Node node = cell0.node(i);
129 Real3 node_coord = nodes_coord[node];
130 if (node_coord.x > cell_coord.x) {
131 if (node_coord.y > cell_coord.y)
132 nodes_indirection[CNP_NextLeft] = i;
134 nodes_indirection[CNP_NextRight] = i;
137 if (node_coord.y > cell_coord.y)
138 nodes_indirection[CNP_PreviousLeft] = i;
140 nodes_indirection[CNP_PreviousRight] = i;
143 cellDirection(MD_DirX).setNodesIndirection(nodes_indirection);
146 nodes_indirection.fill(-1);
147 for (Int8 i = 0; i < i8_nb_node; ++i) {
148 Node node = cell0.node(i);
149 Real3 node_coord = nodes_coord[node];
150 if (node_coord.y > cell_coord.y) {
151 if (node_coord.x > cell_coord.x)
152 nodes_indirection[CNP_NextRight] = i;
154 nodes_indirection[CNP_NextLeft] = i;
157 if (node_coord.x > cell_coord.x)
158 nodes_indirection[CNP_PreviousRight] = i;
160 nodes_indirection[CNP_PreviousLeft] = i;
163 cellDirection(MD_DirY).setNodesIndirection(nodes_indirection);
172void CartesianMeshPatch::
173_computeNodeCellInformations3D(Cell cell0, Real3 cell0_coord, VariableNodeReal3& nodes_coord)
175 using Int8 = std::int8_t;
176 Int8 nodes_indirection_i[CellDirectionMng::MAX_NB_NODE];
177 ArrayView<Int8> nodes_indirection(CellDirectionMng::MAX_NB_NODE, nodes_indirection_i);
178 Integer nb_node = cell0.nbNode();
180 ARCANE_FATAL(
"Number of nodes should be '8' (v={0})", nb_node);
182 Real3 cell_coord = cell0_coord;
183 bool is_3d = m_mesh->mesh()->dimension() == 3;
185 ARCANE_FATAL(
"Invalid call. This mesh is not a 3D mesh");
188 nodes_indirection.fill(-1);
189 for (Int8 i = 0; i < i8_nb_node; ++i) {
190 Node node = cell0.node(i);
191 Real3 node_coord = nodes_coord[node];
192 if (node_coord.z > cell_coord.z) {
193 if (node_coord.x > cell_coord.x) {
194 if (node_coord.y > cell_coord.y)
195 nodes_indirection[CNP_TopNextLeft] = i;
197 nodes_indirection[CNP_TopNextRight] = i;
200 if (node_coord.y > cell_coord.y)
201 nodes_indirection[CNP_TopPreviousLeft] = i;
203 nodes_indirection[CNP_TopPreviousRight] = i;
207 if (node_coord.x > cell_coord.x) {
208 if (node_coord.y > cell_coord.y)
209 nodes_indirection[CNP_NextLeft] = i;
211 nodes_indirection[CNP_NextRight] = i;
214 if (node_coord.y > cell_coord.y)
215 nodes_indirection[CNP_PreviousLeft] = i;
217 nodes_indirection[CNP_PreviousRight] = i;
221 cellDirection(MD_DirX).setNodesIndirection(nodes_indirection);
224 nodes_indirection.fill(-1);
225 for (Int8 i = 0; i < i8_nb_node; ++i) {
226 Node node = cell0.node(i);
227 Real3 node_coord = nodes_coord[node];
228 if (node_coord.z > cell_coord.z) {
229 if (node_coord.y > cell_coord.y) {
230 if (node_coord.x > cell_coord.x)
231 nodes_indirection[CNP_TopNextRight] = i;
233 nodes_indirection[CNP_TopNextLeft] = i;
236 if (node_coord.x > cell_coord.x)
237 nodes_indirection[CNP_TopPreviousRight] = i;
239 nodes_indirection[CNP_TopPreviousLeft] = i;
243 if (node_coord.y > cell_coord.y) {
244 if (node_coord.x > cell_coord.x)
245 nodes_indirection[CNP_NextRight] = i;
247 nodes_indirection[CNP_NextLeft] = i;
250 if (node_coord.x > cell_coord.x)
251 nodes_indirection[CNP_PreviousRight] = i;
253 nodes_indirection[CNP_PreviousLeft] = i;
257 cellDirection(MD_DirY).setNodesIndirection(nodes_indirection);
259 nodes_indirection.fill(-1);
260 for (Int8 i = 0; i < i8_nb_node; ++i) {
261 Node node = cell0.node(i);
262 Real3 node_coord = nodes_coord[node];
263 if (node_coord.y > cell_coord.y) {
264 if (node_coord.z > cell_coord.z) {
265 if (node_coord.x > cell_coord.x)
266 nodes_indirection[CNP_TopNextRight] = i;
268 nodes_indirection[CNP_TopNextLeft] = i;
271 if (node_coord.x > cell_coord.x)
272 nodes_indirection[CNP_TopPreviousRight] = i;
274 nodes_indirection[CNP_TopPreviousLeft] = i;
278 if (node_coord.z > cell_coord.z) {
279 if (node_coord.x > cell_coord.x)
280 nodes_indirection[CNP_NextRight] = i;
282 nodes_indirection[CNP_NextLeft] = i;
285 if (node_coord.x > cell_coord.x)
286 nodes_indirection[CNP_PreviousRight] = i;
288 nodes_indirection[CNP_PreviousLeft] = i;
292 cellDirection(MD_DirZ).setNodesIndirection(nodes_indirection);
298void CartesianMeshPatch::
299_internalComputeNodeCellInformations(Cell cell0, Real3 cell0_coord, VariableNodeReal3& nodes_coord)
301 int dim = m_mesh->mesh()->dimension();
303 _computeNodeCellInformations3D(cell0, cell0_coord, nodes_coord);
305 _computeNodeCellInformations2D(cell0, cell0_coord, nodes_coord);
307 ARCANE_THROW(NotImplementedException,
"this method is implemented only for 2D and 3D mesh (dim={0})", dim);
313void CartesianMeshPatch::
314_internalComputeNodeCellInformations()
316 int dim = m_mesh->mesh()->dimension();
317 Int8 nodes_indirection[CellDirectionMng::MAX_NB_NODE];
318 ArrayView av_nodes_indirection(CellDirectionMng::MAX_NB_NODE, nodes_indirection);
320 av_nodes_indirection.fill(-1);
321 av_nodes_indirection[CNP_NextLeft] = 2;
322 av_nodes_indirection[CNP_NextRight] = 1;
323 av_nodes_indirection[CNP_PreviousRight] = 0;
324 av_nodes_indirection[CNP_PreviousLeft] = 3;
326 av_nodes_indirection[CNP_TopNextLeft] = 6;
327 av_nodes_indirection[CNP_TopNextRight] = 5;
328 av_nodes_indirection[CNP_TopPreviousRight] = 4;
329 av_nodes_indirection[CNP_TopPreviousLeft] = 7;
331 cellDirection(MD_DirX).setNodesIndirection(av_nodes_indirection);
334 av_nodes_indirection.fill(-1);
335 av_nodes_indirection[CNP_NextLeft] = 3;
336 av_nodes_indirection[CNP_NextRight] = 2;
337 av_nodes_indirection[CNP_PreviousRight] = 1;
338 av_nodes_indirection[CNP_PreviousLeft] = 0;
340 av_nodes_indirection[CNP_TopNextLeft] = 7;
341 av_nodes_indirection[CNP_TopNextRight] = 6;
342 av_nodes_indirection[CNP_TopPreviousRight] = 5;
343 av_nodes_indirection[CNP_TopPreviousLeft] = 4;
345 cellDirection(MD_DirY).setNodesIndirection(av_nodes_indirection);
349 av_nodes_indirection.fill(-1);
350 av_nodes_indirection[CNP_NextLeft] = 4;
351 av_nodes_indirection[CNP_NextRight] = 5;
352 av_nodes_indirection[CNP_PreviousRight] = 1;
353 av_nodes_indirection[CNP_PreviousLeft] = 0;
354 av_nodes_indirection[CNP_TopNextLeft] = 7;
355 av_nodes_indirection[CNP_TopNextRight] = 6;
356 av_nodes_indirection[CNP_TopPreviousRight] = 2;
357 av_nodes_indirection[CNP_TopPreviousLeft] = 3;
358 cellDirection(MD_DirZ).setNodesIndirection(av_nodes_indirection);
365void CartesianMeshPatch::
369 Integer nb_dir = m_mesh->mesh()->dimension();
370 for (Integer i = 0; i < nb_dir; ++i) {
371 CellDirectionMng dm = m_cell_directions[i];
372 FaceDirectionMng face_dm = m_face_directions[i];
373 std::set<Int32> cells_ids;
375 info(4) <<
"PATCH i=" << m_amr_patch_index <<
" nb_cell=" << dm_cells.
size();
377 cells_ids.insert(icell.itemLocalId());
379 Int64 nb_null_face_cell = 0;
382 DirCell cc(dm.cell(cell));
383 Cell next_cell = cc.next();
384 if (!next_cell.null()) {
385 if (cells_ids.find(next_cell.localId()) == cells_ids.end())
386 ARCANE_FATAL(
"Bad next cell dir={0} cell={1} next={2}", i, ItemPrinter(cell), ItemPrinter(next_cell));
388 Cell previous_cell = cc.previous();
389 if (!previous_cell.null()) {
390 if (cells_ids.find(previous_cell.localId()) == cells_ids.end())
391 ARCANE_FATAL(
"Bad previous cell dir={0} cell={1} previous={2}", i, ItemPrinter(cell), ItemPrinter(previous_cell));
395 DirCellFace cell_face(dm.cellFace(cell));
396 Face prev_face = cell_face.previous();
397 Face next_face = cell_face.next();
398 DirFace dir_face_prev(face_dm[prev_face]);
399 Cell face_cell_prev = dir_face_prev.previousCell();
400 if (face_cell_prev.null())
402 DirFace dir_face_next(face_dm[next_face]);
403 Cell face_cell_next = dir_face_next.nextCell();
404 if (face_cell_next.null())
407 info(4) <<
"PATCH i=" << m_amr_patch_index <<
" nb_null_face_cell=" << nb_null_face_cell;
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Class allowing the definition of a patch position in the Cartesian mesh.
Interface of a Cartesian mesh.
Integer size() const
Number of elements in the group.
ItemGroupT< Cell > CellGroup
Group of cells.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int8_t Int8
Signed integer type of 8 bits.
Int32 Integer
Type representing an integer.
eMeshDirection
Direction type for a structured mesh.
@ Cell
The mesh is AMR by cell.