TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
DebogIJK.cpp
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16
17#include <DebogIJK.h>
18#include <IJK_Field.h>
19#include <Param.h>
20#include <TRUSTTabs.h>
21#include <Process.h>
22
23Implemente_instanciable(DebogIJK,"DebogIJK",Interprete) ;
24
29double DebogIJK::seuil_absolu_ = 1e-4;
30double DebogIJK::seuil_relatif_ = 1e-8;
32
34{
36 return os;
37}
38
40{
41 return is;
42}
43
45{
46 filename_ = "DEBOG.txt";
47 Param param(que_suis_je());
48 param.ajouter("mode", &debog_mode_);
49 param.dictionnaire("disabled", (int)DISABLED);
50 param.dictionnaire("write_pass", (int)WRITE_PASS);
51 param.dictionnaire("check_pass", (int)CHECK_PASS);
52 param.ajouter("filename", &filename_);
53 param.ajouter("seuil_absolu", &seuil_absolu_);
54 param.ajouter("seuil_relatif", &seuil_relatif_);
55 param.ajouter("seuil_minimum_relatif", &seuil_minimum_relatif_);
56 param.lire_avec_accolades(is);
57
58 if (je_suis_maitre())
59 {
61 outfile_.ouvrir(filename_);
63 infile_.ouvrir(filename_);
64 }
65 return is;
66}
67
68// Computes a numerical signature of the field. We want a signature that varies
69// linearly with the field values and detects small variations.
70// A few weighted sums of the field values are computed with pseudo-random weights.
71void DebogIJK::compute_signature(const IJK_Field_float& field, ArrOfDouble& signature)
72{
73 const int sig_size = 5;
74 signature.resize_array(sig_size);
75 ArrOfDouble facteurs(sig_size);
76
77 // Generate factors: irrational numbers that are not multiples of each other
78 facteurs[0] = 1.35914091422952;
79 for (int i = 1; i < sig_size; i++)
80 facteurs[i] = facteurs[i-1] * facteurs[0];
81
82 for (int i = 0; i < sig_size; i++)
83 signature[i] = 0.;
84
85 VECT(DoubleTab) sig_factors(3);
86 for (int dir = 0; dir < 3; dir++)
87 {
88 const int n = field.nb_elem_local(dir);
89 sig_factors[dir].resize(n, sig_size);
90 const int offset = field.get_domaine().get_offset_local(dir);
91 for (int i = 0; i < n; i++)
92 for (int j = 0; j < sig_size; j++)
93 sig_factors[dir](i,j) = cos(facteurs[j] * (i+offset));
94 }
95
96 const int ni = field.ni();
97 const int nj = field.nj();
98 const int nk = field.nk();
99 for (int k = 0; k < nk; k++)
100 {
101 for (int j = 0; j < nj; j++)
102 {
103 for (int i = 0; i < ni; i++)
104 {
105 double data = field(i,j,k);
106 for (int l = 0; l < sig_size; l++)
107 {
108 signature[l] += data * sig_factors[0](i,l) * sig_factors[1](j,l) * sig_factors[2](k,l);
109 }
110 }
111 }
112 }
113 mp_sum_for_each_item(signature);
114}
115
116void DebogIJK::verifier(const char *msg, const IJK_Field_float& f)
117{
118 if (debog_mode_ == DISABLED)
119 return;
120 ArrOfDouble sig;
121 compute_signature(f, sig);
123 {
124 Nom s("");
125 char ss[1000];
126 for (int i = 0; i < sig.size_array(); i++)
127 {
128 snprintf(ss, 1000, "%20.13g ", sig[i]);
129 s += ss;
130 }
131 s += msg;
132 Journal() << "DEBOG1:" << s << finl;
133 if (debog_mode_ == WRITE_PASS)
134 outfile_ << s << finl;
135 else
136 {
137 ArrOfDouble sig2(sig.size_array());
138 Nom s2("");
139 for (int i = 0; i < sig.size_array(); i++)
140 {
141 infile_ >> sig2[i];
142 snprintf(ss, 1000, "%20.13g ", sig2[i]);
143 s2 += ss;
144 }
145 std::string ligne;
146 std::getline(infile_.get_ifstream(), ligne);
147 Journal() << "DEBOG2:" << s2 << ligne.c_str() << finl;
148
149 bool erreur = false;
150 for (int i = 0; i < sig.size_array(); i++)
151 {
152 double m = std::max(fabs(sig[i]),fabs(sig2[i]));
153 m = std::max(seuil_minimum_relatif_, m);
154 if (fabs(sig[i] - sig2[i]) > seuil_absolu_
155 || fabs(sig[i] - sig2[i]) / m > seuil_relatif_)
156 erreur = true;
157 }
158 if (erreur)
159 {
160 Cerr << "DEBOG: error" << finl << "THIS:" << s << finl << "REF: " << s2 << finl;
161 }
162 }
163 }
164}
165// Computes a numerical signature of the field. We want a signature that varies
166// linearly with the field values and detects small variations.
167// A few weighted sums of the field values are computed with pseudo-random weights.
168void DebogIJK::compute_signature(const IJK_Field_double& field, ArrOfDouble& signature)
169{
170 const int sig_size = 5;
171 signature.resize_array(sig_size);
172 ArrOfDouble facteurs(sig_size);
173
174 // Generate factors: irrational numbers that are not multiples of each other
175 facteurs[0] = 1.35914091422952;
176 for (int i = 1; i < sig_size; i++)
177 facteurs[i] = facteurs[i-1] * facteurs[0];
178
179 for (int i = 0; i < sig_size; i++)
180 signature[i] = 0.;
181
182 VECT(DoubleTab) sig_factors(3);
183 for (int dir = 0; dir < 3; dir++)
184 {
185 const int n = field.nb_elem_local(dir);
186 sig_factors[dir].resize(n, sig_size);
187 const int offset = field.get_domaine().get_offset_local(dir);
188 for (int i = 0; i < n; i++)
189 for (int j = 0; j < sig_size; j++)
190 sig_factors[dir](i,j) = cos(facteurs[j] * (i+offset));
191 }
192
193 const int ni = field.ni();
194 const int nj = field.nj();
195 const int nk = field.nk();
196 for (int k = 0; k < nk; k++)
197 {
198 for (int j = 0; j < nj; j++)
199 {
200 for (int i = 0; i < ni; i++)
201 {
202 double data = field(i,j,k);
203 for (int l = 0; l < sig_size; l++)
204 {
205 signature[l] += data * sig_factors[0](i,l) * sig_factors[1](j,l) * sig_factors[2](k,l);
206 }
207 }
208 }
209 }
210 mp_sum_for_each_item(signature);
211}
212
213void DebogIJK::verifier(const char *msg, const IJK_Field_double& f)
214{
215 if (debog_mode_ == DISABLED)
216 return;
217 ArrOfDouble sig;
218 compute_signature(f, sig);
220 {
221 Nom s("");
222 char ss[1000];
223 for (int i = 0; i < sig.size_array(); i++)
224 {
225 snprintf(ss, 1000, "%20.13g ", sig[i]);
226 s += ss;
227 }
228 s += msg;
229 Journal() << "DEBOG1:" << s << finl;
230 if (debog_mode_ == WRITE_PASS)
231 outfile_ << s << finl;
232 else
233 {
234 ArrOfDouble sig2(sig.size_array());
235 Nom s2("");
236 for (int i = 0; i < sig.size_array(); i++)
237 {
238 infile_ >> sig2[i];
239 snprintf(ss, 1000, "%20.13g ", sig2[i]);
240 s2 += ss;
241 }
242 std::string ligne;
243 std::getline(infile_.get_ifstream(), ligne);
244 Journal() << "DEBOG2:" << s2 << ligne.c_str() << finl;
245
246 bool erreur = false;
247 for (int i = 0; i < sig.size_array(); i++)
248 {
249 double m = std::max(fabs(sig[i]),fabs(sig2[i]));
250 m = std::max(seuil_minimum_relatif_, m);
251 if (fabs(sig[i] - sig2[i]) > seuil_absolu_
252 || fabs(sig[i] - sig2[i]) / m > seuil_relatif_)
253 erreur = true;
254 }
255 if (erreur)
256 {
257 Cerr << "DEBOG: error" << finl << "THIS:" << s << finl << "REF: " << s2 << finl;
258 }
259 }
260 }
261}
262
: class DebogIJK
Definition DebogIJK.h:33
static void compute_signature(const IJK_Field_float &, ArrOfDouble &signature)
Definition DebogIJK.cpp:71
static Nom filename_
Definition DebogIJK.h:45
static SFichier outfile_
Definition DebogIJK.h:47
static void verifier(const char *msg, const IJK_Field_float &)
Definition DebogIJK.cpp:116
static int debog_mode_
Definition DebogIJK.h:44
@ WRITE_PASS
Definition DebogIJK.h:38
@ CHECK_PASS
Definition DebogIJK.h:38
@ DISABLED
Definition DebogIJK.h:38
static double seuil_minimum_relatif_
Definition DebogIJK.h:43
static double seuil_relatif_
Definition DebogIJK.h:43
static EFichier infile_
Definition DebogIJK.h:46
Entree & interpreter(Entree &) override
Definition DebogIJK.cpp:44
static double seuil_absolu_
Definition DebogIJK.h:43
int get_offset_local(int direction) const
Returns the local offset in requested direction.
File for reading. This class is to the C++ ifstream class what the Entree class is to the.
Definition EFichier.h:29
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
const Domaine_IJK & get_domaine() const
Base class for "interpreter" objects.
Definition Interprete.h:38
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
friend class Entree
Definition Objet_U.h:71
const Nom & que_suis_je() const
Returns the string identifying the class.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Reads an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:289
virtual Sortie & printOn(Sortie &) const
Writes the object to an output stream. Virtual method to override.
Definition Objet_U.cpp:278
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void dictionnaire(const char *option_name, int value)
Add an (option name, integer value) entry to the dictionary attached to a previously registered integ...
Definition Param.cpp:293
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
int lire_avec_accolades(Entree &is)
Alias of lire_avec_accolades_depuis.
Definition Param.h:577
static void mp_sum_for_each_item(TRUSTArray< _TYPE_ > &x, int n=-1)
Definition Process.cpp:194
static Sortie & Journal(int message_level=0)
Returns a static Sortie object used as an event journal.
Definition Process.cpp:592
static int je_suis_maitre()
Returns 1 if on the master processor of the current group (i.e. me() == 0), 0 otherwise.
Definition Process.cpp:82
SFichier is to the C++ ofstream class what Sortie is to the C++ ostream class.
Definition SFichier.h:29
Base class for output streams.
Definition Sortie.h:52
_SIZE_ size_array() const
void resize_array(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)