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"
24#include "arcane/utils/MemoryUtils.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"
60MeshMaterialVariablePrivate::
61MeshMaterialVariablePrivate(
const MaterialVariableBuildInfo& v,
MatVarSpace mvs,
62 MeshMaterialVariable* variable)
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::
96copyToBuffer(SmallSpan<const MatVarIndex> matvar_indexes,
97 Span<std::byte> bytes, RunQueue* queue)
const
99 m_variable->_copyToBuffer(matvar_indexes,bytes,queue);
105void MeshMaterialVariablePrivate::
106copyFromBuffer(SmallSpan<const MatVarIndex> matvar_indexes,
107 Span<const std::byte> bytes, RunQueue* queue)
109 m_variable->_copyFromBuffer(matvar_indexes,bytes,queue);
115Ref<IData> MeshMaterialVariablePrivate::
116internalCreateSaveDataRef(Integer nb_value)
118 return m_variable->_internalCreateSaveDataRef(nb_value);
124void MeshMaterialVariablePrivate::
125saveData(IMeshComponent* component,IData* data)
127 m_variable->_saveData(component,data);
133void MeshMaterialVariablePrivate::
134restoreData(IMeshComponent* component,IData* data,Integer data_index,
135 Int32ConstArrayView ids,
bool allow_null_id)
137 m_variable->_restoreData(component,data,data_index,ids,allow_null_id);
143void MeshMaterialVariablePrivate::
144copyBetweenPartialAndGlobal(
const CopyBetweenPartialAndGlobalArgs& args)
146 m_variable->_copyBetweenPartialAndGlobal(args);
152void MeshMaterialVariablePrivate::
153initializeNewItemsWithZero(InitializeWithZeroArgs& args)
155 m_variable->_initializeNewItemsWithZero(args);
161void MeshMaterialVariablePrivate::
162syncReferences(
bool check_resize)
164 m_variable->_syncReferences(check_resize);
170void MeshMaterialVariablePrivate::
171resizeForIndexer(ResizeVariableIndexerArgs& args)
173 m_variable->_resizeForIndexer(args);
182MeshMaterialVariable::
183MeshMaterialVariable(
const MaterialVariableBuildInfo& v,MatVarSpace mvs)
184: m_p(new MeshMaterialVariablePrivate(v,mvs,this))
185, m_views_as_bytes(MemoryUtils::getAllocatorForMostlyReadOnlyData())
192MeshMaterialVariable::
193~MeshMaterialVariable()
201void MeshMaterialVariable::
209 Mutex::ScopedLock sl(m_p->materialMng()->variableLock());
210 ++m_p->m_nb_reference;
216void MeshMaterialVariable::
221 ref->setNextReference(m_p->m_first_reference);
222 if (m_p->m_first_reference){
226 _list->setPreviousReference(ref);
229 ref->setPreviousReference(
nullptr);
231 m_p->m_first_reference = ref;
237void MeshMaterialVariable::
247 if (m_p->m_first_reference==tmp)
248 m_p->m_first_reference = m_p->m_first_reference->nextReference();
252 ref->setNextReference(
nullptr);
253 ref->setPreviousReference(
nullptr);
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);
282firstReference()
const
284 return m_p->m_first_reference;
302 Int32 index = mat->
_internalApi()->variableIndexer()->index() + 1;
303 return m_p->m_refs[index]->variable();
309void MeshMaterialVariable::
310setKeepOnChange(
bool v)
312 m_p->m_keep_on_change = v;
318bool MeshMaterialVariable::
321 return m_p->m_keep_on_change;
327void MeshMaterialVariable::
330 if (m_p->hasRecursiveDepend()){
332 vdi.variable()->update();
336 vdi.variable()->update(mat);
339 Int32 mat_id = mat->
id();
341 bool need_update =
false;
342 Int64 modified_time = m_p->m_modified_times[mat_id];
344 Int64 mt = vdi.variable()->modifiedTime();
345 if (mt>modified_time){
352 Int64 mt = vdi.variable()->modifiedTime(mat);
353 if (mt>modified_time){
366 ARCANE_FATAL(
"no compute function for variable '{0}'",name());
374void MeshMaterialVariable::
377 Int32
id = mat->
id();
378 m_p->m_modified_times[id] = IVariable::incrementModifiedTime();
381Int64 MeshMaterialVariable::
384 Int32
id = mat->
id();
385 return m_p->m_modified_times[id];
388void MeshMaterialVariable::
394void MeshMaterialVariable::
400void MeshMaterialVariable::
407void MeshMaterialVariable::
413void MeshMaterialVariable::
419void MeshMaterialVariable::
426void MeshMaterialVariable::
429 m_p->m_compute_function = v;
435 return m_p->m_compute_function.get();
438void MeshMaterialVariable::
454 return m_p->materialMng()->traceMng();
476 static_assert(
sizeof(
MatVarIndex)==2*
sizeof(Int32),
"Bad size for MatVarIndex");
477 auto* ptr =
reinterpret_cast<const Int32*
>(indexes.
data());
478 return { ptr, indexes.
size()*2 };
484void MeshMaterialVariable::
485_copyToBuffer(SmallSpan<const MatVarIndex> matvar_indexes,
486 Span<std::byte> bytes, RunQueue* queue)
const
488 const Integer one_data_size = dataTypeSize();
489 SmallSpan<const Int32> indexes(_toInt32Indexes(matvar_indexes));
490 const Int32 nb_item = matvar_indexes.size();
491 MutableMemoryView destination_buffer(makeMutableMemoryView(bytes.data(),one_data_size,nb_item));
492 ConstMultiMemoryView source_view(m_views_as_bytes.view(),one_data_size);
493 source_view.copyToIndexes(destination_buffer,indexes,queue);
499void MeshMaterialVariable::
500_copyFromBuffer(SmallSpan<const MatVarIndex> matvar_indexes,
501 Span<const std::byte> bytes, RunQueue* queue)
504 SmallSpan<const Int32> indexes(_toInt32Indexes(matvar_indexes));
505 const Int32 nb_item = matvar_indexes.size();
506 MutableMultiMemoryView destination_view(m_views_as_bytes.view(),one_data_size);
507 ConstMemoryView source_buffer(makeConstMemoryView(bytes.data(),one_data_size,nb_item));
508 destination_view.copyFromIndexes(source_buffer,indexes,queue);
514void MeshMaterialVariable::
515_genericCopyTo(Span<const std::byte> input,
516 SmallSpan<const Int32> input_indexes,
517 Span<std::byte> output,
518 SmallSpan<const Int32> output_indexes,
519 const RunQueue& queue, Int32 data_type_size)
522 Integer nb_value = input_indexes.size();
529 const Int32 dim2_size = data_type_size;
535 Int32 output_base = output_indexes[i] * dim2_size;
536 Int32 input_base = input_indexes[i] * dim2_size;
537 for (Int32 j = 0; j < dim2_size; ++j)
538 output[output_base + j] = input[input_base + j];
545IMeshMaterialVariableInternal* MeshMaterialVariable::
548 return m_p->_internalApi();
#define ARCANE_CHECK_ACCESSIBLE_POINTER(queue_or_runner_or_policy, ptr)
Macro qui vérifie en mode check si ptr est accessible pour une RunQueue ou un Runner.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Fichier contenant les déclarations concernant le modèle de programmation par échange de message.
Types et macros pour gérer les boucles sur les accélérateurs.
#define RUNCOMMAND_LOOP1(iter_name, x1,...)
Boucle sur accélérateur avec arguments supplémentaires pour les réductions.
virtual Int32 id() const =0
Identifiant du composant.
virtual IMeshComponentInternal * _internalApi()=0
API interne.
Interface de la classe fonctor de recalcul d'une variable.
virtual void execute(IMeshMaterial *mat)=0
Exécute la fonction de calcul.
Interface d'une variable matériau d'un maillage.
Interface d'un matériau d'un maillage.
Représente un index sur les variables matériaux et milieux.
Classe de base des références aux variables matériaux.
MeshMaterialVariableRef * nextReference()
Référence suivante (ou null) sur variable()
MeshMaterialVariableRef * previousReference()
Référence précédente (ou null) sur variable()
Informations sur une dépendance de variable.
Informations sur une dépendance de variable.
Classe de base des vecteurs 1D de données.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Interface du gestionnaire de traces.
Vue d'un tableau d'éléments de type T.
constexpr __host__ __device__ SizeType size() const noexcept
Retourne la taille du tableau.
constexpr __host__ __device__ pointer data() const noexcept
Pointeur sur le début de la vue.
Chaîne de caractères unicode.
RunCommand makeCommand(const RunQueue &run_queue)
Créé une commande associée à la file run_queue.
Active toujours les traces dans les parties Arcane concernant les matériaux.
MatVarSpace
Espace de définition d'une variable matériau.
ARCANE_DATATYPE_EXPORT Integer dataTypeSize(eDataType type)
Taille du type de donnée type (qui doit être différent de DT_String)
Int32 Integer
Type représentant un entier.