Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ParticleFamilyPolicyMng.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/* ParticleFamilyPolicyMng.cc (C) 2000-2016 */
9/* */
10/* Manager for the policies of a particle family. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/TraceAccessor.h"
15#include "arcane/utils/NotImplementedException.h"
16
17#include "arcane/core/IItemFamilyCompactPolicy.h"
18#include "arcane/core/ItemFamilyCompactInfos.h"
19#include "arcane/core/IMeshCompacter.h"
20#include "arcane/core/IMesh.h"
21
22#include "arcane/mesh/ItemFamilyPolicyMng.h"
23#include "arcane/mesh/ParticleFamilySerializer.h"
24#include "arcane/mesh/ParticleFamily.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane::mesh
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
40class ParticleFamilyCompactPolicy
41: public TraceAccessor
43{
44 public:
45
46 ParticleFamilyCompactPolicy(ParticleFamily* family)
47 : TraceAccessor(family->traceMng())
48 , m_family(family)
49 {
50 m_cell_family = family->mesh()->cellFamily();
51 }
52
53 public:
54
55 void beginCompact(ItemFamilyCompactInfos& compact_infos) override
56 {
57 if (_checkWantCompact(compact_infos))
58 m_family->beginCompactItems(compact_infos);
59 }
60 void compactVariablesAndGroups(const ItemFamilyCompactInfos& compact_infos) override
61 {
62 if (_checkWantCompact(compact_infos))
63 m_family->compactVariablesAndGroups(compact_infos);
64 }
65 void updateInternalReferences(IMeshCompacter*) override
66 {
67 }
68 void endCompact(ItemFamilyCompactInfos& compact_infos) override
69 {
70 if (_checkWantCompact(compact_infos))
71 m_family->finishCompactItems(compact_infos);
72 }
73 void finalizeCompact(IMeshCompacter* compacter) override
74 {
75 ARCANE_UNUSED(compacter);
76 }
78 {
79 }
80 IItemFamily* family() const override { return m_family; }
81
82 private:
83
84 bool _checkWantCompact(const ItemFamilyCompactInfos& compact_infos)
85 {
86 // For compatibility reasons with the existing code (version 2.4.1
87 // and earlier, we do not compact the particle family if it does not have ghosts,
88 // unless it is the only family being compacted
89 // (which corresponds to a direct call to ItemFamily::compactItems()).
90 // TODO: Once we are sure this is OK, we must always compact
91 // regardless of the family.
92 if (m_family->getEnableGhostItems())
93 return true;
94 ItemFamilyCollection families = compact_infos.compacter()->families();
95 if (families.count() == 1 && families.front() == m_family)
96 return true;
97 return false;
98 }
99
100 private:
101
102 ParticleFamily* m_family;
103 IItemFamily* m_cell_family;
104};
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
111class ARCANE_MESH_EXPORT ParticleFamilyPolicyMng
112: public ItemFamilyPolicyMng
113{
114 public:
115
116 ParticleFamilyPolicyMng(ParticleFamily* family)
117 : ItemFamilyPolicyMng(family, new ParticleFamilyCompactPolicy(family))
118 , m_family(family)
119 {}
120
121 public:
122
123 IItemFamilySerializer* createSerializer(bool use_flags) override
124 {
125 if (use_flags)
126 throw NotSupportedException(A_FUNCINFO, "serialisation with 'use_flags==true'");
127 return new ParticleFamilySerializer(m_family);
128 }
129
130 private:
131
132 ParticleFamily* m_family;
133};
134
135/*---------------------------------------------------------------------------*/
136/*---------------------------------------------------------------------------*/
137
138extern "C++" ARCANE_MESH_EXPORT IItemFamilyPolicyMng*
139createParticleFamilyPolicyMng(ItemFamily* family)
140{
141 ParticleFamily* f = ARCANE_CHECK_POINTER(dynamic_cast<ParticleFamily*>(family));
142 return new ParticleFamilyPolicyMng(f);
143}
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148} // namespace Arcane::mesh
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
Integer count() const
Number of elements in the collection.
Interface for entity family policies.
Manages the serialization/deserialization of entities in a family.
Interface of an entity family.
Definition IItemFamily.h:83
Management of mesh family compaction.
virtual ItemFamilyCollection families() const =0
Families whose entities are compacted.
Information to manage the compaction of entities of a family.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
IItemFamily * family() const override
Associated family.
void compactConnectivityData() override
Compacts the connectivity data.
IItemFamilySerializer * createSerializer(bool use_flags) override
Creates an instance for entity serialization. The returned instance must be destroyed by the delete o...
Serialization/Deserialization of link families.
bool getEnableGhostItems() const override
Retrieves the flag to manage ghost particles for the family.
Collection< IItemFamily * > ItemFamilyCollection
Collection of item families.