Arcane  v3.16.9.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MeshMaterialVariableRef.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2025 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MeshMaterialVariableRef.cc (C) 2000-2025 */
9/* */
10/* Référence à une variable sur un matériau du maillage. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/NotImplementedException.h"
15#include "arcane/utils/TraceInfo.h"
16#include "arcane/utils/NumericTypes.h"
17
18#include "arcane/core/MeshVariableScalarRef.h"
19#include "arcane/core/VariableBuildInfo.h"
20#include "arcane/core/ArcaneException.h"
21
22#include "arcane/core/materials/IMeshMaterialMng.h"
23#include "arcane/core/materials/IMeshMaterial.h"
24#include "arcane/core/materials/MaterialVariableBuildInfo.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane::Materials
31{
32
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
36MeshMaterialVariableRef::
37MeshMaterialVariableRef()
38{
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44MeshMaterialVariableRef::
45~MeshMaterialVariableRef()
46{
47 if (m_is_registered)
49}
50
51/*---------------------------------------------------------------------------*/
52/*---------------------------------------------------------------------------*/
53
56{
57 _checkValid();
58 m_material_variable->removeVariableRef(this);
59 m_is_registered = false;
60}
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
67{
68 _checkValid();
69 m_material_variable->addVariableRef(this);
70 m_is_registered = true;
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76void MeshMaterialVariableRef::
77_internalInit(IMeshMaterialVariable* mat_variable)
78{
79 m_material_variable = mat_variable;
80 m_global_variable = mat_variable->globalVariable();
82 updateFromInternal();
83}
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88MeshMaterialVariableRef* MeshMaterialVariableRef::
90{
92}
93
94/*---------------------------------------------------------------------------*/
95/*---------------------------------------------------------------------------*/
96
97MeshMaterialVariableRef* MeshMaterialVariableRef::
99{
100 return m_next_reference;
101}
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
107setPreviousReference(MeshMaterialVariableRef* v)
108{
110}
111
112/*---------------------------------------------------------------------------*/
113/*---------------------------------------------------------------------------*/
114
116setNextReference(MeshMaterialVariableRef* v)
117{
119}
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
124void MeshMaterialVariableRef::
125_throwInvalid() const
126{
127 ARCANE_THROW(InternalErrorException,"Trying to use uninitialized variable reference");
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
135{
136 _checkValid();
137 m_material_variable->synchronize();
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
145{
146 _checkValid();
147 m_material_variable->synchronize(sync_list);
148}
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153String MeshMaterialVariableRef::
154name() const
155{
156 return m_global_variable->name();
157}
158void MeshMaterialVariableRef::
159setUpToDate()
160{
162}
163bool MeshMaterialVariableRef::
164isUsed() const
165{
166 return m_global_variable->isUsed();
167}
168void MeshMaterialVariableRef::
169update()
170{
171 m_global_variable->update();
172}
173
174void MeshMaterialVariableRef::
175addDependCurrentTime(const VariableRef& var)
176{
177 m_global_variable->addDepend(var.variable(),IVariable::DPT_CurrentTime);
178}
179void MeshMaterialVariableRef::
180addDependCurrentTime(const VariableRef& var,const TraceInfo& tinfo)
181{
182 m_global_variable->addDepend(var.variable(),IVariable::DPT_CurrentTime,tinfo);
183}
184
185void MeshMaterialVariableRef::
186addDependCurrentTime(const MeshMaterialVariableRef& var)
187{
188 m_global_variable->addDepend(var.m_global_variable,IVariable::DPT_CurrentTime);
189}
190
191void MeshMaterialVariableRef::
192addDependPreviousTime(const MeshMaterialVariableRef& var)
193{
194 m_global_variable->addDepend(var.m_global_variable,IVariable::DPT_PreviousTime);
195}
196
197void MeshMaterialVariableRef::
198removeDepend(const MeshMaterialVariableRef& var)
199{
200 m_global_variable->removeDepend(var.m_global_variable);
201}
202
203/*---------------------------------------------------------------------------*/
204/*---------------------------------------------------------------------------*/
205
206void MeshMaterialVariableRef::
207setUpToDate(IMeshMaterial* mat)
208{
209 m_material_variable->setUpToDate(mat);
210}
211
212void MeshMaterialVariableRef::
213update(IMeshMaterial* mat)
214{
216}
217
218void MeshMaterialVariableRef::
219addMaterialDepend(const VariableRef& var)
220{
222}
223
224void MeshMaterialVariableRef::
225addMaterialDepend(const VariableRef& var,const TraceInfo& tinfo)
226{
227 m_material_variable->addDepend(var.variable(),tinfo);
228}
229
230void MeshMaterialVariableRef::
231addMaterialDepend(const MeshMaterialVariableRef& var)
232{
235
236void MeshMaterialVariableRef::
237addMaterialDepend(const MeshMaterialVariableRef& var,const TraceInfo& tinfo)
238{
240}
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
259: m_private_part(PrivatePartType::BuilderType::getVariableReference(vb,MatVarSpace::MaterialAndEnvironment))
260{
261 _init();
262}
263
264/*---------------------------------------------------------------------------*/
265/*---------------------------------------------------------------------------*/
266
267template<typename DataType> CellMaterialVariableScalarRef<DataType>::
269: m_private_part(rhs.m_private_part)
270{
271 // Il faut incrémenter manuellement le compteur de référence car normalement
272 // cela est fait dans getReference() mais ici on ne l'appelle pas
273 if (m_private_part)
274 m_private_part->incrementReference();
275
276 _init();
277}
278
279/*---------------------------------------------------------------------------*/
280/*---------------------------------------------------------------------------*/
281
284: m_private_part(PrivatePartType::BuilderType::getVariableReference(var))
285{
286 // Il faut incrémenter manuellement le compteur de référence car normalement
287 // cela est fait dans getReference() mais ici on ne l'appelle pas
288 m_private_part->incrementReference();
289
290 _init();
291}
292
293/*---------------------------------------------------------------------------*/
294/*---------------------------------------------------------------------------*/
295
296/*---------------------------------------------------------------------------*/
297/*---------------------------------------------------------------------------*/
298
299template<typename DataType> void
301_init()
302{
303 if (m_private_part){
304 _setContainerView();
305 _internalInit(m_private_part->toMeshMaterialVariable());
306 }
307}
308
309/*---------------------------------------------------------------------------*/
310/*---------------------------------------------------------------------------*/
311
312template<typename DataType> void
315{
316 if (rhs.m_private_part==m_private_part)
317 return;
318 if (_isRegistered())
320 m_private_part = rhs.m_private_part;
321 m_container_value = {};
322 m_value = nullptr;
323
324 // Il faut incrémenter manuellement le compteur de référence car normalement
325 // cela est fait dans getReference() mais ici on ne l'appelle pas
326 if (m_private_part)
327 m_private_part->incrementReference();
328 _init();
331/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
334template<typename DataType> void
337{
338 _setContainerView();
339}
340
341/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
344template<typename DataType> DataType
346matValue(AllEnvCell c,Int32 mat_id) const
347{
348 ENUMERATE_CELL_ENVCELL(ienvcell,c){
349 ENUMERATE_CELL_MATCELL(imatcell,(*ienvcell)){
350 MatCell mc = *imatcell;
351 Int32 mid = mc.materialId();
352 if (mid==mat_id)
353 return this->operator[](imatcell);
354 }
355 }
356 return DataType();
357}
358
359/*---------------------------------------------------------------------------*/
360/*---------------------------------------------------------------------------*/
361
362template<typename DataType> DataType
364envValue(AllEnvCell c,Int32 env_id) const
365{
366 ENUMERATE_CELL_ENVCELL(ienvcell,c){
367 EnvCell ec = *ienvcell;
368 Int32 eid = ec.environmentId();
369 if (eid==env_id)
370 return this->operator[](ienvcell);
371 }
372 return DataType();
373}
374
375/*---------------------------------------------------------------------------*/
376/*---------------------------------------------------------------------------*/
389template<typename DataType> void
393 m_private_part->fillFromArray(mat,values);
395
396/*---------------------------------------------------------------------------*/
397/*---------------------------------------------------------------------------*/
401 * Cette méthode effectue l'opération suivante:
402 \code
403 * Integer index=0;
404 * ENUMERATE_MATCELL(imatcell,mat){
405 * matvar[imatcell] = values[index];
406 * ++index;
407 * }
408 \endcode
409*/
410template<typename DataType> void
413{
414 m_private_part->fillFromArray(mat,values,indexes);
415}
416
417/*---------------------------------------------------------------------------*/
418/*---------------------------------------------------------------------------*/
419/*!
420 * \brief Remplit un tableau à partir des valeurs de la variable pour un matériau.
421 *
422 * Cette méthode effectue l'opération suivante:
423 \code
424 * Integer index=0;
425 * ENUMERATE_MATCELL(imatcell,mat){
426 * values[index] = matvar[imatcell];
427 * ++index;
428 * }
429 \endcode
430*/
431template<typename DataType> void
434{
435 m_private_part->fillToArray(mat,values);
437
438/*---------------------------------------------------------------------------*/
439/*---------------------------------------------------------------------------*/
452template<typename DataType> void
455{
456 m_private_part->fillToArray(mat,values,indexes);
457}
458
459/*---------------------------------------------------------------------------*/
460/*---------------------------------------------------------------------------*/
466template<typename DataType> void
469{
470 values.resize(mat->cells().size());
471 fillToArray(mat,values.view());
472}
473
474/*---------------------------------------------------------------------------*/
475/*---------------------------------------------------------------------------*/
481template<typename DataType> void
484{
485 values.resize(mat->cells().size());
486 fillToArray(mat,values.view(),indexes);
487}
488
489/*---------------------------------------------------------------------------*/
490/*---------------------------------------------------------------------------*/
494template<typename DataType> void
496fill(const DataType& value)
497{
498 globalVariable().fill(value);
499 fillPartialValues(value);
500}
501
502/*---------------------------------------------------------------------------*/
503/*---------------------------------------------------------------------------*/
507template<typename DataType> void
509fillPartialValues(const DataType& value)
510{
511 m_private_part->fillPartialValues(value);
512}
513
514/*---------------------------------------------------------------------------*/
515/*---------------------------------------------------------------------------*/
516
517/*---------------------------------------------------------------------------*/
518/*---------------------------------------------------------------------------*/
519
520template<typename DataType> MeshVariableScalarRefT<Cell,DataType>&
523{
524 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
525 if (!rt)
526 ARCANE_FATAL("null global variable");
527 return *rt;
528}
529
530/*---------------------------------------------------------------------------*/
531/*---------------------------------------------------------------------------*/
532
533template<typename DataType> const MeshVariableScalarRefT<Cell,DataType>&
535globalVariable() const
536{
537 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
538 if (!rt)
539 ARCANE_FATAL("null global variable");
540 return *rt;
541}
542
543/*---------------------------------------------------------------------------*/
544/*---------------------------------------------------------------------------*/
545
546template<typename DataType> void
549{
550 if (m_private_part){
551 m_container_value = m_private_part->_internalFullValuesView();
552 m_value = m_container_value.data();
553 }
554 else{
555 m_container_value = {};
556 m_value = nullptr;
557 }
558}
559
560/*---------------------------------------------------------------------------*/
561/*---------------------------------------------------------------------------*/
562
563/*---------------------------------------------------------------------------*/
564/*---------------------------------------------------------------------------*/
565
566// TODO: fusionner avec la version scalaire
572
573/*---------------------------------------------------------------------------*/
574/*---------------------------------------------------------------------------*/
575
576// TODO: fusionner avec la version scalaire
579: m_private_part(PrivatePartType::BuilderType::getVariableReference(vb,MatVarSpace::MaterialAndEnvironment))
580{
581 _init();
582}
583
584/*---------------------------------------------------------------------------*/
585/*---------------------------------------------------------------------------*/
586
589: m_private_part(PrivatePartType::BuilderType::getVariableReference(var))
590{
591 // Il faut incrémenter manuellement le compteur de référence car normalement
592 // cela est fait dans getReference() mais ici on ne l'appelle pas
593 m_private_part->incrementReference();
594
595 _init();
596}
597
598/*---------------------------------------------------------------------------*/
599/*---------------------------------------------------------------------------*/
600
601// TODO: fusionner avec la version scalaire
602template<typename DataType> CellMaterialVariableArrayRef<DataType>::
604: m_private_part(rhs.m_private_part)
605, m_value(nullptr)
606{
607 // Il faut incrémenter manuellement le compteur de référence car normalement
608 // cela est fait dans getReference() mais ici on ne l'appelle pas
609 if (m_private_part)
610 m_private_part->incrementReference();
611
612 _init();
613}
614
615/*---------------------------------------------------------------------------*/
616/*---------------------------------------------------------------------------*/
617
618// TODO: fusionner avec la version scalaire
619template<typename DataType> void
621_init()
622{
623 if (m_private_part){
624 _setContainerView();
625 _internalInit(m_private_part->toMeshMaterialVariable());
626 }
627}
628
629/*---------------------------------------------------------------------------*/
630/*---------------------------------------------------------------------------*/
631
632// TODO: fusionner avec la version scalaire
633template<typename DataType> void
636{
637 if (rhs.m_private_part==m_private_part)
638 return;
639 if (_isRegistered())
641
642 m_private_part = rhs.m_private_part;
643 m_value = nullptr;
644 m_container_value = {};
645
646 // Il faut incrémenter manuellement le compteur de référence car normalement
647 // cela est fait dans getReference() mais ici on ne l'appelle pas
648 if (m_private_part)
649 m_private_part->incrementReference();
650 _init();
651}
652
653/*---------------------------------------------------------------------------*/
654/*---------------------------------------------------------------------------*/
655
656// TODO: fusionner avec la version scalaire
657template<typename DataType> void
660{
661 _setContainerView();
662}
663
664/*---------------------------------------------------------------------------*/
665/*---------------------------------------------------------------------------*/
666
667template<typename DataType> MeshVariableArrayRefT<Cell,DataType>&
670{
671 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
672 if (!rt)
673 ARCANE_FATAL("null global variable");
674 return *rt;
675}
676
677/*---------------------------------------------------------------------------*/
678/*---------------------------------------------------------------------------*/
679
680template<typename DataType> const MeshVariableArrayRefT<Cell,DataType>&
682globalVariable() const
683{
684 GlobalVariableRefType* rt = m_private_part->globalVariableReference();
685 if (!rt)
686 ARCANE_FATAL("null global variable");
687 return *rt;
688}
689
690/*---------------------------------------------------------------------------*/
691/*---------------------------------------------------------------------------*/
692
693template<typename DataType> void
695resize(Integer dim2_size)
696{
697 m_private_part->resize(dim2_size);
698}
699
700/*---------------------------------------------------------------------------*/
701/*---------------------------------------------------------------------------*/
702
703template<typename DataType> void
706{
707 if (m_private_part){
708 m_container_value = m_private_part->_internalFullValuesView();
709 m_value = m_container_value.data();
710 }
711 else{
712 m_container_value = {};
713 m_value = nullptr;
714 }
715}
716
717/*---------------------------------------------------------------------------*/
718/*---------------------------------------------------------------------------*/
719
720/*---------------------------------------------------------------------------*/
721/*---------------------------------------------------------------------------*/
722
723#define ARCANE_INSTANTIATE_MAT(type) \
724 template class ARCANE_TEMPLATE_EXPORT CellMaterialVariableScalarRef<type>;\
725 template class ARCANE_TEMPLATE_EXPORT CellMaterialVariableArrayRef<type>
726
727ARCANE_INSTANTIATE_MAT(Byte);
728ARCANE_INSTANTIATE_MAT(Int8);
729ARCANE_INSTANTIATE_MAT(Int16);
730ARCANE_INSTANTIATE_MAT(Int32);
731ARCANE_INSTANTIATE_MAT(Int64);
732ARCANE_INSTANTIATE_MAT(BFloat16);
733ARCANE_INSTANTIATE_MAT(Float16);
734ARCANE_INSTANTIATE_MAT(Float32);
735ARCANE_INSTANTIATE_MAT(Real);
736ARCANE_INSTANTIATE_MAT(Real2);
737ARCANE_INSTANTIATE_MAT(Real3);
738ARCANE_INSTANTIATE_MAT(Real2x2);
739ARCANE_INSTANTIATE_MAT(Real3x3);
740
741/*---------------------------------------------------------------------------*/
742/*---------------------------------------------------------------------------*/
743
744} // End namespace Arcane::Materials
745
746/*---------------------------------------------------------------------------*/
747/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Vue modifiable d'un tableau d'un type T.
Tableau d'items de types quelconques.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
ArrayView< T > view() const
Vue mutable sur ce tableau.
Vue constante d'un tableau de type T.
virtual void setUpToDate()=0
Indique que la variable vient d'être mise à jour.
virtual bool isUsed() const =0
Etat d'utilisation de la variable.
virtual String name() const =0
Nom de la variable.
Exception lorsqu'une erreur interne survient.
Integer size() const
Nombre d'éléments du groupe.
Definition ItemGroup.h:88
Maille arcane avec info matériaux et milieux.
Variable tableau sur les mailles d'un matériau du maillage. Pour l'instant, cette classe n'est instan...
CellMaterialVariableArrayRef()=delete
Constructeur vide (interdit)
CellMaterialVariableArrayRef(const VariableBuildInfo &vb)
Construit une référence à la variable spécifiée dans vb.
GlobalVariableRefType & globalVariable()
Variable globale associée à cette variable matériau.
virtual void refersTo(const ThatClass &rhs)
Positionne la référence de l'instance à la variable rhs.
void resize(Integer dim2_size)
Redimensionne le nombre d'éléments du tableau.
Variable scalaire sur les mailles d'un matériau du maillage.
DataType matValue(AllEnvCell c, Int32 mat_id) const
Valeur de la variable pour le matériau d'index mat_id de la maille ou 0 si absent de la maille.
CellMaterialVariableScalarRef(const VariableBuildInfo &vb)
Construit une référence à la variable spécifiée dans vb.
DataType envValue(AllEnvCell c, Int32 env_id) const
Valeur de la variable pour le milieu d'index env_id de la maille ou 0 si absent de la maille.
void fill(const DataType &value)
Remplit les valeurs partielles et globales de la variable avec la valeur value.
void fillPartialValues(const DataType &value)
Remplit les valeurs partielles de la variable avec la valeur value.
void fillFromArray(IMeshMaterial *mat, ConstArrayView< DataType > values)
Remplit les valeurs de la variable pour un matériau.
GlobalVariableRefType & globalVariable()
Variable globale associée à cette variable matériau.
virtual void refersTo(const ThatClass &rhs)
Positionne la référence de l'instance à la variable rhs.
CellMaterialVariableScalarRef()=delete
Constructeur vide (interdit)
void fillToArray(IMeshMaterial *mat, ArrayView< DataType > values)
Remplit un tableau à partir des valeurs de la variable pour un matériau.
Maille arcane d'un milieu.
__host__ __device__ Int32 environmentId() const
Identifiant du milieu.
virtual CellGroup cells() const =0
Groupe des mailles de ce matériau.
Interface d'une variable matériau d'un maillage.
virtual void addDepend(IMeshMaterialVariable *var)=0
Ajoute var à la liste des dépendances.
virtual IVariable * globalVariable() const =0
Variable globale sur le maillage associée.
virtual void update(IMeshMaterial *mat)=0
Recalcule la variable pour le matériau mat si nécessaire.
Interface d'un matériau d'un maillage.
Représente un matériau d'une maille multi-matériau.
__host__ __device__ Int32 materialId() const
Identifiant du matériau.
Classe de base des références aux variables matériaux.
MeshMaterialVariableRef * nextReference()
Référence suivante (ou null) sur variable()
IMeshMaterialVariable * materialVariable() const
Variable matériau associée.
void setNextReference(MeshMaterialVariableRef *v)
Positionne la référence suivante.
IMeshMaterialVariable * m_material_variable
Variable associée.
MeshMaterialVariableRef * previousReference()
Référence précédente (ou null) sur variable()
void unregisterVariable()
Supprime l'enregistrement de la variable (interne)
void registerVariable()
Enregistre la variable (interne)
MeshMaterialVariableRef * m_next_reference
Référence suivante sur m_variable.
void synchronize()
Synchronise les valeurs entre les sous-domaines.
MeshMaterialVariableRef * m_previous_reference
Référence précédente sur m_variable.
void setPreviousReference(MeshMaterialVariableRef *v)
Positionne la référence précédente.
Variable tableau sur un type d'entité du maillage.
Variable scalaire sur un type d'entité du maillage.
Chaîne de caractères unicode.
Paramètres nécessaires à la construction d'une variable.
Référence à une variable.
Definition VariableRef.h:56
IVariable * variable() const
Variable associée.
#define ENUMERATE_CELL_MATCELL(iname, env_cell)
Macro pour itérer sur tous les matériaux d'une maille.
#define ENUMERATE_CELL_ENVCELL(iname, all_env_cell)
Macro pour itérer sur tous les milieux d'une maille.
Active toujours les traces dans les parties Arcane concernant les matériaux.
MatVarSpace
Espace de définition d'une variable matériau.
@ MaterialAndEnvironment
Variable ayant des valeurs sur les milieux et matériaux.
std::int8_t Int8
Type entier signé sur 8 bits.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
ConstArrayView< Int32 > Int32ConstArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:569
std::int16_t Int16
Type entier signé sur 16 bits.
double Real
Type représentant un réel.
unsigned char Byte
Type d'un octet.
Definition BaseTypes.h:43
float Float32
Type flottant IEEE-753 simple précision.
std::int32_t Int32
Type entier signé sur 32 bits.