Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
VariableDiff.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/* VariableDiff.cc (C) 2000-2025 */
9/* */
10/* Handling differences between variables */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/core/VariableDiff.h"
15
16#include "arcane/utils/OStringStream.h"
17#include "arcane/utils/ITraceMng.h"
18
19#include "arcane/core/IVariable.h"
20#include "arcane/core/IParallelMng.h"
21#include "arcane/core/VariableComparer.h"
22
23#include <algorithm>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31template <typename DataType> void VariableDiff<DataType>::DiffPrinter::
32sort(ArrayView<DiffInfo> diffs_info)
33{
34 if constexpr (std::is_same<TrueType, typename VarDataTypeTraits::IsNumeric>::value) {
35 std::sort(std::begin(diffs_info), std::end(diffs_info));
36 }
37 else
38 ARCANE_UNUSED(diffs_info);
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44template <typename DataType> void VariableDiff<DataType>::DiffPrinter::
45dump(ConstArrayView<DiffInfo> diffs_info, IVariable* var, IParallelMng* pm,
46 const VariableComparerArgs& compare_args)
47{
48 ITraceMng* msg = pm->traceMng();
49 Int32 sid = pm->commRank();
50 const String& var_name = var->name();
51 Integer nb_diff = diffs_info.size();
52 Integer nb_print = nb_diff;
53 Int32 max_print = compare_args.maxPrint();
54 if (max_print >= 0 && nb_diff > static_cast<Integer>(max_print))
55 nb_print = max_print;
56 OStringStream ostr;
57 ostr().precision(FloatInfo<Real>::maxDigit());
58 ostr() << nb_diff << " entities having different values for the variable "
59 << var_name << '\n';
60 for (Integer i = 0; i < nb_print; ++i) {
61 const DiffInfo& di = diffs_info[i];
62 if (di.m_unique_id != NULL_ITEM_UNIQUE_ID) {
63 // This is an entity
64 char type = di.m_is_own ? 'O' : 'G';
65 ostr() << "VDIFF: Variable '" << var_name << "'"
66 << " (" << type << ")"
67 << " uid=" << di.m_unique_id
68 << " lid=" << di.m_local_id;
69 }
70 else {
71 // This is the index of an array variable
72 ostr() << "VDIFF: Variable '" << var_name << "'"
73 << " index=" << di.m_local_id;
74 }
75 if (di.m_sub_index != NULL_ITEM_ID)
76 ostr() << " [" << di.m_sub_index << "]";
77 // Indicates whether default display is performed.
78 // This is the case unless the norm is requested and the type is numeric
79 // (types like 'String' do not have a notion of norm)
80 bool is_print_default = true;
81 if constexpr (IsNumeric) {
82 if (compare_args.computeDifferenceMethod() == eVariableComparerComputeDifferenceMethod::LocalNormMax) {
83 ostr() << " val: " << VarDataTypeTraits::normeMax(di.m_current)
84 << " ref: " << VarDataTypeTraits::normeMax(di.m_ref)
85 << " rdiff: " << VarDataTypeTraits::normeMax(di.m_diff) << '\n';
86 is_print_default = false;
87 }
88 }
89
90 if (is_print_default) {
91 ostr() << " val: " << di.m_current
92 << " ref: " << di.m_ref << " rdiff: " << di.m_diff << '\n';
93 }
94 }
95 msg->pinfo() << "Processor " << sid << " : " << nb_diff
96 << " values are different on the variable "
97 << var_name << ":\n"
98 << ostr.str();
99}
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
104template class VariableDiff<Byte>::DiffPrinter;
105template class VariableDiff<Real>::DiffPrinter;
106template class VariableDiff<Int8>::DiffPrinter;
107template class VariableDiff<Int16>::DiffPrinter;
108template class VariableDiff<Int32>::DiffPrinter;
109template class VariableDiff<Int64>::DiffPrinter;
110template class VariableDiff<BFloat16>::DiffPrinter;
111template class VariableDiff<Float16>::DiffPrinter;
112template class VariableDiff<Float32>::DiffPrinter;
113template class VariableDiff<Real2>::DiffPrinter;
114template class VariableDiff<Real2x2>::DiffPrinter;
115template class VariableDiff<Real3>::DiffPrinter;
116template class VariableDiff<Real3x3>::DiffPrinter;
117template class VariableDiff<String>::DiffPrinter;
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122} // End namespace Arcane
123
124/*---------------------------------------------------------------------------*/
125/*---------------------------------------------------------------------------*/
Modifiable view of an array of type T.
Base class for value comparisons between two variables.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
std::int32_t Int32
Signed integer type of 32 bits.