14#include "arcane/utils/FatalErrorException.h"
15#include "arcane/utils/ValueChecker.h"
16#include "arcane/utils/PlatformUtils.h"
17#include "arcane/utils/ArraySimdPadder.h"
18#include "arcane/utils/IFunctor.h"
20#include "arcane/core/IItemFamily.h"
22#include "arcane/core/materials/IMeshComponent.h"
23#include "arcane/core/materials/ComponentItemInternal.h"
24#include "arcane/core/materials/ComponentPartItemVectorView.h"
25#include "arcane/core/materials/internal/IMeshComponentInternal.h"
27#include "arcane/materials/internal/MeshComponentPartData.h"
29#include "arcane/accelerator/Filter.h"
30#include "arcane/accelerator/RunCommandLoop.h"
41MeshComponentPartData::
42MeshComponentPartData(
IMeshComponent* component,
const String& debug_name)
43: TraceAccessor(component->traceMng())
44, m_component(component)
45, m_impure_var_idx(component->_internalApi()->variableIndexerIndex() + 1)
49 IMemoryAllocator* allocator = platform::getDefaultDataAllocator();
50 for (Integer i = 0; i < 2; ++i) {
51 m_value_indexes[i] = UniqueArray<Int32>(allocator);
52 m_items_internal_indexes[i] = UniqueArray<Int32>(allocator);
54 if (!debug_name.empty()) {
55 String base_name = String(
"MeshComponentPartData") + debug_name;
56 for (Integer i = 0; i < 2; ++i) {
57 m_value_indexes[i].setDebugName(base_name +
"ValueIndexes" + String::fromNumber(i));
58 m_items_internal_indexes[i].setDebugName(base_name +
"ValueIndexes" + String::fromNumber(i));
75void MeshComponentPartData::
76_notifyValueIndexesChanged(
RunQueue* queue)
82 bool is_need_padding =
false;
83 for (
Int32 i = 0; i < 2; ++i)
94 ArraySimdPadder::applySimdPaddingView(indexes[i]);
98 ArraySimdPadder::applySimdPaddingView(indexes[0]);
99 ArraySimdPadder::applySimdPaddingView(indexes[1]);
106void MeshComponentPartData::
114 Int32Array& pure_internal_indexes = m_items_internal_indexes[(
Int32)eMatPart::Pure];
115 Int32Array& impure_internal_indexes = m_items_internal_indexes[(
Int32)eMatPart::Impure];
117 pure_indexes.
resize(nb_index);
118 pure_internal_indexes.resize(nb_index);
122 info(4) <<
"BEGIN_BUILD_PART_DATA_FOR_COMPONENT c=" << m_component->name();
130 auto is_pure_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 i) ->
bool {
131 return matvar_indexes[i].arrayIndex() == 0;
133 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(
Int32 i,
Int32 output_index) {
134 pure_indexes_view[output_index] = matvar_indexes[i].valueIndex();
135 pure_internal_indexes_view[output_index] = i;
137 filterer.applyWithIndex(nb_index, is_pure_lambda, setter_lambda, A_FUNCINFO);
138 Int32 nb_out = filterer.nbOutputElement();
139 pure_indexes.
resize(nb_out);
140 pure_internal_indexes.resize(nb_out);
141 nb_impure = nb_index - nb_out;
144 impure_indexes.resize(nb_impure);
145 impure_internal_indexes.resize(nb_impure);
148 SmallSpan<Int32> impure_indexes_view(impure_indexes.view());
149 SmallSpan<Int32> impure_internal_indexes_view(impure_internal_indexes.view());
150 auto is_impure_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i) ->
bool {
151 return matvar_indexes[i].arrayIndex() != 0;
153 auto setter_lambda = [=] ARCCORE_HOST_DEVICE(Int32 i, Int32 output_index) {
154 impure_indexes_view[output_index] = matvar_indexes[i].valueIndex();
155 impure_internal_indexes_view[output_index] = i;
157 filterer.applyWithIndex(nb_index, is_impure_lambda, setter_lambda, A_FUNCINFO);
158 filterer.nbOutputElement();
161 info(4) <<
"BUILD_PART_DATA_FOR_COMPONENT c=" << m_component->name()
162 <<
" nb_pure=" << pure_indexes.
size()
163 <<
" nb_impure=" << impure_indexes.size();
165 _notifyValueIndexesChanged(&queue);
171void MeshComponentPartData::
172_setFromMatVarIndexes(ConstArrayView<MatVarIndex> globals,
173 ConstArrayView<MatVarIndex> multiples)
175 Integer nb_global = globals.size();
176 Integer nb_multiple = multiples.size();
179 const auto mat_part =
static_cast<Int32
>(eMatPart::Pure);
182 for (Integer i = 0; i < nb_global; ++i)
183 idx[i] = globals[i].valueIndex();
187 const auto mat_part =
static_cast<Int32
>(eMatPart::Impure);
190 for (Integer i = 0; i < nb_multiple; ++i)
191 idx[i] = multiples[i].valueIndex();
194 _notifyValueIndexesChanged(
nullptr);
200void MeshComponentPartData::
201_setConstituentListView(
const ConstituentItemLocalIdListView& v)
203 m_constituent_list_view = v;
209void MeshComponentPartData::
212 info(4) <<
"CHECK_VALID_COMPONENT_PART_DATA c=" << m_component->name();
213 _checkNeedRecompute();
214 ValueChecker vc(A_FUNCINFO);
216 for (Integer i = 0; i < 2; ++i) {
217 Int32 var_idx = (i == 0) ? 0 : m_impure_var_idx;
220 Integer nb_item = indexes.size();
221 vc.areEqual(nb_item, item_indexes.size(),
"Indexes size");
222 for (Integer k = 0; k < nb_item; ++k) {
223 MatVarIndex mvi(var_idx, indexes[k]);
224 MatVarIndex component_mvi = m_constituent_list_view._matVarIndex(item_indexes[k]);
225 if (mvi != component_mvi) {
226 info() <<
"Bad MatVarIndex i=" << i <<
" k=" << k
227 <<
" mvi=" << mvi <<
" component_mvi=" << component_mvi;
233 ARCANE_FATAL(
"Bad component part data nb_error={0}", nb_error);
239void MeshComponentPartData::
242 if (!m_is_need_recompute)
244 if (!m_compute_functor)
246 m_compute_functor->executeFunctor();
247 m_is_need_recompute =
false;
256 _checkNeedRecompute();
257 const auto mat_part =
static_cast<Int32>(part);
260 Int32 var_idx = (part == eMatPart::Pure) ? 0 : impureVarIdx();
271 _checkNeedRecompute();
272 const auto mat_part =
static_cast<Int32>(eMatPart::Pure);
285 _checkNeedRecompute();
286 const auto mat_part =
static_cast<Int32>(eMatPart::Impure);
289 const Int32 var_idx = impureVarIdx();
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Integer size() const
Number of elements in the vector.
Generic filtering algorithm on accelerator.
Execution queue for an accelerator.
void resize(Int64 s)
Changes the number of elements in the array to s.
ArrayView< T > view() const
Mutable view of this array.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
View over the impure part of a component.
View over pure or partial entities of a component.
View over the pure part of a component.
Interface of a component (material or environment) of a mesh.
FixedArray< UniqueArray< Int32 >, 2 > m_items_internal_indexes
List of indices in m_items_internal for each material cell.
ConstituentItemLocalIdListView m_constituent_list_view
List of ComponentItems for this constituent.
FixedArray< UniqueArray< Int32 >, 2 > m_value_indexes
List of valueIndex() for each part.
IMeshComponent * m_component
Constituent manager.
View of an array of elements of type T.
View of an array of elements of type T.
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
eMatPart
Part of a component.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Array< Int32 > Int32Array
Dynamic one-dimensional array of 32-bit integers.
std::int32_t Int32
Signed integer type of 32 bits.