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"
77extern "C++" IMeshMaterialVariableFactoryMng*
78arcaneCreateMeshMaterialVariableFactoryMng(IMeshMaterialMng* mm);
86arcaneCreateMeshMaterialMng(
const MeshHandle& mesh_handle,
const String& name)
88 MeshMaterialMng* mmm =
new MeshMaterialMng(mesh_handle,name);
99MeshMaterialMng::RunnerInfo::
100RunnerInfo(Runner& runner)
109void MeshMaterialMng::RunnerInfo::
110initializeAsyncPool(Int32 nb_queue)
116 m_async_queue_pool.initialize(m_runner,nb_queue);
118 m_async_queue_pool.setAsync(
true);
128MeshMaterialMng(
const MeshHandle& mesh_handle,
const String& name)
130: TraceAccessor(mesh_handle.traceMng())
131, m_mesh_handle(mesh_handle)
132, m_internal_api(std::make_unique<InternalApi>(this))
133, m_variable_mng(mesh_handle.variableMng())
136 m_all_env_data = std::make_unique<AllEnvData>(
this);
137 m_exchange_mng = std::make_unique<MeshMaterialExchangeMng>(
this);
138 m_variable_factory_mng = arcaneCreateMeshMaterialVariableFactoryMng(
this);
139 m_observer_pool = std::make_unique<ObserverPool>();
140 m_observer_pool->addObserver(
this,&MeshMaterialMng::_onMeshDestroyed,mesh_handle.onDestroyObservable());
142 String s = platform::getEnvironmentVariable(
"ARCANE_ALLENVCELL_FOR_RUNCOMMAND");
144 m_is_use_accelerator_envcell_container =
true;
145 m_mms =
new MeshMaterialSynchronizer(
this);
158 delete m_variable_factory_mng;
159 m_exchange_mng.reset();
160 m_all_cells_env_only_synchronizer.reset();
161 m_all_cells_mat_env_synchronizer.reset();
162 m_all_env_data.reset();
163 m_properties.reset();
165 for( MeshMaterial* m : m_true_materials )
167 m_true_materials.clear();
169 for( MeshEnvironment* e : m_true_environments )
171 m_true_environments.clear();
173 for (IMeshBlock* b : m_true_blocks)
176 for (MeshMaterialInfo* mmi : m_materials_info)
179 for (MeshMaterialVariableIndexer* mvi : m_variables_indexer_to_destroy)
183 m_internal_api.reset();
185 m_accelerator_envcell_container.reset();
189 m_runner_info.reset();
198void MeshMaterialMng::
203 auto* x = MeshMaterialVariableFactoryRegisterer::firstRegisterer();
205 m_variable_factory_mng->registerFactory(x->createFactory());
206 x = x->nextRegisterer();
213 if (
auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_ACCELERATOR_FOR_CONSTITUENTITEMVECTOR",
true)){
214 m_is_use_accelerator_for_constituent_item_vector = (v.value()!=0);
220 if (TaskFactory::isActive())
221 m_is_use_accelerator_for_constituent_item_vector =
false;
222 info() <<
"Use accelerator API for 'ConstituentItemVectorImpl' = " << m_is_use_accelerator_for_constituent_item_vector;
227 IAcceleratorMng* acc_mng = m_variable_mng->_internalApi()->acceleratorMng();
230 Runner* default_runner = acc_mng->defaultRunner();
232 bool use_accelerator_runner =
true;
233 if (
auto v = Convert::Type<Int32>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_USE_QUEUE",
true))
234 use_accelerator_runner = (v.value()!=0);
235 if (use_accelerator_runner && default_runner)
236 runner = *default_runner;
239 if (!runner.isInitialized())
240 runner.initialize(Accelerator::eExecutionPolicy::Sequential);
241 m_runner_info = std::make_unique<RunnerInfo>(runner);
243 info() <<
"Use runner '" << this->runner().executionPolicy() <<
"' for MeshMaterialMng name=" << name()
244 <<
" async_queue_size=" << nb_queue;
245 m_runner_info->initializeAsyncPool(nb_queue);
252 RunQueue& q = runQueue();
254 q.setMemoryRessource(eMemoryRessource::Device);
259 int default_flags = 0;
265 int opt_flag_value = 0;
266 String env_name =
"ARCANE_MATERIAL_MODIFICATION_FLAGS";
267 String opt_flag_str = platform::getEnvironmentVariable(env_name);
268 if (!opt_flag_str.null()){
269 if (builtInGetValue(opt_flag_value,opt_flag_str)){
270 pwarning() <<
"Invalid value '" << opt_flag_str
271 <<
" 'for environment variable '" << env_name
273 opt_flag_value = default_flags;
277 opt_flag_value = default_flags;
279 m_modification_flags = opt_flag_value;
284 String env_name =
"ARCANE_MATSYNCHRONIZE_VERSION";
285 String env_value = platform::getEnvironmentVariable(env_name);
286 info() <<
"ENV_VALUE=" << env_value;
287 Integer version = m_synchronize_variable_version;
288 if (!env_value.null()){
289 if (builtInGetValue(version,env_value)){
290 pwarning() <<
"Invalid value '" << env_value
291 <<
" 'for environment variable '" << env_name
295 m_synchronize_variable_version = version;
297 info() <<
"Set material variable synchronize version to "
298 <<
"'" << m_synchronize_variable_version <<
"'";
303 String env_name =
"ARCANE_MATERIAL_DATA_COMPRESSOR_NAME";
304 String env_value = platform::getEnvironmentVariable(env_name);
305 if (!env_value.null()){
306 info() <<
"Use service '" << env_value <<
"' for material data compression";
307 m_data_compressor_service_name = env_value;
313 if (
auto v = Convert::Type<Real>::tryParseFromEnvironment(
"ARCANE_MATERIALMNG_ADDITIONAL_CAPACITY_RATIO",
true)){
315 m_additional_capacity_ratio = v.value();
316 info() <<
"Set additional capacity ratio to " << m_additional_capacity_ratio;
321 m_exchange_mng->build();
326 IItemEnumeratorTracer* item_tracer = IItemEnumeratorTracer::singleton();
328 info() <<
"Adding material enumerator tracing";
329 EnumeratorTracer::_setSingleton(
new EnumeratorTracer(traceMng(),item_tracer->perfCounterRef()));
336void MeshMaterialMng::
337_addVariableIndexer(MeshMaterialVariableIndexer* var_idx)
339 var_idx->setIndex(m_variables_indexer.size());
340 m_variables_indexer.add(var_idx);
351MeshMaterial* MeshMaterialMng::
352_createMaterial(MeshEnvironment* env,MeshMaterialInfo* infos,
const String& name)
355 if (infos->materialMng()!=
this)
356 ARCANE_FATAL(
"Invalid materialMng() for material info");
357 if (env->materialMng()!=
this)
359 Integer var_index = m_variables_indexer.size();
360 Int16 mat_id = CheckedConvert::toInt16(m_materials.size());
361 MeshMaterial* mat =
new MeshMaterial(infos,env,name,mat_id);
362 info() <<
"Create material name=" << name <<
"mat_id=" << mat_id <<
" var_index=" << var_index;
364 m_materials.add(mat);
365 m_materials_as_components.add(mat);
366 m_true_materials.add(mat);
368 _addVariableIndexer(mat->variableIndexer());
375MeshMaterialInfo* MeshMaterialMng::
376registerMaterialInfo(
const String& name)
380 MeshMaterialInfo* old_mmi = _findMaterialInfo(name);
382 ARCANE_FATAL(
"Un matériau de nom '{0}' est déjà enregistré",name);
384 MeshMaterialInfo* mmi =
new MeshMaterialInfo(
this,name);
385 m_materials_info.add(mmi);
398IMeshEnvironment* MeshMaterialMng::
399createEnvironment(
const MeshEnvironmentBuildInfo& infos)
402 Int16 env_index = CheckedConvert::toInt16(m_environments.size());
404 const String& env_name = infos.name();
405 MeshEnvironment* old_me = _findEnvironment(env_name);
407 ARCANE_FATAL(
"Un milieu de nom '{0}' est déjà enregistré",env_name);
409 info() <<
"Creating environment name=" << env_name <<
" index=" << env_index;
411 MeshEnvironment* me =
new MeshEnvironment(
this,env_name,env_index);
413 m_true_environments.add(me);
414 m_environments.add(me);
415 m_environments_as_components.add(me);
418 Integer nb_mat = infos.materials().size();
419 for( Integer i=0; i<nb_mat; ++i ){
420 const MeshEnvironmentBuildInfo::MatInfo& buildinfo = infos.materials()[i];
421 const String& mat_name = buildinfo.m_name;
422 String new_mat_name = env_name +
"_" + mat_name;
423 MeshMaterialInfo* mat_info = _findMaterialInfo(mat_name);
425 ARCANE_FATAL(
"Aucun matériau de nom '{0}' n'est défini",mat_name);
427 MeshMaterial* mm = _createMaterial(me,mat_info,new_mat_name);
429 mat_info->_addEnvironment(env_name);
435 MeshMaterialVariableIndexer* var_idx =
nullptr;
437 var_idx = me->materials()[0]->_internalApi()->variableIndexer();
440 var_idx =
new MeshMaterialVariableIndexer(traceMng(),me->name());
441 _addVariableIndexer(var_idx);
442 m_variables_indexer_to_destroy.add(var_idx);
444 me->setVariableIndexer(var_idx);
452IMeshBlock* MeshMaterialMng::
453createBlock(
const MeshBlockBuildInfo& infos)
457 Int32 block_index = m_blocks.size();
459 const String& name = infos.name();
460 const MeshBlock* old_mb = _findBlock(name);
462 ARCANE_FATAL(
"Un bloc de nom '{0}' est déjà enregistré",name);
464 info() <<
"Creating block name=" << name <<
" index=" << block_index
465 <<
" nb_env=" << infos.environments().size();
466 Integer nb_env = infos.environments().size();
467 for( Integer i=0; i<nb_env; ++i )
468 info() <<
" Adding environment name=" << infos.environments()[i]->name() <<
" to block";
471 MeshBlock* mb =
new MeshBlock(
this,block_index,infos);
473 m_true_blocks.add(mb);
482void MeshMaterialMng::
483addEnvironmentToBlock(IMeshBlock* block,IMeshEnvironment* env)
486 mb->addEnvironment(env);
492void MeshMaterialMng::
493removeEnvironmentToBlock(IMeshBlock* block,IMeshEnvironment* env)
496 mb->removeEnvironment(env);
502void MeshMaterialMng::
503endCreate(
bool is_continue)
508 _saveInfosInProperties();
510 info() <<
"END CREATE MATERIAL_MNG is_continue=" << is_continue;
512 m_modifier = std::make_unique<MeshMaterialModifierImpl>(
this);
513 m_modifier->initOptimizationFlags();
515 m_all_env_data->endCreate(is_continue);
517 auto synchronizer = mesh()->cellFamily()->allItemsSynchronizer();
518 m_all_cells_mat_env_synchronizer = std::make_unique<MeshMaterialVariableSynchronizer>(
this,synchronizer,MatVarSpace::MaterialAndEnvironment);
519 m_all_cells_env_only_synchronizer = std::make_unique<MeshMaterialVariableSynchronizer>(
this,synchronizer,MatVarSpace::Environment);
523 Integer nb_component = m_environments_as_components.size() + m_materials_as_components.size();
524 m_components.reserve(nb_component);
525 m_components.addRange(m_environments_as_components);
526 m_components.addRange(m_materials_as_components);
531 for(
const auto& i : m_full_name_variable_map ){
532 IMeshMaterialVariable* mv = i.second;
533 info(4) <<
"BUILD FROM MANAGER name=" << mv->name() <<
" this=" <<
this;
534 mv->buildFromManager(is_continue);
538 m_is_end_create =
true;
546 for( IMeshEnvironment* env : m_environments ){
552 m_exchange_mng->registerFactory();
558void MeshMaterialMng::
559setModificationFlags(
int v)
562 m_modification_flags = v;
563 info() <<
"Setting ModificationFlags to v=" << v;
569void MeshMaterialMng::
570setAllocateScalarEnvironmentVariableAsMaterial(
bool v)
573 m_is_allocate_scalar_environment_variable_as_material = v;
574 info() <<
"Setting AllocateScalarEnvironmentVariableAsMaterial to v=" << v;
580void MeshMaterialMng::
581setDataCompressorServiceName(
const String& name)
583 m_data_compressor_service_name = name;
589MeshMaterialModifierImpl* MeshMaterialMng::
592 return m_modifier.get();
598MeshMaterialInfo* MeshMaterialMng::
599_findMaterialInfo(
const String& name)
601 for( MeshMaterialInfo* mmi : m_materials_info )
602 if (mmi->name()==name)
610IMeshEnvironment* MeshMaterialMng::
611findEnvironment(
const String& name,
bool throw_exception)
613 IMeshEnvironment* env = _findEnvironment(name);
624MeshEnvironment* MeshMaterialMng::
625_findEnvironment(
const String& name)
627 for( MeshEnvironment* env : m_true_environments )
628 if (env->name()==name)
636IMeshBlock* MeshMaterialMng::
637findBlock(
const String& name,
bool throw_exception)
639 IMeshBlock* block = _findBlock(name);
650MeshBlock* MeshMaterialMng::
651_findBlock(
const String& name)
653 for( MeshBlock* b : m_true_blocks )
662void MeshMaterialMng::
674void MeshMaterialMng::
677 m_all_env_data->forceRecompute(
true);
689void MeshMaterialMng::
690syncVariablesReferences(
bool check_resize)
692 for(
const auto& i : m_full_name_variable_map ){
693 IMeshMaterialVariable* mv = i.second;
694 info(4) <<
"SYNC REFERENCES FROM MANAGER name=" << mv->name();
695 mv->_internalApi()->syncReferences(check_resize);
702void MeshMaterialMng::
703visitVariables(IFunctorWithArgumentT<IMeshMaterialVariable*>* functor)
707 for(
const auto& i : m_full_name_variable_map ){
708 IMeshMaterialVariable* mv = i.second;
709 functor->executeFunctor(mv);
716void MeshMaterialMng::
719 const IItemFamily* cell_family = mesh()->cellFamily();
720 ItemGroup all_cells = cell_family->allItems();
721 ConstArrayView<Int16> nb_env_per_cell = m_all_env_data->componentConnectivityList()->cellsNbEnvironment();
723 AllEnvCell all_env_cell = *iallenvcell;
724 Integer cell_nb_env = all_env_cell.nbEnvironment();
725 Cell cell = all_env_cell.globalCell();
726 Int64 cell_uid = cell.uniqueId();
727 if (all_env_cell.level()!=LEVEL_ALLENVIRONMENT)
730 if (all_env_cell.globalCell()!=cell)
731 ARCANE_FATAL(
"Bad corresponding globalCell() in all_env_item");
732 if (cell_nb_env != nb_env_per_cell[cell.localId()])
733 ARCANE_FATAL(
"Bad value for nb_env direct='{0}' var='{1}'",
734 cell_nb_env, nb_env_per_cell[cell.localId()]);
735 for( Integer z=0; z<cell_nb_env; ++z ){
736 EnvCell ec = all_env_cell.cell(z);
737 Integer cell_nb_mat = ec.nbMaterial();
738 matimpl::ConstituentItemBase eii = ec.constituentItemBase();
739 if (all_env_cell.constituentItemBase()!=eii._superItemBase())
740 ARCANE_FATAL(
"Bad corresponding allEnvItem() in env_item uid={0}",cell_uid);
741 if (eii.globalItemBase()!=cell)
742 ARCANE_FATAL(
"Bad corresponding globalItem() in env_item");
743 if (eii.level()!=LEVEL_ENVIRONMENT)
744 ARCANE_FATAL(
"Bad level '{0}' for in env_item",eii.level());
747 if (cell_nb_env>1 && ec._varIndex().arrayIndex()==0)
748 ARCANE_FATAL(
"Global index for a partial cell env_item={0}",ec);
750 for( Integer k=0; k<cell_nb_mat; ++k ){
751 MatCell mc = ec.cell(k);
752 matimpl::ConstituentItemBase mci = mc.constituentItemBase();
753 if (eii!=mci._superItemBase())
754 ARCANE_FATAL(
"Bad corresponding env_item in mat_item k={0} mc={1}",k,mc);
755 if (mci.globalItemBase()!=cell)
756 ARCANE_FATAL(
"Bad corresponding globalItem() in mat_item");
757 if (mci.level()!=LEVEL_MATERIAL)
758 ARCANE_FATAL(
"Bad level '{0}' for in mat_item",mci.level());
761 if ((cell_nb_env>1 || cell_nb_mat>1) && mc._varIndex().arrayIndex()==0){
762 ARCANE_FATAL(
"Global index for a partial cell matitem={0} name={1} nb_mat={2} nb_env={3}",
763 mc,mc.material()->name(),cell_nb_mat,cell_nb_env);
769 for( IMeshEnvironment* env : m_environments ){
777IMeshMaterialVariable* MeshMaterialMng::
778findVariable(
const String& name)
780 IMeshMaterialVariable* v = _findVariableFullyQualified(name);
787 const IVariable* global_var = m_variable_mng->findMeshVariable(mesh(),name);
789 v = _findVariableFullyQualified(global_var->fullName());
800IMeshMaterialVariable* MeshMaterialMng::
801_findVariableFullyQualified(
const String& name)
803 auto i = m_full_name_variable_map.find(name);
804 if (i!=m_full_name_variable_map.end())
812IMeshMaterialVariable* MeshMaterialMng::
813checkVariable(IVariable* global_var)
815 auto i = m_var_to_mat_var_map.find(global_var);
816 if (i!=m_var_to_mat_var_map.end())
824void MeshMaterialMng::
825fillWithUsedVariables(Array<IMeshMaterialVariable*>& variables)
831 for(
const auto& i : m_full_name_variable_map ){
832 IMeshMaterialVariable* ivar = i.second;
833 if (ivar->globalVariable()->isUsed())
841void MeshMaterialMng::
842_addVariable(IMeshMaterialVariable* var)
845 IVariable* gvar = var->globalVariable();
846 info(4) <<
"MAT_ADD_VAR global_var=" << gvar <<
" var=" << var <<
" this=" <<
this;
847 m_var_to_mat_var_map.insert(std::make_pair(gvar,var));
848 m_full_name_variable_map.insert(std::make_pair(gvar->fullName(),var));
854void MeshMaterialMng::
855_removeVariable(IMeshMaterialVariable* var)
858 IVariable* gvar = var->globalVariable();
859 info(4) <<
"MAT:Remove variable global_var=" << gvar <<
" var=" << var;
860 m_var_to_mat_var_map.erase(gvar);
861 m_full_name_variable_map.erase(gvar->fullName());
867void MeshMaterialMng::
868dumpInfos(std::ostream& o)
870 Integer nb_mat = m_materials.size();
871 Integer nb_env = m_environments.size();
872 Integer nb_var_idx = m_variables_indexer.size();
873 o <<
"-- Infos sur les milieux et matériaux\n";
874 o <<
"-- Nb Materiaux: " << nb_mat <<
'\n';
875 o <<
"-- Nb Milieux: " << nb_env <<
'\n';
876 o <<
"-- Nb Variables partielles: " << nb_var_idx <<
'\n';
878 o <<
"-- Liste des matériaux\n";
879 for( IMeshMaterial* mat : m_materials ){
880 o <<
"-- Materiau name=" << mat->name() <<
'\n';
883 o <<
"-- Liste des milieux\n";
884 for( IMeshEnvironment* me : m_environments ){
885 ConstArrayView<IMeshMaterial*> env_materials = me->materials();
886 const MeshMaterialVariableIndexer* env_var_idx = me->_internalApi()->variableIndexer();
887 Integer nb_env_mat = env_materials.size();
888 o <<
"-- Milieu name=" << me->name()
889 <<
" nb_mat=" << nb_env_mat
890 <<
" nb_cell=" << me->cells().size()
891 <<
" var_idx = " << env_var_idx->index()
892 <<
" ids=" << env_var_idx->matvarIndexes()
894 for( IMeshMaterial* mm : env_materials ){
895 const MeshMaterialVariableIndexer* idx = mm->_internalApi()->variableIndexer();
896 o <<
"-- Materiau\n";
897 o <<
"-- name = " << mm->name() <<
"\n";
898 o <<
"-- nb_cell = " << mm->cells().size() <<
"\n";
899 o <<
"-- var_idx = " << idx->index() <<
"\n";
907void MeshMaterialMng::
908dumpInfos2(std::ostream& o)
910 const ConstituentConnectivityList& constituent_list = *m_all_env_data->componentConnectivityList();
911 ConstArrayView<Int16> nb_env_per_cell = constituent_list.cellsNbEnvironment();
912 Integer nb_mat = m_materials.size();
913 Integer nb_env = m_environments.size();
914 Integer nb_var_idx = m_variables_indexer.size();
915 o <<
"-- Material and Environment infos: nb_env=" << nb_env
916 <<
" nb_mat=" << nb_mat <<
" timestamp=" << m_timestamp
917 <<
" nb_var_idx=" << nb_var_idx
919 Integer nb_cell = mesh()->allCells().size();
923 if (nb_env_per_cell[icell.localId()] <= 1)
926 o <<
" nb_cell=" << nb_cell <<
" nb_pure_env=" << nb_pure_env
927 <<
" nb_partial=" << (nb_cell-nb_pure_env)
928 <<
" percent=" << (100*nb_pure_env)/nb_cell
932 o <<
"-- Liste des milieux\n";
933 for( MeshEnvironment* me : m_true_environments ){
934 ConstArrayView<IMeshMaterial*> env_materials = me->materials();
935 const MeshMaterialVariableIndexer* env_var_idx = me->variableIndexer();
936 const Int16 env_id = me->componentId();
937 Integer nb_env_mat = env_materials.size();
938 Integer nb_env_cell = me->cells().size();
942 if (constituent_list.cellNbMaterial(icell, env_id) <= 1)
947 nb_pure_mat = nb_env_cell;
948 o <<
"-- Env name=" << me->name()
949 <<
" nb_mat=" << nb_env_mat
950 <<
" var_idx=" << env_var_idx->index()
951 <<
" nb_cell=" << nb_env_cell
952 <<
" nb_pure_mat=" << nb_pure_mat;
954 o <<
" percent=" << (nb_pure_mat*100)/nb_env_cell;
956 for( Integer j=0; j<nb_env_mat; ++j ){
957 IMeshMaterial* mm = env_materials[j];
958 const MeshMaterialVariableIndexer* idx = mm->_internalApi()->variableIndexer();
959 o <<
"-- Mat name=" << mm->name()
960 <<
" nb_cell=" << mm->cells().size()
961 <<
" var_idx=" << idx->index()
970bool MeshMaterialMng::
971synchronizeMaterialsInCells()
973 return m_mms->synchronizeMaterialsInCells();
979void MeshMaterialMng::
980checkMaterialsInCells(Integer max_print)
982 m_mms->checkMaterialsInCells(max_print);
988void MeshMaterialMng::
989dumpCellInfos(Cell cell,std::ostream& o)
991 CellToAllEnvCellConverter all_env_cell_converter(
this);
992 AllEnvCell all_env_cell = all_env_cell_converter[cell];
993 Cell global_cell = all_env_cell.globalCell();
994 o <<
"Cell uid=" << ItemPrinter(global_cell) <<
'\n';
996 o <<
"ENV name=" << (*ienvcell).environment()->name()
997 <<
" component_idx=" << ComponentItemLocalId(ienvcell) <<
'\n';
999 o <<
"MAT name=" << (*imatcell).material()->name()
1000 <<
" component_idx=" << ComponentItemLocalId(imatcell) <<
'\n';
1008CellToAllEnvCellConverter MeshMaterialMng::
1009cellToAllEnvCellConverter()
1011 return CellToAllEnvCellConverter(componentItemSharedInfo(LEVEL_ALLENVIRONMENT));
1017void MeshMaterialMng::
1020 if (m_is_end_create)
1021 ARCANE_FATAL(
"Invalid method call because endCreate() has already been called");
1027AllEnvCellVectorView MeshMaterialMng::
1028_view(SmallSpan<const Int32> local_ids)
1030 return AllEnvCellVectorView(local_ids.constSmallView(), componentItemSharedInfo(LEVEL_ALLENVIRONMENT));
1042 IMeshMaterialMng::_internalSetFactory(
this);
1046 IMeshMaterialMng::_internalSetFactory(
nullptr);
1049 Ref<IMeshMaterialMng> getTrueReference(
const MeshHandle& mesh_handle,
bool is_create)
override;
1059Ref<IMeshMaterialMng> MeshMaterialMngFactory::
1060getTrueReference(
const MeshHandle& mesh_handle,
bool is_create)
1065 const char* name =
"MeshMaterialMng_StdMat";
1072 IMeshMaterialMng* mm = arcaneCreateMeshMaterialMng(mesh_handle,
"StdMat");
1073 Ref<IMeshMaterialMng> mm_ref = makeRef(mm);
1074 udlist->
setData(name,
new UserDataType(
new Ref<IMeshMaterialMng>(mm_ref)));
1077 auto adud =
dynamic_cast<UserDataType*
>(ud);
1080 return *(adud->data());
1086bool MeshMaterialMng::
1087isInMeshMaterialExchange()
const
1089 return m_exchange_mng->isInMeshMaterialExchange();
1095void MeshMaterialMng::
1096_checkCreateProperties()
1100 m_properties = std::make_unique<Properties>(*(mesh()->properties()),String(
"MeshMaterialMng_")+name());
1107const Int32 SERIALIZE_VERSION = 1;
1109void MeshMaterialMng::
1110_saveInfosInProperties()
1112 _checkCreateProperties();
1115 m_properties->set(
"Version",SERIALIZE_VERSION);
1119 UniqueArray<String> material_info_names;
1120 for( MeshMaterialInfo* mat_info : m_materials_info ){
1121 material_info_names.add(mat_info->name());
1123 m_properties->set(
"MaterialInfoNames",material_info_names);
1125 UniqueArray<String> env_names;
1126 UniqueArray<Int32> env_nb_mat;
1127 UniqueArray<String> env_mat_names;
1129 IMeshEnvironment* env = *ienv;
1130 env_names.add(env->name());
1131 info(5) <<
"SAVE ENV_NAME name=" << env->name() <<
" nb_mat=" << env->nbMaterial();
1132 env_nb_mat.add(env->nbMaterial());
1134 const String& name = (*imat)->infos()->name();
1135 info(5) <<
"SAVE MAT_NAME name=" << name;
1136 env_mat_names.add(name);
1139 m_properties->set(
"EnvNames",env_names);
1140 m_properties->set(
"EnvNbMat",env_nb_mat);
1141 m_properties->set(
"EnvMatNames",env_mat_names);
1145 UniqueArray<String> block_names;
1146 UniqueArray<String> block_cell_group_names;
1147 UniqueArray<Int32> block_nb_env;
1148 UniqueArray<String> block_env_names;
1149 for( IMeshBlock* block : m_blocks ){
1150 block_names.add(block->name());
1151 block_cell_group_names.add(block->cells().name());
1152 block_nb_env.add(block->nbEnvironment());
1154 const String& name = (*ienv)->name();
1155 info(5) <<
"SAVE BLOCK ENV_NAME name=" << name;
1156 block_env_names.add(name);
1159 m_properties->set(
"BlockNames",block_names);
1160 m_properties->set(
"BlockCellGroupNames",block_cell_group_names);
1161 m_properties->set(
"BlockNbEnv",block_nb_env);
1162 m_properties->set(
"BlockEnvNames",block_env_names);
1168void MeshMaterialMng::
1171 if (m_is_end_create)
1174 _checkCreateProperties();
1176 info() <<
"Creating material infos from dump";
1179 Int32 v = m_properties->getInt32(
"Version");
1180 if (v!=SERIALIZE_VERSION)
1181 ARCANE_FATAL(
"Bad serializer version: trying to read from incompatible checkpoint v={0} expected={1}",
1182 v,SERIALIZE_VERSION);
1184 UniqueArray<String> material_info_names;
1185 m_properties->get(
"MaterialInfoNames",material_info_names);
1186 for(
const String& mat_name : material_info_names )
1187 this->registerMaterialInfo(mat_name);
1189 UniqueArray<String> env_names;
1190 UniqueArray<Int32> env_nb_mat;
1191 UniqueArray<String> env_mat_names;
1192 m_properties->get(
"EnvNames",env_names);
1193 m_properties->get(
"EnvNbMat",env_nb_mat);
1194 m_properties->get(
"EnvMatNames",env_mat_names);
1197 for( Integer ienv=0, nenv=env_names.size(); ienv<nenv; ++ienv ){
1198 Materials::MeshEnvironmentBuildInfo env_build(env_names[ienv]);
1199 Integer nb_mat = env_nb_mat[ienv];
1200 for( Integer imat=0; imat<nb_mat; ++imat ){
1201 env_build.addMaterial(env_mat_names[mat_index]);
1204 this->createEnvironment(env_build);
1209 UniqueArray<String> block_names;
1210 UniqueArray<String> block_cell_group_names;
1211 UniqueArray<String> block_env_names;
1212 UniqueArray<Int32> block_nb_env;
1213 m_properties->get(
"BlockNames",block_names);
1214 m_properties->get(
"BlockCellGroupNames",block_cell_group_names);
1215 m_properties->get(
"BlockNbEnv",block_nb_env);
1216 m_properties->get(
"BlockEnvNames",block_env_names);
1217 const IItemFamily* cell_family = mesh()->cellFamily();
1219 for( Integer i=0, n=block_names.size(); i<n; ++i ){
1220 String name = block_names[i];
1221 String cell_group_name = block_cell_group_names[i];
1222 CellGroup cells = cell_family->findGroup(cell_group_name);
1224 ARCANE_FATAL(
"Can not find cell group '{0}' for block creation",
1226 MeshBlockBuildInfo mbbi(name,cells);
1227 if (!block_nb_env.empty()){
1228 Integer nb_env = block_nb_env[i];
1229 for( Integer ienv=0; ienv<nb_env; ++ienv ){
1230 const String& name2 = block_env_names[block_env_index];
1232 IMeshEnvironment* env = findEnvironment(name2,
false);
1234 ARCANE_FATAL(
"Invalid environment name '{0}' for recreating blocks",name2);
1235 mbbi.addEnvironment(env);
1238 this->createBlock(mbbi);
1247void MeshMaterialMng::
1254 m_exchange_mng.reset();
1256 _unregisterAllVariables();
1262void MeshMaterialMng::
1263_unregisterAllVariables()
1268 UniqueArray<MeshMaterialVariableRef*> m_all_refs;
1270 for(
const auto& i : m_full_name_variable_map ){
1271 const IMeshMaterialVariable* var = i.second;
1273 for( MeshMaterialVariableRef::Enumerator iref(var); iref.hasNext(); ++iref ){
1274 MeshMaterialVariableRef* ref = *iref;
1275 m_all_refs.add(ref);
1279 for( MeshMaterialVariableRef* ref : m_all_refs )
1280 ref->unregisterVariable();
1286ComponentItemSharedInfo* MeshMaterialMng::
1287componentItemSharedInfo(Int32 level)
const
1289 ComponentItemInternalData* data = m_all_env_data->componentItemInternalData();
1290 ComponentItemSharedInfo* shared_info =
nullptr;
1291 if (level == LEVEL_MATERIAL)
1292 shared_info = data->matSharedInfo();
1293 else if (level == LEVEL_ENVIRONMENT)
1294 shared_info = data->envSharedInfo();
1295 else if (level==LEVEL_ALLENVIRONMENT)
1296 shared_info = data->allEnvSharedInfo();
1306void MeshMaterialMng::
1309 IEnumeratorTracer* tracer = IEnumeratorTracer::singleton();
1311 tracer->dumpStats();
1314 m_modifier->dumpStats();
1316 for (IMeshEnvironment* env : m_environments) {
1320 if (env->nbMaterial() > 1)
1321 env->_internalApi()->variableIndexer()->dumpStats();
1323 for (IMeshMaterial* mat : m_materials) {
1324 mat->_internalApi()->variableIndexer()->dumpStats();
1331void MeshMaterialMng::
1332createAllCellToAllEnvCell()
1334 if (!m_accelerator_envcell_container) {
1335 m_accelerator_envcell_container = std::make_unique<AllCellToAllEnvCellContainer>(
this);
1336 m_accelerator_envcell_container->initialize();
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fonctions de gestion mémoire et des allocateurs.
UserData s'auto-détruisant une fois détaché.
Interface d'une liste qui gère des données utilisateurs.
virtual void setData(const String &name, IUserData *ud)=0
Positionne le user-data associé au nom name.
virtual IUserData * data(const String &name, bool allow_null=false) const =0
Donnée associée à name.
Interface pour une donnée utilisateur attachée à un autre objet.
IUserDataList * meshUserDataList() const
Données utilisateurs associées.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
RunQueue makeQueue(const Runner &runner)
Créé une file associée à runner.
bool isAcceleratorPolicy(eExecutionPolicy exec_policy)
Indique si exec_policy correspond à un accélérateur.
Active toujours les traces dans les parties Arcane concernant les matériaux.
bool arcaneIsCheck()
Vrai si on est en mode vérification.
Int32 Integer
Type représentant un entier.