Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
DoFFamily.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/* DoFFamily.cc (C) 2000-2024 */
9/* */
10/* Degree of freedom family */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/mesh/DoFFamily.h"
15
16#include "arcane/core/IMesh.h"
17#include "arcane/core/ItemTypeMng.h"
18#include "arcane/core/ItemTypeInfo.h"
19#include "arcane/core/IExtraGhostItemsBuilder.h"
20
21#include "arcane/mesh/ExtraGhostItemsManager.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane::mesh
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32Int64 DoFUids::
33getMaxItemUid(IItemFamily* family)
34{
35 Int64 max_uid = 0;
36 // This method can be used within IItemFamily::endUpdate when new items have been created but the groups are not yet updated.
37 // Therefore we use internal map enumeration instead of group enumeration
38 ItemFamily* item_family = ARCANE_CHECK_POINTER(dynamic_cast<ItemFamily*>(family));
39 item_family->itemsMap().eachItem([&](Item item) {
40 if (max_uid < item.uniqueId().asInt64())
41 max_uid = item.uniqueId().asInt64();
42 });
43 Int64 pmax_uid = family->mesh()->parallelMng()->reduce(Parallel::ReduceMax, max_uid);
44 return pmax_uid;
45}
46
47/*---------------------------------------------------------------------------*/
48/*---------------------------------------------------------------------------*/
49
52: ItemFamily(mesh, IK_DoF, name)
53, m_shared_info(nullptr)
54{}
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
59void DoFFamily::
60build()
61{
62 ItemFamily::build();
63 m_sub_domain_id = subDomain()->subDomainId();
64 ItemTypeMng* itm = m_mesh->itemTypeMng();
65 ItemTypeInfo* dof_type_info = itm->typeFromId(IT_NullType);
66 m_shared_info = _findSharedInfo(dof_type_info);
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
75{
76 ARCANE_ASSERT((dof_uids.size() == dof_lids.size()), ("in addDofs(uids,lids) given uids and lids array must have same size"))
77 _addItems(dof_uids, dof_lids);
78 return view(dof_lids);
79}
80
81/*---------------------------------------------------------------------------*/
82/*---------------------------------------------------------------------------*/
83
87{
88 ARCANE_ASSERT((dof_uids.size() == dof_lids.size() && (dof_uids.size() == owners.size())), ("in addGhostDofs given uids, lids and owners array must have same size"))
89 addGhostItems(dof_uids, dof_lids, owners);
90 return view(dof_lids);
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
98{
99 Integer nb_item = unique_ids.size();
100 if (nb_item == 0)
101 return;
102 preAllocate(nb_item);
103 for (Integer i = 0; i < nb_item; ++i) {
104 Int64 uid = unique_ids[i];
105 ItemInternal* ii = _allocDoF(uid);
106 items[i] = ii->localId();
107 }
108
109 m_need_prepare_dump = true;
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
117{
118 Integer nb_item = unique_ids.size();
119 if (nb_item == 0)
120 return;
121 preAllocate(nb_item);
122 for (Integer i = 0; i < nb_item; ++i) {
123 Int64 uid = unique_ids[i];
124 Int32 owner = owners[i];
125 ItemInternal* ii = _allocDoFGhost(uid, owner);
126 items[i] = ii->localId();
127 }
128
129 m_need_prepare_dump = true;
130}
131
132/*---------------------------------------------------------------------------*/
133/*---------------------------------------------------------------------------*/
134
136internalRemoveItems(Int32ConstArrayView local_ids, bool keep_ghost)
137{
138 ARCANE_UNUSED(keep_ghost);
139 _removeMany(local_ids);
140
141 m_need_prepare_dump = true;
142}
143
144/*---------------------------------------------------------------------------*/
145/*---------------------------------------------------------------------------*/
146
147void DoFFamily::
148removeDoFs(Int32ConstArrayView items_local_id)
149{
150 internalRemoveItems(items_local_id, false);
151}
152
153/*---------------------------------------------------------------------------*/
154/*---------------------------------------------------------------------------*/
155
158{
159 debug() << "Creating the list of ghosts dofs";
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166void DoFFamily::
167_printInfos(Integer nb_added)
168{
169 Integer nb_in_map = itemsMap().count();
170
171 info() << "DoFFamily: added=" << nb_added
172 << " nb_internal=" << _infos().m_internals.size()
173 << " nb_free=" << _infos().m_free_internals.size()
174 << " map_nb_bucket=" << itemsMap().nbBucket()
175 << " map_size=" << nb_in_map;
176}
177
178/*---------------------------------------------------------------------------*/
179/*---------------------------------------------------------------------------*/
180
181void DoFFamily::
182preAllocate(Integer nb_item)
183{
184 // Copy paste de particle, pas utilise pour l'instant
185 Integer nb_hash = itemsMap().nbBucket();
186 Integer wanted_size = 2 * (nb_item + nbItem());
187 if (nb_hash < wanted_size)
188 itemsMap().resize(wanted_size, true);
189}
190
191/*---------------------------------------------------------------------------*/
192/*---------------------------------------------------------------------------*/
193
194ItemInternal* DoFFamily::
195_allocDoF(const Int64 uid)
196{
197 bool need_alloc; // given by alloc
198 //ItemInternal* item_internal = ItemFamily::_allocOne(uid,need_alloc);
199 ItemInternal* item_internal = ItemFamily::_findOrAllocOne(uid, need_alloc);
200 if (!need_alloc)
201 item_internal->setUniqueId(uid);
202 else {
203 _allocateInfos(item_internal, uid, m_shared_info);
204 }
205 // Un dof appartient de base au sous-domaine qui l'a créé (sauf ghost)
206 item_internal->setOwner(m_sub_domain_id, m_sub_domain_id);
207 return item_internal;
208}
209
210/*---------------------------------------------------------------------------*/
211/*---------------------------------------------------------------------------*/
212
213ItemInternal* DoFFamily::
214_allocDoFGhost(const Int64 uid, const Int32 owner)
215{
216 bool need_alloc; // given by alloc
217 //ItemInternal* item_internal = ItemFamily::_allocOne(uid,need_alloc);
218 ItemInternal* item_internal = ItemFamily::_findOrAllocOne(uid, need_alloc);
219 //ItemInternal* item_internal = m_infos.findOrAllocOne(uid,need_alloc);
220 if (!need_alloc)
221 item_internal->setUniqueId(uid);
222 else {
223 _allocateInfos(item_internal, uid, m_shared_info);
224 }
225 // Une particule appartient toujours au sous-domaine qui l'a créée
226 item_internal->setOwner(owner, m_sub_domain_id);
227 return item_internal;
228}
229
230ItemInternal* DoFFamily::
231_findOrAllocDoF(const Int64 uid, bool& is_alloc)
232{
233 ItemInternal* item_internal = ItemFamily::_findOrAllocOne(uid, is_alloc);
234 if (!is_alloc) {
235 item_internal->setUniqueId(uid);
236 }
237 else {
238 _allocateInfos(item_internal, uid, m_shared_info);
239 // Un dof appartient de base au sous-domaine qui l'a créé (sauf ghost)
240 item_internal->setOwner(m_sub_domain_id, m_sub_domain_id);
241 }
242 return item_internal;
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
248} // namespace Arcane::mesh
249
250/*---------------------------------------------------------------------------*/
251/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
Integer size() const
Number of elements in the vector.
constexpr Integer size() const noexcept
Returns the size of the array.
constexpr Integer size() const noexcept
Number of elements in the array.
virtual ItemTypeMng * itemTypeMng() const =0
Associated entity type manager.
virtual Int32 subDomainId() const =0
Subdomain ID associated with this manager.
Int32 localId() const
Local number (in the subdomain) of the entity.
Internal structure of a mesh entity.
Info on a mesh entity type.
Mesh entity type manager.
Definition ItemTypeMng.h:66
ItemTypeInfo * typeFromId(Integer id) const
Type corresponding to the number id.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
TraceMessage info() const
Flow for an information message.
DoFVectorView addGhostDoFs(Int64ConstArrayView dof_uids, Int32ArrayView dof_lids, Int32ConstArrayView owners) override
Adding ghosts must be followed by a call to computeSynchronizeInfos.
Definition DoFFamily.cc:86
void computeSynchronizeInfos() override
Collective operation.
Definition DoFFamily.cc:157
DoFFamily(IMesh *mesh, const String &name)
The family cannot be created directly; the DoFManager must be used.
Definition DoFFamily.cc:51
DoFVectorView addDoFs(Int64ConstArrayView dof_uids, Int32ArrayView dof_lids) override
Takes the uids of the dofs and retrieves their lids.
Definition DoFFamily.cc:74
void internalRemoveItems(Int32ConstArrayView local_ids, bool keep_ghost=false) override
Removes the entities given by local_ids.
Definition DoFFamily.cc:136
void addGhostItems(Int64ConstArrayView unique_ids, Int32ArrayView items, Int32ConstArrayView owners) override
Allocates ghost entities.
Definition DoFFamily.cc:116
Integer nbItem() const override
Number of entities.
Definition DoFFamily.h:79
void _addItems(Int64ConstArrayView unique_ids, Int32ArrayView items)
Construction of the Item Family. The DoFManager is responsible for this.
Definition DoFFamily.cc:97
String name() const override
Family name.
Definition DoFFamily.h:77
UniqueArray< ItemInternal * > m_internals
ItemInternals of the entities.
Int32UniqueArray m_free_internals
List of free ItemInternals from m_item_internals_buffer.
IMesh * mesh() const override
Associated mesh.
ItemVectorView view() override
View on all entities in the family.
void computeSynchronizeInfos() override
Constructs the structures necessary for synchronization.
ISubDomain * subDomain() const override
Associated sub-domain.
Int32 nbBucket() const
Number of buckets.
void resize(Int32 new_size, bool use_prime=false)
Resizes the hash table.
Int32 count() const
Number of elements in the table.
ItemVectorViewT< DoF > DoFVectorView
View over a vector of degrees of freedom.
Definition ItemTypes.h:316
@ ReduceMax
Maximum of values.
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< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:480
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
@ IK_DoF
Degree of Freedom mesh entity.
std::int32_t Int32
Signed integer type of 32 bits.