Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
MeshMaterialMng.h
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/* MeshMaterialMng.h (C) 2000-2026 */
9/* */
10/* Implementation of material and environment modification. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_MATERIALS_INTERNAL_MESHMATERIALMNG_H
13#define ARCANE_MATERIALS_INTERNAL_MESHMATERIALMNG_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/Mutex.h"
20
21#include "arcane/core/MeshHandle.h"
22
23#include "arcane/core/materials/IMeshMaterialMng.h"
25#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
26
27#include "arcane/accelerator/core/Runner.h"
28#include "arcane/accelerator/core/RunQueuePool.h"
29
30#include "arcane/materials/MeshBlock.h"
31#include "arcane/materials/AllCellToAllEnvCellConverter.h"
32#include "arcane/materials/internal/MeshMaterial.h"
33#include "arcane/materials/internal/MeshEnvironment.h"
34#include "arcane/materials/internal/MeshMaterialSynchronizer.h"
35
36#include <map>
37#include <memory>
38#include <mutex>
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43namespace Arcane
44{
45class IVariableMng;
46class Properties;
47class ObserverPool;
48} // namespace Arcane
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53namespace Arcane::Materials
54{
55
56/*---------------------------------------------------------------------------*/
57/*---------------------------------------------------------------------------*/
58
62class MeshMaterialMng
63: public TraceAccessor
64, public IMeshMaterialMng
65{
66 public:
67
68 friend class MeshMaterialBackup;
69
70 private:
71
73 class RunnerInfo
74 {
75 public:
76
77 explicit RunnerInfo(Runner& runner);
78
79 public:
80
81 void initializeAsyncPool(Int32 nb_queue);
82
83 public:
84
85 RunQueue runQueue(Accelerator::eExecutionPolicy policy) const;
86
87 public:
88
89 Runner m_runner;
90 RunQueue m_run_queue;
91 Accelerator::RunQueuePool m_async_queue_pool;
92 Runner m_sequential_runner;
93 RunQueue m_sequential_run_queue;
94 Runner m_multi_thread_runner;
95 RunQueue m_multi_thread_run_queue;
96 };
97
98 class InternalApi
100 {
101 public:
102
103 explicit InternalApi(MeshMaterialMng* mm)
104 : m_material_mng(mm)
105 {}
106
107 public:
108
110 {
111 return m_material_mng->getAllCellToAllEnvCellContainer();
112 }
114 {
115 return m_material_mng->createAllCellToAllEnvCell();
116 }
118 {
119 return m_material_mng->_variablesIndexer();
120 }
122 {
123 return m_material_mng->_addVariable(var);
124 }
126 {
127 return m_material_mng->_removeVariable(var);
128 }
130 {
131 return m_material_mng->_modifier();
132 }
134 {
135 return m_material_mng->_allCellsMatEnvSynchronizer();
136 }
138 {
139 return m_material_mng->_allCellsEnvOnlySynchronizer();
140 }
141 ComponentItemSharedInfo* componentItemSharedInfo(Int32 level) const override
142 {
143 return m_material_mng->componentItemSharedInfo(level);
144 }
145 RunQueue& runQueue() const override
146 {
147 return m_material_mng->runQueue();
148 }
150 {
151 return m_material_mng->asyncRunQueuePool();
152 }
154 {
155 return m_material_mng->additionalCapacityRatio();
156 }
158 {
159 return m_material_mng->m_is_use_accelerator_for_constituent_item_vector;
160 }
162 {
163 return m_material_mng->m_runner_info->runQueue(policy);
164 }
166 {
167 return m_material_mng->identitySelectionView();
168 }
169
170 private:
171
172 MeshMaterialMng* m_material_mng = nullptr;
173 };
174
175 public:
176
177 MeshMaterialMng(const MeshHandle& mesh_handle, const String& name);
178 ~MeshMaterialMng() override;
179
180 public:
181
182 void build();
183
184 public:
185
186 IMesh* mesh() override { return m_mesh_handle.mesh(); }
188
189 public:
190
193 IMeshBlock* createBlock(const MeshBlockBuildInfo& infos) override;
194 void addEnvironmentToBlock(IMeshBlock* block, IMeshEnvironment* env) override;
195 void removeEnvironmentToBlock(IMeshBlock* block, IMeshEnvironment* env) override;
196
197 void endCreate(bool is_continue) override;
198
199 void setDataInitialisationWithZero(bool v) override { m_is_data_initialisation_with_zero = v; }
200 bool isDataInitialisationWithZero() const override { return m_is_data_initialisation_with_zero; }
201
202 void setKeepValuesAfterChange(bool v) override { m_keep_values_after_change = v; }
203 bool isKeepValuesAfterChange() const override { return m_keep_values_after_change; }
204
205 void setMeshModificationNotified(bool v) override { m_is_mesh_modification_notified = v; }
206 bool isMeshModificationNotified() const override { return m_is_mesh_modification_notified; }
207
208 void setModificationFlags(int v) override;
209 int modificationFlags() const override { return m_modification_flags; }
210
213 {
214 return m_is_allocate_scalar_environment_variable_as_material;
215 }
216
217 void setDataCompressorServiceName(const String& name) override;
218 String dataCompressorServiceName() const override { return m_data_compressor_service_name; }
219
220 String name() const override { return m_name; }
221 ConstArrayView<IMeshMaterial*> materials() const override { return m_materials; }
222 ConstArrayView<IMeshComponent*> materialsAsComponents() const override { return m_materials_as_components; }
223 ConstArrayView<IMeshEnvironment*> environments() const override { return m_environments; }
224 ConstArrayView<IMeshComponent*> environmentsAsComponents() const override { return m_environments_as_components; }
225 ConstArrayView<IMeshComponent*> components() const override { return m_components; }
226 ConstArrayView<IMeshBlock*> blocks() const override { return m_blocks; }
227
228 IMeshEnvironment* findEnvironment(const String& name, bool throw_exception = true) override;
229 IMeshBlock* findBlock(const String& name, bool throw_exception = true) override;
230
232
234 IMeshMaterialVariable* checkVariable(IVariable* global_var) override;
235
236 void dumpInfos(std::ostream& o) override;
237 void dumpCellInfos(Cell cell, std::ostream& o) override;
238
239 void checkValid() override;
240
241 void forceRecompute() override;
242
243 Mutex* variableLock() override
244 {
245 return &m_variable_lock;
246 }
247
248 bool synchronizeMaterialsInCells() override;
249 void checkMaterialsInCells(Integer max_print) override;
250
251 Int64 timestamp() const override { return m_timestamp; }
252
253 ConstArrayView<MeshEnvironment*> trueEnvironments() const { return m_true_environments; }
254 ConstArrayView<MeshMaterial*> trueMaterials() const { return m_true_materials; }
255 Int32 nbVariable() const { return static_cast<Int32>(m_full_name_variable_map.size()); }
256
257 public:
258
259 AllEnvCellVectorView _view(SmallSpan<const Int32> cells_local_id);
260
262 {
263 return this->_view(cells.view().localIds());
264 }
265
267 {
268 return this->_view(cells.localIds());
269 }
270
272 {
273 return this->_view(cells_local_id);
274 }
275
277
278 void recreateFromDump() override;
279
281
283 {
284 m_synchronize_variable_version = version;
285 }
286
288 {
289 return m_synchronize_variable_version;
290 }
291
292 bool isInMeshMaterialExchange() const override;
293
295 {
296 return m_variable_factory_mng;
297 }
298
300 {
301 m_is_use_material_value_when_removing_partial_value = v;
302 }
303 bool isUseMaterialValueWhenRemovingPartialValue() const override
304 {
305 return m_is_use_material_value_when_removing_partial_value;
306 }
307
308 public:
309
310 AllEnvData* allEnvData() { return m_all_env_data.get(); }
311 ComponentItemSharedInfo* componentItemSharedInfo(Int32 level) const;
312 void syncVariablesReferences(bool check_resize);
313
314 void incrementTimestamp() { ++m_timestamp; }
315 void dumpInfos2(std::ostream& o);
316
317 const MeshHandle& meshHandle() const { return m_mesh_handle; }
318
319 void enableCellToAllEnvCellForRunCommand(bool is_enable, bool force_create = false) override
320 {
321 m_is_use_accelerator_envcell_container = is_enable;
322 if (force_create)
323 createAllCellToAllEnvCell();
324 }
325 bool isCellToAllEnvCellForRunCommand() const override { return m_is_use_accelerator_envcell_container; }
326
327 IMeshMaterialMngInternal* _internalApi() const override { return m_internal_api.get(); }
328
329 public:
330
332 Runner& runner() const { return m_runner_info->m_runner; }
333 RunQueue& runQueue() const { return m_runner_info->m_run_queue; }
334 Accelerator::RunQueuePool& asyncRunQueuePool() const { return m_runner_info->m_async_queue_pool; }
335 Real additionalCapacityRatio() const { return m_additional_capacity_ratio; }
336 SmallSpan<const Int32> identitySelectionView();
338
339 private:
340
341 AllCellToAllEnvCellContainer* getAllCellToAllEnvCellContainer() const { return m_accelerator_envcell_container.get(); }
342 void createAllCellToAllEnvCell();
343
344 private:
345
347 using FullNameVariableMap = std::map<String, IMeshMaterialVariable*>;
349 using FullNameVariablePair = FullNameVariableMap::value_type;
350
351 using VariableToMaterialVariableMap = std::map<IVariable*, IMeshMaterialVariable*>;
352 using VariableToMaterialVariablePair = VariableToMaterialVariableMap::value_type;
353
354 private:
355
356 MeshHandle m_mesh_handle;
357 std::unique_ptr<InternalApi> m_internal_api;
358 IVariableMng* m_variable_mng = nullptr;
359 String m_name;
360 bool m_is_end_create = false;
361 bool m_is_verbose = false;
362 bool m_keep_values_after_change = true;
363 bool m_is_data_initialisation_with_zero = false;
364 bool m_is_mesh_modification_notified = false;
365 bool m_is_allocate_scalar_environment_variable_as_material = false;
366 bool m_is_use_material_value_when_removing_partial_value = false;
367 int m_modification_flags = 0;
368 Real m_additional_capacity_ratio = 0.05;
369
370 Mutex m_variable_lock;
371
372 std::unique_ptr<MeshMaterialModifierImpl> m_modifier;
373 UniqueArray<MeshMaterialInfo*> m_materials_info;
374 UniqueArray<IMeshMaterial*> m_materials;
375 UniqueArray<IMeshComponent*> m_materials_as_components;
376 UniqueArray<MeshMaterial*> m_true_materials;
377 UniqueArray<IMeshEnvironment*> m_environments;
378 UniqueArray<IMeshComponent*> m_environments_as_components;
379 UniqueArray<IMeshComponent*> m_components;
380 UniqueArray<MeshEnvironment*> m_true_environments;
382 UniqueArray<MeshBlock*> m_true_blocks;
384 UniqueArray<MeshMaterialVariableIndexer*> m_variables_indexer_to_destroy;
385
386 FullNameVariableMap m_full_name_variable_map;
387 VariableToMaterialVariableMap m_var_to_mat_var_map;
388
389 std::unique_ptr<Properties> m_properties;
390 std::unique_ptr<AllEnvData> m_all_env_data;
392 std::unique_ptr<IMeshMaterialVariableSynchronizer> m_all_cells_mat_env_synchronizer;
393 std::unique_ptr<IMeshMaterialVariableSynchronizer> m_all_cells_env_only_synchronizer;
394 Integer m_synchronize_variable_version = 1;
395 std::unique_ptr<MeshMaterialExchangeMng> m_exchange_mng;
396 IMeshMaterialVariableFactoryMng* m_variable_factory_mng = nullptr;
397 std::unique_ptr<ObserverPool> m_observer_pool;
398 String m_data_compressor_service_name;
399 MeshMaterialSynchronizer* m_mms = nullptr;
400
401 std::unique_ptr<RunnerInfo> m_runner_info;
402
404 std::unique_ptr<AllCellToAllEnvCellContainer> m_accelerator_envcell_container;
405 bool m_is_use_accelerator_envcell_container = false;
406
407 bool m_is_use_accelerator_for_constituent_item_vector = true;
408
411 std::mutex m_indexed_selection_identity_mutex;
412
413 private:
414
415 void _endUpdate();
416 IMeshMaterialVariable* _findVariableFullyQualified(const String& name);
417 MeshMaterialInfo* _findMaterialInfo(const String& name);
418 MeshEnvironment* _findEnvironment(const String& name);
419 MeshBlock* _findBlock(const String& name);
421 void _addVariableIndexer(MeshMaterialVariableIndexer* var_idx);
422 void _checkEndCreate();
423 void _addVariableUnlocked(IMeshMaterialVariable* var);
424 void _saveInfosInProperties();
425 void _checkCreateProperties();
426 void _onMeshDestroyed();
427 void _unregisterAllVariables();
428 void _addVariable(IMeshMaterialVariable* var);
429 void _removeVariable(IMeshMaterialVariable* var);
430 MeshMaterialModifierImpl* _modifier();
432 {
433 return m_variables_indexer;
434 }
436 {
437 return m_all_cells_mat_env_synchronizer.get();
438 }
440 {
441 return m_all_cells_env_only_synchronizer.get();
442 }
443 void _dumpStats();
444};
445
446/*---------------------------------------------------------------------------*/
447/*---------------------------------------------------------------------------*/
448
449} // End namespace Arcane::Materials
450
451/*---------------------------------------------------------------------------*/
452/*---------------------------------------------------------------------------*/
453
454#endif
Base class for 1D data vectors.
Cell of a mesh.
Definition Item.h:1300
Constant view of an array of type T.
Interface of a functor with an argument but without a return value.
Variable manager interface.
Interface of a variable.
Definition IVariable.h:40
Connectivity table of 'Cell' to its 'AllEnvCell' intended for use on accelerator.
View over a list of cells with environment information.
Information on environment values.
Definition AllEnvData.h:45
Internal Arcane API for 'IMeshMaterialMng'.
Interface for the material and environment manager of a mesh.
Interface of the material variable factory manager.
Interface of a material variable on a mesh.
Brief: Information for the creation of a block.
Information for creating an environment.
Info about a material of a mesh.
bool isUseAcceleratorForConstituentItemVector() const override
Indicates whether the accelerator API is used to position the values of ConstituentItemVectorImpl.
Real additionalCapacityRatio() const override
Ratio for additional capacity to allocate when resizing variables.
RunQueue runQueue(Accelerator::eExecutionPolicy policy) const override
Run queue for the policy.
SmallSpan< const Int32 > identitySelectionView() const override
View of the array corresponding to a selection across all entities.
ComponentItemSharedInfo * componentItemSharedInfo(Int32 level) const override
ComponentItemSharedInfo instance for a constituent.
MeshMaterialModifierImpl * modifier() override
Modifier implementation.
IMeshMaterialVariableSynchronizer * allCellsEnvOnlySynchronizer() override
Synchronizer for medium-only variables across all cells.
void removeVariable(IMeshMaterialVariable *var) override
Removes the variable var.
AllCellToAllEnvCellContainer * getAllCellToAllEnvCellContainer() const override
Returns the "connectivity" table CellLocalId -> AllEnvCell intended to be used in a RUNCOMMAND_ENUMER...
void createAllCellToAllEnvCell() override
Constructs the "connectivity" table CellLocalId -> AllEnvCell intended to be used in a RUNCOMMAND_ENU...
void addVariable(IMeshMaterialVariable *var) override
Adds the variable var.
RunQueue & runQueue() const override
Default run queue.
Accelerator::RunQueuePool & asyncRunQueuePool() const override
List of asynchronous queues.
IMeshMaterialVariableSynchronizer * allCellsMatEnvSynchronizer() override
Synchronizer for material and medium variables across all cells.
ConstArrayView< MeshMaterialVariableIndexer * > variablesIndexer() override
List of information to index material variables.
Implementation of a material manager.
bool isInMeshMaterialExchange() const override
True if a mesh exchange with material management is underway.
void removeEnvironmentToBlock(IMeshBlock *block, IMeshEnvironment *env) override
Removes an environment from an existing block.
IMeshMaterialVariableFactoryMng * variableFactoryMng() const override
Interface of the variable factory.
String dataCompressorServiceName() const override
Virtual name of the service used to compress data.
std::map< String, IMeshMaterialVariable * > FullNameVariableMap
Type of the list of variables by full name.
AllEnvCellVectorView view(const CellGroup &cells) final
View of environment cells corresponding to the group cells.
Int64 m_timestamp
Counter for the number of material modifications.
void setDataCompressorServiceName(const String &name) override
Name of the service used to compress data during forceRecompute().
void visitVariables(IFunctorWithArgumentT< IMeshMaterialVariable * > *functor) override
Applies the functor functor to all material variables.
void endCreate(bool is_continue) override
Indicates that environment creation is finished.
IMeshBlock * createBlock(const MeshBlockBuildInfo &infos) override
Creates a block.
Integer synchronizeVariableVersion() const override
Version of the implementation for synchronizing material variables.
bool isKeepValuesAfterChange() const override
Indicates if variable values are preserved between modifications.
ITraceMng * traceMng() override
Trace manager.
FullNameVariableMap::value_type FullNameVariablePair
Pair of the list of variables by full name.
Int64 timestamp() const override
Counter for the number of modifications of the material list and environments.
IMesh * mesh() override
Associated mesh.
IMeshMaterialVariableSynchronizer * _allCellsEnvOnlySynchronizer() override
Synchronizer for environment-only variables on all cells.
CellToAllEnvCellConverter cellToAllEnvCellConverter() override
Creates an instance to convert from 'Cell' to 'AllEnvCell'.
void addEnvironmentToBlock(IMeshBlock *block, IMeshEnvironment *env) override
Adds an environment to an existing block.
void dumpInfos(std::ostream &o) override
Writes the material and environment info to the stream o.
IMeshMaterialVariableSynchronizer * _allCellsMatEnvSynchronizer() override
Synchronizer for material and environment variables on all cells.
MeshMaterialInfo * registerMaterialInfo(const String &name) override
Registers the material info with name name.
void setMeshModificationNotified(bool v) override
Indicates if environments and materials follow changes in the mesh topology.
ConstArrayView< IMeshComponent * > components() const override
List of all components.
void setAllocateScalarEnvironmentVariableAsMaterial(bool v) override
Sets the option indicating whether scalar variables of environments are allocated on materials.
ConstArrayView< IMeshMaterial * > materials() const override
List of materials.
IMeshEnvironment * createEnvironment(const MeshEnvironmentBuildInfo &infos) override
Creation of an environment.
void recreateFromDump() override
Recreates the material and environment info from the dump info.
void enableCellToAllEnvCellForRunCommand(bool is_enable, bool force_create=false) override
Activates or deactivates the construction and update of the table of "connectivity" CellLocalId -> Al...
int modificationFlags() const override
Flags to parameterize modifications.
void fillWithUsedVariables(Array< IMeshMaterialVariable * > &variables) override
Fills the array variables with the list of used material variables.
ConstArrayView< IMeshComponent * > environmentsAsComponents() const override
List of environments viewed as components.
ConstArrayView< IMeshEnvironment * > environments() const override
List of environments.
IMeshMaterialVariable * checkVariable(IVariable *global_var) override
Material variable associated with the global variable global_var (nullptr if none).
void forceRecompute() override
Forces the recalculation of material information.
void _endUpdate()
Updates the structures following a modification of material or environment cells.
void setDataInitialisationWithZero(bool v) override
Indicates how to initialize new values in material and environment cells.
void setKeepValuesAfterChange(bool v) override
Sets the saving of values between two modifications of the materials.
AllEnvCellVectorView view(CellVectorView cells) final
View of environment cells corresponding to the group cells.
bool isMeshModificationNotified() const override
Indicates if environments and materials follow changes in the mesh topology.
IMeshMaterialMngInternal * _internalApi() const override
Internal API for Arcane.
void checkMaterialsInCells(Integer max_print) override
Checks that material cells are consistent between subdomains.
IMeshEnvironment * findEnvironment(const String &name, bool throw_exception=true) override
Returns the environment with name name.
bool isDataInitialisationWithZero() const override
Indicates how to initialize new values in material and environment cells.
Mutex * variableLock() override
Lock used for multi-threading.
void setSynchronizeVariableVersion(Integer version) override
Sets the version of the implementation for synchronizing material variables.
bool synchronizeMaterialsInCells() override
Synchronizes material cells.
ConstArrayView< IMeshComponent * > materialsAsComponents() const override
List of materials viewed as components.
IMeshMaterialVariable * findVariable(const String &name) override
Variable with name name or nullptr if none of this name exists.
void setUseMaterialValueWhenRemovingPartialValue(bool v) override
Indicates whether the material or environment value is used when transforming a cell from a partial c...
void dumpCellInfos(Cell cell, std::ostream &o) override
Writes the cell info cell to the stream o.
std::unique_ptr< AllCellToAllEnvCellContainer > m_accelerator_envcell_container
Container for AllEnvCellToAllEnvCell for accelerator.
ConstArrayView< IMeshBlock * > blocks() const override
List of blocks.
void checkValid() override
Checks the validity of internal structures.
void syncVariablesReferences(bool check_resize)
Updates the variable references.
MeshMaterial * _createMaterial(MeshEnvironment *env, MeshMaterialInfo *infos, const String &name)
Creation of a material.
AllEnvCellVectorView view(SmallSpan< const Int32 > cells_local_id) final
View of environment cells corresponding to local cell IDs cells_local_id.
bool isAllocateScalarEnvironmentVariableAsMaterial() const override
Indicates if environment scalar variables are allocated on materials.
String name() const override
Manager name.
UniqueArray< Int32 > m_indexed_selection_identity
Identity array for selection.
IMeshBlock * findBlock(const String &name, bool throw_exception=true) override
Returns the block with name name.
void setModificationFlags(int v) override
Sets the flags to parameterize material/environment modifications.
Synchronization of the list of materials/media of entities.
Handle on a mesh.
Definition MeshHandle.h:48
List of observers.
List of properties.
Definition Properties.h:65
View of an array of elements of type T.
Definition Span.h:805
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
ITraceMng * traceMng() const
Trace manager.
1D data vector with value semantics (STL style).
ItemGroupT< Cell > CellGroup
Group of cells.
Definition ItemTypes.h:184
ItemVectorViewT< Cell > CellVectorView
View over a vector of cells.
Definition ItemTypes.h:305
eExecutionPolicy
Execution policy for a Runner.
Always enables tracing in Arcane parts concerning materials.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.