14#include "arcane/materials/internal/MeshMaterialMng.h"
16#include "arcane/utils/TraceAccessor.h"
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/AutoDestroyUserData.h"
19#include "arcane/utils/IUserDataList.h"
20#include "arcane/utils/OStringStream.h"
21#include "arcane/utils/PlatformUtils.h"
22#include "arcane/utils/ValueConvert.h"
23#include "arcane/utils/CheckedConvert.h"
26#include "arcane/core/IMesh.h"
27#include "arcane/core/IItemFamily.h"
28#include "arcane/core/VariableTypes.h"
29#include "arcane/core/ItemPrinter.h"
30#include "arcane/core/IVariableMng.h"
31#include "arcane/core/Properties.h"
32#include "arcane/core/ObserverPool.h"
33#include "arcane/core/materials/IMeshMaterialVariableFactoryMng.h"
34#include "arcane/core/materials/IMeshMaterialVariable.h"
36#include "arcane/core/materials/internal/IMeshMaterialVariableInternal.h"
37#include "arcane/core/internal/IVariableMngInternal.h"
39#include "arcane/accelerator/core/IAcceleratorMng.h"
41#include "arcane/materials/MeshMaterialInfo.h"
42#include "arcane/materials/MeshEnvironmentBuildInfo.h"
43#include "arcane/materials/CellToAllEnvCellConverter.h"
44#include "arcane/materials/MeshMaterialExchangeMng.h"
45#include "arcane/materials/EnumeratorTracer.h"
46#include "arcane/materials/MeshMaterialVariableFactoryRegisterer.h"
47#include "arcane/materials/internal/AllEnvData.h"
48#include "arcane/materials/internal/MeshMaterialModifierImpl.h"
49#include "arcane/materials/internal/MeshMaterialSynchronizer.h"
50#include "arcane/materials/internal/MeshMaterialVariableSynchronizer.h"
51#include "arcane/materials/internal/ConstituentConnectivityList.h"
52#include "arcane/materials/internal/AllCellToAllEnvCellContainer.h"
88 arcaneCreateMeshMaterialMng(
const MeshHandle& mesh_handle,
const String& name)
101MeshMaterialMng::RunnerInfo::
102RunnerInfo(Runner& runner)
106, m_sequential_run_queue(
makeQueue(m_sequential_runner))
108, m_multi_thread_run_queue(
makeQueue(m_multi_thread_runner))
115void MeshMaterialMng::RunnerInfo::
116initializeAsyncPool(Int32 nb_queue)
122 m_async_queue_pool.initialize(m_runner, nb_queue);
124 m_async_queue_pool.setAsync(
true);
130RunQueue MeshMaterialMng::RunnerInfo::
131runQueue(Accelerator::eExecutionPolicy policy)
const
133 if (policy == Accelerator::eExecutionPolicy::None)
135 if (policy == Accelerator::eExecutionPolicy::Sequential)
136 return m_sequential_run_queue;
137 if (policy == Accelerator::eExecutionPolicy::Thread)
138 return m_multi_thread_run_queue;
139 ARCANE_FATAL(
"Invalid value '{0}' for execution policy. Valid values are None, Sequential or Thread", policy);
149MeshMaterialMng(
const MeshHandle& mesh_handle,
const String& name)
151: TraceAccessor(mesh_handle.traceMng())
152, m_mesh_handle(mesh_handle)
153, m_internal_api(std::make_unique<InternalApi>(this))
154, m_variable_mng(mesh_handle.variableMng())
158 m_all_env_data = std::make_unique<AllEnvData>(
this);
159 m_exchange_mng = std::make_unique<MeshMaterialExchangeMng>(
this);
160 m_variable_factory_mng = arcaneCreateMeshMaterialVariableFactoryMng(
this);
161 m_observer_pool = std::make_unique<ObserverPool>();
162 m_observer_pool->addObserver(
this, &MeshMaterialMng::_onMeshDestroyed, mesh_handle.onDestroyObservable());
164 String s = platform::getEnvironmentVariable(
"ARCANE_ALLENVCELL_FOR_RUNCOMMAND");
166 m_is_use_accelerator_envcell_container =
true;
167 m_mms =
new MeshMaterialSynchronizer(
this);
180 delete m_variable_factory_mng;
181 m_exchange_mng.reset();
182 m_all_cells_env_only_synchronizer.reset();
183 m_all_cells_mat_env_synchronizer.reset();
184 m_all_env_data.reset();
185 m_properties.reset();
187 for (MeshMaterial* m : m_true_materials)
189 m_true_materials.clear();
191 for (MeshEnvironment* e : m_true_environments)
193 m_true_environments.clear();
195 for (IMeshBlock* b : m_true_blocks)
198 for (MeshMaterialInfo* mmi : m_materials_info)
201 for (MeshMaterialVariableIndexer* mvi : m_variables_indexer_to_destroy)
205 m_internal_api.reset();
207 m_accelerator_envcell_container.reset();
211 m_runner_info.reset();
220void MeshMaterialMng::
225 auto* x = MeshMaterialVariableFactoryRegisterer::firstRegisterer();
227 m_variable_factory_mng->registerFactory(x->createFactory());
228 x = x->nextRegisterer();
235 bool force_enable =
false;
236 if (
const auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_ACCELERATOR_FOR_CONSTITUENTITEMVECTOR",
true)) {
237 m_is_use_accelerator_for_constituent_item_vector = (v.value() != 0);
238 force_enable = m_is_use_accelerator_for_constituent_item_vector;
244 if (!force_enable && TaskFactory::isActive())
245 m_is_use_accelerator_for_constituent_item_vector =
false;
246 info() <<
"Use accelerator API for 'ConstituentItemVectorImpl' = " << m_is_use_accelerator_for_constituent_item_vector;
251 IAcceleratorMng* acc_mng = m_variable_mng->_internalApi()->acceleratorMng();
254 Runner* default_runner = acc_mng->defaultRunner();
256 bool use_accelerator_runner =
true;
257 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_QUEUE",
true))
258 use_accelerator_runner = (v.value() != 0);
259 if (use_accelerator_runner && default_runner)
260 runner = *default_runner;
263 if (!runner.isInitialized())
264 runner.initialize(Accelerator::eExecutionPolicy::Sequential);
265 m_runner_info = std::make_unique<RunnerInfo>(runner);
267 info() <<
"Use runner '" << this->runner().executionPolicy() <<
"' for MeshMaterialMng name=" << name()
268 <<
" async_queue_size=" << nb_queue;
269 m_runner_info->initializeAsyncPool(nb_queue);
276 RunQueue& q = runQueue();
278 q.setMemoryRessource(eMemoryRessource::Device);
283 int default_flags = 0;
289 int opt_flag_value = 0;
290 String env_name =
"ARCANE_MATERIAL_MODIFICATION_FLAGS";
291 String opt_flag_str = platform::getEnvironmentVariable(env_name);
292 if (!opt_flag_str.null()) {
293 if (builtInGetValue(opt_flag_value, opt_flag_str)) {
294 pwarning() <<
"Invalid value '" << opt_flag_str
295 <<
" 'for environment variable '" << env_name
297 opt_flag_value = default_flags;
301 opt_flag_value = default_flags;
303 m_modification_flags = opt_flag_value;
308 String env_name =
"ARCANE_MATSYNCHRONIZE_VERSION";
309 String env_value = platform::getEnvironmentVariable(env_name);
310 info() <<
"ENV_VALUE=" << env_value;
311 Integer version = m_synchronize_variable_version;
312 if (!env_value.null()) {
313 if (builtInGetValue(version, env_value)) {
314 pwarning() <<
"Invalid value '" << env_value
315 <<
" 'for environment variable '" << env_name
319 m_synchronize_variable_version = version;
321 info() <<
"Set material variable synchronize version to "
322 <<
"'" << m_synchronize_variable_version <<
"'";
327 String env_name =
"ARCANE_MATERIAL_DATA_COMPRESSOR_NAME";
328 String env_value = platform::getEnvironmentVariable(env_name);
329 if (!env_value.null()) {
330 info() <<
"Use service '" << env_value <<
"' for material data compression";
331 m_data_compressor_service_name = env_value;
337 if (
auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_ADDITIONAL_CAPACITY_RATIO",
true)) {
339 m_additional_capacity_ratio = v.value();
340 info() <<
"Set additional capacity ratio to " << m_additional_capacity_ratio;
345 m_exchange_mng->build();
350 IItemEnumeratorTracer* item_tracer = IItemEnumeratorTracer::singleton();
352 info() <<
"Adding material enumerator tracing";
353 EnumeratorTracer::_setSingleton(
new EnumeratorTracer(traceMng(), item_tracer->perfCounterRef()));
360void MeshMaterialMng::
361_addVariableIndexer(MeshMaterialVariableIndexer* var_idx)
363 var_idx->setIndex(m_variables_indexer.size());
364 m_variables_indexer.add(var_idx);
381 ARCANE_FATAL(
"Invalid materialMng() for material info");
384 Integer var_index = m_variables_indexer.size();
385 Int16 mat_id = CheckedConvert::toInt16(m_materials.size());
387 info() <<
"Create material name=" <<
name <<
"mat_id=" << mat_id <<
" var_index=" << var_index;
389 m_materials.add(mat);
390 m_materials_as_components.add(mat);
391 m_true_materials.add(mat);
393 _addVariableIndexer(mat->variableIndexer());
410 m_materials_info.add(mmi);
427 Int16 env_index = CheckedConvert::toInt16(m_environments.size());
432 ARCANE_FATAL(
"An environment named '{0}' is already registered", env_name);
434 info() <<
"Creating environment name=" << env_name <<
" index=" << env_index;
438 m_true_environments.add(me);
439 m_environments.add(me);
440 m_environments_as_components.add(me);
445 for (
Integer i = 0; i < nb_mat; ++i) {
447 const String& mat_name = buildinfo.m_name;
448 String new_mat_name = env_name +
"_" + mat_name;
451 ARCANE_FATAL(
"No material named '{0}' is defined", mat_name);
455 mat_info->_addEnvironment(env_name);
463 var_idx = me->
materials()[0]->_internalApi()->variableIndexer();
467 _addVariableIndexer(var_idx);
468 m_variables_indexer_to_destroy.add(var_idx);
470 me->setVariableIndexer(var_idx);
483 Int32 block_index = m_blocks.size();
490 info() <<
"Creating block name=" <<
name <<
" index=" << block_index
493 for (
Integer i = 0; i < nb_env; ++i)
494 info() <<
" Adding environment name=" << infos.
environments()[i]->name() <<
" to block";
499 m_true_blocks.add(mb);
508void MeshMaterialMng::
518void MeshMaterialMng::
528void MeshMaterialMng::
529endCreate(
bool is_continue)
534 _saveInfosInProperties();
536 info() <<
"END CREATE MATERIAL_MNG is_continue=" << is_continue;
538 m_modifier = std::make_unique<MeshMaterialModifierImpl>(
this);
539 m_modifier->initOptimizationFlags();
541 m_all_env_data->endCreate(is_continue);
543 auto synchronizer =
mesh()->cellFamily()->allItemsSynchronizer();
545 m_all_cells_env_only_synchronizer = std::make_unique<MeshMaterialVariableSynchronizer>(
this, synchronizer,
MatVarSpace::Environment);
549 Integer nb_component = m_environments_as_components.size() + m_materials_as_components.size();
550 m_components.reserve(nb_component);
551 m_components.addRange(m_environments_as_components);
552 m_components.addRange(m_materials_as_components);
557 for (
const auto& i : m_full_name_variable_map) {
559 info(4) <<
"BUILD FROM MANAGER name=" << mv->
name() <<
" this=" <<
this;
564 m_is_end_create =
true;
578 m_exchange_mng->registerFactory();
584void MeshMaterialMng::
585setModificationFlags(
int v)
588 m_modification_flags = v;
589 info() <<
"Setting ModificationFlags to v=" << v;
595void MeshMaterialMng::
596setAllocateScalarEnvironmentVariableAsMaterial(
bool v)
599 m_is_allocate_scalar_environment_variable_as_material = v;
600 info() <<
"Setting AllocateScalarEnvironmentVariableAsMaterial to v=" << v;
606void MeshMaterialMng::
607setDataCompressorServiceName(
const String&
name)
609 m_data_compressor_service_name =
name;
618 return m_modifier.get();
625_findMaterialInfo(
const String& name)
628 if (mmi->name() == name)
637findEnvironment(
const String&
name,
bool throw_exception)
651_findEnvironment(
const String& name)
654 if (env->name() == name)
663findBlock(
const String&
name,
bool throw_exception)
677_findBlock(
const String& name)
680 if (b->name() == name)
688void MeshMaterialMng::
701void MeshMaterialMng::
704 m_all_env_data->forceRecompute(
true);
717void MeshMaterialMng::
718syncVariablesReferences(
bool check_resize)
720 for (
const auto& i : m_full_name_variable_map) {
722 info(4) <<
"SYNC REFERENCES FROM MANAGER name=" << mv->
name();
730void MeshMaterialMng::
735 for (
const auto& i : m_full_name_variable_map) {
737 functor->executeFunctor(mv);
744void MeshMaterialMng::
749 ConstArrayView<Int16> nb_env_per_cell = m_all_env_data->componentConnectivityList()->cellsNbEnvironment();
755 if (all_env_cell.
level() != LEVEL_ALLENVIRONMENT)
759 ARCANE_FATAL(
"Bad corresponding globalCell() in all_env_item");
760 if (cell_nb_env != nb_env_per_cell[cell.
localId()])
761 ARCANE_FATAL(
"Bad value for nb_env direct='{0}' var='{1}'",
762 cell_nb_env, nb_env_per_cell[cell.
localId()]);
763 for (
Integer z = 0; z < cell_nb_env; ++z) {
765 Integer cell_nb_mat = ec.nbMaterial();
768 ARCANE_FATAL(
"Bad corresponding allEnvItem() in env_item uid={0}", cell_uid);
770 ARCANE_FATAL(
"Bad corresponding globalItem() in env_item");
771 if (eii.level() != LEVEL_ENVIRONMENT)
772 ARCANE_FATAL(
"Bad level '{0}' for in env_item", eii.level());
776 ARCANE_FATAL(
"Global index for a partial cell env_item={0}", ec);
778 for (
Integer k = 0; k < cell_nb_mat; ++k) {
782 ARCANE_FATAL(
"Bad corresponding env_item in mat_item k={0} mc={1}", k, mc);
784 ARCANE_FATAL(
"Bad corresponding globalItem() in mat_item");
785 if (mci.level() != LEVEL_MATERIAL)
786 ARCANE_FATAL(
"Bad level '{0}' for in mat_item", mci.level());
790 ARCANE_FATAL(
"Global index for a partial cell matitem={0} name={1} nb_mat={2} nb_env={3}",
817 v = _findVariableFullyQualified(global_var->
fullName());
829_findVariableFullyQualified(
const String& name)
831 auto i = m_full_name_variable_map.find(name);
832 if (i != m_full_name_variable_map.end())
843 auto i = m_var_to_mat_var_map.find(global_var);
844 if (i != m_var_to_mat_var_map.end())
852void MeshMaterialMng::
859 for (
const auto& i : m_full_name_variable_map) {
869void MeshMaterialMng::
874 info(4) <<
"MAT_ADD_VAR global_var=" << gvar <<
" var=" << var <<
" this=" <<
this;
875 m_var_to_mat_var_map.insert(std::make_pair(gvar, var));
876 m_full_name_variable_map.insert(std::make_pair(gvar->
fullName(), var));
882void MeshMaterialMng::
887 info(4) <<
"MAT:Remove variable global_var=" << gvar <<
" var=" << var;
888 m_var_to_mat_var_map.erase(gvar);
889 m_full_name_variable_map.erase(gvar->
fullName());
895void MeshMaterialMng::
896dumpInfos(std::ostream& o)
898 Integer nb_mat = m_materials.size();
899 Integer nb_env = m_environments.size();
900 Integer nb_var_idx = m_variables_indexer.size();
901 o <<
"-- Infos sur les milieux et matériaux\n";
902 o <<
"-- Nb Materiaux: " << nb_mat <<
'\n';
903 o <<
"-- Nb Milieux: " << nb_env <<
'\n';
904 o <<
"-- Nb Variables partielles: " << nb_var_idx <<
'\n';
906 o <<
"-- Liste des matériaux\n";
908 o <<
"-- Materiau name=" << mat->name() <<
'\n';
911 o <<
"-- Liste des milieux\n";
916 o <<
"-- Milieu name=" << me->name()
917 <<
" nb_mat=" << nb_env_mat
918 <<
" nb_cell=" << me->cells().size()
919 <<
" var_idx = " << env_var_idx->index()
920 <<
" ids=" << env_var_idx->matvarIndexes()
924 o <<
"-- Materiau\n";
925 o <<
"-- name = " << mm->
name() <<
"\n";
926 o <<
"-- nb_cell = " << mm->cells().size() <<
"\n";
927 o <<
"-- var_idx = " << idx->index() <<
"\n";
936void MeshMaterialMng::
937dumpInfos2(std::ostream& o)
941 Integer nb_mat = m_materials.size();
942 Integer nb_env = m_environments.size();
943 Integer nb_var_idx = m_variables_indexer.size();
944 o <<
"-- Material and Environment infos: nb_env=" << nb_env
945 <<
" nb_mat=" << nb_mat <<
" timestamp=" << m_timestamp
946 <<
" nb_var_idx=" << nb_var_idx
952 if (nb_env_per_cell[icell.localId()] <= 1)
955 o <<
" nb_cell=" << nb_cell <<
" nb_pure_env=" << nb_pure_env
956 <<
" nb_partial=" << (nb_cell - nb_pure_env)
957 <<
" percent=" << (100 * nb_pure_env) / nb_cell
961 o <<
"-- Liste des milieux\n";
962 for (MeshEnvironment* me : m_true_environments) {
963 ConstArrayView<IMeshMaterial*> env_materials = me->materials();
964 const MeshMaterialVariableIndexer* env_var_idx = me->variableIndexer();
965 const Int16 env_id = me->componentId();
966 Integer nb_env_mat = env_materials.size();
967 Integer nb_env_cell = me->cells().size();
968 Integer nb_pure_mat = 0;
969 if (nb_env_mat > 1) {
976 nb_pure_mat = nb_env_cell;
977 o <<
"-- Env name=" << me->name()
978 <<
" nb_mat=" << nb_env_mat
979 <<
" var_idx=" << env_var_idx->index()
980 <<
" nb_cell=" << nb_env_cell
981 <<
" nb_pure_mat=" << nb_pure_mat;
982 if (nb_env_cell != 0)
983 o <<
" percent=" << (nb_pure_mat * 100) / nb_env_cell;
985 for (Integer j = 0; j < nb_env_mat; ++j) {
986 IMeshMaterial* mm = env_materials[j];
987 const MeshMaterialVariableIndexer* idx = mm->_internalApi()->variableIndexer();
988 o <<
"-- Mat name=" << mm->name()
989 <<
" nb_cell=" << mm->cells().size()
990 <<
" var_idx=" << idx->index()
999bool MeshMaterialMng::
1000synchronizeMaterialsInCells()
1002 return m_mms->synchronizeMaterialsInCells();
1008void MeshMaterialMng::
1009checkMaterialsInCells(
Integer max_print)
1011 m_mms->checkMaterialsInCells(max_print);
1017void MeshMaterialMng::
1018dumpCellInfos(
Cell cell, std::ostream& o)
1021 AllEnvCell all_env_cell = all_env_cell_converter[cell];
1023 o <<
"Cell uid=" <<
ItemPrinter(global_cell) <<
'\n';
1025 o <<
"ENV name=" << (*ienvcell).environment()->name()
1026 <<
" component_idx=" << ComponentItemLocalId(ienvcell) <<
'\n';
1028 o <<
"MAT name=" << (*imatcell).material()->name()
1029 <<
" component_idx=" << ComponentItemLocalId(imatcell) <<
'\n';
1038cellToAllEnvCellConverter()
1046void MeshMaterialMng::
1049 if (m_is_end_create)
1050 ARCANE_FATAL(
"Invalid method call because endCreate() has already been called");
1065class MeshMaterialMngFactory
1070 MeshMaterialMngFactory()
1074 ~MeshMaterialMngFactory()
1085 static MeshMaterialMngFactory m_mesh_material_mng_factory;
1094getTrueReference(
const MeshHandle& mesh_handle,
bool is_create)
1099 const char* name =
"MeshMaterialMng_StdMat";
1106 IMeshMaterialMng* mm = arcaneCreateMeshMaterialMng(mesh_handle,
"StdMat");
1107 Ref<IMeshMaterialMng> mm_ref = makeRef(mm);
1108 udlist->
setData(name,
new UserDataType(
new Ref<IMeshMaterialMng>(mm_ref)));
1111 auto adud =
dynamic_cast<UserDataType*
>(ud);
1114 return *(adud->data());
1120bool MeshMaterialMng::
1121isInMeshMaterialExchange()
const
1123 return m_exchange_mng->isInMeshMaterialExchange();
1129void MeshMaterialMng::
1130_checkCreateProperties()
1134 m_properties = std::make_unique<Properties>(*(
mesh()->properties()),
String(
"MeshMaterialMng_") + name());
1141 const Int32 SERIALIZE_VERSION = 1;
1143void MeshMaterialMng::
1144_saveInfosInProperties()
1146 _checkCreateProperties();
1149 m_properties->set(
"Version", SERIALIZE_VERSION);
1153 UniqueArray<String> material_info_names;
1154 for (MeshMaterialInfo* mat_info : m_materials_info) {
1155 material_info_names.add(mat_info->name());
1157 m_properties->set(
"MaterialInfoNames", material_info_names);
1159 UniqueArray<String> env_names;
1160 UniqueArray<Int32> env_nb_mat;
1161 UniqueArray<String> env_mat_names;
1163 IMeshEnvironment* env = *ienv;
1164 env_names.add(env->name());
1165 info(5) <<
"SAVE ENV_NAME name=" << env->name() <<
" nb_mat=" << env->nbMaterial();
1166 env_nb_mat.add(env->nbMaterial());
1168 const String& name = (*imat)->infos()->name();
1169 info(5) <<
"SAVE MAT_NAME name=" << name;
1170 env_mat_names.add(name);
1173 m_properties->set(
"EnvNames", env_names);
1174 m_properties->set(
"EnvNbMat", env_nb_mat);
1175 m_properties->set(
"EnvMatNames", env_mat_names);
1179 UniqueArray<String> block_names;
1180 UniqueArray<String> block_cell_group_names;
1181 UniqueArray<Int32> block_nb_env;
1182 UniqueArray<String> block_env_names;
1183 for (IMeshBlock* block : m_blocks) {
1184 block_names.add(block->name());
1185 block_cell_group_names.add(block->cells().name());
1186 block_nb_env.add(block->nbEnvironment());
1188 const String& name = (*ienv)->name();
1189 info(5) <<
"SAVE BLOCK ENV_NAME name=" << name;
1190 block_env_names.add(name);
1193 m_properties->set(
"BlockNames", block_names);
1194 m_properties->set(
"BlockCellGroupNames", block_cell_group_names);
1195 m_properties->set(
"BlockNbEnv", block_nb_env);
1196 m_properties->set(
"BlockEnvNames", block_env_names);
1202void MeshMaterialMng::
1205 if (m_is_end_create)
1208 _checkCreateProperties();
1210 info() <<
"Creating material infos from dump";
1213 Int32 v = m_properties->getInt32(
"Version");
1214 if (v != SERIALIZE_VERSION)
1215 ARCANE_FATAL(
"Bad serializer version: trying to read from incompatible checkpoint v={0} expected={1}",
1216 v, SERIALIZE_VERSION);
1219 m_properties->get(
"MaterialInfoNames", material_info_names);
1220 for (
const String& mat_name : material_info_names)
1226 m_properties->get(
"EnvNames", env_names);
1227 m_properties->get(
"EnvNbMat", env_nb_mat);
1228 m_properties->get(
"EnvMatNames", env_mat_names);
1231 for (
Integer ienv = 0, nenv = env_names.
size(); ienv < nenv; ++ienv) {
1233 Integer nb_mat = env_nb_mat[ienv];
1234 for (
Integer imat = 0; imat < nb_mat; ++imat) {
1247 m_properties->get(
"BlockNames", block_names);
1248 m_properties->get(
"BlockCellGroupNames", block_cell_group_names);
1249 m_properties->get(
"BlockNbEnv", block_nb_env);
1250 m_properties->get(
"BlockEnvNames", block_env_names);
1253 for (
Integer i = 0, n = block_names.
size(); i < n; ++i) {
1255 String cell_group_name = block_cell_group_names[i];
1258 ARCANE_FATAL(
"Can not find cell group '{0}' for block creation",
1261 if (!block_nb_env.
empty()) {
1262 Integer nb_env = block_nb_env[i];
1263 for (
Integer ienv = 0; ienv < nb_env; ++ienv) {
1264 const String& name2 = block_env_names[block_env_index];
1268 ARCANE_FATAL(
"Invalid environment name '{0}' for recreating blocks", name2);
1281void MeshMaterialMng::
1288 m_exchange_mng.reset();
1290 _unregisterAllVariables();
1296void MeshMaterialMng::
1297_unregisterAllVariables()
1304 for (
const auto& i : m_full_name_variable_map) {
1309 m_all_refs.
add(ref);
1313 for (MeshMaterialVariableRef* ref : m_all_refs)
1314 ref->unregisterVariable();
1320ComponentItemSharedInfo* MeshMaterialMng::
1321componentItemSharedInfo(Int32 level)
const
1323 ComponentItemInternalData* data = m_all_env_data->componentItemInternalData();
1324 ComponentItemSharedInfo* shared_info =
nullptr;
1325 if (level == LEVEL_MATERIAL)
1326 shared_info = data->matSharedInfo();
1327 else if (level == LEVEL_ENVIRONMENT)
1328 shared_info = data->envSharedInfo();
1329 else if (level == LEVEL_ALLENVIRONMENT)
1330 shared_info = data->allEnvSharedInfo();
1340void MeshMaterialMng::
1343 IEnumeratorTracer* tracer = IEnumeratorTracer::singleton();
1345 tracer->dumpStats();
1348 m_modifier->dumpStats();
1350 for (IMeshEnvironment* env : m_environments) {
1354 if (env->nbMaterial() > 1)
1355 env->_internalApi()->variableIndexer()->dumpStats();
1357 for (IMeshMaterial* mat : m_materials) {
1358 mat->_internalApi()->variableIndexer()->dumpStats();
1365void MeshMaterialMng::
1366createAllCellToAllEnvCell()
1368 if (!m_accelerator_envcell_container) {
1369 m_accelerator_envcell_container = std::make_unique<AllCellToAllEnvCellContainer>(
this);
1370 m_accelerator_envcell_container->initialize();
1377SmallSpan<const Int32> MeshMaterialMng::
1378identitySelectionView()
1382 Int32 max_local_id = m_mesh_handle.mesh()->cellFamily()->maxLocalId();
1384 std::scoped_lock sl(m_indexed_selection_identity_mutex);
1385 Int32 size = m_indexed_selection_identity.size();
1386 if (max_local_id > size) {
1387 m_indexed_selection_identity.resize(max_local_id);
1388 for (Int32 i = size; i < max_local_id; ++i)
1389 m_indexed_selection_identity[i] = i;
1391 return m_indexed_selection_identity.constView();
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Memory and allocator management functions.
Integer size() const
Number of elements in the vector.
bool empty() const
Capacity (number of allocated elements) of the vector.
Base class for 1D data vectors.
void clear()
Removes the elements from the array.
void add(ConstReferenceType val)
Adds element val to the end of the array.
UserData that self-destructs once detached.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of a functor with an argument but without a return value.
Interface of an entity family.
virtual ItemGroup findGroup(const String &name) const =0
Searches for a group.
virtual ItemGroup allItems() const =0
Group of all entities.
Interface of a list that manages user data.
virtual void setData(const String &name, IUserData *ud)=0
Sets the user data associated with the name name.
virtual IUserData * data(const String &name, bool allow_null=false) const =0
Data associated with name.
Interface for user data attached to another object.
virtual String fullName() const =0
Full variable name (with family prefix).
virtual bool isUsed() const =0
Usage state of the variable.
ItemVectorView view() const
View of the group entities.
bool null() const
true means the group is the null group
Utility class for printing information about an entity.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
ItemUniqueId uniqueId() const
Unique identifier across all domains.
View over a list of cells with environment information.
Arcane cell with material and environment information.
__host__ __device__ Int32 nbEnvironment() const
Number of environments present in the cell.
EnvCell cell(Int32 i) const
i-th environment cell
Conversion of 'Cell' to 'AllEnvCell'.
Management of constituent connectivity lists.
Int16 cellNbMaterial(CellLocalId cell_id, Int16 env_id)
Number of materials of the cell cell_id for environment index env_id.
Cell globalCell() const
Global cell.
__host__ __device__ Int32 level() const
Hierarchical level of the entity.
__host__ __device__ MatVarIndex _varIndex() const
Arcane cell of an environment.
__host__ __device__ MatCell cell(Integer i) const
i-th material cell of this cell
Interface of a mesh block.
virtual String name() const =0
Component name.
Interface of a mesh environment.
Interface for the material and environment manager of a mesh.
static void _internalSetFactory(IFactory *f)
Interface of the material variable factory manager.
virtual void syncReferences(bool check_resize)=0
Synchronizes references.
Interface of a material variable on a mesh.
virtual IVariable * globalVariable() const =0
Associated global variable on the mesh.
virtual String name() const =0
Name of the variable.
virtual void buildFromManager(bool is_continue)=0
Builds the variable information. For internal use in Arcane.
Interface of a mesh material.
Represents a material in a multi-material cell.
IMeshMaterial * material() const
Associated material.
constexpr __host__ __device__ Int32 arrayIndex() const
Returns the index of the value array in the list of variables.
Brief: Information for the creation of a block.
const String & name() const
Block name.
void addEnvironment(IMeshEnvironment *env)
Brief: Adds the environment env to the block.
ConstArrayView< IMeshEnvironment * > environments() const
List of environments in the block.
void addEnvironment(IMeshEnvironment *env)
Adds the environment env to the block.
void build()
Public functions but reserved for IMeshMaterialMng.
void removeEnvironment(IMeshEnvironment *env)
Removes the environment env from the block.
Information for creating an environment.
void addMaterial(const String &name)
Adds the material named name to the environment.
ConstArrayView< MatInfo > materials() const
const String & name() const
Name of the environment.
void build()
Public functions but reserved for IMeshMaterialMng.
ConstArrayView< IMeshMaterial * > materials() override
List of materials in this environment.
IMeshMaterialMng * materialMng() override
Associated manager.
String name() const override
Component name.
Info about a material of a mesh.
IMeshMaterialMng * materialMng()
Associated manager.
Implementation of a material manager.
AllEnvCellVectorView view(const CellGroup &cells) final
View of environment cells corresponding to the group cells.
void endCreate(bool is_continue) override
Indicates that environment creation is finished.
IMeshBlock * createBlock(const MeshBlockBuildInfo &infos) override
Creates a block.
ITraceMng * traceMng() override
Trace manager.
IMesh * mesh() override
Associated mesh.
MeshMaterialInfo * registerMaterialInfo(const String &name) override
Registers the material info with name name.
IMeshEnvironment * createEnvironment(const MeshEnvironmentBuildInfo &infos) override
Creation of an environment.
void _endUpdate()
Updates the structures following a modification of material or environment cells.
IMeshEnvironment * findEnvironment(const String &name, bool throw_exception=true) override
Returns the environment with name name.
MeshMaterial * _createMaterial(MeshEnvironment *env, MeshMaterialInfo *infos, const String &name)
Creation of a material.
String name() const override
Manager name.
Indexer for material variables.
const String & name() const
Name of the indexer.
Base class for material variable references.
void build()
Public functions but reserved for IMeshMaterialMng.
General information about a constituent entity.
__host__ __device__ matimpl::ConstituentItemBase _superItemBase() const
Parent component (0 if none).
impl::ItemBase globalItemBase() const
Corresponding global entity.
IUserDataList * meshUserDataList() const
Associated user data.
Reference to an instance.
View of an array of elements of type T.
constexpr ConstArrayView< value_type > constSmallView() const
Constant view of this view.
Unicode character string.
TraceMessage info() const
Flow for an information message.
1D data vector with value semantics (STL style).
ItemGroupT< Cell > CellGroup
Group of cells.
RunQueue makeQueue(const Runner &runner)
Creates a queue associated with runner.
eExecutionPolicy
Execution policy for a Runner.
@ Sequential
Sequential execution policy.
@ Thread
Multi-threaded execution policy.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indicates if exec_policy corresponds to an accelerator.
Always enables tracing in Arcane parts concerning materials.
@ Environment
Variable having values only on environments.
@ MaterialAndEnvironment
Variable having values on environments and materials.
bool arcaneIsCheck()
True if running in check mode.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
std::int16_t Int16
Signed integer type of 16 bits.
std::int32_t Int32
Signed integer type of 32 bits.
Memory management utility functions.