Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
VariableComparer.h
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/* VariableComparer.h (C) 2000-2025 */
9/* */
10/* Class to perform comparisons between variables. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_VARIABLECOMPARER_H
13#define ARCANE_CORE_VARIABLECOMPARER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/TraceAccessor.h"
18
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30//! Comparison method to use
32{
33 //! Compares with a reference
34 Same = 0,
35 //! Checks that the variable is synchronized
36 Sync = 1,
37 //! Checks that the variable values are the same on all replicas
39};
40
41//! Method used to calculate the difference between two values \a v1 and \a v2.
43{
44 //! Uses (v1-v2) / v1
46 /*!
47 * \brief Uses (v1-v2) / local_norm_max.
48 *
49 * \a local_norm_max is the maximum of math::abs() of the values on the subdomain.
50 */
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57/*!
58 * \brief Arguments for VariableComparer methods.
59 */
60class ARCANE_CORE_EXPORT VariableComparerArgs
61{
62 public:
63
64 /*!
65 * \brief Sets the number of errors to display in the listing.
66 *
67 * If 0, no elements are displayed. If positive, displays at most
68 * \a v elements. If negative, all elements are displayed.
69 */
70 void setMaxPrint(Int32 v) { m_max_print = v; }
71 Int32 maxPrint() const { return m_max_print; }
72
73 /*!
74 * \brief Indicates on which entities the comparison is performed.
75 *
76 * If \a v is true, compares the values both on the proper entities and
77 * the ghost entities. Otherwise, it only performs the comparison on the
78 * proper entities.
79 *
80 * This parameter is only used if compareMode() equals eCompareMode::Same.
81 */
82 void setCompareGhost(bool v) { m_is_compare_ghost = v; }
83 bool isCompareGhost() const { return m_is_compare_ghost; }
84
85 void setDataReader(IDataReader* v) { m_data_reader = v; }
86 IDataReader* dataReader() const { return m_data_reader; }
87
88 void setCompareMode(eVariableComparerCompareMode v) { m_compare_mode = v; }
89 eVariableComparerCompareMode compareMode() const { return m_compare_mode; }
90
91 void setComputeDifferenceMethod(eVariableComparerComputeDifferenceMethod v) { m_compute_difference_method = v; }
92 eVariableComparerComputeDifferenceMethod computeDifferenceMethod() const { return m_compute_difference_method; }
93
94 private:
95
96 Int32 m_max_print = 0;
97 bool m_is_compare_ghost = false;
98 IDataReader* m_data_reader = nullptr;
99 eVariableComparerCompareMode m_compare_mode = eVariableComparerCompareMode::Same;
100 eVariableComparerComputeDifferenceMethod m_compute_difference_method = eVariableComparerComputeDifferenceMethod::Relative;
101};
102
103/*---------------------------------------------------------------------------*/
104/*---------------------------------------------------------------------------*/
105
106/*!
107 * \brief Results of a comparison operation.
108 */
109class ARCANE_CORE_EXPORT VariableComparerResults
110{
111 public:
112
113 VariableComparerResults() = default;
114 explicit VariableComparerResults(Int32 nb_diff)
115 : m_nb_diff(nb_diff)
116 {}
117
118 public:
119
120 void setNbDifference(Int32 v) { m_nb_diff = v; }
121 Int32 nbDifference() const { return m_nb_diff; }
122
123 public:
124
125 Int32 m_nb_diff = 0;
126};
127
128/*---------------------------------------------------------------------------*/
129/*---------------------------------------------------------------------------*/
130
131/*!
132 * \brief Class to perform comparisons between variables.
133 *
134 * To use this class, you must create an instance of
135 * VariableComparerArgs via one of the following methods:
136 *
137 * - buildForCheckIfSame()
138 * - buildForCheckIfSync()
139 * - buildForCheckIfSameOnAllReplica()
140 *
141 * You must then call the apply() method with the created instance for
142 * each variable you wish to compare.
143 */
144class ARCANE_CORE_EXPORT VariableComparer
145{
146 public:
147
148 VariableComparer() = default;
149
150 public:
151
152 /*!
153 * \brief Creates a comparison to verify that a variable is synchronized.
154 *
155 * This operation only works for mesh variables.
156 *
157 * A variable is synchronized when its values are the same across all
158 * subdomains, both on proper elements and ghost elements.
159 *
160 * It is possible to call the methods
161 * VariableComparerArgs::setMaxPrint(),
162 * VariableComparerArgs::setCompareGhost()
163 * or VariableComparerArgs::setComputeDifferenceMethod() on the returned
164 * instance to modify the behavior.
165 */
167
168 /*!
169 * \brief Creates a comparison to verify that a variable is identical on
170 * all replicas.
171 *
172 * Compares the variable values with those of the same subdomain on other
173 * replicas. For each differing element, a message is displayed.
174 *
175 * Using apply() for this type of comparison is a collective method on the
176 * replica of the variable passed as an argument. Therefore, it should only
177 * be called if the variable exists on all subdomains, otherwise it will cause
178 * a blockage.
179 *
180 * This comparison only works for variables of numerical types. In this case,
181 * it throws a NotSupportedException.
182 *
183 * It is possible to call the methods
184 * VariableComparerArgs::setMaxPrint() or
185 * VariableComparerArgs::setComputeDifferenceMethod() on the returned instance
186 * to modify the behavior.
187 */
189
190 public:
191
192 /*!
193 * \brief Creates a comparison to verify that a variable is identical to
194 * a reference value.
195 *
196 * This operation verifies that the variable values are identical to a
197 * reference value which will be read from the \a data_reader.
198 *
199 * It is possible to call the methods
200 * VariableComparerArgs::setMaxPrint(),
201 * VariableComparerArgs::setCompareGhost() or
202 * VariableComparerArgs::setComputeDifferenceMethod() on the returned
203 * instance to modify the behavior.
204 *
205 * It is then possible to call the apply() method on the returned instance
206 * to perform comparisons on a variable.
207 */
209
210 public:
211
212 //! Applies the comparison \a compare_args to the variable \a var
214};
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
219} // namespace Arcane
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223
224#endif
Declarations of Arcane's general types.
Interface for reading variable data.
Definition IDataReader.h:35
Interface of a variable.
Definition IVariable.h:40
Arguments for VariableComparer methods.
void setMaxPrint(Int32 v)
Sets the number of errors to display in the listing.
void setCompareGhost(bool v)
Indicates on which entities the comparison is performed.
Results of a comparison operation.
VariableComparerArgs buildForCheckIfSameOnAllReplica()
Creates a comparison to verify that a variable is identical on all replicas.
VariableComparerResults apply(IVariable *var, const VariableComparerArgs &compare_args)
Applies the comparison compare_args to the variable var.
VariableComparerArgs buildForCheckIfSame(IDataReader *data_reader)
Creates a comparison to verify that a variable is identical to a reference value.
VariableComparerArgs buildForCheckIfSync()
Creates a comparison to verify that a variable is synchronized.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eVariableComparerComputeDifferenceMethod
Method used to calculate the difference between two values v1 and v2.
eVariableComparerCompareMode
Comparison method to use.
@ SameOnAllReplica
Checks that the variable values are the same on all replicas.
@ Same
Compares with a reference.
@ Sync
Checks that the variable is synchronized.
std::int32_t Int32
Signed integer type of 32 bits.