Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
CellFamilySerializer.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/* CellFamilySerializer.cc (C) 2000-2024 */
9/* */
10/* Serialization/Deserialization of cell families. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/CellFamilySerializer.h"
15
16#include "arcane/core/ISerializer.h"
17#include "arcane/core/ItemPrinter.h"
18#include "arcane/core/IMesh.h"
19#include "arcane/core/MeshPartInfo.h"
20
21#include "arcane/mesh/FullItemInfo.h"
22#include "arcane/mesh/DynamicMeshIncrementalBuilder.h"
23#include "arcane/mesh/OneMeshItemAdder.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane::mesh
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34CellFamilySerializer::
35CellFamilySerializer(CellFamily* family, bool use_flags,
37: TraceAccessor(family->traceMng())
38, m_mesh_builder(mesh_builder)
39, m_family(family)
40, m_use_flags(use_flags)
41{
42}
43
44/*---------------------------------------------------------------------------*/
45/*---------------------------------------------------------------------------*/
46
47void CellFamilySerializer::
48serializeItems(ISerializer* buf, Int32ConstArrayView cells_local_id)
49{
50 ItemInternalList cells_internal = m_family->itemsInternal();
51
52 const Integer nb_cell = cells_local_id.size();
53
54 IMesh* mesh = m_family->mesh();
55 Int32 my_rank = mesh->meshPartInfo().partRank();
56 const Integer parent_info = FullCellInfo::parentInfo(mesh);
57 const bool has_amr = mesh->isAmrActivated();
58 const bool has_edge = m_mesh_builder->hasEdge();
59 const bool use_flags = m_use_flags;
60
61 info(4) << "_serializeItems : "
62 << mesh->name() << " "
63 << m_family->name() << " "
64 << m_family->parentFamilyDepth();
65
66 switch (buf->mode()) {
67 case ISerializer::ModeReserve: {
68 buf->reserveInt64(2); // 1 for the subdomain rank and 1 for the number of cells
69 UniqueArray<Int64> tmp_buf;
70 tmp_buf.reserve(200);
71 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
72 Int32 lid = cells_local_id[i_cell];
73 ItemInternal* cell = cells_internal[lid];
74 tmp_buf.clear();
75 FullCellInfo::dump(cell, tmp_buf, parent_info, has_edge, has_amr, use_flags);
76 buf->reserveInt64(1);
77 buf->reserveSpan(tmp_buf);
78 }
79 } break;
81 buf->putInt64(my_rank); // Stores the subdomain number
82 buf->putInt64(nb_cell); // Stores the number of cells
83 info(4) << "Serialize: Put: nb_cell=" << nb_cell;
84 UniqueArray<Int64> tmp_buf;
85 tmp_buf.reserve(200);
86 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
87 Int32 lid = cells_local_id[i_cell];
88 ItemInternal* cell = cells_internal[lid];
89 tmp_buf.clear();
90 FullCellInfo::dump(cell, tmp_buf, parent_info, has_edge, has_amr, use_flags);
91 buf->putInt64(tmp_buf.largeSize());
92 buf->putSpan(tmp_buf);
93 }
94 } break;
96 deserializeItems(buf, nullptr);
97 } break;
98 }
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104void CellFamilySerializer::
105deserializeItems(ISerializer* buf, Int32Array* cells_local_id)
106{
107 IMesh* mesh = m_family->mesh();
108 ItemTypeMng* itm = mesh->itemTypeMng();
109 Int32 my_rank = mesh->meshPartInfo().partRank();
110 Int32 orig_rank = CheckedConvert::toInt32(buf->getInt64()); // Source subdomain number
111 Int64 nb_cell = buf->getInt64();
112 const Integer parent_info = FullCellInfo::parentInfo(mesh);
113
114 Int64UniqueArray mem_buf;
115 mem_buf.reserve(200);
116 Int32ArrayView locals_id_view;
117 bool use_array = false;
118 if (cells_local_id) {
119 cells_local_id->resize(nb_cell);
120 locals_id_view = (*cells_local_id);
121 use_array = true;
122 }
123 const bool is_check = arcaneIsCheck();
124 const bool has_edge = m_mesh_builder->hasEdge();
125 const bool has_amr = mesh->isAmrActivated();
126 const bool use_flags = m_use_flags;
127 info(4) << "DeserializeCells: nb_cell=" << nb_cell << " orig=" << orig_rank << " has_edge=" << has_edge
128 << " has_amr=" << has_amr << " use_flags=" << use_flags;
129 for (Integer i_cell = 0; i_cell < nb_cell; ++i_cell) {
130 Int64 memory_needed = buf->getInt64();
131 mem_buf.resize(memory_needed);
132 buf->getSpan(mem_buf);
133 FullCellInfo current_cell(mem_buf, 0, itm, parent_info, has_edge, has_amr, use_flags);
134 ItemInternal* icell = m_mesh_builder->oneMeshItemAdder()->addOneCell(current_cell);
135 Cell cell(icell);
136 if (use_array)
137 locals_id_view[i_cell] = icell->localId();
138 {
139 // Note that the IT_Own flag is not correct; it is forced later
140 if (use_flags)
141 icell->setFlags(current_cell.flags());
142 // Force the owners to the serialization value, because they will not be
143 // correct in the case where the cell or one of its elements
144 // already existed
145 icell->setOwner(current_cell.owner(), my_rank);
146 if (is_check) {
147 // Checks that the unique IDs of the current elements of the cell
148 // are the same as those being deserialized.
149 bool has_error = false;
150 Integer node_index = 0;
151 for (Node node : cell.nodes()) {
152 has_error |= (node.uniqueId() != current_cell.nodeUniqueId(node_index));
153 ++node_index;
154 }
155 Integer edge_index = 0;
156 for (Edge edge : cell.edges()) {
157 has_error |= (edge.uniqueId() != current_cell.edgeUniqueId(edge_index));
158 ++edge_index;
159 }
160 Integer face_index = 0;
161 for (Face face : cell.faces()) {
162 has_error |= (face.uniqueId() != current_cell.faceUniqueId(face_index));
163 ++face_index;
164 }
165 if (has_error) {
166 node_index = 0;
167 for (Node node : cell.nodes()) {
168 info() << "Cell c=" << ItemPrinter(cell) << " node=" << ItemPrinter(node)
169 << " remote_uid=" << current_cell.nodeUniqueId(node_index);
170 ++node_index;
171 }
172 edge_index = 0;
173 for (Edge edge : cell.edges()) {
174 info() << "Cell c=" << ItemPrinter(cell) << " edge=" << ItemPrinter(edge)
175 << " remote_uid=" << current_cell.edgeUniqueId(edge_index);
176 ++edge_index;
177 }
178 face_index = 0;
179 for (Face face : cell.faces()) {
180 info() << "Cell c=" << ItemPrinter(cell) << " face=" << ItemPrinter(face)
181 << " remote_uid=" << current_cell.faceUniqueId(face_index);
182 ++face_index;
183 }
184 ARCANE_FATAL("Incoherent local and remote node, edge or face unique id");
185 }
186 }
187
188 // TODO: check if this is useful. Probably not because the work
189 // is done during cells deserialization.
190 Integer node_index = 0;
191 for (Node node : cell.nodes()) {
192 node.mutableItemBase().setOwner(current_cell.nodeOwner(node_index), my_rank);
193 ++node_index;
194 }
195 Integer edge_index = 0;
196 for (Edge edge : cell.edges()) {
197 edge.mutableItemBase().setOwner(current_cell.edgeOwner(edge_index), my_rank);
198 ++edge_index;
199 }
200 Integer face_index = 0;
201 for (Face face : cell.faces()) {
202 face.mutableItemBase().setOwner(current_cell.faceOwner(face_index), my_rank);
203 ++face_index;
204 }
205 }
206 }
207 info(4) << "EndDeserializeCells: nb_cell=" << nb_cell << " orig=" << orig_rank;
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213IItemFamily* CellFamilySerializer::
214family() const
215{
216 return m_family;
217}
218
219/*---------------------------------------------------------------------------*/
220/*---------------------------------------------------------------------------*/
221
222} // End namespace Arcane::mesh
223
224/*---------------------------------------------------------------------------*/
225/*---------------------------------------------------------------------------*/
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Int64 largeSize() const
Number of elements in the vector (in 64 bits).
void resize(Int64 s)
Changes the number of elements in the array to s.
void clear()
Removes the elements from the array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
Cell of a mesh.
Definition Item.h:1300
FaceConnectedListViewType faces() const
List of faces of the cell.
Definition Item.h:1403
EdgeConnectedListViewType edges() const
List of edges of the cell.
Definition Item.h:1421
constexpr Integer size() const noexcept
Number of elements in the array.
Edge of a cell.
Definition Item.h:875
Face of a cell.
Definition Item.h:1032
Interface of an entity family.
Definition IItemFamily.h:83
virtual Int64 getInt64()=0
Retrieve a size.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void putInt64(Int64 value)=0
Add the integer value.
Int32 localId() const
Local number (in the subdomain) of the entity.
Internal structure of a mesh entity.
Utility class for printing information about an entity.
Definition ItemPrinter.h:35
Mesh entity type manager.
Definition ItemTypeMng.h:66
NodeConnectedListViewType nodes() const
List of nodes of the entity.
Definition Item.h:843
void setOwner(Integer suid, Int32 current_sub_domain)
Sets the sub-domain number of the entity owner.
void setFlags(Int32 f)
Sets the entity flags.
Node of a mesh.
Definition Item.h:598
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
void deserializeItems(ISerializer *buf, Int32Array *cells_local_id) override
Deserializes the entities of the family family() from buf.
Info to create/serialize a cell knowing the uniqueId() and owner() of all these sub-entities (cells,...
bool arcaneIsCheck()
True if running in check mode.
Definition Misc.cc:66
UniqueArray< Int64 > Int64UniqueArray
Dynamic 1D array of 64-bit integers.
Definition UtilsTypes.h:339
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.
Definition UtilsTypes.h:482
ConstArrayView< ItemInternal * > ItemInternalList
Type of the internal list of entities.
Definition ItemTypes.h:466
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127
std::int32_t Int32
Signed integer type of 32 bits.