Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
IndirectItemFamilySerializer.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/* IndirectItemFamilySerializer.cc (C) 2000-2024 */
9/* */
10/* Indirect serialization/deserialization of entity families. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/ISerializer.h"
15#include "arcane/core/IItemFamily.h"
16#include "arcane/core/ItemInfoListView.h"
17#include "arcane/core/Item.h"
18
19#include "arcane/mesh/IndirectItemFamilySerializer.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane::mesh
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30IndirectItemFamilySerializer::
31IndirectItemFamilySerializer(IItemFamily* family)
32: TraceAccessor(family->traceMng())
33, m_family(family)
34{
35}
36
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
39
40void IndirectItemFamilySerializer::
41serializeItems(ISerializer* sbuf, Int32ConstArrayView local_ids)
42{
43 const Integer nb_item = local_ids.size();
44 ItemInfoListView items_internal(m_family);
45
46 switch (sbuf->mode()) {
47 case ISerializer::ModeReserve:
48 sbuf->reserveInt64(1); // For the number of entities
49 sbuf->reserveSpan(eBasicDataType::Int64, nb_item); // For the uniqueId() of the entities.
50 break;
52 sbuf->putInt64(nb_item);
53 {
54 Int64UniqueArray particle_unique_ids(nb_item);
55 for (Integer z = 0; z < nb_item; ++z) {
56 Item item = items_internal[local_ids[z]];
57 particle_unique_ids[z] = item.uniqueId().asInt64();
58 }
59 sbuf->putSpan(particle_unique_ids);
60 }
61 break;
63 deserializeItems(sbuf, nullptr);
64 break;
65 }
66}
67
68/*---------------------------------------------------------------------------*/
69/*---------------------------------------------------------------------------*/
70
71void IndirectItemFamilySerializer::
72deserializeItems(ISerializer* sbuf, Int32Array* local_ids)
73{
74 Int64UniqueArray unique_ids;
75
76 Int64 nb_item = sbuf->getInt64();
77 unique_ids.resize(nb_item);
78 sbuf->getSpan(unique_ids);
79
80 Int32UniqueArray temporary_local_ids;
81 Int32Array* work_local_id = (local_ids) ? local_ids : &temporary_local_ids;
82 work_local_id->resize(nb_item);
83
84 m_family->itemsUniqueIdToLocalId(*work_local_id, unique_ids, true);
85}
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90IItemFamily* IndirectItemFamilySerializer::
91family() const
92{
93 return m_family;
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99} // namespace Arcane::mesh
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
void resize(Int64 s)
Changes the number of elements in the array to s.
constexpr Integer size() const noexcept
Number of elements in the array.
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.
View of a list to obtain information about entities.
Base class for a mesh element.
Definition Item.h:84
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Definition Item.h:239
void deserializeItems(ISerializer *buf, Int32Array *local_ids) override
Deserializes the entities of the family family() from buf.
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
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
Definition UtilsTypes.h:341
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
Definition UtilsTypes.h:127