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 if (
auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_ACCELERATOR_FOR_CONSTITUENTITEMVECTOR",
true)) {
236 m_is_use_accelerator_for_constituent_item_vector = (v.value() != 0);
242 if (TaskFactory::isActive())
243 m_is_use_accelerator_for_constituent_item_vector =
false;
244 info() <<
"Use accelerator API for 'ConstituentItemVectorImpl' = " << m_is_use_accelerator_for_constituent_item_vector;
249 IAcceleratorMng* acc_mng = m_variable_mng->_internalApi()->acceleratorMng();
252 Runner* default_runner = acc_mng->defaultRunner();
254 bool use_accelerator_runner =
true;
255 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_QUEUE",
true))
256 use_accelerator_runner = (v.value() != 0);
257 if (use_accelerator_runner && default_runner)
258 runner = *default_runner;
261 if (!runner.isInitialized())
262 runner.initialize(Accelerator::eExecutionPolicy::Sequential);
263 m_runner_info = std::make_unique<RunnerInfo>(runner);
265 info() <<
"Use runner '" << this->runner().executionPolicy() <<
"' for MeshMaterialMng name=" << name()
266 <<
" async_queue_size=" << nb_queue;
267 m_runner_info->initializeAsyncPool(nb_queue);
274 RunQueue& q = runQueue();
276 q.setMemoryRessource(eMemoryRessource::Device);
281 int default_flags = 0;
287 int opt_flag_value = 0;
288 String env_name =
"ARCANE_MATERIAL_MODIFICATION_FLAGS";
289 String opt_flag_str = platform::getEnvironmentVariable(env_name);
290 if (!opt_flag_str.null()) {
291 if (builtInGetValue(opt_flag_value, opt_flag_str)) {
292 pwarning() <<
"Invalid value '" << opt_flag_str
293 <<
" 'for environment variable '" << env_name
295 opt_flag_value = default_flags;
299 opt_flag_value = default_flags;
301 m_modification_flags = opt_flag_value;
306 String env_name =
"ARCANE_MATSYNCHRONIZE_VERSION";
307 String env_value = platform::getEnvironmentVariable(env_name);
308 info() <<
"ENV_VALUE=" << env_value;
309 Integer version = m_synchronize_variable_version;
310 if (!env_value.null()) {
311 if (builtInGetValue(version, env_value)) {
312 pwarning() <<
"Invalid value '" << env_value
313 <<
" 'for environment variable '" << env_name
317 m_synchronize_variable_version = version;
319 info() <<
"Set material variable synchronize version to "
320 <<
"'" << m_synchronize_variable_version <<
"'";
325 String env_name =
"ARCANE_MATERIAL_DATA_COMPRESSOR_NAME";
326 String env_value = platform::getEnvironmentVariable(env_name);
327 if (!env_value.null()) {
328 info() <<
"Use service '" << env_value <<
"' for material data compression";
329 m_data_compressor_service_name = env_value;
335 if (
auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_ADDITIONAL_CAPACITY_RATIO",
true)) {
337 m_additional_capacity_ratio = v.value();
338 info() <<
"Set additional capacity ratio to " << m_additional_capacity_ratio;
343 m_exchange_mng->build();
348 IItemEnumeratorTracer* item_tracer = IItemEnumeratorTracer::singleton();
350 info() <<
"Adding material enumerator tracing";
351 EnumeratorTracer::_setSingleton(
new EnumeratorTracer(traceMng(), item_tracer->perfCounterRef()));
358void MeshMaterialMng::
359_addVariableIndexer(MeshMaterialVariableIndexer* var_idx)
361 var_idx->setIndex(m_variables_indexer.size());
362 m_variables_indexer.add(var_idx);
379 ARCANE_FATAL(
"Invalid materialMng() for material info");
382 Integer var_index = m_variables_indexer.size();
383 Int16 mat_id = CheckedConvert::toInt16(m_materials.size());
385 info() <<
"Create material name=" <<
name <<
"mat_id=" << mat_id <<
" var_index=" << var_index;
387 m_materials.add(mat);
388 m_materials_as_components.add(mat);
389 m_true_materials.add(mat);
391 _addVariableIndexer(mat->variableIndexer());
408 m_materials_info.add(mmi);
425 Int16 env_index = CheckedConvert::toInt16(m_environments.size());
430 ARCANE_FATAL(
"An environment named '{0}' is already registered", env_name);
432 info() <<
"Creating environment name=" << env_name <<
" index=" << env_index;
436 m_true_environments.add(me);
437 m_environments.add(me);
438 m_environments_as_components.add(me);
443 for (
Integer i = 0; i < nb_mat; ++i) {
445 const String& mat_name = buildinfo.m_name;
446 String new_mat_name = env_name +
"_" + mat_name;
449 ARCANE_FATAL(
"No material named '{0}' is defined", mat_name);
453 mat_info->_addEnvironment(env_name);
461 var_idx = me->
materials()[0]->_internalApi()->variableIndexer();
465 _addVariableIndexer(var_idx);
466 m_variables_indexer_to_destroy.add(var_idx);
468 me->setVariableIndexer(var_idx);
481 Int32 block_index = m_blocks.size();
488 info() <<
"Creating block name=" <<
name <<
" index=" << block_index
491 for (
Integer i = 0; i < nb_env; ++i)
492 info() <<
" Adding environment name=" << infos.
environments()[i]->name() <<
" to block";
497 m_true_blocks.add(mb);
506void MeshMaterialMng::
516void MeshMaterialMng::
526void MeshMaterialMng::
527endCreate(
bool is_continue)
532 _saveInfosInProperties();
534 info() <<
"END CREATE MATERIAL_MNG is_continue=" << is_continue;
536 m_modifier = std::make_unique<MeshMaterialModifierImpl>(
this);
537 m_modifier->initOptimizationFlags();
539 m_all_env_data->endCreate(is_continue);
541 auto synchronizer =
mesh()->cellFamily()->allItemsSynchronizer();
543 m_all_cells_env_only_synchronizer = std::make_unique<MeshMaterialVariableSynchronizer>(
this, synchronizer,
MatVarSpace::Environment);
547 Integer nb_component = m_environments_as_components.size() + m_materials_as_components.size();
548 m_components.reserve(nb_component);
549 m_components.addRange(m_environments_as_components);
550 m_components.addRange(m_materials_as_components);
555 for (
const auto& i : m_full_name_variable_map) {
557 info(4) <<
"BUILD FROM MANAGER name=" << mv->
name() <<
" this=" <<
this;
562 m_is_end_create =
true;
576 m_exchange_mng->registerFactory();
582void MeshMaterialMng::
583setModificationFlags(
int v)
586 m_modification_flags = v;
587 info() <<
"Setting ModificationFlags to v=" << v;
593void MeshMaterialMng::
594setAllocateScalarEnvironmentVariableAsMaterial(
bool v)
597 m_is_allocate_scalar_environment_variable_as_material = v;
598 info() <<
"Setting AllocateScalarEnvironmentVariableAsMaterial to v=" << v;
604void MeshMaterialMng::
605setDataCompressorServiceName(
const String&
name)
607 m_data_compressor_service_name =
name;
616 return m_modifier.get();
623_findMaterialInfo(
const String& name)
626 if (mmi->name() == name)
635findEnvironment(
const String&
name,
bool throw_exception)
649_findEnvironment(
const String& name)
652 if (env->name() == name)
661findBlock(
const String&
name,
bool throw_exception)
675_findBlock(
const String& name)
678 if (b->name() == name)
686void MeshMaterialMng::
699void MeshMaterialMng::
702 m_all_env_data->forceRecompute(
true);
715void MeshMaterialMng::
716syncVariablesReferences(
bool check_resize)
718 for (
const auto& i : m_full_name_variable_map) {
720 info(4) <<
"SYNC REFERENCES FROM MANAGER name=" << mv->
name();
728void MeshMaterialMng::
733 for (
const auto& i : m_full_name_variable_map) {
735 functor->executeFunctor(mv);
742void MeshMaterialMng::
747 ConstArrayView<Int16> nb_env_per_cell = m_all_env_data->componentConnectivityList()->cellsNbEnvironment();
753 if (all_env_cell.
level() != LEVEL_ALLENVIRONMENT)
757 ARCANE_FATAL(
"Bad corresponding globalCell() in all_env_item");
758 if (cell_nb_env != nb_env_per_cell[cell.
localId()])
759 ARCANE_FATAL(
"Bad value for nb_env direct='{0}' var='{1}'",
760 cell_nb_env, nb_env_per_cell[cell.
localId()]);
761 for (
Integer z = 0; z < cell_nb_env; ++z) {
763 Integer cell_nb_mat = ec.nbMaterial();
766 ARCANE_FATAL(
"Bad corresponding allEnvItem() in env_item uid={0}", cell_uid);
768 ARCANE_FATAL(
"Bad corresponding globalItem() in env_item");
769 if (eii.level() != LEVEL_ENVIRONMENT)
770 ARCANE_FATAL(
"Bad level '{0}' for in env_item", eii.level());
774 ARCANE_FATAL(
"Global index for a partial cell env_item={0}", ec);
776 for (
Integer k = 0; k < cell_nb_mat; ++k) {
780 ARCANE_FATAL(
"Bad corresponding env_item in mat_item k={0} mc={1}", k, mc);
782 ARCANE_FATAL(
"Bad corresponding globalItem() in mat_item");
783 if (mci.level() != LEVEL_MATERIAL)
784 ARCANE_FATAL(
"Bad level '{0}' for in mat_item", mci.level());
788 ARCANE_FATAL(
"Global index for a partial cell matitem={0} name={1} nb_mat={2} nb_env={3}",
815 v = _findVariableFullyQualified(global_var->
fullName());
827_findVariableFullyQualified(
const String& name)
829 auto i = m_full_name_variable_map.find(name);
830 if (i != m_full_name_variable_map.end())
841 auto i = m_var_to_mat_var_map.find(global_var);
842 if (i != m_var_to_mat_var_map.end())
850void MeshMaterialMng::
857 for (
const auto& i : m_full_name_variable_map) {
867void MeshMaterialMng::
872 info(4) <<
"MAT_ADD_VAR global_var=" << gvar <<
" var=" << var <<
" this=" <<
this;
873 m_var_to_mat_var_map.insert(std::make_pair(gvar, var));
874 m_full_name_variable_map.insert(std::make_pair(gvar->
fullName(), var));
880void MeshMaterialMng::
885 info(4) <<
"MAT:Remove variable global_var=" << gvar <<
" var=" << var;
886 m_var_to_mat_var_map.erase(gvar);
887 m_full_name_variable_map.erase(gvar->
fullName());
893void MeshMaterialMng::
894dumpInfos(std::ostream& o)
896 Integer nb_mat = m_materials.size();
897 Integer nb_env = m_environments.size();
898 Integer nb_var_idx = m_variables_indexer.size();
899 o <<
"-- Infos sur les milieux et matériaux\n";
900 o <<
"-- Nb Materiaux: " << nb_mat <<
'\n';
901 o <<
"-- Nb Milieux: " << nb_env <<
'\n';
902 o <<
"-- Nb Variables partielles: " << nb_var_idx <<
'\n';
904 o <<
"-- Liste des matériaux\n";
906 o <<
"-- Materiau name=" << mat->name() <<
'\n';
909 o <<
"-- Liste des milieux\n";
914 o <<
"-- Milieu name=" << me->name()
915 <<
" nb_mat=" << nb_env_mat
916 <<
" nb_cell=" << me->cells().size()
917 <<
" var_idx = " << env_var_idx->index()
918 <<
" ids=" << env_var_idx->matvarIndexes()
922 o <<
"-- Materiau\n";
923 o <<
"-- name = " << mm->
name() <<
"\n";
924 o <<
"-- nb_cell = " << mm->cells().size() <<
"\n";
925 o <<
"-- var_idx = " << idx->index() <<
"\n";
934void MeshMaterialMng::
935dumpInfos2(std::ostream& o)
939 Integer nb_mat = m_materials.size();
940 Integer nb_env = m_environments.size();
941 Integer nb_var_idx = m_variables_indexer.size();
942 o <<
"-- Material and Environment infos: nb_env=" << nb_env
943 <<
" nb_mat=" << nb_mat <<
" timestamp=" << m_timestamp
944 <<
" nb_var_idx=" << nb_var_idx
950 if (nb_env_per_cell[icell.localId()] <= 1)
953 o <<
" nb_cell=" << nb_cell <<
" nb_pure_env=" << nb_pure_env
954 <<
" nb_partial=" << (nb_cell - nb_pure_env)
955 <<
" percent=" << (100 * nb_pure_env) / nb_cell
959 o <<
"-- Liste des milieux\n";
960 for (MeshEnvironment* me : m_true_environments) {
961 ConstArrayView<IMeshMaterial*> env_materials = me->materials();
962 const MeshMaterialVariableIndexer* env_var_idx = me->variableIndexer();
963 const Int16 env_id = me->componentId();
964 Integer nb_env_mat = env_materials.size();
965 Integer nb_env_cell = me->cells().size();
966 Integer nb_pure_mat = 0;
967 if (nb_env_mat > 1) {
974 nb_pure_mat = nb_env_cell;
975 o <<
"-- Env name=" << me->name()
976 <<
" nb_mat=" << nb_env_mat
977 <<
" var_idx=" << env_var_idx->index()
978 <<
" nb_cell=" << nb_env_cell
979 <<
" nb_pure_mat=" << nb_pure_mat;
980 if (nb_env_cell != 0)
981 o <<
" percent=" << (nb_pure_mat * 100) / nb_env_cell;
983 for (Integer j = 0; j < nb_env_mat; ++j) {
984 IMeshMaterial* mm = env_materials[j];
985 const MeshMaterialVariableIndexer* idx = mm->_internalApi()->variableIndexer();
986 o <<
"-- Mat name=" << mm->name()
987 <<
" nb_cell=" << mm->cells().size()
988 <<
" var_idx=" << idx->index()
997bool MeshMaterialMng::
998synchronizeMaterialsInCells()
1000 return m_mms->synchronizeMaterialsInCells();
1006void MeshMaterialMng::
1007checkMaterialsInCells(
Integer max_print)
1009 m_mms->checkMaterialsInCells(max_print);
1015void MeshMaterialMng::
1016dumpCellInfos(
Cell cell, std::ostream& o)
1019 AllEnvCell all_env_cell = all_env_cell_converter[cell];
1021 o <<
"Cell uid=" <<
ItemPrinter(global_cell) <<
'\n';
1023 o <<
"ENV name=" << (*ienvcell).environment()->name()
1024 <<
" component_idx=" << ComponentItemLocalId(ienvcell) <<
'\n';
1026 o <<
"MAT name=" << (*imatcell).material()->name()
1027 <<
" component_idx=" << ComponentItemLocalId(imatcell) <<
'\n';
1036cellToAllEnvCellConverter()
1044void MeshMaterialMng::
1047 if (m_is_end_create)
1048 ARCANE_FATAL(
"Invalid method call because endCreate() has already been called");
1063class MeshMaterialMngFactory
1068 MeshMaterialMngFactory()
1072 ~MeshMaterialMngFactory()
1083 static MeshMaterialMngFactory m_mesh_material_mng_factory;
1092getTrueReference(
const MeshHandle& mesh_handle,
bool is_create)
1097 const char* name =
"MeshMaterialMng_StdMat";
1104 IMeshMaterialMng* mm = arcaneCreateMeshMaterialMng(mesh_handle,
"StdMat");
1105 Ref<IMeshMaterialMng> mm_ref = makeRef(mm);
1106 udlist->
setData(name,
new UserDataType(
new Ref<IMeshMaterialMng>(mm_ref)));
1109 auto adud =
dynamic_cast<UserDataType*
>(ud);
1112 return *(adud->data());
1118bool MeshMaterialMng::
1119isInMeshMaterialExchange()
const
1121 return m_exchange_mng->isInMeshMaterialExchange();
1127void MeshMaterialMng::
1128_checkCreateProperties()
1132 m_properties = std::make_unique<Properties>(*(
mesh()->properties()),
String(
"MeshMaterialMng_") + name());
1139 const Int32 SERIALIZE_VERSION = 1;
1141void MeshMaterialMng::
1142_saveInfosInProperties()
1144 _checkCreateProperties();
1147 m_properties->set(
"Version", SERIALIZE_VERSION);
1151 UniqueArray<String> material_info_names;
1152 for (MeshMaterialInfo* mat_info : m_materials_info) {
1153 material_info_names.add(mat_info->name());
1155 m_properties->set(
"MaterialInfoNames", material_info_names);
1157 UniqueArray<String> env_names;
1158 UniqueArray<Int32> env_nb_mat;
1159 UniqueArray<String> env_mat_names;
1161 IMeshEnvironment* env = *ienv;
1162 env_names.add(env->name());
1163 info(5) <<
"SAVE ENV_NAME name=" << env->name() <<
" nb_mat=" << env->nbMaterial();
1164 env_nb_mat.add(env->nbMaterial());
1166 const String& name = (*imat)->infos()->name();
1167 info(5) <<
"SAVE MAT_NAME name=" << name;
1168 env_mat_names.add(name);
1171 m_properties->set(
"EnvNames", env_names);
1172 m_properties->set(
"EnvNbMat", env_nb_mat);
1173 m_properties->set(
"EnvMatNames", env_mat_names);
1177 UniqueArray<String> block_names;
1178 UniqueArray<String> block_cell_group_names;
1179 UniqueArray<Int32> block_nb_env;
1180 UniqueArray<String> block_env_names;
1181 for (IMeshBlock* block : m_blocks) {
1182 block_names.add(block->name());
1183 block_cell_group_names.add(block->cells().name());
1184 block_nb_env.add(block->nbEnvironment());
1186 const String& name = (*ienv)->name();
1187 info(5) <<
"SAVE BLOCK ENV_NAME name=" << name;
1188 block_env_names.add(name);
1191 m_properties->set(
"BlockNames", block_names);
1192 m_properties->set(
"BlockCellGroupNames", block_cell_group_names);
1193 m_properties->set(
"BlockNbEnv", block_nb_env);
1194 m_properties->set(
"BlockEnvNames", block_env_names);
1200void MeshMaterialMng::
1203 if (m_is_end_create)
1206 _checkCreateProperties();
1208 info() <<
"Creating material infos from dump";
1211 Int32 v = m_properties->getInt32(
"Version");
1212 if (v != SERIALIZE_VERSION)
1213 ARCANE_FATAL(
"Bad serializer version: trying to read from incompatible checkpoint v={0} expected={1}",
1214 v, SERIALIZE_VERSION);
1217 m_properties->get(
"MaterialInfoNames", material_info_names);
1218 for (
const String& mat_name : material_info_names)
1224 m_properties->get(
"EnvNames", env_names);
1225 m_properties->get(
"EnvNbMat", env_nb_mat);
1226 m_properties->get(
"EnvMatNames", env_mat_names);
1229 for (
Integer ienv = 0, nenv = env_names.
size(); ienv < nenv; ++ienv) {
1231 Integer nb_mat = env_nb_mat[ienv];
1232 for (
Integer imat = 0; imat < nb_mat; ++imat) {
1245 m_properties->get(
"BlockNames", block_names);
1246 m_properties->get(
"BlockCellGroupNames", block_cell_group_names);
1247 m_properties->get(
"BlockNbEnv", block_nb_env);
1248 m_properties->get(
"BlockEnvNames", block_env_names);
1251 for (
Integer i = 0, n = block_names.
size(); i < n; ++i) {
1253 String cell_group_name = block_cell_group_names[i];
1256 ARCANE_FATAL(
"Can not find cell group '{0}' for block creation",
1259 if (!block_nb_env.
empty()) {
1260 Integer nb_env = block_nb_env[i];
1261 for (
Integer ienv = 0; ienv < nb_env; ++ienv) {
1262 const String& name2 = block_env_names[block_env_index];
1266 ARCANE_FATAL(
"Invalid environment name '{0}' for recreating blocks", name2);
1279void MeshMaterialMng::
1286 m_exchange_mng.reset();
1288 _unregisterAllVariables();
1294void MeshMaterialMng::
1295_unregisterAllVariables()
1302 for (
const auto& i : m_full_name_variable_map) {
1307 m_all_refs.
add(ref);
1311 for (MeshMaterialVariableRef* ref : m_all_refs)
1312 ref->unregisterVariable();
1318ComponentItemSharedInfo* MeshMaterialMng::
1319componentItemSharedInfo(Int32 level)
const
1321 ComponentItemInternalData* data = m_all_env_data->componentItemInternalData();
1322 ComponentItemSharedInfo* shared_info =
nullptr;
1323 if (level == LEVEL_MATERIAL)
1324 shared_info = data->matSharedInfo();
1325 else if (level == LEVEL_ENVIRONMENT)
1326 shared_info = data->envSharedInfo();
1327 else if (level == LEVEL_ALLENVIRONMENT)
1328 shared_info = data->allEnvSharedInfo();
1338void MeshMaterialMng::
1341 IEnumeratorTracer* tracer = IEnumeratorTracer::singleton();
1343 tracer->dumpStats();
1346 m_modifier->dumpStats();
1348 for (IMeshEnvironment* env : m_environments) {
1352 if (env->nbMaterial() > 1)
1353 env->_internalApi()->variableIndexer()->dumpStats();
1355 for (IMeshMaterial* mat : m_materials) {
1356 mat->_internalApi()->variableIndexer()->dumpStats();
1363void MeshMaterialMng::
1364createAllCellToAllEnvCell()
1366 if (!m_accelerator_envcell_container) {
1367 m_accelerator_envcell_container = std::make_unique<AllCellToAllEnvCellContainer>(
this);
1368 m_accelerator_envcell_container->initialize();
1375SmallSpan<const Int32> MeshMaterialMng::
1376identitySelectionView()
1380 Int32 max_local_id = m_mesh_handle.mesh()->cellFamily()->maxLocalId();
1382 std::scoped_lock sl(m_indexed_selection_identity_mutex);
1383 Int32 size = m_indexed_selection_identity.size();
1384 if (max_local_id > size) {
1385 m_indexed_selection_identity.resize(max_local_id);
1386 for (Int32 i = size; i < max_local_id; ++i)
1387 m_indexed_selection_identity[i] = i;
1389 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.