14#include "arcane/cartesianmesh/FaceDirectionMng.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/Real3.h"
18#include "arcane/utils/PlatformUtils.h"
20#include "arcane/core/IItemFamily.h"
21#include "arcane/core/ItemGroup.h"
22#include "arcane/core/IMesh.h"
23#include "arcane/core/VariableTypes.h"
25#include "arcane/cartesianmesh/ICartesianMesh.h"
26#include "arcane/cartesianmesh/CellDirectionMng.h"
27#include "arcane/cartesianmesh/internal/ICartesianMeshInternal.h"
71void FaceDirectionMng::
78 m_p->m_cartesian_mesh = cm;
79 m_p->m_patch_index = patch_index;
85void FaceDirectionMng::
95void FaceDirectionMng::
96_internalResizeInfos(
Int32 new_size)
98 m_p->m_infos.
resize(new_size);
99 m_infos_view = m_p->m_infos.view();
105void FaceDirectionMng::
109 IMesh* mesh = m_p->m_cartesian_mesh->mesh();
110 IItemFamily* face_family = mesh->faceFamily();
111 IItemFamily* cell_family = mesh->cellFamily();
112 int dir = (int)m_direction;
113 String base_group_name = String(
"Direction") + dir;
114 if (m_p->m_patch_index >= 0)
115 base_group_name = base_group_name + String(
"AMRPatch") + m_p->m_patch_index;
121 UniqueArray<Int32> faces_lid;
123 CellGroup all_cells = cell_dm.allCells();
124 faces_lid.reserve(all_cells.size());
126 UniqueArray<bool> done_faces(face_family->maxLocalId(),
false);
128 DirCellFace dcf(cell_dm.cellFace(*icell));
129 Face next_face = dcf.next();
130 Face prev_face = dcf.previous();
133 Int32 prev_lid = prev_face.localId();
134 if (!done_faces[prev_lid]) {
135 faces_lid.add(prev_lid);
136 done_faces[prev_lid] =
true;
138 Int32 next_lid = next_face.localId();
139 if (!done_faces[next_lid]) {
140 faces_lid.add(next_lid);
141 done_faces[next_lid] =
true;
147 all_faces.
setItems(faces_lid,
true);
149 UniqueArray<Int32> inner_lids;
150 UniqueArray<Int32> outer_lids;
152 Int32 lid = iitem.itemLocalId();
155 if (
face.nbCell() == 1)
160 m_p->m_inner_all_items = face_family->createGroup(String(
"AllInner") + base_group_name, inner_lids,
true);
161 m_p->m_outer_all_items = face_family->createGroup(String(
"AllOuter") + base_group_name, outer_lids,
true);
162 m_p->m_all_items = all_faces;
163 m_cells = CellInfoListView(cell_family);
165 _computeCellInfos(cell_dm, cells_center, faces_center);
171void FaceDirectionMng::
174 IMesh* mesh = m_p->m_cartesian_mesh->mesh();
175 IItemFamily* face_family = mesh->faceFamily();
176 IItemFamily* cell_family = mesh->cellFamily();
177 int dir = (int)m_direction;
178 String base_group_name = String(
"Direction") + dir;
179 if (m_p->m_patch_index >= 0)
180 base_group_name = base_group_name + String(
"AMRPatch") + m_p->m_patch_index;
186 UniqueArray<Int32> faces_lid;
188 CellGroup all_cells = cell_dm.allCells();
189 faces_lid.reserve(all_cells.size());
191 UniqueArray<bool> done_faces(face_family->maxLocalId(),
false);
193 DirCellFace dcf(cell_dm.cellFace(*icell));
194 Face next_face = dcf.next();
195 Face prev_face = dcf.previous();
198 Int32 prev_lid = prev_face.localId();
199 if (!done_faces[prev_lid]) {
200 faces_lid.add(prev_lid);
201 done_faces[prev_lid] =
true;
203 Int32 next_lid = next_face.localId();
204 if (!done_faces[next_lid]) {
205 faces_lid.add(next_lid);
206 done_faces[next_lid] =
true;
212 all_faces.
setItems(faces_lid,
true);
214 UniqueArray<Int32> inner_cells_lid;
215 UniqueArray<Int32> outer_cells_lid;
216 cell_dm.innerCells().view().fillLocalIds(inner_cells_lid);
217 cell_dm.outerCells().view().fillLocalIds(outer_cells_lid);
219 UniqueArray<Int32> inner_lids;
220 UniqueArray<Int32> outer_lids;
221 UniqueArray<Int32> inpatch_lids;
222 UniqueArray<Int32> overlap_lids;
224 Int32 lid = iface.itemLocalId();
226 if (
face.nbCell() == 1) {
227 if (inner_cells_lid.contains(
face.cell(0).localId())) {
229 inpatch_lids.add(lid);
231 else if (outer_cells_lid.contains(
face.cell(0).localId())) {
233 inpatch_lids.add(lid);
236 overlap_lids.add(lid);
240 bool c0_inner_cell = inner_cells_lid.contains(
face.cell(0).localId());
241 bool c1_inner_cell = inner_cells_lid.contains(
face.cell(1).localId());
242 if (c0_inner_cell || c1_inner_cell) {
244 inpatch_lids.add(lid);
247 bool c0_outer_cell = outer_cells_lid.contains(
face.cell(0).localId());
248 bool c1_outer_cell = outer_cells_lid.contains(
face.cell(1).localId());
249 if (c0_outer_cell || c1_outer_cell) {
251 inpatch_lids.add(lid);
254 overlap_lids.add(lid);
259 m_p->m_inner_all_items = face_family->createGroup(String(
"AllInner") + base_group_name, inner_lids,
true);
260 m_p->m_outer_all_items = face_family->createGroup(String(
"AllOuter") + base_group_name, outer_lids,
true);
261 m_p->m_inpatch_all_items = face_family->createGroup(String(
"AllInPatch") + base_group_name, inpatch_lids,
true);
262 m_p->m_overlap_all_items = face_family->createGroup(String(
"AllOverlap") + base_group_name, overlap_lids,
true);
263 m_p->m_all_items = all_faces;
264 m_cells = CellInfoListView(cell_family);
272bool FaceDirectionMng::
273_hasFace(
Cell cell,
Int32 face_local_id)
const
275 for (FaceLocalId iface_lid : cell.faceIds()) {
276 if (iface_lid == face_local_id)
290void FaceDirectionMng::
299 UniqueArray<bool> is_patch_cell(cell_dm.allCells().itemFamily()->maxLocalId(),
false);
301 is_patch_cell[icell.itemLocalId()] =
true;
306 Int32 face_lid = iface.itemLocalId();
307 Real3 face_coord = faces_center[iface];
312 if (!front_cell.null())
313 if (!is_patch_cell[front_cell.localId()])
315 if (!back_cell.null())
316 if (!is_patch_cell[back_cell.localId()])
319 bool is_inverse =
false;
320 if (!front_cell.null()) {
321 Real3 front_coord = cells_center[front_cell];
323 if (front_coord.x < face_coord.x)
327 if (front_coord.y < face_coord.y)
331 if (front_coord.z < face_coord.z)
336 Real3 back_coord = cells_center[back_cell];
338 if (back_coord.x > face_coord.x)
342 if (back_coord.y > face_coord.y)
346 if (back_coord.z > face_coord.z)
353 if (!back_cell.null() && !front_cell.null()) {
354 Int32 back_level = back_cell.level();
355 Int32 front_level = front_cell.level();
356 if (back_level != front_level) {
360 if (!_hasFace(back_cell, face_lid))
362 if (!_hasFace(front_cell, face_lid))
367 m_infos_view[face_lid] = ItemDirectionInfo(back_cell, front_cell);
369 m_infos_view[face_lid] = ItemDirectionInfo(front_cell, back_cell);
376void FaceDirectionMng::
377_computeCellInfos()
const
379 Ref<ICartesianMeshNumberingMngInternal> numbering = m_p->m_cartesian_mesh->_internalApi()->cartesianMeshNumberingMngInternal();
393 bool is_inverse =
false;
394 if (!front_cell.null() && !back_cell.null()) {
399 Int32 front_cell_level = front_cell.level();
400 Int32 back_cell_level = back_cell.level();
401 if (front_cell_level != back_cell_level) {
402 Int32 face_level = numbering->faceLevel(
face.uniqueId());
403 if (front_cell_level != face_level) {
411 if (back_cell.uniqueId() > front_cell.uniqueId()) {
417 if (back_cell.null()) {
419 ArrayView av_uids(numbering->nbFaceByCell(), uids);
420 numbering->cellFaceUniqueIds(front_cell, av_uids);
421 if (m_p->m_cartesian_mesh->mesh()->dimension() == 2) {
423 if (
face.uniqueId() == av_uids[1])
425 else if (
face.uniqueId() != av_uids[3])
426 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[3],
face.uniqueId());
429 if (
face.uniqueId() == av_uids[2])
431 else if (
face.uniqueId() != av_uids[0])
432 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[0],
face.uniqueId());
435 else if (m_p->m_cartesian_mesh->mesh()->dimension() == 3) {
437 if (
face.uniqueId() == av_uids[4])
439 else if (
face.uniqueId() != av_uids[1])
440 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[1],
face.uniqueId());
443 if (
face.uniqueId() == av_uids[5])
445 else if (
face.uniqueId() != av_uids[2])
446 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[2],
face.uniqueId());
449 if (
face.uniqueId() == av_uids[3])
451 else if (
face.uniqueId() != av_uids[0])
452 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[0],
face.uniqueId());
456 else if (front_cell.null()) {
458 ArrayView av_uids(numbering->nbFaceByCell(), uids);
459 numbering->cellFaceUniqueIds(back_cell, av_uids);
460 if (m_p->m_cartesian_mesh->mesh()->dimension() == 2) {
462 if (
face.uniqueId() == av_uids[3])
464 else if (
face.uniqueId() != av_uids[1])
465 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[1],
face.uniqueId());
468 if (
face.uniqueId() == av_uids[0])
470 else if (
face.uniqueId() != av_uids[2])
471 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[2],
face.uniqueId());
474 else if (m_p->m_cartesian_mesh->mesh()->dimension() == 3) {
476 if (
face.uniqueId() == av_uids[1])
478 else if (
face.uniqueId() != av_uids[4])
479 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[4],
face.uniqueId());
482 if (
face.uniqueId() == av_uids[2])
484 else if (
face.uniqueId() != av_uids[5])
485 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[5],
face.uniqueId());
488 if (
face.uniqueId() == av_uids[0])
490 else if (
face.uniqueId() != av_uids[3])
491 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[3],
face.uniqueId());
502 m_infos_view[iface.itemLocalId()] = ItemDirectionInfo(back_cell, front_cell);
504 m_infos_view[iface.itemLocalId()] = ItemDirectionInfo(front_cell, back_cell);
514 return m_p->m_all_items;
523 return m_p->m_overlap_all_items;
532 return m_p->m_inpatch_all_items;
541 return m_p->m_inner_all_items;
550 return m_p->m_outer_all_items;
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Info about the cells in a specific X, Y, or Z direction of a structured mesh.
FaceGroup inPatchFaces() const
Group of all faces within the patch in the direction.
DirFace face(Face f) const
Direction face corresponding to face f.
FaceGroup overlapFaces() const
Group of all overlap faces in the direction.
FaceDirectionMng()
Creates an empty instance.
FaceGroup innerFaces() const
Group of all internal faces in the direction.
FaceGroup outerFaces() const
Group of all external faces in the direction.
FaceGroup allFaces() const
Group of all faces in the direction.
Interface of a Cartesian mesh.
void setItems(Int32ConstArrayView items_local_id)
Sets the entities of the group.
1D data vector with value semantics (STL style).
void resize(Int64 s)
Changes the number of elements in the array to s.
ItemGroupT< Cell > CellGroup
Group of cells.
ItemGroupT< Face > FaceGroup
Group of faces.
MeshVariableScalarRefT< Cell, Real3 > VariableCellReal3
Coordinate type quantity at cell center.
MeshVariableScalarRefT< Face, Real3 > VariableFaceReal3
Coordinate type quantity at face.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
eMeshDirection
Direction type for a structured mesh.
@ MD_DirInvalid
Invalid or uninitialized direction.
@ Cell
The mesh is AMR by cell.
std::int32_t Int32
Signed integer type of 32 bits.