14#include "arcane/materials/internal/ComponentItemInternalData.h"
18#include "arcane/core/IItemFamily.h"
20#include "arcane/core/internal/IItemFamilyInternal.h"
22#include "arcane/materials/internal/MeshMaterialMng.h"
24#include "arcane/accelerator/RunCommandLoop.h"
25#include "arcane/accelerator/SpanViews.h"
36MemoryAllocationOptions ComponentItemInternalData::Storage::
37_allocInfo(
const MemoryAllocationOptions& alloc_info,
const String& base_name,
const String& name)
39 MemoryAllocationOptions opts(alloc_info);
40 opts.setArrayName(base_name + name);
47ComponentItemInternalData::Storage::
48Storage(
const MemoryAllocationOptions& alloc_info,
const String& base_name)
49: m_first_sub_constituent_item_id_list(_allocInfo(alloc_info, base_name,
"FirtSubComponentIdList"))
50, m_super_component_item_local_id_list(_allocInfo(alloc_info, base_name,
"SuperComponentIdList"))
51, m_component_id_list(_allocInfo(alloc_info, base_name,
"ComponentIdList"))
52, m_nb_sub_constituent_item_list(_allocInfo(alloc_info, base_name,
"NbSubConstituentItemList"))
53, m_global_item_local_id_list(_allocInfo(alloc_info, base_name,
"GlobalItemLocalIdList"))
54, m_var_index_list(_allocInfo(alloc_info, base_name,
"VarIndexList"))
61void ComponentItemInternalData::Storage::
62resize(Int32 new_size, ComponentItemSharedInfo* shared_info, RunQueue& queue)
67 Int32 true_size = new_size + 1;
70 const bool force_resize =
false;
71 MemoryUtils::checkResizeArrayWithCapacity(m_first_sub_constituent_item_id_list, true_size, force_resize);
72 MemoryUtils::checkResizeArrayWithCapacity(m_super_component_item_local_id_list, true_size, force_resize);
73 MemoryUtils::checkResizeArrayWithCapacity(m_component_id_list, true_size, force_resize);
74 MemoryUtils::checkResizeArrayWithCapacity(m_nb_sub_constituent_item_list, true_size, force_resize);
75 MemoryUtils::checkResizeArrayWithCapacity(m_global_item_local_id_list, true_size, force_resize);
76 MemoryUtils::checkResizeArrayWithCapacity(m_var_index_list, true_size, force_resize);
78 auto first_sub_constituent_item_id_list = m_first_sub_constituent_item_id_list.smallSpan();
79 auto super_component_item_local_id_list = m_super_component_item_local_id_list.smallSpan();
80 auto component_id_list = m_component_id_list.smallSpan();
81 auto nb_sub_constituent_item_list = m_nb_sub_constituent_item_list.smallSpan();
82 auto global_item_local_id_list = m_global_item_local_id_list.smallSpan();
83 auto var_index_list = m_var_index_list.smallSpan();
91 shared_info->m_storage_size = new_size;
92 first_sub_constituent_item_id_list[0] = {};
93 component_id_list[0] = -1;
94 nb_sub_constituent_item_list[0] = 0;
95 global_item_local_id_list[0] = NULL_ITEM_LOCAL_ID;
96 var_index_list[0].reset();
98 shared_info->m_first_sub_constituent_item_id_data = first_sub_constituent_item_id_list.data() + 1;
99 shared_info->m_super_component_item_local_id_data = super_component_item_local_id_list.data() + 1;
100 shared_info->m_component_id_data = component_id_list.data() + 1;
102 shared_info->m_nb_sub_constituent_item_data = nb_sub_constituent_item_list.data() + 1;
103 shared_info->m_global_item_local_id_data = global_item_local_id_list.data() + 1;
104 shared_info->m_var_index_data = var_index_list.data() + 1;
115ComponentItemInternalData::
116ComponentItemInternalData(MeshMaterialMng* mmg)
117: TraceAccessor(mmg->traceMng())
120, m_all_env_storage(_allocOptions(),
"AllEnvStorage")
121, m_env_storage(_allocOptions(),
"EnvStorage")
122, m_mat_storage(_allocOptions(),
"MatStorage")
126 ComponentItemSharedInfo::_setNullInstance();
131 m_shared_infos.resize(3);
132 m_shared_infos.setDebugName(
"ComponentItemInternalDataSharedInfo");
138MemoryAllocationOptions ComponentItemInternalData::
141 return MemoryAllocationOptions(platform::getDefaultDataAllocator());
147void ComponentItemInternalData::
159void ComponentItemInternalData::
165 RunQueue queue(m_material_mng->runQueue());
168 ComponentItemSharedInfo* all_env_shared_info = allEnvSharedInfo();
169 ComponentItemSharedInfo* env_shared_info = envSharedInfo();
170 ComponentItemSharedInfo* mat_shared_info = matSharedInfo();
171 const Int32 all_env_size = m_all_env_storage.size();
172 const Int32 env_size = m_env_storage.size();
173 const Int32 mat_size = m_mat_storage.size();
174 Int32 max_size = math::max(all_env_size, env_size, mat_size);
180 ConstituentItemIndex cii(i);
181 if (i < all_env_size)
182 all_env_shared_info->_reset(cii);
184 env_shared_info->_reset(cii);
186 mat_shared_info->_reset(cii);
194void ComponentItemInternalData::
195resizeComponentItemInternals(Int32 max_local_id, Int32 total_nb_env_cell)
197 RunQueue& queue(m_material_mng->runQueue());
199 auto environments = m_material_mng->trueEnvironments();
200 const Int32 nb_env = environments.size();
201 NumArray<ComponentItemInternalRange, MDDim1> host_mats_range(nb_env);
204 Int32 total_nb_mat_cell = 0;
205 for (
const MeshEnvironment* env : m_material_mng->trueEnvironments())
206 total_nb_mat_cell += env->totalNbCellMat();
210 m_all_env_items_internal_range.setRange(0, max_local_id);
211 m_env_items_internal_range.setRange(0, total_nb_env_cell);
212 Int32 index_in_container = 0;
213 for (MeshEnvironment* env : m_material_mng->trueEnvironments()) {
214 Int32 nb_cell_mat = env->totalNbCellMat();
215 ComponentItemInternalRange mat_range;
216 mat_range.setRange(index_in_container, nb_cell_mat);
217 env->setMatInternalDataRange(mat_range);
218 index_in_container += nb_cell_mat;
222 info(4) <<
"ResizeStorage max_local_id=" << max_local_id
223 <<
" total_nb_env_cell=" << total_nb_env_cell
224 <<
" total_nb_mat_cell=" << total_nb_mat_cell;
226 RunQueue::ScopedAsync sc(&queue);
227 m_all_env_storage.resize(max_local_id, allEnvSharedInfo(), queue);
228 m_env_storage.resize(total_nb_env_cell, envSharedInfo(), queue);
229 m_mat_storage.resize(total_nb_mat_cell, matSharedInfo(), queue);
232 _resetItemsInternal();
238void ComponentItemInternalData::
241 IItemFamily* family = m_material_mng->mesh()->cellFamily();
242 ItemSharedInfo* item_shared_info = family->_internalApi()->commonItemSharedInfo();
247 ComponentItemSharedInfo* info_mat = sharedInfo(LEVEL_MATERIAL);
248 ComponentItemSharedInfo* info_env = sharedInfo(LEVEL_ENVIRONMENT);
249 ComponentItemSharedInfo* info_all_env = sharedInfo(LEVEL_ALLENVIRONMENT);
251 info_mat->m_level = LEVEL_MATERIAL;
252 info_mat->m_item_shared_info = item_shared_info;
253 info_mat->m_components = m_material_mng->materialsAsComponents();
254 info_mat->m_super_component_item_shared_info = info_env;
256 info_env->m_level = LEVEL_ENVIRONMENT;
257 info_env->m_item_shared_info = item_shared_info;
258 info_env->m_components = m_material_mng->environmentsAsComponents();
259 info_env->m_super_component_item_shared_info = info_all_env;
260 info_env->m_sub_component_item_shared_info = info_mat;
262 info_all_env->m_level = LEVEL_ALLENVIRONMENT;
263 info_all_env->m_item_shared_info = item_shared_info;
264 info_all_env->m_components = ConstArrayView<IMeshComponent*>();
265 info_all_env->m_sub_component_item_shared_info = info_env;
266 info() <<
"EndCreate ComponentItemInternalData nb_mat=" << info_mat->m_components.size()
267 <<
" nb_env=" << info_env->m_components.size();
268 info() <<
"EndCreate ComponentItemInternalData mat_shared_info=" << info_mat
269 <<
" env_shared_info=" << info_env;
Various mathematical functions.
Memory and allocator management functions.
#define RUNCOMMAND_SINGLE(...)
Loop on accelerator for execution with a single thread.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
MemoryAllocationOptions getAllocatorForMostlyReadOnlyData()
Default allocator for mostly read-only data.
bool arcaneIsCheck()
True if running in check mode.
Memory management utility functions.