TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
champ_init_canal_sinal.cpp
1/****************************************************************************
2* Copyright (c) 2024, 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_init_canal_sinal.h>
17#include <Motcle.h>
18
19Implemente_instanciable(champ_init_canal_sinal,"champ_init_canal_sinal",TRUSTChamp_Divers_generique<Champ_Divers_Type::CANAL>);
20// XD champ_init_canal_sinal champ_don_base champ_init_canal_sinal NO_BRACE For a parabolic profile on U velocity with
21// XD_CONT an unpredictable disturbance on V and W and a sinusoidal disturbance on V velocity.
22// XD attr dim entier dim REQ Number of field components.
23// XD attr bloc bloc_lec_champ_init_canal_sinal bloc REQ Parameters for the class champ_init_canal_sinal.
24
25// XD bloc_lec_champ_init_canal_sinal objet_lecture nul BRACE Parameters for the class champ_init_canal_sinal. NL2 in
26// XD_CONT 2D: NL2 U=ucent*y(2h-y)/h/h NL2 V=ampli_bruit*rand+ampli_sin*sin(omega*x) NL2 rand: unpredictable value
27// XD_CONT between -1 and 1. NL2 in 3D: NL2 U=ucent*y(2h-y)/h/h NL2 V=ampli_bruit*rand1+ampli_sin*sin(omega*x) NL2
28// XD_CONT W=ampli_bruit*rand2 NL2 rand1 and rand2: unpredictables values between -1 and 1.
29// XD attr ucent floattant ucent REQ Velocity value at the center of the channel.
30// XD attr h floattant h REQ Half hength of the channel.
31// XD attr ampli_bruit floattant ampli_bruit REQ Amplitude for the disturbance.
32// XD attr ampli_sin floattant ampli_sin OPT Amplitude for the sinusoidal disturbance (by default equals to ucent/10).
33// XD attr omega floattant omega REQ Value of pulsation for the of the sinusoidal disturbance.
34// XD attr dir_flow entier(into=[0,1,2]) dir_flow OPT Flow direction for the initialization of the flow in a channel.
35// XD_CONT NL2 - if dir_flow=0, the flow direction is X NL2 - if dir_flow=1, the flow direction is Y NL2 - if
36// XD_CONT dir_flow=2, the flow direction is Z NL2 Default value for dir_flow is 0
37// XD attr dir_wall entier(into=[0,1,2]) dir_wall OPT Wall direction for the initialization of the flow in a channel.
38// XD_CONT NL2 - if dir_wall=0, the normal to the wall is in X direction NL2 - if dir_wall=1, the normal to the wall is
39// XD_CONT in Y direction NL2 - if dir_wall=2, the normal to the wall is in Z direction NL2 Default value for dir_flow
40// XD_CONT is 1
41// XD attr min_dir_flow floattant min_dir_flow OPT Value of the minimum coordinate in the flow direction for the
42// XD_CONT initialization of the flow in a channel. Default value for dir_flow is 0.
43// XD attr min_dir_wall floattant min_dir_wall OPT Value of the minimum coordinate in the wall direction for the
44// XD_CONT initialization of the flow in a channel. Default value for dir_flow is 0.
45
46Sortie& champ_init_canal_sinal::printOn(Sortie& os) const { return os; }
47
49{
50 int dim = lire_dimension(is, que_suis_je());
51 dimensionner(1, dim);
52 if (abs(dim) > 3)
53 {
54 Cerr << "Problem while reading the dimension of field champ_init_canal_sinal" << finl;
55 Cerr << "Check that it was correctly indicated : dim = " << dim << finl;
57 }
58
59 ArrOfInt Verif(9);
60 Verif[3] = 1;
61 Verif[5] = 1;
62 Verif[6] = 1;
63 Verif[7] = 1;
64 Verif[8] = 1;
65 Motcles les_mots(9);
66 Motcle mot_lu;
67 {
68 les_mots[0] = "Ucent";
69 les_mots[1] = "h";
70 les_mots[2] = "ampli_bruit";
71 les_mots[3] = "ampli_sin";
72 les_mots[4] = "omega";
73 les_mots[5] = "dir_flow";
74 les_mots[6] = "dir_wall";
75 les_mots[7] = "min_dir_flow";
76 les_mots[8] = "min_dir_wall";
77 }
78 Motcle acc_ouverte("{");
79 Motcle acc_fermee("}");
80 is >> mot_lu;
81 if (mot_lu != acc_ouverte)
82 {
83 Cerr << "Expecting a { instead of " << mot_lu << "while reading intial condition" << finl;
84 }
85 is >> mot_lu;
86 while (mot_lu != acc_fermee)
87 {
88 int rang = les_mots.search(mot_lu);
89 switch(rang)
90 {
91 case 0:
92 is >> Ucent;
93 Cerr << "Centerline Longitudinal Velocity = " << Ucent << finl;
94 // valeur par defaut de ampli_sin = Ucent/10.
95 ampli_sin = Ucent / 10.;
96 Verif[0] = 1;
97 break;
98 case 1:
99 is >> h;
100 Cerr << "Channel Half-height = " << h << finl;
101 Verif[1] = 1;
102 break;
103 case 2:
104 is >> ampli_bruit;
105 Cerr << "Noise Amplitude = " << ampli_bruit << finl;
106 Verif[2] = 1;
107 break;
108 case 3:
109 is >> ampli_sin;
110 Cerr << "Sine Perturbation Amplitude = " << ampli_sin << finl;
111 Verif[3] = 1;
112 break;
113 case 4:
114 is >> omega;
115 Cerr << "Omega = " << omega << finl;
116 Verif[4] = 1;
117 break;
118 case 5:
119 is >> dir_flow;
120 Cerr << "Flow direction : " << dir_flow << finl;
121 Verif[5] = 1;
122 break;
123 case 6:
124 is >> dir_wall;
125 Cerr << "The specified Wall direction : " << dir_wall << finl;
126 Verif[6] = 1;
127 break;
128 case 7:
129 is >> min_dir_flow;
130 Cerr << "Minimum value position in flow direction : " << min_dir_flow << finl;
131 Verif[7] = 1;
132 break;
133 case 8:
134 is >> min_dir_wall;
135 Cerr << "Minimum value position in wall direction : " << min_dir_wall << finl;
136 Verif[8] = 1;
137 break;
138 default:
139 {
140 Cerr << "Error in champ_init_canal_sinal::readOn " << finl;
141 Cerr << mot_lu << " is not understood by velocity initial condition generation." << finl;
142 Cerr << "The understood keywords are : " << les_mots << finl;
144 }
145 }
146 is >> mot_lu;
147 }
148
149 if (dir_flow == dir_wall)
150 {
151 Cerr << "Error in champ_init_canal_sinal::readOn " << finl;
152 Cerr << "You gave the same direction for a wall and the flow direction : Impossible !" << finl;
154 }
155
156 if ((dir_wall > 2) || (dir_flow > 2))
157 {
158 Cerr << "Error in champ_init_canal_sinal::readOn " << finl;
159 Cerr << "One of the specified directions are not possible." << finl;
160 Cerr << "Use : 0 for X, 1 for Y and 2 for Z !" << finl;
162 }
163
164 int valmin = min_array(Verif);
165 if (valmin == 0)
166 {
167 for (int i = 0; i < 5; i++)
168 if (Verif[i] == 0) Cerr << "You didn't give a value for " << les_mots[i] << finl;
169
170 Cerr << "Error in champ_init_canal_sinal::readOn " << finl;
171 Cerr << "User needs to specify values for the parameters below.";
172 Cerr << "The syntax is : Ucent val_Ucent h val_h ampli_bruit val_ampli_bruit [ampli_sin val_ampli_sin] omega val_omega" << finl;
173 Cerr << "dir_flow val_dir_flow dir_wall val_dir_wall" << finl;
175 }
176
177 return is;
178}
179
180DoubleVect& champ_init_canal_sinal::valeur_a(const DoubleVect& positions, DoubleVect& tab_valeurs) const
181{
182 Cerr << "values = " << tab_valeurs << finl;
183 Cerr << "In champ_init_canal_sinal::valeur_a nb_compo_=" << nb_compo_ << finl;
184 tab_valeurs.resize(nb_compo_);
185 switch(dimension)
186 {
187 case (1):
188 {
189 assert(nb_compo_ == 1);
190 tab_valeurs(dir_flow) = fx(positions(dir_flow));
191 break;
192 }
193 case (2):
194 {
195 assert(nb_compo_ <= 2);
196 tab_valeurs(dir_flow) = fx(positions(dir_flow), positions(dir_wall));
197 if (nb_compo_ == 2) tab_valeurs(dir_wall) = fy(positions(dir_flow), positions(dir_wall));
198 break;
199 }
200 case (3):
201 {
202 assert(nb_compo_ <= 3);
203 tab_valeurs(dir_flow) = fx(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
204 if (nb_compo_ >= 2) tab_valeurs(dir_wall) = fy(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
205 if (nb_compo_ >= 3) tab_valeurs(3 - dir_flow - dir_wall) = fz(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
206 break;
207 }
208 }
209 return tab_valeurs;
210}
211
212double champ_init_canal_sinal::valeur_a_elem_compo(const DoubleVect& positions, int, int ncomp) const
213{
214 double val = 0.;
215 switch(dimension)
216 {
217 case (1):
218 val = fx(positions(dir_flow));
219 break;
220 case (2):
221 {
222 if (ncomp == 1 + dir_flow) val = fx(positions(dir_flow), positions(dir_wall));
223 else val = fy(positions(dir_flow), positions(dir_wall));
224 }
225 break;
226 case (3):
227 {
228 if (ncomp == 1 + dir_flow) val = fx(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
229 else if (ncomp == 1 + dir_wall) val = fy(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
230 else val = fz(positions(dir_flow), positions(dir_wall), positions(3 - dir_flow - dir_wall));
231 }
232 break;
233 default:
234 val = -1;
236 break;
237 }
238 return val;
239}
240
241DoubleTab& champ_init_canal_sinal::valeur_aux(const DoubleTab& positions, DoubleTab& tab_valeurs) const
242{
243 assert(tab_valeurs.size_totale() == dimension * positions.dimension(0));
244 int i;
245 switch(dimension)
246 {
247 case (1):
248 {
249 assert(nb_compo_ == 1);
250 for (i = 0; i < tab_valeurs.dimension(0); i++)
251 tab_valeurs(i, dir_flow) = fx(positions(i, dir_flow));
252 break;
253 }
254 case (2):
255 {
256 assert(nb_compo_ <= 2);
257 for (i = 0; i < tab_valeurs.dimension(0); i++)
258 {
259 tab_valeurs(i, dir_flow) = fx(positions(i, dir_flow), positions(i, dir_wall));
260 if (nb_compo_ == 2) tab_valeurs(i, dir_wall) = fy(positions(i, dir_flow), positions(i, dir_wall));
261 }
262 break;
263 }
264 case (3):
265 {
266 assert(nb_compo_ <= 3);
267 for (i = 0; i < tab_valeurs.dimension(0); i++)
268 {
269 tab_valeurs(i, dir_flow) = fx(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
270 if (nb_compo_ >= 2) tab_valeurs(i, dir_wall) = fy(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
271 if (nb_compo_ >= 3) tab_valeurs(i, 3 - dir_flow - dir_wall) = fz(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
272 }
273 break;
274 }
275 }
276 return tab_valeurs;
277}
278
279DoubleVect& champ_init_canal_sinal::valeur_aux_compo(const DoubleTab& positions, DoubleVect& tab_valeurs, int ncomp) const
280{
281 int nb_pos = positions.dimension(0);
282 tab_valeurs.resize(nb_pos);
283 assert(ncomp < 3);
284 int i;
285 switch(dimension)
286 {
287 case 1:
288 {
289 for (i = 0; i < nb_pos; i++)
290 tab_valeurs(i) = fx(positions(i, dir_flow));
291 break;
292 }
293 case 2:
294 {
295 if (ncomp == dir_flow)
296 for (i = 0; i < nb_pos; i++)
297 tab_valeurs(i) = fx(positions(i, dir_flow), positions(i, dir_wall));
298 else
299 for (i = 0; i < nb_pos; i++)
300 tab_valeurs(i) = fy(positions(i, dir_flow), positions(i, dir_wall));
301 break;
302 }
303 case 3:
304 {
305 if (ncomp == dir_flow)
306 for (i = 0; i < nb_pos; i++)
307 tab_valeurs(i) = fx(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
308 else if (ncomp == dir_wall)
309 for (i = 0; i < nb_pos; i++)
310 tab_valeurs(i) = fy(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
311 else
312 for (i = 0; i < nb_pos; i++)
313 tab_valeurs(i) = fz(positions(i, dir_flow), positions(i, dir_wall), positions(i, 3 - dir_flow - dir_wall));
314 break;
315 }
316 }
317 return tab_valeurs;
318}
void dimensionner(int, int)
Fixe le nombre de composantes et le nombre de valeurs nodales.
int lire_dimension(Entree &, const Nom &)
Verification de la dimension du champ Renvoie la dimension du champ.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
int nb_compo_
Definition Field_base.h:95
static int dimension
Definition Objet_U.h:99
const Nom & que_suis_je() const
renvoie la chaine identifiant la classe.
Definition Objet_U.cpp:104
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
Definition Objet_U.cpp:293
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
Definition Objet_U.cpp:282
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
Classe de base des flux de sortie.
Definition Sortie.h:52
_SIZE_ dimension(int d) const
Definition TRUSTTab.tpp:133
_SIZE_ size_totale() const
Definition TRUSTVect.tpp:61
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91
DoubleTab & valeur_aux(const DoubleTab &positions, DoubleTab &valeurs) const override
Provoque une erreur ! Doit etre surchargee par les classes derivees.
DoubleVect & valeur_a(const DoubleVect &position, DoubleVect &valeurs) const override
Calcule les "valeurs" du champ au point de coordonnees "pos".
double valeur_a_elem_compo(const DoubleVect &position, int le_poly, int ncomp) const override
provoque une erreur ! doit etre surchargee par les classes derivees
double fz(double x, double y, double z) const
double fx(double x) const
DoubleVect & valeur_aux_compo(const DoubleTab &positions, DoubleVect &valeurs, int ncomp) const override
Idem que valeur_aux(const DoubleTab &, DoubleTab &), mais calcule uniquement la composante compo du c...
double fy(double x, double y) const