14#include "arcane/cartesianmesh/NodeDirectionMng.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/Real3.h"
20#include "arcane/utils/PlatformUtils.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/ItemGroup.h"
24#include "arcane/core/IMesh.h"
25#include "arcane/core/VariableTypes.h"
26#include "arcane/core/UnstructuredMeshConnectivity.h"
28#include "arcane/cartesianmesh/ICartesianMesh.h"
29#include "arcane/cartesianmesh/CellDirectionMng.h"
30#include "arcane/cartesianmesh/internal/ICartesianMeshInternal.h"
75void NodeDirectionMng::
83 m_p->m_cartesian_mesh = cm;
84 m_p->m_patch_index = patch_index;
90void NodeDirectionMng::
103 m_p->m_infos.
resize(new_size);
104 m_infos_view = m_p->m_infos.view();
110void NodeDirectionMng::
115 m_infos_view.
fill(NodeDirectionMng::ItemDirectionInfo());
125 NodeLocalId node_next_left = cn.nextLeftId();
126 NodeLocalId node_next_right = cn.nextRightId();
128 NodeLocalId node_previous_left = cn.previousLeftId();
129 NodeLocalId node_previous_right = cn.previousRightId();
131 m_infos_view[node_previous_left].m_next_lid = node_next_left;
132 m_infos_view[node_next_left].m_previous_lid = node_previous_left;
134 m_infos_view[node_previous_right].m_next_lid = node_next_right;
135 m_infos_view[node_next_right].m_previous_lid = node_previous_right;
138 NodeLocalId top_node_next_left = cn.topNextLeftId();
139 NodeLocalId top_node_next_right = cn.topNextRightId();
141 NodeLocalId top_node_previous_left = cn.topPreviousLeftId();
142 NodeLocalId top_node_previous_right = cn.topPreviousRightId();
144 m_infos_view[top_node_previous_left].m_next_lid = top_node_next_left;
145 m_infos_view[top_node_next_left].m_previous_lid = top_node_previous_left;
147 m_infos_view[top_node_previous_right].m_next_lid = top_node_next_right;
148 m_infos_view[top_node_next_right].m_previous_lid = top_node_previous_right;
156 Int32 lid = iitem.itemLocalId();
157 Int32 i1 = m_infos_view[lid].m_next_lid;
158 Int32 i2 = m_infos_view[lid].m_previous_lid;
159 if (i1 == NULL_ITEM_LOCAL_ID || i2 == NULL_ITEM_LOCAL_ID)
164 int dir = (int)m_direction;
165 String base_group_name = String(
"Direction")+dir;
166 if (m_p->m_patch_index>=0)
167 base_group_name = base_group_name + String(
"AMRPatch")+m_p->m_patch_index;
168 m_p->m_inner_all_items = family->
createGroup(String(
"AllInner")+base_group_name,inner_lids,
true);
169 m_p->m_outer_all_items = family->createGroup(String(
"AllOuter")+base_group_name,outer_lids,
true);
170 m_p->m_all_items = all_nodes;
173 _computeNodeCellInfos(cell_dm,cells_center);
176 UnstructuredMeshConnectivityView mesh_connectivity;
177 mesh_connectivity.setMesh(m_p->m_cartesian_mesh->mesh());
178 m_node_cell_view = mesh_connectivity.nodeCell();
185void NodeDirectionMng::
188 m_infos_view.fill(ItemDirectionInfo());
190 Integer mesh_dim = m_p->m_cartesian_mesh->mesh()->dimension();
196 DirCellNode cn(cell_dm.cellNode(cell));
198 NodeLocalId node_next_left = cn.nextLeftId();
199 NodeLocalId node_next_right = cn.nextRightId();
201 NodeLocalId node_previous_left = cn.previousLeftId();
202 NodeLocalId node_previous_right = cn.previousRightId();
204 m_infos_view[node_previous_left].m_next_lid = node_next_left;
205 m_infos_view[node_next_left].m_previous_lid = node_previous_left;
207 m_infos_view[node_previous_right].m_next_lid = node_next_right;
208 m_infos_view[node_next_right].m_previous_lid = node_previous_right;
211 NodeLocalId top_node_next_left = cn.topNextLeftId();
212 NodeLocalId top_node_next_right = cn.topNextRightId();
214 NodeLocalId top_node_previous_left = cn.topPreviousLeftId();
215 NodeLocalId top_node_previous_right = cn.topPreviousRightId();
217 m_infos_view[top_node_previous_left].m_next_lid = top_node_next_left;
218 m_infos_view[top_node_next_left].m_previous_lid = top_node_previous_left;
220 m_infos_view[top_node_previous_right].m_next_lid = top_node_next_right;
221 m_infos_view[top_node_next_right].m_previous_lid = top_node_previous_right;
225 UniqueArray<Int32> inner_cells_lid;
226 UniqueArray<Int32> outer_cells_lid;
227 cell_dm.innerCells().view().fillLocalIds(inner_cells_lid);
228 cell_dm.outerCells().view().fillLocalIds(outer_cells_lid);
230 UniqueArray<Int32> inner_lids;
231 UniqueArray<Int32> outer_lids;
234 IItemFamily* family = all_nodes.itemFamily();
236 Int32 lid = inode.itemLocalId();
239 for (
Cell cell : inode->cells()) {
240 if (inner_cells_lid.contains(cell.localId())) {
243 else if (outer_cells_lid.contains(cell.localId())) {
247 if (nb_inner_cells + nb_outer_cells == inode->nbCell()) {
250 else if (nb_outer_cells != 0) {
261 int dir = (int)m_direction;
262 String base_group_name = String(
"Direction") + dir;
263 if (m_p->m_patch_index >= 0)
264 base_group_name = base_group_name + String(
"AMRPatch") + m_p->m_patch_index;
265 m_p->m_inner_all_items = family->createGroup(String(
"AllInner") + base_group_name, inner_lids,
true);
266 m_p->m_outer_all_items = family->createGroup(String(
"AllOuter") + base_group_name, outer_lids,
true);
269 m_p->m_inpatch_all_items = cell_dm.inPatchCells().nodeGroup();
270 m_p->m_overlap_all_items = cell_dm.overlapCells().nodeGroup();
271 m_p->m_all_items = all_nodes;
274 _computeNodeCellInfos();
277 UnstructuredMeshConnectivityView mesh_connectivity;
278 mesh_connectivity.setMesh(m_p->m_cartesian_mesh->mesh());
279 m_node_cell_view = mesh_connectivity.nodeCell();
290void NodeDirectionMng::
294 UniqueArray<bool> is_in_patch(
allNodes().itemFamily()->maxLocalId(),
false);
296 is_in_patch[inode.itemLocalId()] =
true;
299 for( ItemDirectionInfo& idi : m_infos_view ){
301 Int32 next_lid = idi.m_next_lid;
302 if (next_lid != NULL_ITEM_LOCAL_ID && !is_in_patch[next_lid])
303 idi.m_next_lid = NodeLocalId{};
306 Int32 prev_lid = idi.m_previous_lid;
307 if (prev_lid != NULL_ITEM_LOCAL_ID && !is_in_patch[prev_lid])
308 idi.m_previous_lid = NodeLocalId{};
319void NodeDirectionMng::
323 IndexType indexes_ptr[8];
324 ArrayView<IndexType> indexes(8,indexes_ptr);
327 NodeGroup dm_all_nodes = node_dm.allNodes();
329 IMesh* mesh = m_p->m_cartesian_mesh->
mesh();
332 if (mesh_dim!=2 && mesh_dim!=3)
333 ARCANE_FATAL(
"Invalid mesh dimension '{0}'. Valid dimensions are 2 or 3",mesh_dim);
337 UniqueArray<bool> is_inside_cell(mesh->cellFamily()->maxLocalId(),
false);
339 is_inside_cell[icell.itemLocalId()] =
true;
345 Real3 node_pos = nodes_coord[
node];
346 indexes.fill(DirNode::NULL_CELL);
347 for(
Integer i=0; i<nb_cell; ++i ){
348 const IndexType bi = (IndexType)i;
350 if (!is_inside_cell[cell.localId()])
353 Real3 center = cells_center[cell];
354 Real3 wanted_cell_pos;
355 Real3 wanted_node_pos;
357 wanted_cell_pos = center;
358 wanted_node_pos = node_pos;
360 wanted_cell_pos = Real3(center.y, -center.x, center.z);
361 wanted_node_pos = Real3(node_pos.y, -node_pos.x, node_pos.z);
364 wanted_cell_pos = Real3(center.z, -center.y, center.x);
365 wanted_node_pos = Real3(node_pos.z, -node_pos.y, node_pos.x);
367 bool is_top = ((wanted_cell_pos.z > wanted_node_pos.z) && mesh_dim==3);
369 if (wanted_cell_pos.x > wanted_node_pos.x ){
370 if (wanted_cell_pos.y > wanted_node_pos.y )
371 indexes_ptr[CNP_NextLeft] = bi;
373 indexes_ptr[CNP_NextRight] = bi;
376 if (wanted_cell_pos.y > wanted_node_pos.y )
377 indexes_ptr[CNP_PreviousLeft] = bi;
379 indexes_ptr[CNP_PreviousRight] = bi;
383 if (wanted_cell_pos.x > wanted_node_pos.x ){
384 if (wanted_cell_pos.y > wanted_node_pos.y )
385 indexes_ptr[CNP_TopNextLeft] = bi;
387 indexes_ptr[CNP_TopNextRight] = bi;
390 if (wanted_cell_pos.y > wanted_node_pos.y )
391 indexes_ptr[CNP_TopPreviousLeft] = bi;
393 indexes_ptr[CNP_TopPreviousRight] = bi;
397 m_infos_view[
node.localId()].setCellIndexes(indexes_ptr);
404void NodeDirectionMng::
405_computeNodeCellInfos()
const
407 Ref<ICartesianMeshNumberingMngInternal> numbering = m_p->m_cartesian_mesh->_internalApi()->cartesianMeshNumberingMngInternal();
409 IndexType indexes_ptr[8];
410 ArrayView indexes(8, indexes_ptr);
414 IMesh* mesh = m_p->m_cartesian_mesh->mesh();
415 Integer mesh_dim = mesh->dimension();
418 constexpr Integer nb_cells_max = 4;
420 Int64 uids[nb_cells_max];
421 ArrayView av_uids(nb_cells_max, uids);
439 constexpr Int32 dir_x_pos_2d[nb_cells_max] = { CNP_PreviousRight, CNP_NextRight, CNP_PreviousLeft, CNP_NextLeft };
440 constexpr Int32 dir_y_pos_2d[nb_cells_max] = { CNP_PreviousLeft, CNP_PreviousRight, CNP_NextLeft, CNP_NextRight };
444 numbering->cellUniqueIdsAroundNode(
node, av_uids);
447 indexes.fill(DirNode::NULL_CELL);
449 for (
Integer i = 0; i < nb_cell; ++i) {
452 for (; pos < nb_cells_max; ++pos) {
453 if (cell.uniqueId() == av_uids[pos])
456 if (pos == nb_cells_max)
459 const IndexType bi = (IndexType)i;
461 indexes[dir_x_pos_2d[pos]] = bi;
464 indexes[dir_y_pos_2d[pos]] = bi;
467 m_infos_view[
node.localId()].setCellIndexes(indexes_ptr);
470 else if (mesh_dim == 3) {
471 constexpr Integer nb_cells_max = 8;
473 Int64 uids[nb_cells_max];
474 ArrayView av_uids(nb_cells_max, uids);
494 constexpr Int32 dir_x_pos_3d[nb_cells_max] = { CNP_PreviousRight, CNP_NextRight, CNP_PreviousLeft, CNP_NextLeft, CNP_TopPreviousRight, CNP_TopNextRight, CNP_TopPreviousLeft, CNP_TopNextLeft };
495 constexpr Int32 dir_y_pos_3d[nb_cells_max] = { CNP_PreviousLeft, CNP_PreviousRight, CNP_NextLeft, CNP_NextRight, CNP_TopPreviousLeft, CNP_TopPreviousRight, CNP_TopNextLeft, CNP_TopNextRight };
496 constexpr Int32 dir_z_pos_3d[nb_cells_max] = { CNP_PreviousLeft, CNP_PreviousRight, CNP_TopPreviousLeft, CNP_TopPreviousRight, CNP_NextLeft, CNP_NextRight, CNP_TopNextLeft, CNP_TopNextRight };
500 numbering->cellUniqueIdsAroundNode(
node, av_uids);
503 indexes.fill(DirNode::NULL_CELL);
505 for (
Integer i = 0; i < nb_cell; ++i) {
508 for (; pos < nb_cells_max; ++pos) {
509 if (cell.uniqueId() == av_uids[pos])
512 if (pos == nb_cells_max)
515 const IndexType bi = (IndexType)i;
518 indexes[dir_x_pos_3d[pos]] = bi;
521 indexes[dir_y_pos_3d[pos]] = bi;
524 indexes[dir_z_pos_3d[pos]] = bi;
527 m_infos_view[
node.localId()].setCellIndexes(indexes_ptr);
532 ARCANE_FATAL(
"Invalid mesh dimension '{0}'. Valid dimensions are 2 or 3", mesh_dim);
542 return m_p->m_all_items;
551 return m_p->m_overlap_all_items;
560 return m_p->m_inpatch_all_items;
569 return m_p->m_inner_all_items;
578 return m_p->m_outer_all_items;
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Infos sur les mailles d'une direction spécifique X,Y ou Z d'un maillage structuré.
CellGroup allCells() const
Groupe de toutes les mailles dans la direction.
DirCellNode cellNode(Cell c) const
Maille avec infos directionnelles aux noeuds correspondant à la maille c.
Maille avec info directionnelle des noeuds.
Interface d'un maillage cartésien.
virtual IMesh * mesh() const =0
Maillage associé à ce maillage cartésien.
virtual ItemGroup createGroup(const String &name, Int32ConstArrayView local_ids, bool do_override=false)=0
Créé un groupe d'entités de nom name contenant les entités local_ids.
virtual IItemFamily * nodeFamily()=0
Retourne la famille des noeuds.
virtual Integer dimension()=0
Dimension du maillage (1D, 2D ou 3D).
IItemFamily * itemFamily() const
Famille d'entité à laquelle appartient ce groupe (0 pour le group nul).
IMesh * mesh() const
Maillage auquel appartient ce groupe (0 pour le group nul).
NodeGroup innerNodes() const
Groupe de tous les noeuds internes dans la direction.
NodeDirectionMng()
Créé une instance vide.
NodeGroup outerNodes() const
Groupe de tous les noeuds externes dans la direction.
NodeGroup overlapNodes() const
Groupe de tous les noeuds de recouvrement dans la direction.
NodeGroup allNodes() const
Groupe de tous les noeuds dans la direction.
DirNode node(Node n) const
Noeud direction correspondant au noeud n.
NodeGroup inPatchNodes() const
Groupe de tous les noeuds du patch dans la direction.
void _internalResizeInfos(Int32 new_size)
Redimensionne le conteneur contenant les ItemDirectionInfo.
Vue sur les informations des noeuds.
Vecteur 1D de données avec sémantique par valeur (style STL).
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
__host__ __device__ void fill(T o)
Remplit le tableau avec la valeur o.
ItemGroupT< Node > NodeGroup
Groupe de noeuds.
MeshVariableScalarRefT< Cell, Real3 > VariableCellReal3
Grandeur au centre des mailles de type coordonnées.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Grandeur au noeud de type coordonnées.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
eMeshDirection
Type de la direction pour un maillage structuré
@ MD_DirInvalid
Direction invalide ou non initialisée.
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
@ Cell
Le maillage est AMR par maille.
std::int32_t Int32
Type entier signé sur 32 bits.