14#include "arcane/core/Array2Variable.h"
16#include "arcane/utils/NotSupportedException.h"
17#include "arcane/utils/ArgumentException.h"
18#include "arcane/utils/FatalErrorException.h"
19#include "arcane/utils/TraceInfo.h"
20#include "arcane/utils/Ref.h"
21#include "arcane/utils/CheckedConvert.h"
22#include "arcane/utils/ArrayShape.h"
23#include "arcane/utils/ITraceMng.h"
25#include "arcane/datatype/DataTypeTraits.h"
26#include "arcane/datatype/DataStorageBuildInfo.h"
28#include "arcane/core/VariableDiff.h"
29#include "arcane/core/VariableBuildInfo.h"
30#include "arcane/core/VariableInfo.h"
31#include "arcane/core/IApplication.h"
32#include "arcane/core/IVariableMng.h"
33#include "arcane/core/IItemFamily.h"
34#include "arcane/core/IVariableSynchronizer.h"
35#include "arcane/core/IDataReader.h"
36#include "arcane/core/ItemGroup.h"
37#include "arcane/core/IParallelMng.h"
38#include "arcane/core/IDataFactoryMng.h"
39#include "arcane/core/IMesh.h"
41#include "arcane/core/internal/IDataInternal.h"
42#include "arcane/core/internal/IVariableMngInternal.h"
43#include "arcane/core/internal/IVariableInternal.h"
54template<
class DataType>
78 Int32
sid =
pm->commRank();
94 msg->pinfo() <<
"Processor: " <<
sid <<
" VDIFF: Variable '" <<
var->name()
98 const Item& item = *i;
101 Integer index = item.
localId();
103 index = (*group_index_table)[index];
107 msg->pinfo() <<
"Processor: " <<
sid <<
" VDIFF: Variable '" <<
var->name()
108 <<
"wrong number of elements : impossible comparison";
114 DataType
diff = DataType();
135 if constexpr(std::is_same<TrueType,ReduceType>::value)
171 msg->info(4) <<
"Array2Variable::CheckReplica2 rep_size=" <<
pm->commSize() <<
" rank=" <<
pm->commRank();
174 msg->info() <<
"Can not compare values on replica for variable '" <<
var_name <<
"'"
175 <<
" because the number of elements is not the same on all the replica "
185 pm->reduce(Parallel::ReduceMax,
max_values.viewAsArray());
186 pm->reduce(Parallel::ReduceMin,
min_values.viewAsArray());
191 Integer index = item.
localId();
193 index = (*group_index_table)[index];
197 msg->pinfo() <<
"Processor: " <<
msg->traceId() <<
" VDIFF: Variable '" <<
var->name()
198 <<
"wrong number of elements : impossible comparison";
204 DataType
diff = DataType();
258 ARCANE_CHECK_PTR(true_ptr);
265template<
typename T> Array2VariableT<T>* Array2VariableT<T>::
266getReference(IVariable* var)
269 throw ArgumentException(A_FUNCINFO,
"null variable");
270 ThatClass* true_ptr =
dynamic_cast<ThatClass*
>(var);
272 ARCANE_FATAL(
"Cannot build a reference from variable {0}",var->name());
279template<
typename T>
void Array2VariableT<T>::
286 m_data->_internal()->resizeOnlyDim1(s);
293template<
typename DataType>
void Array2VariableT<DataType>::
302 m_data->_internal()->resize(dim1_size,dim2_size);
314template<
typename DataType>
void Array2VariableT<DataType>::
315directResizeAndReshape(
const ArrayShape& shape)
317 Int32 dim1_size = valueView().dim1Size();
318 Int32 dim2_size = CheckedConvert::toInt32(shape.totalNbElement());
320 m_data->_internal()->resize(dim1_size,dim2_size);
321 m_data->setShape(shape);
332 m_data->_internal()->shrink();
340print(std::ostream&)
const
356 ARCANE_FATAL(
"variable '{0}' without family",fullName());
358 itemGroup().synchronizer()->synchronize(
this);
373 ARCANE_FATAL(
"variable '{0}' without family",fullName());
375 itemGroup().synchronizer()->synchronize(
this,
local_ids);
386 Real v1 =
static_cast<Real>(
sizeof(T));
387 Real v2 =
static_cast<Real>(m_data->view().totalNbElement());
397 ValueType&
data_values = m_data->_internal()->_internalDeprecatedValue();
399 Integer dim1_size = valueView().dim1Size();
420template<
typename T>
Integer Array2VariableT<T>::
421checkIfSame(IDataReader* reader,
int max_print,
bool compare_ghost)
423 if (itemKind()==IK_Particle)
425 ConstArray2View<T> from_array(valueView());
427 Ref< IArray2DataT<T> > ref_data(m_data->cloneTrueEmptyRef());
428 reader->read(
this,ref_data.get());
430 Array2VariableDiff<T> csa;
431 return csa.check(
this,ref_data->view(),from_array,max_print,compare_ghost);
442 _checkIfSameOnAllReplicaHelper(IParallelMng* pm,IVariable* var,
443 ConstArray2View<T> values,
Integer max_print)
445 Array2VariableDiff<T> csa;
446 return csa.checkReplica(pm,var,values,max_print);
451 _checkIfSameOnAllReplicaHelper(IParallelMng* pm,IVariable* var,
452 ConstArray2View<Byte> values,
Integer max_print)
454 Integer dim1_size = values.dim1Size();
455 Integer dim2_size = values.dim2Size();
456 UniqueArray2<Integer> int_values(dim1_size,dim2_size);
457 for(
Integer i=0; i<dim1_size; ++i )
458 for(
Integer j=0; j<dim2_size; ++j )
459 int_values[i][j] = values[i][j];
460 Array2VariableDiff<Integer> csa;
461 return csa.checkReplica(pm,var,int_values,max_print);
468template<
typename T>
Integer Array2VariableT<T>::
469_checkIfSameOnAllReplica(IParallelMng* replica_pm,
Integer max_print)
471 return _checkIfSameOnAllReplicaHelper(replica_pm,
this,constValueView(),max_print);
477template<
typename T>
void Array2VariableT<T>::
478_internalResize(
const VariableResizeArgs& resize_args)
480 Int32 new_size = resize_args.newSize();
481 Int32 nb_additional_element = resize_args.nbAdditionalCapacity();
482 bool use_no_init = resize_args.isUseNoInit();
490 ValueType& data_values = m_data->_internal()->_internalDeprecatedValue();
491 ValueType& container_ref = data_values;
493 Integer dim2_size = data_values.dim2Size();
495 if (nb_additional_element!=0){
496 Integer capacity = data_values.capacity();
497 if (new_size>capacity)
498 data_values.reserve(new_size+nb_additional_element*dim2_size);
505 Integer current_size = data_values.dim1Size();
512 if (use_no_init || (init_policy!=DIP_InitWithDefault))
513 data_values.resizeNoInit(new_size,dim2_size);
515 data_values.resize(new_size,dim2_size);
517 if (new_size>current_size){
520 if (use_nan || use_nan2){
521 for(
Integer i=current_size; i<new_size; ++i )
522 DataTypeTraitsT<T>::fillNan(data_values[i]);
528 if (container_ref.totalNbElement() < container_ref.capacity())
529 container_ref.shrink();
544 ARCANE_ASSERT(source.
size()==destination.
size(),
545 (
"Unable to copy: source and destination have different sizes !"));
547 const Integer dim2_size = valueView().dim2Size();
553 value[destination[i]][
j] = value[source[i]][
j];
567 (
"Unable to copy: source and destination have different sizes !"));
569 const Integer dim2_size = valueView().dim2Size();
587 debug(
Trace::High) <<
"Skip compact for partial variable " << name();
648template<
typename DataType>
void
652 _checkSwapIsValid(&
rhs);
655 m_data->swapValues(
rhs.m_data);
658 rhs.syncReferences();
664template<
typename DataType>
auto
665Array2VariableT<DataType>::
668 return m_data->_internal()->_internalDeprecatedValue();
674template<
typename DataType>
void
675Array2VariableT<DataType>::
676fillShape(ArrayShape& shape_with_item)
680 ArrayShape shape = m_data->shape();
681 const Int32 nb_rank = shape_with_item.nbDimension();
683 auto array_view = m_data->view();
684 Int32 dim0_size = array_view.dim1Size();
686 shape_with_item.setDimension(0, dim0_size);
687 Int32 nb_orig_shape = shape.nbDimension();
688 for (
Int32 i = 0; i < nb_orig_shape; ++i) {
689 shape_with_item.setDimension(i + 1, shape.dimension(i));
694 for (
Int32 i = (nb_orig_shape + 1); i < nb_rank; ++i) {
695 shape_with_item.setDimension(i, 1);
705ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE(Array2VariableT);
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Array2VariableT(const VariableBuildInfo &v, const VariableInfo &vi)
Construit une variable basée sur la référence v.
IData * data() override
Données associées à la variable.
Informations pour construire une instance de 'IData'.
Interface d'une famille d'entités.
virtual IVariableSynchronizer * allItemsSynchronizer()=0
Synchroniseur sur toutes les entités de la famille.
virtual ITraceMng * traceMng()=0
Gestionnaire de message associé
virtual IParallelMng * parallelMng()=0
Gestionnaire de parallèlisme.
Interface du gestionnaire de parallélisme pour un sous-domaine.
Interface du gestionnaire de variables.
Groupe d'entités de maillage.
SharedPtrT< GroupIndexTable > localIdToIndex() const
Table des local ids vers une position pour toutes les entités du groupe.
bool null() const
true is le groupe est le groupe nul
IMesh * mesh() const
Maillage auquel appartient ce groupe (0 pour le group nul)
Classe de base d'un élément de maillage.
constexpr Int32 localId() const
Identifiant local de l'entité dans le sous-domaine du processeur.
bool isOwn() const
true si l'entité est appartient au sous-domaine
Paramètres nécessaires à la construction d'une variable.
Infos caractérisant une variable.
DataStorageTypeInfo storageTypeInfo() const
Informations sur le type de conteneur de la variable.
void _setData(const Ref< IData > &data)
Positionne la donnée.
Classe représentant un tableau 2D classique.
Vue constante d'un tableau de type T.
constexpr Integer size() const noexcept
Nombre d'éléments du tableau.
Interface du gestionnaire de traces.
Référence à une instance.
InstanceType * get() const
Instance associée ou nullptr si aucune.
bool isNull() const
Indique si le compteur référence une instance non nulle.
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
bool arcaneIsCheck()
Vrai si on est en mode vérification.
eDataInitialisationPolicy
Type de politique d'initialisation possible pour une donnée.
@ DIP_InitInitialWithNanResizeWithDefault
Initialisation avec des NaN pour à la création et le constructeur par défaut ensuite.
@ DIP_InitWithNan
Initialisation avec des NaN (Not a Number)
eDataInitialisationPolicy getGlobalDataInitialisationPolicy()
Récupère la politique d'initialisation des variables.
@ IK_Unknown
Entité de maillage de genre inconnu ou non initialisé
double Real
Type représentant un réel.
Int32 Integer
Type représentant un entier.