Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
Array2Variable.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* Array2Variable.cc (C) 2000-2026 */
9/* */
10/* 2D array variable. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/Array2Variable.h"
15
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"
24
25#include "arcane/datatype/DataTypeTraits.h"
26#include "arcane/datatype/DataStorageBuildInfo.h"
27
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"
40#include "arcane/core/VariableComparer.h"
41
42#include "arcane/core/internal/IDataInternal.h"
43#include "arcane/core/internal/IVariableMngInternal.h"
44#include "arcane/core/internal/IVariableInternal.h"
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49namespace Arcane
50{
51
52/*---------------------------------------------------------------------------*/
53/*---------------------------------------------------------------------------*/
54
55template <class DataType>
57: public VariableDiff<DataType>
58{
59 typedef VariableDataTypeTraitsT<DataType> VarDataTypeTraits;
60 typedef typename VariableDiff<DataType>::DiffInfo DiffInfo;
61
62 public:
63
66 const VariableComparerArgs& compare_args)
67 {
68 const bool compare_ghost = compare_args.isCompareGhost();
69 ItemGroup group = var->itemGroup();
70 if (group.null())
71 return {};
72 IMesh* mesh = group.mesh();
73 if (!mesh)
74 return {};
75 ITraceMng* msg = mesh->traceMng();
76 IParallelMng* pm = mesh->parallelMng();
77
78 GroupIndexTable* group_index_table = (var->isPartial()) ? group.localIdToIndex().get() : 0;
79
80 int nb_diff = 0;
81 Int32 sid = pm->commRank();
82 Integer current_total_nb_element = current.totalNbElement();
83 /*if (ref.totalNbElement()!=current_total_nb_element){
84 msg->pinfo() << "Processeur: " << sid << " VDIFF: Variable '" << var->name()
85 << "'different number of elements "
86 << " current: " << current_total_nb_element
87 << " ref: " << ref.totalNbElement();
88 return current_total_nb_element;
89 }*/
90 if (current_total_nb_element == 0)
91 return {};
92 Integer ref_size1 = ref.dim1Size();
93 Integer current_size1 = current.dim1Size();
94 Integer ref_size2 = ref.dim2Size();
95 Integer current_size2 = current.dim2Size();
96 if (ref_size2 != current_size2) {
97 msg->pinfo() << "Processor: " << sid << " VDIFF: Variable '" << var->name()
98 << " bad dim2 size: ref=" << ref_size2 << " current=" << current_size2;
99 }
100 ENUMERATE_ITEM (i, group) {
101 Item item = *i;
102 if (!item.isOwn() && !compare_ghost)
103 continue;
104 Integer index = item.localId();
105 if (group_index_table)
106 index = (*group_index_table)[index];
107
108 if (index >= ref_size1 || index >= current_size1) {
109 ++nb_diff;
110 msg->pinfo() << "Processor: " << sid << " VDIFF: Variable '" << var->name()
111 << "wrong number of elements : impossible comparison";
112 continue;
113 }
114 ConstArrayView<DataType> lref = ref[index];
115 ConstArrayView<DataType> lcurrent = current[index];
116 for (Integer z = 0; z < ref_size2; ++z) {
117 DataType diff = DataType();
118 DataType dref = lref[z];
119 DataType dcurrent = lcurrent[z];
120 if (VarDataTypeTraits::verifDifferent(dref, dcurrent, diff, true)) {
121 this->m_diffs_info.add(DiffInfo(dcurrent, dref, diff, item, z));
122 ++nb_diff;
123 }
124 }
125 }
126 if (nb_diff != 0)
127 this->_sortAndDump(var, pm, compare_args);
128
129 return VariableComparerResults(nb_diff);
130 }
131
133 checkReplica(IVariable* var, ConstArray2View<DataType> var_values,
134 const VariableComparerArgs& compare_args)
135 {
136 IParallelMng* replica_pm = var->_internalApi()->replicaParallelMng();
137 if (!replica_pm)
138 return {};
139 // Calls the correct specialization to ensure the template type has reduction.
140 using ReduceType = typename VariableDataTypeTraitsT<DataType>::HasReduceMinMax;
141 if constexpr (std::is_same<TrueType, ReduceType>::value)
142 return _checkReplica2(replica_pm, var, var_values, compare_args);
143
144 ARCANE_UNUSED(replica_pm);
145 ARCANE_UNUSED(var);
146 ARCANE_UNUSED(var_values);
147 ARCANE_UNUSED(compare_args);
148 throw NotSupportedException(A_FUNCINFO);
149 }
150
151 private:
152
154 _checkReplica2(IParallelMng* pm, IVariable* var, ConstArray2View<DataType> var_values,
155 const VariableComparerArgs& compare_args)
156 {
157 ITraceMng* msg = pm->traceMng();
158 ItemGroup group = var->itemGroup();
159 //TODO: handle variables that are not on mesh elements.
160 if (group.null())
161 return {};
162 GroupIndexTable* group_index_table = (var->isPartial()) ? group.localIdToIndex().get() : 0;
163 // Checks that all replicas have the same number of elements in each
164 // dimension for the variable.
165 Integer total_nb_element = var_values.totalNbElement();
166 Integer ref_size1 = var_values.dim1Size();
167 Integer ref_size2 = var_values.dim2Size();
168
169 Integer a_min_dims[2];
170 ArrayView<Integer> min_dims(2, a_min_dims);
171 Integer a_max_dims[2];
172 ArrayView<Integer> max_dims(2, a_max_dims);
173 max_dims[0] = min_dims[0] = ref_size1;
174 max_dims[1] = min_dims[1] = ref_size2;
175
176 pm->reduce(Parallel::ReduceMax, max_dims);
177 pm->reduce(Parallel::ReduceMin, min_dims);
178 msg->info(4) << "Array2Variable::CheckReplica2 rep_size=" << pm->commSize() << " rank=" << pm->commRank();
179 if (max_dims[0] != min_dims[0] || max_dims[1] != min_dims[1]) {
180 const String& var_name = var->name();
181 msg->info() << "Can not compare values on replica for variable '" << var_name << "'"
182 << " because the number of elements is not the same on all the replica "
183 << " min=" << min_dims[0] << "," << min_dims[1]
184 << " max=" << max_dims[0] << "," << max_dims[1];
185 return VariableComparerResults(total_nb_element);
186 }
187 if (total_nb_element == 0)
188 return {};
189 Integer nb_diff = 0;
190 UniqueArray2<DataType> min_values(var_values);
191 UniqueArray2<DataType> max_values(var_values);
192 pm->reduce(Parallel::ReduceMax, max_values.viewAsArray());
193 pm->reduce(Parallel::ReduceMin, min_values.viewAsArray());
194
195 ENUMERATE_ITEM (i, group) {
196 Item item = *i;
197 Integer index = item.localId();
198 if (group_index_table)
199 index = (*group_index_table)[index];
200
201 if (index >= ref_size1) {
202 ++nb_diff;
203 msg->pinfo() << "Processor: " << msg->traceId() << " VDIFF: Variable '" << var->name()
204 << "wrong number of elements : impossible comparison";
205 continue;
206 }
207 ConstArrayView<DataType> lref = min_values[index];
208 ConstArrayView<DataType> lcurrent = max_values[index];
209 for (Integer z = 0; z < ref_size2; ++z) {
210 DataType diff = DataType();
211 DataType dref = lref[z];
212 DataType dcurrent = lcurrent[z];
213 if (VarDataTypeTraits::verifDifferent(dref, dcurrent, diff, true)) {
214 this->m_diffs_info.add(DiffInfo(dcurrent, dref, diff, item, z));
215 ++nb_diff;
216 }
217 }
218 }
219
220 if (nb_diff != 0)
221 this->_sortAndDump(var, pm, compare_args);
222
223 return VariableComparerResults(nb_diff);
224 }
225};
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233template <typename T> Array2VariableT<T>::
235: Variable(vb, info)
236, m_data(nullptr)
237{
238 IDataFactoryMng* df = vb.dataFactoryMng();
239 DataStorageBuildInfo storage_build_info(vb.traceMng());
240 String storage_full_type = info.storageTypeInfo().fullName();
241 Ref<IData> data = df->createSimpleDataRef(storage_full_type, storage_build_info);
242 m_data = dynamic_cast<ValueDataType*>(data.get());
243 _setData(makeRef(m_data));
244}
245
246/*---------------------------------------------------------------------------*/
247/*---------------------------------------------------------------------------*/
248
249template <typename T> Array2VariableT<T>* Array2VariableT<T>::
250getReference(const VariableBuildInfo& vb, const VariableInfo& vi)
251{
252 if (vb.isNull())
253 return nullptr;
254 ThatClass* true_ptr = nullptr;
255 IVariableMng* vm = vb.variableMng();
256 IVariable* var = vm->checkVariable(vi);
257 if (var)
258 true_ptr = dynamic_cast<ThatClass*>(var);
259 else {
260 true_ptr = new ThatClass(vb, vi);
261 vm->_internalApi()->addVariable(true_ptr);
262 }
263 ARCANE_CHECK_PTR(true_ptr);
264 return true_ptr;
265}
266
267/*---------------------------------------------------------------------------*/
268/*---------------------------------------------------------------------------*/
269
270template <typename T> Array2VariableT<T>* Array2VariableT<T>::
272{
273 if (!var)
274 throw ArgumentException(A_FUNCINFO, "null variable");
275 ThatClass* true_ptr = dynamic_cast<ThatClass*>(var);
276 if (!true_ptr)
277 ARCANE_FATAL("Cannot build a reference from variable {0}", var->name());
278 return true_ptr;
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
284template <typename T> void Array2VariableT<T>::
286{
287 /*info() << "RESIZE(1) " << fullName()
288 << " wanted_dim1_size=" << s
289 << " dim2_size=" << m_data->value().dim2Size()
290 << " total=" << m_data->value().totalNbElement();*/
291 m_data->_internal()->resizeOnlyDim1(s);
292 syncReferences();
293}
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
298template <typename DataType> void Array2VariableT<DataType>::
299directResize(Integer dim1_size, Integer dim2_size)
300{
301 /*info() << "RESIZE(2) " << fullName()
302 << " wanted_dim1_size=" << dim1_size
303 << " wanted_dim2_size=" << dim2_size
304 << " total=" << m_data->value().totalNbElement()
305 << " dim1_size=" << m_data->value().dim1Size()
306 << " dim2_size=" << m_data->value().dim2Size();*/
307 m_data->_internal()->resize(dim1_size, dim2_size);
308 /*info() << "RESIZE(2) AFTER " << fullName()
309 << " total=" << m_data->value().totalNbElement()
310 << " dim1_size=" << m_data->value().dim1Size()
311 << " dim2_size=" << m_data->value().dim2Size()
312 << " addr=" << m_data->value().view().unguardedBasePointer();*/
313 syncReferences();
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
319template <typename DataType> void Array2VariableT<DataType>::
321{
322 Int32 dim1_size = valueView().dim1Size();
323 Int32 dim2_size = CheckedConvert::toInt32(shape.totalNbElement());
324
325 m_data->_internal()->resize(dim1_size, dim2_size);
326 m_data->setShape(shape);
327
328 syncReferences();
329}
330
331/*---------------------------------------------------------------------------*/
332/*---------------------------------------------------------------------------*/
333
334template <typename DataType> void Array2VariableT<DataType>::
336{
337 m_data->_internal()->shrink();
339}
340
341/*---------------------------------------------------------------------------*/
342/*---------------------------------------------------------------------------*/
343
344template <typename T> void Array2VariableT<T>::
345print(std::ostream&) const
346{
347 //ConstArray2View<T> x(m_data->value().constView());
348 //arrayDumpValue(o,x);
349}
350
351/*---------------------------------------------------------------------------*/
352/*---------------------------------------------------------------------------*/
353
354template <typename T> void Array2VariableT<T>::
356{
357 if (itemKind() == IK_Unknown)
358 ARCANE_THROW(NotSupportedException, "variable '{0}' is not a mesh variable", fullName());
359 IItemFamily* family = itemGroup().itemFamily();
360 if (!family)
361 ARCANE_FATAL("variable '{0}' without family", fullName());
362 if (isPartial())
363 itemGroup().synchronizer()->synchronize(this);
364 else
365 family->allItemsSynchronizer()->synchronize(this);
366}
367
368/*---------------------------------------------------------------------------*/
369/*---------------------------------------------------------------------------*/
370
371template <typename T> void Array2VariableT<T>::
373{
374 if (itemKind() == IK_Unknown)
375 ARCANE_THROW(NotSupportedException, "variable '{0}' is not a mesh variable", fullName());
376 IItemFamily* family = itemGroup().itemFamily();
377 if (!family)
378 ARCANE_FATAL("variable '{0}' without family", fullName());
379 if (isPartial())
380 itemGroup().synchronizer()->synchronize(this, local_ids);
381 else
382 family->allItemsSynchronizer()->synchronize(this, local_ids);
383}
384
385/*---------------------------------------------------------------------------*/
386/*---------------------------------------------------------------------------*/
387
388template <typename T> Real Array2VariableT<T>::
389allocatedMemory() const
390{
391 Real v1 = static_cast<Real>(sizeof(T));
392 Real v2 = static_cast<Real>(m_data->view().totalNbElement());
393 return v1 * v2;
394}
395
396/*---------------------------------------------------------------------------*/
397/*---------------------------------------------------------------------------*/
398
399// Uses a Helper function to specialize the call for the 'Byte' type because
400// ArrayVariableDiff::checkReplica() uses a Min/Max reduction, and this is not
401// available in MPI for the Byte type.
402namespace
403{
404 template <typename T> VariableComparerResults
405 _checkIfSameOnAllReplicaHelper(IVariable* var, ConstArray2View<T> values,
406 const VariableComparerArgs& compare_args)
407 {
409 return csa.checkReplica(var, values, compare_args);
410 }
411
412 // Specialization for the 'Byte' type which does not support reductions.
413 VariableComparerResults
414 _checkIfSameOnAllReplicaHelper(IVariable* var, ConstArray2View<Byte> values,
415 const VariableComparerArgs& compare_args)
416 {
417 Integer dim1_size = values.dim1Size();
418 Integer dim2_size = values.dim2Size();
419 UniqueArray2<Integer> int_values(dim1_size, dim2_size);
420 for (Integer i = 0; i < dim1_size; ++i)
421 for (Integer j = 0; j < dim2_size; ++j)
422 int_values[i][j] = values[i][j];
423 Array2VariableDiff<Integer> csa;
424 return csa.checkReplica(var, int_values, compare_args);
425 }
426} // namespace
427
428/*---------------------------------------------------------------------------*/
429/*---------------------------------------------------------------------------*/
430
432_compareVariable(const VariableComparerArgs& compare_args)
433{
434 switch (compare_args.compareMode()) {
436 if (itemKind() == IK_Particle)
437 return {};
438 IDataReader* reader = compare_args.dataReader();
439 ARCANE_CHECK_POINTER(reader);
440
441 ConstArray2View<T> from_array(valueView());
442 Ref<IArray2DataT<T>> ref_data(m_data->cloneTrueEmptyRef());
443 reader->read(this, ref_data.get());
444
446 VariableComparerResults r = csa.check(this, ref_data->view(), from_array, compare_args);
447 return r;
448 } break;
450 IItemFamily* family = itemGroup().itemFamily();
451 if (!family)
452 return {};
453
454 Integer dim1_size = valueView().dim1Size();
455 if (dim1_size == 0)
456 return {};
457
458 ValueType& data_values = m_data->_internal()->_internalDeprecatedValue();
459
460 UniqueArray2<T> ref_array(constValueView());
461 this->synchronize(); // works for all variables
463 Array2View<T> from_array(valueView());
464 VariableComparerResults results = csa.check(this, ref_array, from_array, compare_args);
465 data_values.copy(ref_array);
466 return results;
467 }
469 VariableComparerResults r = _checkIfSameOnAllReplicaHelper(this, constValueView(), compare_args);
470 return r;
471 }
472 }
473 ARCANE_FATAL("Invalid value for compare mode '{0}'", (int)compare_args.compareMode());
474}
475
476/*---------------------------------------------------------------------------*/
477/*---------------------------------------------------------------------------*/
478
479template <typename T> void Array2VariableT<T>::
480_internalResize(const VariableResizeArgs& resize_args)
481{
482 Int32 new_size = resize_args.newSize();
483 Int32 nb_additional_element = resize_args.nbAdditionalCapacity();
484 bool use_no_init = resize_args.isUseNoInit();
485
486 // Moved exception from ItemGroupImpl::removeItems.
487 // This is an implementation problem of Arcane partial variables and not of
488 // the partial variable concept (cf ItemGroupMap which implements it).
489 // if (isPartial() && new_size < value().dim1Size())
490 // throw NotSupportedException(A_FUNCINFO,"Cannot remove items to group with partial variables");
491
492 ValueType& data_values = m_data->_internal()->_internalDeprecatedValue();
493 ValueType& container_ref = data_values;
494
495 Integer dim2_size = data_values.dim2Size();
496
497 const bool is_collective_allocator = data_values.allocator()->isCollective();
498 if (is_collective_allocator) {
499 data_values.reserve(new_size + nb_additional_element * dim2_size);
500 }
501 else if (nb_additional_element != 0) {
502 Integer capacity = data_values.capacity();
503 if (new_size > capacity)
504 data_values.reserve(new_size + nb_additional_element * dim2_size);
505 }
506
508 // If the new size is greater than the old one,
509 // initialize the new elements according to the desired policy
510 Integer current_size = data_values.dim1Size();
511
512 /*info() << "RESIZE INTERNAL " << fullName()
513 << " wanted_dim1_size=" << new_size
514 << " dim1_size=" << value().dim1Size()
515 << " dim2size=" << dim2_size
516 << " total=" << value().totalNbElement();*/
517 if (use_no_init || (init_policy != DIP_InitWithDefault))
518 data_values.resizeNoInit(new_size, dim2_size);
519 else
520 data_values.resize(new_size, dim2_size);
521
522 if (new_size > current_size) {
523 bool use_nan = (init_policy == DIP_InitWithNan);
524 bool use_nan2 = (init_policy == DIP_InitInitialWithNanResizeWithDefault) && !_hasValidData();
525 if (use_nan || use_nan2) {
526 for (Integer i = current_size; i < new_size; ++i)
527 DataTypeTraitsT<T>::fillNan(data_values[i]);
528 }
529 }
530
531 // Compacts the memory if requested
532 if (_wantShrink()) {
533 if (container_ref.totalNbElement() < container_ref.capacity())
534 container_ref.shrink();
535 }
536
537 /*info() << "RESIZE INTERNAL AFTER " << fullName()
538 << " addr=" << m_data->value().view().unguardedBasePointer()
539 << " dim1=" << value().dim1Size()
540 << " dim2=" << value().dim2Size();*/
541}
542
543/*---------------------------------------------------------------------------*/
544/*---------------------------------------------------------------------------*/
545
546template <typename T> void Array2VariableT<T>::
548{
549 ARCANE_ASSERT(source.size() == destination.size(),
550 ("Unable to copy: source and destination have different sizes !"));
551
552 const Integer dim2_size = valueView().dim2Size();
553 const Integer nb_copy = source.size();
554 Array2View<T> value = m_data->view();
555
556 for (Integer i = 0; i < nb_copy; ++i) {
557 for (Integer j = 0; j < dim2_size; ++j)
558 value[destination[i]][j] = value[source[i]][j];
559 }
561}
562
563/*---------------------------------------------------------------------------*/
564/*---------------------------------------------------------------------------*/
565
566template <typename T> void Array2VariableT<T>::
568 Int32ConstArrayView second_source,
569 Int32ConstArrayView destination)
570{
571 ARCANE_ASSERT((first_source.size() == destination.size()) && (second_source.size() == destination.size()),
572 ("Unable to copy: source and destination have different sizes !"));
573
574 const Integer dim2_size = valueView().dim2Size();
575 const Integer nb_copy = first_source.size();
576 Array2View<T> value = m_data->view();
577
578 for (Integer i = 0; i < nb_copy; ++i) {
579 for (Integer j = 0; j < dim2_size; ++j)
580 value[destination[i]][j] = (T)((value[first_source[i]][j] + value[second_source[i]][j]) / 2);
581 }
583}
584
585/*---------------------------------------------------------------------------*/
586/*---------------------------------------------------------------------------*/
587
588template <typename T> void Array2VariableT<T>::
589compact(Int32ConstArrayView new_to_old_ids)
590{
591 if (isPartial()) {
592 debug(Trace::High) << "Skip compact for partial variable " << name();
593 return;
594 }
595
596 ValueType& current_value = m_data->_internal()->_internalDeprecatedValue();
597 Integer current_size = current_value.dim1Size();
598 if (current_size == 0)
599 return;
600
601 Integer dim2_size = current_value.dim2Size();
602 if (dim2_size == 0)
603 return;
604
605 //TODO: avoid the clone
606 UniqueArray2<T> old_value(current_value);
607
608 Integer new_size = new_to_old_ids.size();
609 current_value.resize(new_size, dim2_size);
610 /*info() << "Variable: " << name() << " Compacte2D: size=" << current_size
611 << " dim2_size=" << dim2_size
612 << " new_size=" << new_size;*/
613
614 if (arcaneIsCheck()) {
615 for (Integer i = 0; i < new_size; ++i) {
616 Integer nto = new_to_old_ids[i];
617 ArrayView<T> v = current_value.at(i);
618 ArrayView<T> ov = old_value.at(nto);
619 for (Integer j = 0; j < dim2_size; ++j)
620 v.setAt(j, ov.at(j));
621 }
622 }
623 else {
624 for (Integer i = 0; i < new_size; ++i) {
625 Integer nto = new_to_old_ids[i];
626 for (Integer j = 0; j < dim2_size; ++j)
627 current_value[i][j] = old_value[nto][j];
628 }
629 }
630
632}
633
634/*---------------------------------------------------------------------------*/
635/*---------------------------------------------------------------------------*/
636
637template <typename T> void Array2VariableT<T>::
639{
640}
641
642/*---------------------------------------------------------------------------*/
643/*---------------------------------------------------------------------------*/
644
645template <typename T> void Array2VariableT<T>::
647{
648}
649
650/*---------------------------------------------------------------------------*/
651/*---------------------------------------------------------------------------*/
652
653template <typename DataType> void
655swapValues(ThatClass& rhs)
656{
657 _checkSwapIsValid(&rhs);
658 // TODO: check if the two variables must have the same number
659 // of elements, but apparently this does not seem essential.
660 m_data->swapValues(rhs.m_data);
661 // References must be updated for this variable and for rhs.
662 syncReferences();
663 rhs.syncReferences();
664}
665
666/*---------------------------------------------------------------------------*/
667/*---------------------------------------------------------------------------*/
668
669template <typename DataType> auto
670Array2VariableT<DataType>::
671value() -> ValueType&
672{
673 return m_data->_internal()->_internalDeprecatedValue();
674}
675
676/*---------------------------------------------------------------------------*/
677/*---------------------------------------------------------------------------*/
678
679template <typename DataType> void
681fillShape(ArrayShape& shape_with_item)
682{
683 // TODO: This method is independent of the data type.
684 // It would be necessary to make a single version of it.
685 ArrayShape shape = m_data->shape();
686 const Int32 nb_rank = shape_with_item.nbDimension();
687 //std::cout << "SHAPE=" << shape.dimensions() << " internal_rank=" << nb_rank << "\n";
688 auto array_view = m_data->view();
689 Int32 dim0_size = array_view.dim1Size();
690
691 shape_with_item.setDimension(0, dim0_size);
692 Int32 nb_orig_shape = shape.nbDimension();
693 for (Int32 i = 0; i < nb_orig_shape; ++i) {
694 shape_with_item.setDimension(i + 1, shape.dimension(i));
695 }
696
697 // If the shape is smaller than our rank, fill the
698 // additional dimensions with the value 1.
699 for (Int32 i = (nb_orig_shape + 1); i < nb_rank; ++i) {
700 shape_with_item.setDimension(i, 1);
701 }
702}
703
704/*---------------------------------------------------------------------------*/
705/*---------------------------------------------------------------------------*/
706
707ARCANE_INTERNAL_INSTANTIATE_TEMPLATE_FOR_NUMERIC_DATATYPE(Array2VariableT);
708
709/*---------------------------------------------------------------------------*/
710/*---------------------------------------------------------------------------*/
711
712} // End namespace Arcane
713
714/*---------------------------------------------------------------------------*/
715/*---------------------------------------------------------------------------*/
#define ARCANE_CHECK_POINTER(ptr)
Macro returning the pointer ptr if it is not null or throwing an exception if it is null.
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ENUMERATE_ITEM(name, group)
Generic enumerator for a node group.
Variable on a 2D array.
VariableComparerResults _compareVariable(const VariableComparerArgs &compare_args) final
Comparison of values between variables.
void compact(Int32ConstArrayView old_to_new_ids) override
Compresses the variable's values.
void setIsSynchronized() override
Indicates that the variable is synchronized.
Array2VariableT(const VariableBuildInfo &v, const VariableInfo &vi)
Constructs a variable based on the reference v.
IData * data() override
Data associated with the variable.
void copyItemsMeanValues(Int32ConstArrayView first_source, Int32ConstArrayView second_source, Int32ConstArrayView destination) override
Copies the mean values of entities numbered first_source and second_source into entities numbered des...
void copyItemsValues(Int32ConstArrayView source, Int32ConstArrayView destination) override
Copies the values of entities numbered source into entities numbered destination.
void synchronize() override
Synchronizes the variable.
Real allocatedMemory() const override
Memory size (in Bytes) used by the variable.
void print(std::ostream &o) const override
Prints the variable's values to the stream o.
void shrinkMemory() override
Frees any additional memory allocated for the data.
void copy(Span2< const DataType > rhs)
Resizes the instance based on the dimensions of rhs and copies the values of rhs into it.
ArrayView< DataType > viewAsArray()
View of the array as a 1D array.
void resize(Int64 new_size)
Resizes only the first dimension, leaving the second dimension unchanged.
ConstArrayView< DataType > at(Int64 i) const
Element at index i. Always checks for bounds.
Array shape.
Definition ArrayShape.h:42
Modifiable view of an array of type T.
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Information to construct an instance of 'IData'.
Base class of a hash table between group items and their positions in the table.
Interface of the data factory manager.
Interface for reading variable data.
Definition IDataReader.h:35
virtual void read(IVariable *var, IData *data)=0
Reads the data data of the variable var.
Interface of an entity family.
Definition IItemFamily.h:83
virtual IVariableSynchronizer * allItemsSynchronizer()=0
Synchronizer on all entities of the family.
Interface of the parallelism manager for a subdomain.
virtual ITraceMng * traceMng() const =0
Trace manager.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual Int32 commSize() const =0
Number of instances in the communicator.
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
virtual const String & traceId() const =0
Manager identifier.
virtual TraceMessage pinfo()=0
Stream for a parallel information message.
virtual TraceMessage info()=0
Stream for an information message.
virtual IParallelMng * replicaParallelMng() const =0
Returns the IParallelMng of the mesh replica associated with the variable.
virtual void addVariable(IVariable *var)=0
Adds a variable.
Variable manager interface.
virtual IVariable * checkVariable(const VariableInfo &infos)=0
Checks a variable.
virtual IVariableMngInternal * _internalApi()=0
Internal Arcane API.
virtual void synchronize(IVariable *var)=0
Synchronizes the variable var in blocking mode.
Interface of a variable.
Definition IVariable.h:40
virtual bool isPartial() const =0
Indicates if the variable is partial.
virtual ItemGroup itemGroup() const =0
Associated mesh group.
virtual String name() const =0
Variable name.
virtual IVariableInternal * _internalApi()=0
Internal Arcane API.
Mesh entity group.
Definition ItemGroup.h:51
SharedPtrT< GroupIndexTable > localIdToIndex() const
Table of local ids to a position for all entities in the group.
Definition ItemGroup.h:312
bool null() const
true means the group is the null group
Definition ItemGroup.h:75
IMesh * mesh() const
Mesh to which this group belongs (0 for the null group).
Definition ItemGroup.h:131
Base class for a mesh element.
Definition Item.h:84
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
Definition Item.h:233
constexpr bool isOwn() const
true if the entity belongs to the subdomain
Definition Item.h:267
InstanceType * get() const
Associated instance or nullptr if none.
Reference to an instance.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
TraceMessage info() const
Flow for an information message.
2D data vector with value semantics (STL style).
Parameters necessary for building a variable.
Arguments for VariableComparer methods.
Results of a comparison operation.
Template class for information about a variable type.
Base class for value comparisons between two variables.
Information characterizing a variable.
Arguments for resizing a variable.
Variable(const VariableBuildInfo &v, const VariableInfo &vi)
Creates a variable linked to the reference v.
Definition Variable.cc:344
void _setData(const Ref< IData > &data)
Positions the data.
Definition Variable.cc:918
bool isPartial() const override
Indicates if the variable is partial.
Definition Variable.cc:900
String name() const final
Variable name.
Definition Variable.cc:484
ItemGroup itemGroup() const final
Associated mesh group.
Definition Variable.cc:864
void syncReferences() override
Synchronizes references.
Definition Variable.cc:786
String fullName() const final
Full variable name (with family prefix).
Definition Variable.cc:493
eItemKind itemKind() const override
Kind of mesh entities on which the variable is based.
Definition Variable.cc:873
void resize(Integer n) override
Sets the number of elements for an array variable.
Definition Variable.cc:1012
@ ReduceMin
Minimum of values.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
bool arcaneIsCheck()
True if running in check mode.
Definition Misc.cc:66
eDataInitialisationPolicy
Possible data initialization policy.
Definition DataTypes.h:135
@ DIP_InitInitialWithNanResizeWithDefault
Initialization with NaN upon creation and default constructor thereafter.
Definition DataTypes.h:175
@ DIP_InitWithNan
Initialization with NaN (Not a Number).
Definition DataTypes.h:153
@ DIP_InitWithDefault
Initialization with the default constructor.
Definition DataTypes.h:144
eDataInitialisationPolicy getGlobalDataInitialisationPolicy()
Gets the initialization policy for variables.
Definition DataTypes.cc:164
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
@ SameOnAllReplica
Checks that the variable values are the same on all replicas.
@ Same
Compares with a reference.
@ Sync
Checks that the variable is synchronized.
@ IK_Particle
Particle mesh entity.
@ IK_Unknown
Unknown or uninitialized mesh entity.
double Real
Type representing a real number.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
std::int32_t Int32
Signed integer type of 32 bits.