12#ifndef ARCANE_MATERIALS_MESHMATERIALVARIABLE_H
13#define ARCANE_MATERIALS_MESHMATERIALVARIABLE_H
17#include "arcane/utils/NotImplementedException.h"
18#include "arcane/utils/Array.h"
19#include "arcane/utils/MemoryView.h"
21#include "arcane/core/materials/IMeshMaterialVariable.h"
22#include "arcane/core/materials/MatVarIndex.h"
26#include "arcane/materials/MeshMaterialVariableFactoryRegisterer.h"
28#include "arcane/core/materials/IScalarMeshMaterialVariable.h"
29#include "arcane/core/materials/IArrayMeshMaterialVariable.h"
72 friend MeshMaterialVariablePrivate;
74 friend MeshMaterialVariableSynchronizerList;
79 ~MeshMaterialVariable()
override;
143 MeshMaterialVariablePrivate* m_p =
nullptr;
157 virtual void _syncReferences(
bool update_views) = 0;
177template <
typename DataType>
182 using ValueType = DataType;
184 using SubViewType = DataType;
185 using SubConstViewType = DataType;
186 using SubInputViewType = DataType;
205 resizeAndFillWithDefault(ValueDataType* data, ContainerType& container,
Integer dim1_size);
207 static ARCCORE_HOST_DEVICE
void setValue(DataType& view,
const DataType& v)
212 resizeWithReserve(PrivatePartType* var,
Int32 new_size,
Real reserve_ratio);
213 static Integer dimension() {
return 0; }
225template <
typename DataType>
230 using ValueType = DataType;
254 static void resizeAndFillWithDefault(ValueDataType* data, ContainerType& container,
265 static void resizeWithReserve(PrivatePartType* var,
Integer new_size,
Real resize_ratio);
272 static Integer dimension() {
return 0; }
282template <
typename Traits>
283class ItemMaterialVariableBase
284:
public MeshMaterialVariable
288 using TraitsType = Traits;
289 using ValueType =
typename Traits::ValueType;
290 using DataType =
typename Traits::ValueType;
291 using ThatClass = ItemMaterialVariableBase<Traits>;
293 using SubViewType =
typename Traits::SubViewType;
294 using SubConstViewType =
typename Traits::SubConstViewType;
295 using SubInputViewType =
typename Traits::SubInputViewType;
296 using ContainerSpanType =
typename Traits::ContainerSpanType;
297 using ContainerViewType =
typename Traits::ContainerViewType;
298 using ContainerConstViewType =
typename Traits::ContainerConstViewType;
299 using PrivatePartType =
typename Traits::PrivatePartType;
300 using ValueDataType =
typename Traits::ValueDataType;
301 using ContainerType =
typename Traits::ContainerType;
302 using UniqueContainerType =
typename Traits::UniqueContainerType;
303 using VariableRefType =
typename Traits::VariableRefType;
309 PrivatePartType* global_var,
340 void setFillValue(
MatVarIndex mvi,
const DataType& v)
352 void _syncFromGlobalVariable();
353 PrivatePartType* _trueGlobalVariable()
355 return m_global_variable;
358 void _init(ArrayView<PrivatePartType*> vars);
368 PrivatePartType* m_global_variable =
nullptr;
369 VariableRef* m_global_variable_ref =
nullptr;
387 ContainerViewType view;
389 view =
m_vars[index]->valueView();
391 m_views_as_bytes[index] = TraitsType::toBytes(view);
396 bool _isValidAndUsedAndGlobalUsed(PrivatePartType* partial_var);
402template <
typename TrueType>
426template <
typename DataType>
427class ItemMaterialVariableScalar
428:
public ItemMaterialVariableBase<MaterialVariableScalarTraits<DataType>>
432 using BaseClass = ItemMaterialVariableBase<MaterialVariableScalarTraits<DataType>>;
434 using ThatClass = ItemMaterialVariableScalar<DataType>;
436 using ContainerViewType =
typename Traits::ContainerViewType;
437 using PrivatePartType =
typename Traits::PrivatePartType;
438 using ValueDataType =
typename Traits::ValueDataType;
439 using ContainerType =
typename Traits::ContainerType;
440 using VariableRefType =
typename Traits::VariableRefType;
446 PrivatePartType* global_var,
464 using BaseClass::setValue;
465 using BaseClass::value;
497 using BaseClass::m_p;
501 using BaseClass::m_global_variable;
502 using BaseClass::m_global_variable_ref;
508 void _synchronizeV1();
509 void _synchronizeV2();
510 void _synchronizeV5();
511 Int64 _synchronize2();
529template <
typename ItemType,
typename DataType>
530class MeshMaterialVariableScalar
531:
public ItemMaterialVariableScalar<DataType>
536 using ThatClass = MeshMaterialVariableScalar<ItemType, DataType>;
538 using BuilderType =
typename ThatInterface::BuilderType;
540 using ItemTypeTemplate = ItemType;
542 using BaseClass = ItemMaterialVariableScalar<DataType>;
544 using PrivatePartType =
typename BaseClass::PrivatePartType;
552 PrivatePartType* global_var,
555 ~MeshMaterialVariableScalar();
559 VariableRefType* globalVariableReference()
const final {
return m_true_global_variable_ref; }
583 VariableRefType* m_true_global_variable_ref =
nullptr;
594template <
typename DataType>
595class ItemMaterialVariableArray
596:
public ItemMaterialVariableBase<MaterialVariableArrayTraits<DataType>>
600 using BaseClass = ItemMaterialVariableBase<MaterialVariableArrayTraits<DataType>>;
603 using ThatClass = ItemMaterialVariableArray<DataType>;
605 using ContainerViewType =
typename Traits::ContainerViewType;
606 using PrivatePartType =
typename Traits::PrivatePartType;
607 using ValueDataType =
typename Traits::ValueDataType;
608 using ContainerType =
typename Traits::ContainerType;
609 using VariableRefType =
typename Traits::VariableRefType;
615 PrivatePartType* global_var,
620 ARCANE_DEPRECATED_REASON(
"Y2022: Do not use internal storage accessor")
654 using BaseClass::setValue;
655 using BaseClass::value;
659 using BaseClass::m_p;
664 using BaseClass::m_global_variable;
665 using BaseClass::m_global_variable_ref;
683template <
typename ItemType,
typename DataType>
684class MeshMaterialVariableArray
685:
public ItemMaterialVariableArray<DataType>
690 using ThatClass = MeshMaterialVariableArray<ItemType, DataType>;
692 using BuilderType =
typename ThatInterface::BuilderType;
694 using ItemTypeTemplate = ItemType;
696 using BaseClass = ItemMaterialVariableArray<DataType>;
698 using PrivatePartType =
typename BaseClass::PrivatePartType;
706 PrivatePartType* global_var,
713 void resize(
Int32 dim2_size)
final { BaseClass::resize(dim2_size); }
714 VariableRefType* globalVariableReference()
const final {
return m_true_global_variable_ref; }
719 VariableRefType* m_true_global_variable_ref =
nullptr;
Execution queue for an accelerator.
Mutable view for a 2D array.
constexpr DataType * data()
Pointer to the allocated memory.
constexpr Integer totalNbElement() const
Total number of elements.
Class representing a classic 2D array.
Modifiable view of an array of type T.
Base class for 1D data vectors.
View for a constant 2D array.
Constant view of an array of type T.
Interface of a bi-dimensional array data item of type T.
Interface of a 1D array data item of type T.
Interface of a data item.
View over a list of cells with environment information.
Arguments for methods copying between partial and global values.
Access interface for CellMaterialVariableArrayRef.
Interface of a component (material or environment) of a mesh.
Interface of the functor class for recalculating a variable.
Arcane internal API for 'IMeshMaterialVariable'.
Interface of a material variable on a mesh.
Interface of a mesh material.
Access interface for CellMaterialVariableScalarRef.
Arguments for methods copying between partial and global values.
UniqueArray< ContainerViewType > m_host_views
List of views visible only from the host.
ARCANE_MATERIALS_EXPORT void synchronize() override
Synchronizes the variable.
ARCANE_MATERIALS_EXPORT void serialize(ISerializer *sbuffer, Int32ConstArrayView ids) override
Serializes the variable for local ID entities ids.
ARCANE_MATERIALS_EXPORT void dumpValues(std::ostream &ostr) override
Dumps the variable values to the stream ostr.
ARCANE_MATERIALS_EXPORT void syncReferences() override
Synchronizes references.
ARCANE_MATERIALS_EXPORT void buildFromManager(bool is_continue) override
Builds the variable information. For internal use in Arcane.
ARCANE_MATERIALS_EXPORT IVariable * globalVariable() const override
Associated global variable on the mesh.
UniqueArray< ContainerViewType > m_host_views
UniqueArray< PrivatePartType * > m_vars
UniqueArray< ContainerViewType > m_device_views
ARCANE_MATERIALS_EXPORT void fillPartialValuesWithGlobalValues() override
Fills partial values with the value of the associated global cell.
void _setView(Int32 index)
Positions the views from the container.
ARCANE_MATERIALS_EXPORT void fillPartialValuesWithSuperValues(Int32 level) override
Fills partial values with the value of the super cell. If level equals LEVEL_MATERIAL,...
UniqueArray< ContainerViewType > m_host_views
List of views visible only from the host.
ARCANE_MATERIALS_EXPORT void fillPartialValues(const DataType &value)
Fills the partial values with the value value.
ARCANE_MATERIALS_EXPORT void synchronize() override
Synchronizes the variable.
ARCANE_MATERIALS_EXPORT void fillToArray(IMeshMaterial *mat, ArrayView< DataType > values)
Fills an array from the variable values for a material.
ARCANE_MATERIALS_EXPORT void serialize(ISerializer *sbuffer, Int32ConstArrayView ids) override
Serializes the variable for local ID entities ids.
ARCANE_MATERIALS_EXPORT void dumpValues(std::ostream &ostr) override
Dumps the variable values to the stream ostr.
ARCANE_MATERIALS_EXPORT void fillFromArray(IMeshMaterial *mat, ConstArrayView< DataType > values)
Fills the variable values for a material from an array.
Represents an index on material and environment variables.
constexpr __host__ __device__ Int32 arrayIndex() const
Returns the index of the value array in the list of variables.
constexpr __host__ __device__ Int32 valueIndex() const
Returns the index in the value array.
Characteristics for an array material variable.
Characteristics for a scalar material variable.
static ARCANE_MATERIALS_EXPORT IMeshMaterialVariable * getReference(const MaterialVariableBuildInfo &v, MatVarSpace mvs)
Retrieves or constructs a variable.
Registerer for a material variable factory..
Private section of a material variable.
Base class for material variable references.
Synchronizing a list of material variables.
void setUpToDate(IMeshMaterial *mat) override
Indicates that the variable has just been updated.
MeshMaterialVariableRef * firstReference() const override
void incrementReference()
Int64 modifiedTime(IMeshMaterial *mat) override
Time when the variable was updated.
void removeVariableRef(MeshMaterialVariableRef *var_ref) override
Removes a reference to this variable.
void update(IMeshMaterial *mat) override
Recalculates the variable for material mat if necessary.
void dependInfos(Array< VariableDependInfo > &infos, Array< MeshMaterialVariableDependInfo > &mat_infos) override
Dependency information.
void addVariableRef(MeshMaterialVariableRef *var_ref) override
Adds a reference to this variable.
IMeshMaterialVariableComputeFunction * computeFunction() override
Function used to update the variable.
void setKeepOnChange(bool v) override
Indicates whether the variable value should be kept after a change in the list of materials.
void addDepend(IMeshMaterialVariable *var) override
Adds var to the dependency list.
void removeDepend(IMeshMaterialVariable *var) override
Removes var from the dependency list.
IVariable * materialVariable(IMeshMaterial *mat) override
Variable containing the specific values of the material mat.
void setComputeFunction(IMeshMaterialVariableComputeFunction *v) override
Sets the variable's recalculation function.
String name() const override
Name of the variable.
MatVarSpace space() const override
Variable definition space (material+environment or environment only).
static SmallSpan< const Int32 > _toInt32Indexes(SmallSpan< const MatVarIndex > indexes)
Converts a view of MatVarIndex to a view of Int32.
bool keepOnChange() const override
Indicates whether the variable value should be kept after a change in the list of materials.
Arguments for methods copying between partial and global values.
Array variable on a mesh entity type.
Scalar variable on a mesh entity type.
Reference to an instance.
View for a 2D array whose size is an 'Int32'.
View of an array of elements of type T.
__host__ __device__ void copy(const U ©_array)
Copies the array copy_array into the instance.
__host__ __device__ void fill(T o)
Fills the array with the value o.
View of an array of elements of type T.
Unicode character string.
2D data vector with value semantics (STL style).
1D data vector with value semantics (STL style).
Implementation of a variable on a 1D array.
Parameters necessary for building a variable.
Information characterizing a variable.
Two-dimensional array variable.
Always enables tracing in Arcane parts concerning materials.
ConstArrayView< IMeshComponent * > MeshComponentList
List of multi-material components of the mesh.
MatVarSpace
Definition space for a material variable.
class ARCANE_MATERIALS_EXPORT(64) SimdMatVarIndex
SIMD indexer on a component.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
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.
double Real
Type representing a real number.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
Impl::SpanTypeFromSize< std::byte, SizeType >::SpanType asWritableBytes(const SpanImpl< DataType, SizeType, Extent > &s)
Converts the view into an array of modifiable bytes.
std::int32_t Int32
Signed integer type of 32 bits.