14#include "arcane/materials/MeshMaterialVariable.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/TraceInfo.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/Real2.h"
20#include "arcane/utils/Real3.h"
21#include "arcane/utils/Real2x2.h"
22#include "arcane/utils/Real3x3.h"
23#include "arcane/utils/Mutex.h"
25#include "arcane/utils/PlatformUtils.h"
27#include "arcane/core/materials/IMeshMaterial.h"
28#include "arcane/core/materials/ComponentItemVectorView.h"
29#include "arcane/core/Variable.h"
30#include "arcane/core/VariableDependInfo.h"
31#include "arcane/core/MeshVariable.h"
32#include "arcane/core/IItemFamily.h"
33#include "arcane/core/IMesh.h"
34#include "arcane/core/IObserver.h"
35#include "arcane/core/IParallelMng.h"
37#include "arcane/core/materials/internal/IMeshComponentInternal.h"
38#include "arcane/core/materials/internal/IMeshMaterialMngInternal.h"
40#include "arcane/materials/MaterialVariableBuildInfo.h"
41#include "arcane/materials/MatItemEnumerator.h"
42#include "arcane/materials/MeshMaterialVariableRef.h"
43#include "arcane/materials/MeshMaterialVariableDependInfo.h"
44#include "arcane/materials/IMeshMaterialVariableComputeFunction.h"
45#include "arcane/materials/IMeshMaterialVariableSynchronizer.h"
46#include "arcane/materials/internal/MeshMaterialVariablePrivate.h"
47#include "arcane/materials/internal/MeshMaterialVariableIndexer.h"
49#include "arcane/accelerator/RunCommandLoop.h"
60MeshMaterialVariablePrivate::
64, m_material_mng(v.materialMng())
69 if (!platform::getEnvironmentVariable(
"ARCANE_NO_RECURSIVE_DEPEND").null())
70 m_has_recursive_depend =
false;
76MeshMaterialVariablePrivate::
77~MeshMaterialVariablePrivate()
79 if (m_global_variable_changed_observer)
80 std::cerr <<
"WARNING: MeshMaterialVariablePrivate: in destructor: observer is not destroyed\n";
86Int32 MeshMaterialVariablePrivate::
89 return m_variable->dataTypeSize();
95void MeshMaterialVariablePrivate::
99 m_variable->_copyToBuffer(matvar_indexes, bytes, queue);
105void MeshMaterialVariablePrivate::
109 m_variable->_copyFromBuffer(matvar_indexes, bytes, queue);
116internalCreateSaveDataRef(
Integer nb_value)
118 return m_variable->_internalCreateSaveDataRef(nb_value);
124void MeshMaterialVariablePrivate::
127 m_variable->_saveData(component, data);
133void MeshMaterialVariablePrivate::
137 m_variable->_restoreData(component, data, data_index, ids, allow_null_id);
143void MeshMaterialVariablePrivate::
146 m_variable->_copyBetweenPartialAndGlobal(args);
152void MeshMaterialVariablePrivate::
155 m_variable->_initializeNewItemsWithZero(args);
161void MeshMaterialVariablePrivate::
162syncReferences(
bool check_resize)
164 m_variable->_syncReferences(check_resize);
170void MeshMaterialVariablePrivate::
173 m_variable->_resizeForIndexer(args);
182MeshMaterialVariable::
185, m_views_as_bytes(
MemoryUtils::getAllocatorForMostlyReadOnlyData())
192MeshMaterialVariable::
193~MeshMaterialVariable()
210 ++m_p->m_nb_reference;
222 if (m_p->m_first_reference) {
231 m_p->m_first_reference = ref;
247 if (m_p->m_first_reference == tmp)
248 m_p->m_first_reference = m_p->m_first_reference->nextReference();
255 Int32 nb_ref = --m_p->m_nb_reference;
271 delete m_p->m_global_variable_changed_observer;
272 m_p->m_global_variable_changed_observer =
nullptr;
273 m_p->materialMng()->_internalApi()->removeVariable(
this);
284 return m_p->m_first_reference;
303 return m_p->m_refs[index]->variable();
312 m_p->m_keep_on_change = v;
321 return m_p->m_keep_on_change;
330 if (m_p->hasRecursiveDepend()) {
341 bool need_update =
false;
342 Int64 modified_time = m_p->m_modified_times[mat_id];
345 if (mt > modified_time) {
353 if (mt > modified_time) {
385 return m_p->m_modified_times[id];
429 m_p->m_compute_function = v;
435 return m_p->m_compute_function.get();
454 return m_p->materialMng()->
traceMng();
477 static_assert(
sizeof(
MatVarIndex) == 2 *
sizeof(
Int32),
"Bad size for MatVarIndex");
478 auto* ptr =
reinterpret_cast<const Int32*
>(indexes.
data());
479 return { ptr, indexes.
size() * 2 };
485void MeshMaterialVariable::
491 const Int32 nb_item = matvar_indexes.
size();
500void MeshMaterialVariable::
506 const Int32 nb_item = matvar_indexes.
size();
515void MeshMaterialVariable::
516_genericCopyTo(Span<const std::byte> input,
517 SmallSpan<const Int32> input_indexes,
518 Span<std::byte> output,
519 SmallSpan<const Int32> output_indexes,
520 const RunQueue& queue, Int32 data_type_size)
523 Integer nb_value = input_indexes.size();
526 ARCANE_CHECK_ACCESSIBLE_POINTER(queue, output.data());
527 ARCANE_CHECK_ACCESSIBLE_POINTER(queue, input.data());
528 ARCANE_CHECK_ACCESSIBLE_POINTER(queue, input_indexes.data());
529 ARCANE_CHECK_ACCESSIBLE_POINTER(queue, output_indexes.data());
530 const Int32 dim2_size = data_type_size;
536 Int32 output_base = output_indexes[i] * dim2_size;
537 Int32 input_base = input_indexes[i] * dim2_size;
538 for (Int32 j = 0; j < dim2_size; ++j)
539 output[output_base + j] = input[input_base + j];
549 return m_p->_internalApi();
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
File containing declarations concerning the message passing model.
Memory and allocator management functions.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
1D loop on accelerator with additional arguments.
Execution queue for an accelerator.
Base class for 1D data vectors.
void add(ConstReferenceType val)
Adds element val to the end of the array.
Constant view on a contiguous memory region containing fixed-size elements.
List of constant views on contiguous memory regions.
Interface of a data item.
virtual Int64 modifiedTime()=0
Time when the variable was updated.
static Int64 incrementModifiedTime()
Increments the modification counter and returns its value before modification.
virtual void update()=0
Recalculates the variable if necessary.
Arguments for methods copying between partial and global values.
virtual MeshMaterialVariableIndexer * variableIndexer() const =0
Indexer to access partial variables.
Interface of a component (material or environment) of a mesh.
virtual Int32 id() const =0
Component identifier.
virtual IMeshComponentInternal * _internalApi()=0
Internal API.
virtual ITraceMng * traceMng()=0
Trace manager.
Interface of the functor class for recalculating a variable.
virtual void execute(IMeshMaterial *mat)=0
Executes the calculation function.
Arcane internal API for 'IMeshMaterialVariable'.
Interface of a material variable on a mesh.
virtual Int64 modifiedTime(IMeshMaterial *mat)=0
Time when the variable was updated.
Interface of a mesh material.
Arguments for methods copying between partial and global values.
Represents an index on material and environment variables.
Information about a variable dependency.
IMeshMaterialVariable * variable() const
Variable.
Private section of a material variable.
Base class for material variable references.
MeshMaterialVariableRef * nextReference()
Next reference (or null) on variable().
void setNextReference(MeshMaterialVariableRef *v)
Positions the next reference.
MeshMaterialVariableRef * previousReference()
Previous reference (or null) on variable().
void setPreviousReference(MeshMaterialVariableRef *v)
Positions the previous reference.
Base class for 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.
Mutable view on a contiguous memory region containing fixed-size elements.
List of mutable views on contiguous memory regions.
Exception when a function is not implemented.
Reference to an instance.
View of an array of elements of type T.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
Unicode character string.
Information about a variable dependency.
IVariable * variable() const
Variable.
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.
void copyWithIndexedDestination(MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr)
Memory copy with indirection.
void copyWithIndexedSource(MutableMemoryView destination, ConstMemoryView source, SmallSpan< const Int32 > indexes, RunQueue *run_queue=nullptr)
Copies data on the host with indirection.
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Size of data type type (which must be different from DT_String).
MutableMemoryView makeMutableMemoryView(void *ptr, Int32 datatype_size, Int64 nb_element)
Creates a mutable memory view.
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.
ConstMemoryView makeConstMemoryView(const void *ptr, Int32 datatype_size, Int64 nb_element)
Creates a read-only memory view.
std::int32_t Int32
Signed integer type of 32 bits.
Memory management utility functions.