14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/NumericTypes.h"
16#include "arcane/utils/ITraceMng.h"
17#include "arcane/utils/CheckedConvert.h"
19#include "arcane/materials/MeshMaterialVariable.h"
20#include "arcane/materials/MaterialVariableBuildInfo.h"
21#include "arcane/materials/MeshMaterialVariableSynchronizerList.h"
22#include "arcane/materials/MatItemEnumerator.h"
23#include "arcane/materials/ComponentItemVectorView.h"
24#include "arcane/materials/internal/MeshMaterialVariablePrivate.h"
26#include "arcane/core/Array2Variable.h"
27#include "arcane/core/VariableRefArray2.h"
28#include "arcane/core/MeshVariable.h"
29#include "arcane/core/ISerializer.h"
30#include "arcane/core/internal/IVariableInternal.h"
32#include "arcane/materials/ItemMaterialVariableBaseT.H"
34#include "arcane/datatype/DataTypeTraits.h"
35#include "arcane/datatype/DataStorageBuildInfo.h"
46template <
typename DataType>
void
48copyTo(SmallSpan2<const DataType> input, SmallSpan<const Int32> input_indexes,
49 SmallSpan2<DataType> output, SmallSpan<const Int32> output_indexes,
50 const RunQueue& queue)
53 Integer nb_value = input_indexes.size();
54 Integer dim2_size = input.dim2Size();
60 auto xo = output[output_indexes[i]];
61 auto xi = input[input_indexes[i]];
62 for (
Integer j = 0; j < dim2_size; ++j)
70template <
typename DataType>
void
74 ContainerType& values = data->_internal()->_internalDeprecatedValue();
75 Integer dim2_size = values.dim2Size();
79 container.resize(dim1_size, dim2_size);
85template <
typename DataType>
void
92 Int32 nb_add =
static_cast<Int32>(dim1_size * reserve_ratio);
93 var->_internalApi()->resize(VariableResizeArgs(dim1_size, nb_add,
true));
99template <
typename DataType>
void
102 Array<ContainerViewType>& cviews)
107 ConstArrayView<Array2View<DataType>> views = cviews;
110 auto* true_data =
dynamic_cast<ValueDataType*
>(data);
112 ContainerType& values = true_data->_internal()->_internalDeprecatedValue();
115 Integer dim2_size = views[0].dim2Size();
116 Integer current_dim1_size = values.dim1Size();
118 values.resizeNoInit(current_dim1_size + added_dim1_size, dim2_size);
119 ConstArrayView<MatVarIndex> mvi_indexes = component_view._matvarIndexes();
121 for (
Integer i = 0, n = mvi_indexes.size(); i < n; ++i) {
123 values[i + current_dim1_size].copy(views[mvi.arrayIndex()][mvi.valueIndex()]);
133: BaseClass(v, global_var, global_var_ref, mvs)
140template <
typename DataType>
void
141ItemMaterialVariableArray<DataType>::
142dumpValues(std::ostream& ostr)
151template <
typename DataType>
void
152ItemMaterialVariableArray<DataType>::
163template <
typename DataType>
void
164ItemMaterialVariableArray<DataType>::
168 IItemFamily* family = m_global_variable->itemFamily();
176 Int32 dim2_size = m_global_variable->valueView().dim2Size();
178 switch (sbuf->
mode()) {
179 case ISerializer::ModeReserve: {
186 nb_val += envcell.nbMaterial();
189 sbuf->
reserve(m_global_variable->fullName());
191 Int64 nb_basic_value = nb_val * nb_count * dim2_size;
198 values.
addRange(value(ienvcell._varIndex()));
201 values.
addRange(value(imatcell._varIndex()));
208 sbuf->
put(m_global_variable->fullName());
216 if (m_global_variable->fullName() != ref_name)
217 ARCANE_FATAL(
"Bad serialization expected={0} found={1}", m_global_variable->fullName(), ref_name);
219 Int32 nb_basic_value = nb_value * nb_count;
220 basic_values.
resize(nb_basic_value);
222 if (dim2_size != 0) {
228 setValue(ienvcell._varIndex(), data_values[index]);
232 setValue(imatcell._varIndex(), data_values[index]);
248template <
typename DataType>
void
249ItemMaterialVariableArray<DataType>::
260template <
typename DataType>
void
270template <
typename DataType>
void
274 for (PrivatePartType* pvar : m_vars) {
276 Integer dim1_size = pvar->valueView().dim1Size();
277 pvar->directResize(dim1_size, dim2_size);
287 this->syncReferences();
293template <
typename DataType> Int32
294ItemMaterialVariableArray<DataType>::
297 Int32 dim2_size = m_vars[0]->valueView().dim2Size();
298 return (Int32)
sizeof(DataType) * dim2_size;
304template <
typename DataType>
void
305ItemMaterialVariableArray<DataType>::
306_copyToBufferLegacy(SmallSpan<const MatVarIndex> matvar_indexes, Span<std::byte> bytes)
const
309 Integer dim2_size = m_vars[0]->valueView().dim2Size();
313 const Int32 value_size = CheckedConvert::toInt32(bytes.size() / one_data_size);
314 Array2View<DataType> values(
reinterpret_cast<DataType*
>(bytes.data()), value_size, dim2_size);
315 for (Integer z = 0; z < value_size; ++z) {
316 values[z].copy(value(matvar_indexes[z]));
323template <
typename DataType>
void
324ItemMaterialVariableArray<DataType>::
325copyToBuffer(ConstArrayView<MatVarIndex> matvar_indexes, ByteArrayView bytes)
const
327 auto* ptr =
reinterpret_cast<std::byte*
>(bytes.data());
328 return _copyToBufferLegacy(matvar_indexes, { ptr, bytes.size() });
334template <
typename DataType>
void
335ItemMaterialVariableArray<DataType>::
336_copyFromBufferLegacy(SmallSpan<const MatVarIndex> matvar_indexes, Span<const std::byte> bytes)
339 Integer dim2_size = m_vars[0]->valueView().dim2Size();
343 const Integer value_size = CheckedConvert::toInt32(bytes.size() / one_data_size);
344 ConstArray2View<DataType> values(
reinterpret_cast<const DataType*
>(bytes.data()), value_size, dim2_size);
345 for (Integer z = 0; z < value_size; ++z) {
346 setValue(matvar_indexes[z], values[z]);
353template <
typename DataType>
void
354ItemMaterialVariableArray<DataType>::
355copyFromBuffer(ConstArrayView<MatVarIndex> matvar_indexes, ByteConstArrayView bytes)
357 auto* ptr =
reinterpret_cast<const std::byte*
>(bytes.data());
358 return _copyFromBufferLegacy(matvar_indexes, { ptr, bytes.size() });
367template <
typename ItemType,
typename DataType>
368MeshMaterialVariableArray<ItemType, DataType>::
369MeshMaterialVariableArray(
const MaterialVariableBuildInfo& v, PrivatePartType* global_var,
370 VariableRefType* global_var_ref, MatVarSpace mvs)
371: ItemMaterialVariableArray<DataType>(v, global_var, global_var_ref, mvs)
372, m_true_global_variable_ref(global_var_ref)
379#define ARCANE_INSTANTIATE_MAT(type) \
380 template class ItemMaterialVariableBase<MaterialVariableArrayTraits<type>>; \
381 template class ItemMaterialVariableArray<type>; \
382 template class MeshMaterialVariableArray<Cell, type>; \
383 template class MeshMaterialVariableCommonStaticImpl<MeshMaterialVariableArray<Cell, type>>
#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_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Int64 largeSize() const
Number of elements in the vector (in 64 bits).
void addRange(ConstReferenceType val, Int64 n)
Adds n elements of value val to the end of the array.
void resize(Int64 s)
Changes the number of elements in the array to s.
const T * data() const
Access to the root of the array without any protection.
Interface of an entity family.
virtual ItemVectorView view(Int32ConstArrayView local_ids)=0
View on the entities.
void reserveInt64(Int64 n)
Reserve for n Int64.
virtual void reserve(eBasicDataType dt, Int64 n)=0
Reserves memory for n objects of type dt.
@ ModePut
The serializer expects reserve().
@ ModeGet
The serializer expects get().
virtual Int64 getInt64()=0
Retrieve a size.
virtual void put(Span< const Real > values)=0
Add the array values.
virtual void putSpan(Span< const Real > values)
Add the array values.
virtual eMode mode() const =0
Current operating mode.
virtual void getSpan(Span< Real > values)
Retrieve the array values.
virtual void get(ArrayView< Real > values)=0
Retrieve the array values.
virtual void reserveSpan(eBasicDataType dt, Int64 n)=0
Reserves memory for n values of dt.
virtual void putInt64(Int64 value)=0
Add the integer value.
View on a vector of entities.
View over a vector of entities of a component.
Integer nbItem() const
Number of entities in the view.
Arcane cell of an environment.
Interface of a component (material or environment) of a mesh.
Interface for the material and environment manager of a mesh.
Represents an index on material and environment variables.
Characteristics for an array material variable.
Synchronizing a list of material variables.
void apply()
Performs the synchronization.
void add(MeshMaterialVariable *var)
Adds the variable var to the list of variables to synchronize.
MatVarSpace space() const override
Variable definition space (material+environment or environment only).
View for a 2D array whose size is an 'Int32'.
View of an array of elements of type T.
Unicode character string.
1D data vector with value semantics (STL style).
RunCommand makeCommand(const RunQueue &run_queue)
Creates a command associated with the queue run_queue.
Always enables tracing in Arcane parts concerning materials.
MatVarSpace
Definition space for a material variable.
@ Environment
Variable having values only on environments.
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
eBasicDataType
Type of a basic data item.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.