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"
73void FaceDirectionMng::
80 m_p->m_cartesian_mesh = cm;
81 m_p->m_patch_index = patch_index;
87void FaceDirectionMng::
97void FaceDirectionMng::
98_internalResizeInfos(
Int32 new_size)
100 m_p->m_infos.
resize(new_size);
101 m_infos_view = m_p->m_infos.view();
107void FaceDirectionMng::
111 IMesh* mesh = m_p->m_cartesian_mesh->mesh();
112 IItemFamily* face_family = mesh->faceFamily();
113 IItemFamily* cell_family = mesh->cellFamily();
114 int dir = (int)m_direction;
115 String base_group_name = String(
"Direction") + dir;
116 if (m_p->m_patch_index >= 0)
117 base_group_name = base_group_name + String(
"AMRPatch") + m_p->m_patch_index;
123 UniqueArray<Int32> faces_lid;
125 CellGroup all_cells = cell_dm.allCells();
126 faces_lid.reserve(all_cells.size());
128 std::set<Int32> done_faces;
130 DirCellFace dcf(cell_dm.cellFace(*icell));
131 Face next_face = dcf.next();
132 Face prev_face = dcf.previous();
135 Int32 prev_lid = prev_face.localId();
136 if (done_faces.find(prev_lid) == done_faces.end()) {
137 faces_lid.add(prev_lid);
138 done_faces.insert(prev_lid);
140 Int32 next_lid = next_face.localId();
141 if (done_faces.find(next_lid) == done_faces.end()) {
142 faces_lid.add(next_lid);
143 done_faces.insert(next_lid);
149 all_faces.
setItems(faces_lid,
true);
151 UniqueArray<Int32> inner_lids;
152 UniqueArray<Int32> outer_lids;
154 Int32 lid = iitem.itemLocalId();
157 if (
face.nbCell() == 1)
162 m_p->m_inner_all_items = face_family->createGroup(String(
"AllInner") + base_group_name, inner_lids,
true);
163 m_p->m_outer_all_items = face_family->createGroup(String(
"AllOuter") + base_group_name, outer_lids,
true);
164 m_p->m_all_items = all_faces;
165 m_cells = CellInfoListView(cell_family);
167 _computeCellInfos(cell_dm, cells_center, faces_center);
173void FaceDirectionMng::
176 IMesh* mesh = m_p->m_cartesian_mesh->mesh();
177 IItemFamily* face_family = mesh->faceFamily();
178 IItemFamily* cell_family = mesh->cellFamily();
179 int dir = (int)m_direction;
180 String base_group_name = String(
"Direction") + dir;
181 if (m_p->m_patch_index >= 0)
182 base_group_name = base_group_name + String(
"AMRPatch") + m_p->m_patch_index;
188 UniqueArray<Int32> faces_lid;
190 CellGroup all_cells = cell_dm.allCells();
191 faces_lid.reserve(all_cells.size());
193 std::set<Int32> done_faces;
195 DirCellFace dcf(cell_dm.cellFace(*icell));
196 Face next_face = dcf.next();
197 Face prev_face = dcf.previous();
200 Int32 prev_lid = prev_face.localId();
201 if (done_faces.find(prev_lid) == done_faces.end()) {
202 faces_lid.add(prev_lid);
203 done_faces.insert(prev_lid);
205 Int32 next_lid = next_face.localId();
206 if (done_faces.find(next_lid) == done_faces.end()) {
207 faces_lid.add(next_lid);
208 done_faces.insert(next_lid);
214 all_faces.
setItems(faces_lid,
true);
216 UniqueArray<Int32> inner_cells_lid;
217 UniqueArray<Int32> outer_cells_lid;
218 cell_dm.innerCells().view().fillLocalIds(inner_cells_lid);
219 cell_dm.outerCells().view().fillLocalIds(outer_cells_lid);
221 UniqueArray<Int32> inner_lids;
222 UniqueArray<Int32> outer_lids;
223 UniqueArray<Int32> inpatch_lids;
224 UniqueArray<Int32> overlap_lids;
226 Int32 lid = iface.itemLocalId();
228 if (
face.nbCell() == 1) {
229 if (inner_cells_lid.contains(
face.cell(0).localId())) {
231 inpatch_lids.add(lid);
233 else if (outer_cells_lid.contains(
face.cell(0).localId())) {
235 inpatch_lids.add(lid);
238 overlap_lids.add(lid);
242 bool c0_inner_cell = inner_cells_lid.contains(
face.cell(0).localId());
243 bool c1_inner_cell = inner_cells_lid.contains(
face.cell(1).localId());
244 if (c0_inner_cell || c1_inner_cell) {
246 inpatch_lids.add(lid);
249 bool c0_outer_cell = outer_cells_lid.contains(
face.cell(0).localId());
250 bool c1_outer_cell = outer_cells_lid.contains(
face.cell(1).localId());
251 if (c0_outer_cell || c1_outer_cell) {
253 inpatch_lids.add(lid);
256 overlap_lids.add(lid);
261 m_p->m_inner_all_items = face_family->createGroup(String(
"AllInner") + base_group_name, inner_lids,
true);
262 m_p->m_outer_all_items = face_family->createGroup(String(
"AllOuter") + base_group_name, outer_lids,
true);
263 m_p->m_inpatch_all_items = face_family->createGroup(String(
"AllInPatch") + base_group_name, inpatch_lids,
true);
264 m_p->m_overlap_all_items = face_family->createGroup(String(
"AllOverlap") + base_group_name, overlap_lids,
true);
265 m_p->m_all_items = all_faces;
266 m_cells = CellInfoListView(cell_family);
274bool FaceDirectionMng::
275_hasFace(
Cell cell,
Int32 face_local_id)
const
277 for (FaceLocalId iface_lid : cell.faceIds()) {
278 if (iface_lid == face_local_id)
292void FaceDirectionMng::
301 std::set<Int32> patch_cells_set;
303 patch_cells_set.insert(icell.itemLocalId());
308 Int32 face_lid = iface.itemLocalId();
309 Real3 face_coord = faces_center[iface];
314 if (!front_cell.null())
315 if (patch_cells_set.find(front_cell.localId()) == patch_cells_set.end())
317 if (!back_cell.null())
318 if (patch_cells_set.find(back_cell.localId()) == patch_cells_set.end())
321 bool is_inverse =
false;
322 if (!front_cell.null()) {
323 Real3 front_coord = cells_center[front_cell];
325 if (front_coord.x < face_coord.x)
329 if (front_coord.y < face_coord.y)
333 if (front_coord.z < face_coord.z)
338 Real3 back_coord = cells_center[back_cell];
340 if (back_coord.x > face_coord.x)
344 if (back_coord.y > face_coord.y)
348 if (back_coord.z > face_coord.z)
355 if (!back_cell.null() && !front_cell.null()) {
356 Int32 back_level = back_cell.level();
357 Int32 front_level = front_cell.level();
358 if (back_level != front_level) {
362 if (!_hasFace(back_cell, face_lid))
364 if (!_hasFace(front_cell, face_lid))
369 m_infos_view[face_lid] = ItemDirectionInfo(back_cell, front_cell);
371 m_infos_view[face_lid] = ItemDirectionInfo(front_cell, back_cell);
378void FaceDirectionMng::
379_computeCellInfos()
const
381 Ref<ICartesianMeshNumberingMngInternal> numbering = m_p->m_cartesian_mesh->_internalApi()->cartesianMeshNumberingMngInternal();
395 bool is_inverse =
false;
396 if (!front_cell.null() && !back_cell.null()) {
401 Int32 front_cell_level = front_cell.level();
402 Int32 back_cell_level = back_cell.level();
403 if (front_cell_level != back_cell_level) {
404 Int32 face_level = numbering->faceLevel(
face.uniqueId());
405 if (front_cell_level != face_level) {
413 if (back_cell.uniqueId() > front_cell.uniqueId()) {
419 if (back_cell.null()) {
421 ArrayView av_uids(numbering->nbFaceByCell(), uids);
422 numbering->cellFaceUniqueIds(front_cell, av_uids);
423 if (m_p->m_cartesian_mesh->mesh()->dimension() == 2) {
425 if (
face.uniqueId() == av_uids[1])
427 else if (
face.uniqueId() != av_uids[3])
428 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[3],
face.uniqueId());
431 if (
face.uniqueId() == av_uids[2])
433 else if (
face.uniqueId() != av_uids[0])
434 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[0],
face.uniqueId());
437 else if (m_p->m_cartesian_mesh->mesh()->dimension() == 3) {
439 if (
face.uniqueId() == av_uids[4])
441 else if (
face.uniqueId() != av_uids[1])
442 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[1],
face.uniqueId());
445 if (
face.uniqueId() == av_uids[5])
447 else if (
face.uniqueId() != av_uids[2])
448 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[2],
face.uniqueId());
451 if (
face.uniqueId() == av_uids[3])
453 else if (
face.uniqueId() != av_uids[0])
454 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[0],
face.uniqueId());
458 else if (front_cell.null()) {
460 ArrayView av_uids(numbering->nbFaceByCell(), uids);
461 numbering->cellFaceUniqueIds(back_cell, av_uids);
462 if (m_p->m_cartesian_mesh->mesh()->dimension() == 2) {
464 if (
face.uniqueId() == av_uids[3])
466 else if (
face.uniqueId() != av_uids[1])
467 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[1],
face.uniqueId());
470 if (
face.uniqueId() == av_uids[0])
472 else if (
face.uniqueId() != av_uids[2])
473 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[2],
face.uniqueId());
476 else if (m_p->m_cartesian_mesh->mesh()->dimension() == 3) {
478 if (
face.uniqueId() == av_uids[1])
480 else if (
face.uniqueId() != av_uids[4])
481 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[4],
face.uniqueId());
484 if (
face.uniqueId() == av_uids[2])
486 else if (
face.uniqueId() != av_uids[5])
487 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[5],
face.uniqueId());
490 if (
face.uniqueId() == av_uids[0])
492 else if (
face.uniqueId() != av_uids[3])
493 ARCANE_FATAL(
"Bad connectivity, did you call computeDirection() ? -- Expected : {0} -- Found : {1}", av_uids[3],
face.uniqueId());
504 m_infos_view[iface.itemLocalId()] = ItemDirectionInfo(back_cell, front_cell);
506 m_infos_view[iface.itemLocalId()] = ItemDirectionInfo(front_cell, back_cell);
516 return m_p->m_all_items;
525 return m_p->m_overlap_all_items;
534 return m_p->m_inpatch_all_items;
543 return m_p->m_inner_all_items;
552 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.