14#include "arcane/mesh/ParticleFamily.h"
16#include "arcane/utils/FatalErrorException.h"
17#include "arcane/utils/PlatformUtils.h"
19#include "arcane/core/ISubDomain.h"
20#include "arcane/core/IMesh.h"
21#include "arcane/core/IVariableMng.h"
22#include "arcane/core/Properties.h"
23#include "arcane/core/ItemPrinter.h"
25#include "arcane/mesh/ItemsExchangeInfo2.h"
26#include "arcane/mesh/DynamicMesh.h"
27#include "arcane/mesh/ItemConnectivitySelector.h"
28#include "arcane/mesh/DynamicMeshKindInfos.h"
40ParticleFamily(IMesh* mesh,
const String& name)
42, m_particle_type_info(nullptr)
43, m_particle_shared_info(nullptr)
44, m_sub_domain_id(NULL_SUB_DOMAIN_ID)
45, m_enable_ghost_items(false)
46, m_cell_connectivity(nullptr)
65 ItemTypeMng* itm = m_mesh->itemTypeMng();
66 m_particle_type_info = itm->typeFromId(IT_NullType);
67 m_sub_domain_id = subDomain()->subDomainId();
70 if (!platform::getEnvironmentVariable(
"ARCANE_PARTICLE_NO_UNIQUE_ID_MAP").null()) {
71 pwarning() <<
"TEMPORARY: suppress particule uniqueId map";
72 setHasUniqueIdMap(
false);
75 bool has_unique_id_map = !m_properties->getBool(
"no-unique-id-map");
76 _setHasUniqueIdMap(has_unique_id_map);
79 m_cell_connectivity =
new CellConnectivity(
this, mesh()->cellFamily(),
"ParticleCell");
81 _addConnectivitySelector(m_cell_connectivity);
83 _buildConnectivitySelectors();
86 m_cell_connectivity->setPreAllocatedSize(1);
90 auto network = m_mesh->itemFamilyNetwork();
92 network->addDependency(
this, mesh()->cellFamily(), m_cell_connectivity->customConnectivity(),
false);
101inline void ParticleFamily::
104 _allocateInfos(particle, uid, m_particle_shared_info);
112_allocParticle(
Int64 uid,
bool& need_alloc)
117 ii->setUniqueId(uid);
119 _initializeNewlyAllocatedParticle(ii, uid);
122 ii->
setOwner(m_sub_domain_id, m_sub_domain_id);
130_findOrAllocParticle(
Int64 uid,
bool& is_alloc)
132 ItemInternal* ii = ItemFamily::_findOrAllocOne(uid, is_alloc);
134 _initializeNewlyAllocatedParticle(ii, uid);
144 _addItems(unique_ids, items);
156 addItems(unique_ids, owners, items);
166 m_cell_connectivity->replaceItem(particle, 0, cell);
177 _addItems(unique_ids, items);
179 for (
Integer i = 0; i < n; ++i) {
192 _setCell(particle, new_cell);
193 m_need_prepare_dump =
true;
204 for (
Integer i = 0, n = particle_ids.
size(); i < n; ++i)
206 m_need_prepare_dump =
true;
218 preAllocate(nb_item);
220 bool need_alloc =
false;
221 for (
Integer i = 0; i < nb_item; ++i) {
222 Int64 uid = unique_ids[i];
227 m_need_prepare_dump =
true;
228 _printInfos(nb_item);
235addItems(Int64ConstArrayView unique_ids, Int32ConstArrayView owners, Int32ArrayView items)
237 Integer nb_item = unique_ids.size();
240 preAllocate(nb_item);
242 if (!hasUniqueIdMap())
243 ARCANE_FATAL(
"Can not add particles with owners when hasUniqueIdMap()==false family={0}",
246 bool need_alloc =
false;
247 for (Integer i = 0; i < nb_item; ++i) {
248 Int64 uid = unique_ids[i];
249 ItemInternal* ii = _findOrAllocParticle(uid, need_alloc);
250 ii->setOwner(owners[i], m_sub_domain_id);
252 items[i] = ii->localId();
255 m_need_prepare_dump =
true;
256 _printInfos(nb_item);
284 ARCANE_UNUSED(nb_added);
293 ARCANE_UNUSED(keep_ghost);
304 auto network = m_mesh->itemFamilyNetwork();
306 std::set<Int32> remove_lids;
307 if (want_nullify_cell) {
308 for (
Integer i = 0, n = local_ids.
size(); i < n; ++i) {
310 m_cell_connectivity->replaceItem(lid, 0, null_item_lid);
311 remove_lids.insert(local_ids[i]);
314 for (
auto parent_connectivity : m_mesh->itemFamilyNetwork()->getParentConnectivities(
this)) {
316 for (
auto source_item : parent_connectivity->sourceFamily()->itemsInternal()) {
317 if (source_item->isSuppressed())
321 if (remove_lids.find(connected_item->localId()) != remove_lids.end()) {
322 parent_connectivity->removeConnectedItem(
ItemLocalId(source_item), connected_item);
329 if (want_nullify_cell) {
330 for (
Integer i = 0, n = local_ids.
size(); i < n; ++i) {
332 m_cell_connectivity->replaceItem(lid, 0, null_item_lid);
336 _removeMany(local_ids);
338 m_need_prepare_dump =
true;
347 internalRemoveItems(items_local_id,
false);
357 info(4) <<
"ParticleFamily::prepareForDump: " <<
name()
379 Integer nb_hash = itemsMap().nbBucket();
380 Integer wanted_size = 2 * (nb_item + nbItem());
381 if (nb_hash < wanted_size)
382 itemsMap().resize(wanted_size,
true);
389setHasUniqueIdMap(
bool v)
391 _setHasUniqueIdMap(v);
392 m_properties->setBool(
"no-unique-id-map", !v);
399hasUniqueIdMap()
const
401 return _infos().hasUniqueIdMap();
410 m_particle_shared_info = _findSharedInfo(m_particle_type_info);
417checkValidConnectivity()
426removeNeedRemoveMarkedItems()
432 ItemInternalMap& particle_map = itemsMap();
442 info() <<
"Number of particles of family " <<
name() <<
" to remove: " << lids_to_remove.
size();
443 if (lids_to_remove.
size() > 0)
444 removeParticles(lids_to_remove);
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Integer size() const
Number of elements in the vector.
constexpr Integer size() const noexcept
Returns the size of the array.
void add(ConstReferenceType val)
Adds element val to the end of the array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
Manages the retrieval of connectivity information.
ItemVectorView connectedItems(ItemLocalId item)
Returns the entities connected to item.
constexpr Integer size() const noexcept
Number of elements in the array.
Int32 flags() const
Flags of the entity.
Int32 localId() const
Local number (in the subdomain) of the entity.
Flags for entity characteristics.
@ II_NeedRemove
The entity must be removed.
Internal structure of a mesh entity.
Index of an Item in a variable.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
Base class for a mesh element.
impl::MutableItemBase mutableItemBase() const
Mutable internal part of the entity.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
impl::ItemBase itemBase() const
Internal part of the entity.
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.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
IMesh * mesh() const override
Associated mesh.
void prepareForDump() override
Prepares data for dumping.
void checkValidConnectivity() override
Verification of the validity of internal structures concerning connectivity.
ItemVectorView view(Int32ConstArrayView local_ids) override
View on the entities.
void notifyItemsOwnerChanged() override
Notifies that the entities specific to the family's subdomain have been modified.
void readFromDump() override
Reads data from a dump.
void eachItem(const Lambda &lambda)
Template function to iterate over the instance's entities.
Information for exchanging entities of a given family and their characteristics.
void readAndAllocItems() override
After receiving messages, reads and creates the transferred entities.
void readVariables() override
After receiving messages, reads the variable values.
void removeSentItems() override
Deletes the sent entities.
void computeExchangeItems() override
Determines the list of entities to exchange.
void processExchange() override
Sends the exchange messages.
bool computeExchangeInfos() override
Determines the necessary information for the exchanges.
void prepareToSend() override
Prepares the sending structures.
void readGroups() override
After receiving messages, reads the groups.
Integer nbItem() const override
Number of entities.
String name() const override
Family name.
void endUpdate() override
Notifies the end of modification of the entity list.
bool getEnableGhostItems() const override
Retrieves the flag to manage ghost particles for the family.
ItemVectorViewT< Cell > CellVectorView
View over a vector of cells.
ItemVectorViewT< Particle > ParticleVectorView
View over a vector of particles.
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.
ConstArrayView< Int64 > Int64ConstArrayView
C equivalent of a 1D array of 64-bit integers.
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
@ IK_Particle
Particle mesh entity.
InternalConnectivityPolicy
Connectivity usage policy.
@ Legacy
Historical connectivities.