Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
FullItemInfo.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/* FullItemInfo.h (C) 2000-2021 */
9/* */
10/* Serialization information for a mesh. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/FullItemInfo.h"
15
16#include "arcane/ISerializer.h"
17#include "arcane/ItemInternal.h"
18#include "arcane/ItemInternalEnumerator.h"
19
20#include "arcane/mesh/DynamicMesh.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane::mesh
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
32FullCellInfo(Int64ConstArrayView cells_infos, Integer cell_index,
33 ItemTypeMng* itm, Integer parent_info,
34 bool has_edge, bool has_amr, bool with_flags)
35: m_nb_node(0)
36, m_nb_edge(0)
37, m_nb_face(0)
38, m_first_edge(0)
39, m_first_face(0)
40, m_memory_used(0)
41, m_type(0)
42, m_first_parent_node(0)
43, m_first_parent_edge(0)
44, m_first_parent_face(0)
45, m_first_parent_cell(0)
46, m_parent_info(parent_info)
47, m_has_edge(has_edge)
49, m_has_amr(has_amr)
50, m_with_flags(with_flags)
51{
52 Integer item_type_id = (Integer)cells_infos[cell_index];
53 ItemTypeInfo* it = itm->typeFromId(item_type_id);
54 m_type = it;
56 m_infos = Int64ConstArrayView(m_memory_used, &cells_infos[cell_index]);
57}
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
62void FullCellInfo::
63print(std::ostream& o) const
64{
65 o << "Cell uid=" << uniqueId()
66 << " nb_node=" << nbNode()
67 << " nb_edge=" << nbEdge()
68 << " nb_face=" << nbFace()
69 << ' ';
70 for (Integer z = 0, zs = nbNode(); z < zs; ++z)
71 o << " N" << z << "=" << nodeUniqueId(z);
72 for (Integer z = 0, zs = nbEdge(); z < zs; ++z)
73 o << " E" << z << "=" << edgeUniqueId(z);
74 for (Integer z = 0, zs = nbFace(); z < zs; ++z)
75 o << " F" << z << "=" << faceUniqueId(z);
76}
77
78/*---------------------------------------------------------------------------*/
79/*---------------------------------------------------------------------------*/
80
81Integer FullCellInfo::
82memoryUsed(ItemTypeInfo* it, Integer parent_info, bool has_edge, bool has_amr, bool with_flags)
83{
84 Integer memory_used = 0;
85 // basic description of a cell
86 memory_used += 3 + 2 * it->nbLocalNode() + 2 * it->nbLocalFace();
87 if (has_edge)
88 memory_used += 2 * it->nbLocalEdge();
89 // Factor *2: uid + type (all except node)
90 if (parent_info & PI_Node)
91 memory_used += it->nbLocalNode();
92 if (parent_info & PI_Edge)
93 memory_used += 2 * it->nbLocalEdge();
94 if (parent_info & PI_Face)
95 memory_used += 2 * it->nbLocalFace();
96 if (parent_info & PI_Cell)
97 memory_used += 2;
99 if (has_amr)
100 memory_used += 3;
101 if (with_flags)
102 memory_used += 1;
103
104 return memory_used;
105}
106
107namespace
108{
109 class SerializerDumpAdapter
110 {
111 public:
112
113 SerializerDumpAdapter(ISerializer* s)
114 : m_serializer(s)
115 {}
116 void put(Int64 v)
117 {
118 m_serializer->putInt64(v);
119 }
120
121 private:
122
123 ISerializer* m_serializer;
124 };
125
126 class ArrayDumpAdapter
127 {
128 public:
129
130 ArrayDumpAdapter(Array<Int64>& a)
131 : m_array_ref(a)
132 {}
133 void put(Int64 v)
134 {
135 m_array_ref.add(v);
136 }
137
138 private:
139
140 Array<Int64>& m_array_ref;
141 };
142
143 template <typename Adapter> void
144 _dumpCellInfo(Cell cell, Adapter buf, Integer parent_info,
145 bool has_edge, bool has_amr, bool with_flags)
146 {
147 buf.put(cell.type());
148 buf.put(cell.uniqueId().asInt64());
149 buf.put(cell.owner());
150 // Adds the list of nodes
151 for (Item node : cell.nodes()) {
152 buf.put(node.uniqueId().asInt64());
153 buf.put(node.owner());
154 }
155 // Adds the list of edges
156 if (has_edge)
157 for (Edge edge : cell.edges()) {
158 buf.put(edge.uniqueId().asInt64());
159 buf.put(edge.owner());
160 }
161 // Adds the list of faces
162 for (Face face : cell.faces()) {
163 buf.put(face.uniqueId().asInt64());
164 buf.put(face.owner());
165 }
166 if (parent_info & FullCellInfo::PI_Node) {
167 for (Node node : cell.nodes()) {
168 Item parent = node.parent(0);
169 buf.put(parent.uniqueId().asInt64());
170 }
171 }
172 if (parent_info & FullCellInfo::PI_Edge) {
173 for (Edge edge : cell.edges()) {
174 Item parent = edge.parent(0);
175 buf.put(parent.uniqueId().asInt64());
176 buf.put(parent.type());
177 }
178 }
179 if (parent_info & FullCellInfo::PI_Face) {
180 for (Face face : cell.faces()) {
181 Item parent = face.parent(0);
182 buf.put(parent.uniqueId().asInt64());
183 buf.put(parent.type());
184 }
185 }
186 if (parent_info & FullCellInfo::PI_Cell) {
187 Item parent = cell.parent(0);
188 buf.put(parent.uniqueId().asInt64());
189 buf.put(parent.type());
190 }
192 if (has_amr) {
193 buf.put(cell.level());
194 if (cell.level() == 0) {
195 buf.put(NULL_ITEM_ID);
196 buf.put(NULL_ITEM_ID);
197 }
198 else {
199 Cell hParent = cell.hParent();
200 buf.put(hParent.uniqueId().asInt64());
201 buf.put(hParent.whichChildAmI(cell));
202 }
203 }
204 if (with_flags)
205 buf.put(cell.itemBase().flags());
206 }
207
208} // namespace
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213void FullCellInfo::
214dump(ItemInternal* icell, ISerializer* buf, Integer parent_info,
215 bool has_edge, bool has_amr, bool with_flags)
216{
217 SerializerDumpAdapter adapter(buf);
218 _dumpCellInfo(icell, adapter, parent_info, has_edge, has_amr, with_flags);
219}
220
221void FullCellInfo::
222dump(Cell cell, Array<Int64>& buf, Integer parent_info,
223 bool has_edge, bool has_amr, bool with_flags)
224{
225 ArrayDumpAdapter adapter(buf);
226 _dumpCellInfo(cell, adapter, parent_info, has_edge, has_amr, with_flags);
227}
228
229/*---------------------------------------------------------------------------*/
230/*---------------------------------------------------------------------------*/
231
232Integer FullCellInfo::
233parentInfo(IMesh* mesh)
234{
235 Integer info = 0;
236 if (mesh->cellFamily()->parentFamily())
237 info |= PI_Cell;
238 if (mesh->faceFamily()->parentFamily())
239 info |= PI_Face;
240 if (mesh->edgeFamily()->parentFamily())
241 info |= PI_Edge;
242 if (mesh->nodeFamily()->parentFamily())
243 info |= PI_Node;
244 return info;
245}
246
247/*---------------------------------------------------------------------------*/
248/*---------------------------------------------------------------------------*/
249
252{
253 m_nb_node = m_type->nbLocalNode();
254 if (m_has_edge)
255 m_nb_edge = m_type->nbLocalEdge();
256 else
257 m_nb_edge = 0;
258 m_nb_face = m_type->nbLocalFace();
259 m_first_edge = 3 + m_nb_node * 2;
260 m_first_face = m_first_edge + m_nb_edge * 2;
261 m_first_parent_node = m_first_face + m_nb_face * 2;
262 m_first_parent_edge = m_first_parent_node;
263 if (m_parent_info & PI_Node)
264 m_first_parent_edge += m_nb_node;
265 m_first_parent_face = m_first_parent_edge;
266 if (m_parent_info & PI_Edge)
267 m_first_parent_face += m_nb_edge * 2;
268 m_first_parent_cell = m_first_parent_face;
269 if (m_parent_info & PI_Face)
270 m_first_parent_cell += m_nb_face * 2;
271 m_memory_used = m_first_parent_cell;
272 if (m_parent_info & PI_Cell)
273 m_memory_used += 2;
275 if (m_has_amr) {
276 m_first_hParent_cell = m_memory_used;
277 m_memory_used += 3;
278 }
279 if (m_with_flags)
280 m_memory_used += 1;
281}
282
283/*---------------------------------------------------------------------------*/
284/*---------------------------------------------------------------------------*/
285
286} // End namespace Arcane::mesh
287
288/*---------------------------------------------------------------------------*/
289/*---------------------------------------------------------------------------*/
Info on a mesh entity type.
Integer nbLocalEdge() const
Number of edges of the entity.
Integer nbLocalNode() const
Number of nodes of the entity.
Integer nbLocalFace() const
Number of faces of the entity.
Mesh entity type manager.
Definition ItemTypeMng.h:66
ItemTypeInfo * typeFromId(Integer id) const
Type corresponding to the number id.
FullCellInfo(Int64ConstArrayView cells_infos, Integer cell_index, ItemTypeMng *itm, Integer parent_info, bool has_edge, bool has_amr, bool with_flags=false)
References the info of a cell.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
@ Cell
The mesh is AMR by cell.
Definition MeshKind.h:53