TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Traitement_particulier_NS_THI.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 <Traitement_particulier_NS_THI.h>
17#include <MD_Vector_tools.h>
18#include <ArrOfBit.h>
19#include <Scatter.h>
20#include <Domaine.h>
21
22Implemente_base(Traitement_particulier_NS_THI,"Traitement_particulier_NS_THI",Traitement_particulier_NS_base);
23// XD thi traitement_particulier_base thi INHERITS_BRACE Keyword for a THI (Homogeneous Isotropic Turbulence)
24// XD_CONT calculation.
25// XD attr init_Ec entier init_Ec REQ Keyword to renormalize initial velocity so that kinetic energy equals to the value
26// XD_CONT given by keyword val_Ec.
27// XD attr val_Ec floattant val_Ec OPT Keyword to impose a value for kinetic energy by velocity renormalizated if
28// XD_CONT init_Ec value is 1.
29// XD attr facon_init entier(into=["0","1"]) facon_init OPT Keyword to specify how kinetic energy is computed (0 or 1).
30// XD attr calc_spectre entier(into=["0","1"]) calc_spectre OPT Calculate or not the spectrum of kinetic energy. NL2
31// XD_CONT Files called Sorties_THI are written with inside four columns : NL2 time:t global_kinetic_energy:Ec
32// XD_CONT enstrophy:D skewness:S NL2 If calc_spectre is set to 1, a file Sorties_THI2_2 is written with three columns :
33// XD_CONT NL2 time:t kinetic_energy_at_kc=32 enstrophy_at_kc=32 NL2 If calc_spectre is set to 1, a file spectre_xxxxx
34// XD_CONT is written with two columns at each time xxxxx : NL2 frequency:k energy:E(k).
35// XD attr periode_calc_spectre floattant periode_calc_spectre OPT Period for calculating spectrum of kinetic energy
36// XD attr spectre_3D entier(into=["0","1"]) Spectre_3D OPT Calculate or not the 3D spectrum
37// XD attr spectre_1D entier(into=["0","1"]) Spectre_1D OPT Calculate or not the 1D spectrum
38// XD attr conservation_Ec rien conservation_Ec OPT If set to 1, velocity field will be changed as to have a constant
39// XD_CONT kinetic energy (default 0)
40// XD attr longueur_boite floattant longueur_boite OPT Length of the calculation domain
41
43{
44 return is;
45}
46
48{
49 return is;
50}
51
53{
54 Motcle accouverte = "{" , accfermee = "}" ;
55 Motcle valec="val_Ec";
56 Motcle facon="facon_init";
57 Motcle motbidon, motlu;
58 is >> motbidon ;
59 if (motbidon == accouverte)
60 {
61 Motcles les_mots(2);
62 {
63 les_mots[0] = "init_Ec";
64 les_mots[1] = "calc_spectre";
65 }
66 {
67 is >> motlu;
68 while(motlu != accfermee)
69 {
70 int rang=les_mots.search(motlu);
71 switch(rang)
72 {
73 case 0 :
74 {
75 is >> init; // init_Ec = 1
76 if (init!=0)
77 {
78 is >> motlu;
79 if (motlu==valec)
80 {
81 is >> Ec_init; // read the value of Ec_init
82 Cerr << "With initialization of kinetic energy Ec_init= " << Ec_init << finl;
83 is >> motlu;
84 if (motlu==facon)
85 {
86 is >> fac_init; // Which value is the initialization based on??
87 Cerr << "With initialization of kinetic energy on Ecspat (init_fac==0) or Ecspec (init_fac==1) : fac_init=" << fac_init << finl;
88 }
89 }
90 else
91 {
92 Cerr << "Error while reading Traitement_particulier_NS_THI_VDF" << finl;
93 Cerr << "The only possible keyword here is: val_Ec" << finl;
94 Cerr << "You read:" << motlu << finl;
95 exit();
96 }
97 }
98 break;
99 }
100 case 1 :
101 {
102 is >> oui_calc_spectre;
103 if (oui_calc_spectre!=0) Cerr << "Computing spectra." << finl;
104 break;
105 }
106
107 default :
108 {
109 Cerr << "Error while reading Traitement_particulier_NS_THI";
110 Cerr << "Possible keywords are: init_Ec, calc_spectre, { and }" << finl;
111 Cerr << "You read:" << motlu << finl;
112 exit();
113 break;
114 }
115 }
116 is >> motlu;
117 }
118 is >> motlu;
119 if (motlu != accfermee)
120 {
121 Cerr << "Error while reading Traitement_particulier_NS_THI";
122 Cerr << "We expected a }" << finl;
123 exit();
124 }
125 }
126 }
127 else
128 {
129 Cerr << "Error while reading Traitement_particulier_NS_THI";
130 Cerr << "We expected a {" << finl;
131 exit();
132 }
133 return is;
134}
135
136
146
154
155void Traitement_particulier_NS_THI::en_cours_de_resolution(int nb_op, DoubleTab& u, DoubleTab& u_av, double dt)
156{
157 // it is actually never called, cf. below
158 if (oui_transf == 1)
159 {
160 calcul_spectre_operateur( nb_op, u, u_av,dt);
161 }
162 return;
163}
164
166{
167 const char* methode_actuelle="Traitement_particulier_NS_THI::calcul_nb_som_dir";
168
169 // Used to compute the number of common vertices in parallel
170 ArrOfBit unused;
171 trustIdType nb_som = domaine.les_sommets().get_md_vector()->get_sequential_items_flags(unused);
172 // Sum over all processors
173 nb_som = mp_sum(nb_som);
174
175 // [ABN] OMG, the below is so ugly ... how could this ever work?!
176 double nb=pow(static_cast<double>(nb_som),1./3.);
177 nb_som_dir = static_cast<int>(nb);
178 if (nb_som_dir*nb_som_dir*nb_som_dir != nb_som)
179 {
181 if (nb_som_dir*nb_som_dir*nb_som_dir != nb_som)
182 msg_erreur_maillage(methode_actuelle);
183 }
185 return nb_som_dir;
186}
187
189{
190 const char* methode_actuelle="Traitement_particulier_NS_THI::calcul_nb_elem_dir";
191 trustIdType nb_elem = domaine.nb_elem();
192
193 // Sum over all processors
194 nb_elem=mp_sum(nb_elem);
195
196 // [ABN] (same as above) -> OMG, the below is so ugly ... how could this ever work?!
197 double nb=pow(static_cast<double>(nb_elem),1./3.);
198 nb_elem_dir = static_cast<int>(nb);
199 if (nb_elem_dir*nb_elem_dir*nb_elem_dir != nb_elem)
200 {
202 if (nb_elem_dir*nb_elem_dir*nb_elem_dir != nb_elem)
203 msg_erreur_maillage(methode_actuelle);
204 }
205 return nb_elem_dir;
206}
207
209{
210 if (je_suis_maitre())
211 {
212 Cerr << finl;
213 Cerr << "Problem in " << methode_actuelle << " :" << finl;
214 Cerr << "Your mesh does not seem to have the same number of nodes" << finl;
215 Cerr << "in all directions. Check your data file... " << finl << finl;
216 // Abort for parallel cases!
217 abort();
218 }
219}
220
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
An array of Motcle objects.
Definition Motcle.h:63
int search(const Motcle &t) const
Definition Motcle.cpp:319
friend class Entree
Definition Objet_U.h:71
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
static void abort()
Abort routine for TRUST on a fatal error.
Definition Process.cpp:573
static double mp_sum(double)
Computes the sum of x over all processors in the current group.
Definition Process.cpp:145
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
Definition Process.cpp:466
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
Base class for output streams.
Definition Sortie.h:52
Traitement_particulier_THI This class performs specific post-processing treatments.
virtual void calcul_spectre_operateur(int, DoubleTab &, DoubleTab &, double)=0
virtual void init_calc_spectre()=0
virtual void calcul_spectre()=0
virtual void sorties_globales()=0
void en_cours_de_resolution(int, DoubleTab &, DoubleTab &, double) override
Traitement_particulier_NS_base Derives from Support_Champ_Masse_Volumique: use of rho.