TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Operateurs_Statistique_tps.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#include <Champ_Generique_Statistiques_base.h>
17#include <Operateurs_Statistique_tps.h>
18#include <EcritureLectureSpecial.h>
19#include <Postraitement.h>
20#include <TRUST_2_PDI.h>
21
22Implemente_instanciable(Operateurs_Statistique_tps,"Operateurs_Statistique_tps",LIST(OWN_PTR(Operateur_Statistique_tps_base)));
23
24Sortie& Operateurs_Statistique_tps::printOn(Sortie& s ) const { return s << que_suis_je() << " " << le_nom(); }
25Entree& Operateurs_Statistique_tps::readOn(Entree& s) { return s; }
26
27inline const OWN_PTR(Operateur_Statistique_tps_base)& recherche(Operateurs_Statistique_tps& op, const Nom& champ, const Motcle& motlu)
28{
29 for (auto &itr : op)
30 {
31 if (itr->le_nom() == champ)
32 return itr;
33 }
34 Cerr << "The post_processing request " << motlu << " of a variable" << finl;
35 Cerr << "must be preceded by the post-processing request of the average of the same variable." << finl;
37 throw;
38}
39
40
42{
43 // in special write mode only the master writes the header
44 int a_faire,special;
46
47 if (a_faire)
48 {
49 Nom mon_ident(que_suis_je());
50 mon_ident += mon_post_->probleme().domaine().le_nom();
51 double temps = mon_post_->probleme().schema_temps().temps_courant();
52 mon_ident += Nom(temps, "%e");
53 os << mon_ident << finl;
54 os << que_suis_je() << finl;
55 os << size() << finl;
56 os << Nom(this->dernier()->tstat_deb(), "%e") << finl;
57 os << Nom(this->dernier()->tstat_dernier_calcul(), "%e") << finl;
58 }
59
60 int bytes = 0;
61 for (const auto &itr : *this)
62 bytes += itr->sauvegarder(os);
63
64 if (a_faire) os.flush();
65 return bytes;
66}
67
68
70{
71 //Cerr << "Operateurs_Statistique_tps::reprendre" << finl;
72 if (mon_post_)
73 {
74 double tstat_deb_sauv,temps_derniere_mise_a_jour_stats;
76 {
77 TRUST_2_PDI pdi_interface;
78 const std::string& pb_name = mon_post_->probleme().le_nom().getString();
79 Nom vide;
80 const Nom& nom_post = mon_post_->le_nom();
81 std::string post_name = (nom_post != "neant") && (nom_post != vide) ? nom_post.getString() + "_" : "";
82 std::string name = pb_name + "_" + post_name + "stat_tdeb";
83 pdi_interface.read(name, &tstat_deb_sauv);
84 name = pb_name + "_" + post_name + "stat_tend";
85 pdi_interface.read(name, &temps_derniere_mise_a_jour_stats);
86 }
87 else
88 {
89 Nom bidon;
90 is >> bidon;
91 if (bidon=="fin")
92 {
93 // This test avoids a nasty segmentation fault when reading
94 // the second dummy value during a save/restart in binary format
95 Cerr << "The end of the restarting file is reached." << finl;
96 Cerr << "This file does not contain statistics." << finl;
97 Cerr << "The restarting time tinit must therefore be lower" << finl;
98 Cerr << "than the statistics begining time t_deb." << finl;
99 exit();
100 }
101 is >> bidon;
102 int n;
103 is >> n;
104 is >> tstat_deb_sauv;
105 is >> temps_derniere_mise_a_jour_stats;
106 }
107 //Cerr << "temps_derniere_mise_a_jour_stats" << temps_derniere_mise_a_jour_stats << finl;
108 double tinit = mon_post_->probleme().schema_temps().temps_courant();
109
110 // Plusieurs cas possibles:
111 if (inf_strict(tinit,temps_derniere_mise_a_jour_stats,1.e-5))
112 {
113 Cerr << "The initial time " << tinit << " of the restarting calculation is lower" << finl;
114 Cerr << "than the last statistics update time " << temps_derniere_mise_a_jour_stats << finl;
115 Cerr << "One is not able to treat this case." << finl;
116 exit();
117 }
118 else if (!est_egal(tstat_deb_sauv,this->dernier()->tstat_deb()))
119 {
120 // t_deb has been modified: statistics are restarted from scratch without resuming in some cases
121 if (inf_strict(this->dernier()->tstat_deb(),tinit,1.e-5))
122 {
123 Cerr << "t_deb has been modified to carry out a new statistics calculation without restarting" << finl;
124 Cerr << "but t_deb is lower than tinit : it is not possible." << finl;
125 exit();
126 }
127 Cerr << "Statistics are not restarted and therefore the statistics calculation" << finl;
128 Cerr << "will restart a t_deb =" << this->dernier()->tstat_deb() << finl;
129
131 {
132 Nom bidon2;
133 double dbidon;
134 BigDoubleTab tab_bidon;
135 auto& list = get_stl_list();
136 for (auto&& itr = list.begin(); itr != list.end(); ) // Skipping fields
137 {
138 is >> bidon2 >> bidon2;
139 is >> dbidon;
140 tab_bidon.reset(); // otherwise size error in lit()
141 tab_bidon.jump(is);
142 ++itr;
143 }
144 }
145 }
146 else // tinit=>temps_derniere_mise_a_jour_stats: resuming statistics
147 {
148 Nom bidon2;
149 for (auto &itr : *this)
150 {
152 is >> bidon2 >> bidon2; // Skipping the field identifier and type
153 itr->reprendre(is);
154 }
155 // Updating the tstat_deb_ attribute of the fields to account for the restart
156 for (auto &itr : *this)
157 itr->fixer_tstat_deb(tstat_deb_sauv,temps_derniere_mise_a_jour_stats);
158 }
159 }
160 else // reading to skip the block
161 {
163 {
164 Cerr << "Problem in the resumption of Operateurs_Statistique_tps" << finl;
165 Cerr << "PDI format does not require to navigate through file..." << finl;
167 }
168 int n;
169 is >> n;
170 double tstat_deb_sauv,temps_derniere_mise_a_jour_stats;
171 is >> tstat_deb_sauv;
172 is >> temps_derniere_mise_a_jour_stats;
173 Nom bidon;
174 double dbidon;
175 BigDoubleTab tab_bidon;
176 for (int i=0; i<n; i++)
177 {
178 is >> bidon >> bidon;
179 is >> dbidon;
180 tab_bidon.reset(); // otherwise size error in lit()
181 tab_bidon.jump(is);
182 }
183 }
184 return 1;
185}
static int is_ecriture_special(int &special, int &a_faire)
Indicates whether the special format was requested in active writing by xyz save.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
A character string (Nom) in uppercase.
Definition Motcle.h:26
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
const std::string & getString() const
Definition Nom.h:92
const Nom & le_nom() const override
Returns *this.
Definition Nom.cpp:555
virtual int reprendre(Entree &)
Restores an Objet_U from an input stream. Virtual method to override.
Definition Objet_U.cpp:336
class Operateur_Statistique_tps_base
class Operateurs_Statistique_tps
int sauvegarder(Sortie &os) const override
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
Base class for output streams.
Definition Sortie.h:52
virtual Sortie & flush()
Definition Sortie.cpp:138
void jump(Entree &) override
Definition TRUSTTab.tpp:701
void reset() override
Definition TRUSTTab.tpp:362
TRUST_2_PDI Encapsulation of PDI methods (library used for IO operations). See the website pdi....
Definition TRUST_2_PDI.h:59
void read(const std::string &name, void *data)
static int is_PDI_restart()