Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
CellDirectionMng.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* CellDirectionMng.cc (C) 2000-2026 */
9/* */
10/* Info on the cells of an X, Y, or Z direction of a structured mesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/FatalErrorException.h"
15#include "arcane/utils/ArgumentException.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/PlatformUtils.h"
18
19#include "arcane/core/IItemFamily.h"
20#include "arcane/core/ItemGroup.h"
21#include "arcane/core/IMesh.h"
22#include "arcane/core/UnstructuredMeshConnectivity.h"
23
24#include "arcane/cartesianmesh/CellDirectionMng.h"
25#include "arcane/cartesianmesh/ICartesianMesh.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
37{
38 public:
39
40 Impl()
42 {}
43
44 public:
45
46 CellGroup m_inner_all_items;
47 CellGroup m_outer_all_items;
48 CellGroup m_inpatch_all_items;
49 CellGroup m_overlap_all_items;
50 CellGroup m_all_items;
51 ICartesianMesh* m_cartesian_mesh = nullptr;
52 Integer m_patch_index = -1;
54 Int32 m_sub_domain_offset = -1;
55 Int32 m_own_nb_cell = -1;
56 Int64 m_global_nb_cell = -1;
57 Int64 m_own_cell_offset = -1;
58};
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
65: m_direction(MD_DirInvalid)
66, m_next_face_index(-1)
67, m_previous_face_index(-1)
68{
69 for (Integer i = 0; i < MAX_NB_NODE; ++i)
70 m_nodes_indirection[i] = (-1);
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76void CellDirectionMng::
77_internalInit(ICartesianMesh* cm, eMeshDirection dir, Integer patch_index)
78{
79 if (m_p)
80 ARCANE_FATAL("Initialisation already done");
81 m_p = new Impl();
82 m_direction = dir;
83 m_p->m_cartesian_mesh = cm;
84 m_p->m_patch_index = patch_index;
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90void CellDirectionMng::
91_internalDestroy()
92{
93 delete m_p;
94 m_p = nullptr;
95}
96
97/*---------------------------------------------------------------------------*/
98/*---------------------------------------------------------------------------*/
99
102{
103 m_p->m_infos.resize(new_size);
104 m_infos_view = m_p->m_infos.view();
105}
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110void CellDirectionMng::
111_internalComputeInnerAndOuterItems(const ItemGroup& items)
112{
113 Int32UniqueArray inner_lids;
114 Int32UniqueArray outer_lids;
115 IItemFamily* family = items.itemFamily();
116 ENUMERATE_ITEM (iitem, items) {
117 Int32 lid = iitem.itemLocalId();
118 Int32 i1 = m_infos_view[lid].m_next_lid;
119 Int32 i2 = m_infos_view[lid].m_previous_lid;
120 if (i1 == NULL_ITEM_LOCAL_ID || i2 == NULL_ITEM_LOCAL_ID)
121 outer_lids.add(lid);
122 else
123 inner_lids.add(lid);
124 }
125 int dir = (int)m_direction;
126 String base_group_name = String("Direction") + dir;
127 if (m_p->m_patch_index >= 0)
128 base_group_name = base_group_name + String("AMRPatch") + m_p->m_patch_index;
129 m_p->m_inner_all_items = family->createGroup(String("AllInner") + base_group_name, inner_lids, true);
130 m_p->m_outer_all_items = family->createGroup(String("AllOuter") + base_group_name, outer_lids, true);
131 m_p->m_all_items = items;
132 m_cells = CellInfoListView(family);
133
134 UnstructuredMeshConnectivityView mesh_connectivity;
135 mesh_connectivity.setMesh(m_p->m_cartesian_mesh->mesh());
136 m_cell_node_view = mesh_connectivity.cellNode();
137 m_cell_face_view = mesh_connectivity.cellFace();
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143void CellDirectionMng::
144_internalComputeCellGroups(const CellGroup& all_cells, const CellGroup& in_patch_cells, const CellGroup& overlap_cells)
145{
146 m_p->m_inpatch_all_items = in_patch_cells;
147 m_p->m_overlap_all_items = overlap_cells;
148 m_p->m_all_items = all_cells;
149
150 UniqueArray<Int32> overlap_lid;
151 overlap_cells.view().fillLocalIds(overlap_lid);
152
153 UniqueArray<Int32> inner_lids;
154 UniqueArray<Int32> outer_lids;
155
156 ENUMERATE_ (Cell, icell, in_patch_cells) {
157 Int32 lid = icell.itemLocalId();
158 Int32 i1 = m_infos_view[lid].m_next_lid;
159 Int32 i2 = m_infos_view[lid].m_previous_lid;
160 if (i1 == NULL_ITEM_LOCAL_ID || i2 == NULL_ITEM_LOCAL_ID || overlap_lid.contains(i1) || overlap_lid.contains(i2))
161 outer_lids.add(lid);
162 else
163 inner_lids.add(lid);
164 }
165 int dir = (int)m_direction;
166 IItemFamily* family = all_cells.itemFamily();
167 String base_group_name = String("Direction") + dir;
168 if (m_p->m_patch_index >= 0)
169 base_group_name = base_group_name + String("AMRPatch") + m_p->m_patch_index;
170 m_p->m_inner_all_items = family->createGroup(String("AllInner") + base_group_name, inner_lids, true);
171 m_p->m_outer_all_items = family->createGroup(String("AllOuter") + base_group_name, outer_lids, true);
172 m_cells = CellInfoListView(family);
173
174 UnstructuredMeshConnectivityView mesh_connectivity;
175 mesh_connectivity.setMesh(m_p->m_cartesian_mesh->mesh());
176 m_cell_node_view = mesh_connectivity.cellNode();
177 m_cell_face_view = mesh_connectivity.cellFace();
178}
179
180/*---------------------------------------------------------------------------*/
181/*---------------------------------------------------------------------------*/
182
184allCells() const
185{
186 return m_p->m_all_items;
187}
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
193overlapCells() const
194{
195 return m_p->m_overlap_all_items;
196}
197
198/*---------------------------------------------------------------------------*/
199/*---------------------------------------------------------------------------*/
200
202inPatchCells() const
203{
204 return m_p->m_inpatch_all_items;
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
211innerCells() const
212{
213 return m_p->m_inner_all_items;
214}
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
220outerCells() const
221{
222 return m_p->m_outer_all_items;
223}
224
225/*---------------------------------------------------------------------------*/
226/*---------------------------------------------------------------------------*/
227
228void CellDirectionMng::
229setNodesIndirection(ConstArrayView<Int8> nodes_indirection)
230{
231 for (Integer i = 0; i < MAX_NB_NODE; ++i)
232 m_nodes_indirection[i] = nodes_indirection[i];
233
234 ITraceMng* tm = m_p->m_cartesian_mesh->traceMng();
235
236 tm->info(4) << "Set computed indirection dir=" << (int)m_direction;
237 for (Integer i = 0; i < MAX_NB_NODE; ++i) {
238 tm->info(5) << "Indirection i=" << i << " v=" << (int)m_nodes_indirection[i];
239 }
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
246globalNbCell() const
247{
248 return (m_p) ? m_p->m_global_nb_cell : -1;
249}
250
251/*---------------------------------------------------------------------------*/
252/*---------------------------------------------------------------------------*/
253
255ownNbCell() const
256{
257 return (m_p) ? m_p->m_own_nb_cell : -1;
258}
259
260/*---------------------------------------------------------------------------*/
261/*---------------------------------------------------------------------------*/
262
264subDomainOffset() const
265{
266 return (m_p) ? m_p->m_sub_domain_offset : -1;
267}
268
269/*---------------------------------------------------------------------------*/
270/*---------------------------------------------------------------------------*/
271
273ownCellOffset() const
274{
275 return (m_p) ? m_p->m_own_cell_offset : -1;
276}
277
278/*---------------------------------------------------------------------------*/
279/*---------------------------------------------------------------------------*/
280
281void CellDirectionMng::
282_internalSetOffsetAndNbCellInfos(Int64 global_nb_cell, Int32 own_nb_cell,
283 Int32 sub_domain_offset, Int64 own_cell_offset)
284{
285 m_p->m_global_nb_cell = global_nb_cell;
286 m_p->m_own_nb_cell = own_nb_cell;
287 m_p->m_sub_domain_offset = sub_domain_offset;
288 m_p->m_own_cell_offset = own_cell_offset;
289}
290
291/*---------------------------------------------------------------------------*/
292/*---------------------------------------------------------------------------*/
293
294} // End namespace Arcane
295
296/*---------------------------------------------------------------------------*/
297/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_(type, name, group)
Generic enumerator for an entity group.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
void add(ConstReferenceType val)
Adds element val to the end of the array.
CellGroup outerCells() const
Group of all outer cells in the direction.
CellGroup allCells() const
Group of all cells in the direction.
CellGroup overlapCells() const
Group of all overlap cells in the direction.
Int64 ownCellOffset() const
Offset of the first own cell of this subdomain in this direction.
Int64 globalNbCell() const
Global number of cells in this direction.
CellGroup innerCells() const
Group of all inner cells in the direction.
CellDirectionMng()
Creates an empty instance.
Int32 subDomainOffset() const
Offset of the subdomain in this direction.
Int32 ownNbCell() const
Number of own cells in this direction.
void _internalResizeInfos(Int32 new_size)
Resizes the container holding the ItemDirectionInfo.
CellGroup inPatchCells() const
Group of all patch cells in the direction.
Constant view of an array of type T.
virtual ITraceMng * traceMng() const =0
Associated trace manager.
virtual IMesh * mesh() const =0
Mesh associated with this Cartesian mesh.
Interface of an entity family.
Definition IItemFamily.h:83
virtual ItemGroup createGroup(const String &name, Int32ConstArrayView local_ids, bool do_override=false)=0
Creates an entity group named name containing the entities local_ids.
virtual TraceMessage info()=0
Stream for an information message.
Mesh entity group.
Definition ItemGroup.h:51
IItemFamily * itemFamily() const
Entity family to which this group belongs (0 for the null group).
Definition ItemGroup.h:128
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.
Definition ItemTypes.h:184
IMemoryAllocator * getDefaultDataAllocator()
Default allocator for data.
-- 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.
eMeshDirection
Direction type for a structured mesh.
@ MD_DirInvalid
Invalid or uninitialized direction.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53
std::int32_t Int32
Signed integer type of 32 bits.