TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
init_forcage_THI.cpp
1/****************************************************************************
2* Copyright (c) 2019, 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 <init_forcage_THI.h>
17#include <IJK_Field_vector.h>
18#include <Param.h>
19#include <string>
20#include <iostream>
21#include <math.h>
22#include <fftw3.h>
23
24#include <Force_ph.h>
25#include <Force_sp.h>
26#include <Random_process.h>
27
28Implemente_instanciable_sans_constructeur( init_forcage_THI, "init_forcage_THI", Objet_U ) ;
29
30// TODO : Il faudrait aussi initialiser
31//Force_sp f_sp_THI;
32//Force_ph f_ph_THI;
33//Random_process random;
34init_forcage_THI::init_forcage_THI()
35{
36 advection_length_.resize_array(3);
38}
39
41{
42 //Objet_U::printOn(os);
43 os << "{\n"
44 << " type " << type_forcage << "\n"
45 << " facteur " << facteur_forcage_ << "\n"
46 << " forced_advection " << forced_advection_ << "\n"
47 << " advection_velocity " << advection_velocity_ << "\n"
48 << " advection_length " << advection_length_ << "\n"
49 << " stops_at_time_step " << forcage_ts_stop << "\n"
50 << " stops_at_time " << forcage_t_stop << "\n";
51 os << " minimal_forced_mode " << mode_min << "\n"
52 << " maximal_forced_mode " << mode_max << "\n";
53 os << " amplitude " << amplitude << "\n";
54 os << " dissipation " << eps_etoile << "\n";
55 os << " temps_grande_echelle " << tL << "\n";
56// if (random_fixed_)
57// os << " random_fixed \n" ;
58 os << " random_process " << random_ << "\n";
59 os << " }\n" ;
60 return os;
61}
62
64{
65 // Objet_U::readOn( is );
66 Param param(que_suis_je());
67 param.ajouter("type",&type_forcage);
68 param.ajouter("facteur",&facteur_forcage_);
69 param.ajouter("forced_advection",&forced_advection_);
70 if (forced_advection_==1)
71 param.ajouter("advection_velocity", &advection_velocity_, Param::REQUIRED);
72 else
73 param.ajouter("advection_velocity", &advection_velocity_);
74 param.ajouter("advection_length", &advection_length_);
75 param.ajouter("stops_at_time_step",&forcage_ts_stop);
76 param.ajouter("stops_at_time",&forcage_t_stop);
77 param.ajouter("minimal_forced_mode",&mode_min);
78 param.ajouter("maximal_forced_mode",&mode_max);
79 param.ajouter("amplitude",&amplitude);
80 param.ajouter("dissipation",&eps_etoile);
81 param.ajouter("temps_grande_echelle",&tL);
82 if (type_forcage == 3)
83 {param.ajouter("random_process",&random_, Param::REQUIRED);}
84 else
85 {param.ajouter("random_process",&random_);}
86 param.lire_avec_accolades(is);
87 return is;
88}
89
91 const Domaine_IJK& my_geom,
92 int my_ni, int my_nj, int my_nk,
93 const Domaine_IJK& splitting_,
94 Nom nom_sauvegarde)
95// IJK_Field_vector3_double v_)
96{
97 double Lx(my_geom.get_domain_length(DIRECTION_I));
98 double Ly(my_geom.get_domain_length(DIRECTION_J));
99 double Lz(my_geom.get_domain_length(DIRECTION_K));
100
101 const double Ox = my_geom.get_origin(DIRECTION_I) ;
102 const double Oy = my_geom.get_origin(DIRECTION_J) ;
103 const double Oz = my_geom.get_origin(DIRECTION_K) ;
104
105 // Test parallelisation
106 i_offset = splitting_.get_offset_local(DIRECTION_I);
107 j_offset = splitting_.get_offset_local(DIRECTION_J);
108 k_offset = splitting_.get_offset_local(DIRECTION_K);
109
110 int ni(my_ni), nj(my_nj), nk(my_nk);
111
112 int mmin(mode_min), mmax(mode_max);
113 // double kmin(2.*M_PI*mmin/Lx), kmax(2.*M_PI*mmax/Lx);
114 double kmin(2.*M_PI*mmin/Lx), kmax(2.*M_PI*mmax/Lx);
115 int nl(mmax), nm(mmax), nn(mmax);
116
117 std::string nom_fichier_random("./random_gen.out");
118 std::string nom_fichier_spectral("./spectral.out");
119 std::string nom_fichier_physique("./physique.out");
120
121 f_sp_THI.initialise(nl,nm,nn, mmin,mmax,kmin,kmax,amplitude, nom_fichier_spectral);
122 // f_ph_THI.initialise(my_nproc_tot,ni,nj,nk,nl,nm,nn,Lx,Ly,Lz,Ox,Oy,Oz,mmin,mmax,kmin,kmax, nom_fichier_physique, splitting_);//,i_offset,j_offset,k_offset);
123 f_ph_THI.initialise(my_nproc_tot,ni,nj,nk,nl,nm,nn,Lx,Ly,Lz,Ox,Oy,Oz,mmin,mmax,kmin,kmax, nom_fichier_physique, splitting_,i_offset,j_offset,k_offset);
124 if (type_forcage == 3)
125 {
126 random_.initialise(eps_etoile,tL, nl,nm,nn, nom_fichier_random, nom_sauvegarde);//, random_fixed_);//,i_offset,j_offset,k_offset);
127 // random.initialise(eps_etoile,tL, nl,nm,nn, nom_fichier_random, random_fixed_,i_offset,j_offset,k_offset);
128 }
129}
130
131
132void init_forcage_THI::compute_THI_force(const int time_iteration,
133 const double tstep,
134 const double current_time,
135 const Domaine_IJK& my_splitting
136 // const int rk_step,
137 )
138{
139 /*
140 * En fonction de l'entree utilisateur pour type dans le jdd, cette methode va appeler
141 * La fonction de forcage adequate.
142 * -> type; facteur; forced_advection>advection_velocity; stops_at_time.step; ...
143 * o forced_advection_==-1 : on advecte avec \ol{u}^l
144 * o forced_advection_== 1 : on advecte avec la valeur lue dans le jdd
145 * Remarque : dans le cas d'une fonction de forcage deterministe, appelee lors d'une resolution
146 * RK3, est ce qu'on pourrai forcer uniquement un des 3 sous pas de temps plutot que tous les forcer ?
147 * Remarque : Pour un calcul avec reprise et pour forced_advection_==-1, il s'ssurer que la vitesse d'advection
148 * correspond bien a \ol{u}^l DES LE PREMIER PAS DE TEMPS.
149 */
150 int type_forcage_active(activate_forcage(time_iteration,current_time));
151
152 if (type_forcage_active==0)
153 {
154 Cout << "Normalement on ne rentre pas ici. Que si on a force de la thi, puisqu'on arrete.";
155 f_sp_THI.set_zero();
156 f_ph_THI.set_zero();
157 }
158 if (type_forcage_active==100)
159 {
160 Cout << "On force un dirac en spectral, uniX : cos(kx) ex" << finl;
161 f_sp_THI.compute_dirac_point_uniX_alongX();
162 }
163 if (type_forcage_active==200)
164 {
165 Cout << "On force un dirac en spectral, uniX : cos(kx) ey" << finl;
166 f_sp_THI.compute_dirac_point_uniX_alongY();
167 }
168 if (type_forcage_active==010)
169 {
170 Cout << "On force un dirac en spectral, uniY : cos(k(x-z)) ey" << finl;
171 Cout << "f_sp = 1/sq(2) (d(k-k_0)+d(k+k_0)) . [0;1;0]" << finl;
172 Cout << "f_ph = sq(2) cos(nk_0(x-z)) . [0;1;0]" << finl;
173 f_sp_THI.compute_dirac_point_uniY();
174 }
175 if (type_forcage_active==001 || type_forcage_active==1)
176 {
177 Cout << "On force un dirac en spectral, uniZ" << finl;
178 f_sp_THI.compute_dirac_point_uniZ();
179 }
180 if (type_forcage_active==101)
181 {
182 Cout << "On force un dirac en spectral, uniXZ" << finl;
183 Cout << "f_sp = 1/sq(2) (d(k-k_0)+d(k+k_0)) . [1;0;-1]" << finl;
184 Cout << "f_ph = sq(2) cos(nk_0(x-z)) . [1;0;-1]" << finl;
185 // k_0 = nk0 [1, 0, -1], nk0 = minimal_forced_mode
186 f_sp_THI.compute_dirac_point_div_nulle();
187 }
188 if (type_forcage_active==2)
189 {
190 Cout << "On force une porte en spectral, soit un cube" << finl;
191 f_sp_THI.compute_door_cube();
192 }
193 if (type_forcage_active==66)
194 {
195 Cout << "On force des diracs de sorte a avoir : cos^2(ky) ex" << finl;
196 f_sp_THI.compute_diracs_for_cos_squarred();
197 }
198 if (type_forcage_active==166)
199 {
200 Cout << "On force des diracs de sorte a avoir : t*cos^2(ky) ex" << finl;
201 f_sp_THI.compute_diracs_for_t_times_cos_squarred(current_time);
202 }
203 if (type_forcage_active==3)
204 {
205// Cout << "type_forcage_active : " << type_forcage_active << finl;
206// Cout << "On applique le processus Ornstein-Uhlenbeck" << finl;
207
208 random_.next_step2(tstep, time_iteration);
209 f_sp_THI.compute_step2(random_.get_b_flt());
210 }
211 if (type_forcage_active==20)
212 {
213 f_ph_THI.cheat_function();
214 }
215 /* PASSAGE DU DOMAINE SPECTRAL AU DOMAINE PHYSIQUE */
216 if (type_forcage_active!=20 && type_forcage_active!=0)
217 {
218 /*type 20 ecrit directement le champ physique sans passer par la TF
219 * Remarque : Si on ajoute d'autre "type"s qui ne doivent pas passer par la TF il faut penser
220 * a changer le if () juste au dessus.
221 */
222
223 /* ADVECTION DU CHAMP FORCE : forced_advection 1 ou forced_advection -1 dans jdd
224 * forced_advection 1 : advection selon advection_velocity (jdd)
225 * forced_advection -1 : advection selon moy{u_l}^l (calcul),
226 * /!\ Dans le cas d'une reprise, doit on lire la valeur inscrite dans le .sauv ?
227 * forced_advection 0 : advcetion nulle
228 * */
230 {
231 f_ph_THI.from_spect_to_phys_opti2_advection(f_sp_THI.get_coeff_flt(),advection_length_);
232 }
233 else
234 f_ph_THI.from_spect_to_phys_opti2(f_sp_THI.get_coeff_flt());
235 }
236
237}
238
240{
241 return random_.get_semi_gen();
242}
243
245{
246 return random_.get_b_flt();
247
248}
249
250IJK_Field_vector3_double init_forcage_THI::get_force_ph()
251{
252 return f_ph_THI.get_force_attribute();
253}
254
255
256IJK_Field_vector3_double& init_forcage_THI::get_force_ph2()
257{
258 return f_ph_THI.get_force_attribute2();
259}
260
261
266
271
273{
274 advection_velocity_.resize_array(3);
275 for (int dir=0; dir<3; dir++)
276 {
277 advection_velocity_[dir]= value[dir];
278 }
279}
280
282{
283 Cout <<"update_advection_length : dt " << dt << finl;
284 time_to_be_del_+=dt;
285 Cout << "update_advection_length : time_to_be_del_ " << time_to_be_del_ << finl;
286 for (int dir=0; dir<3; dir++)
287 {
288 Cout << "update_advection_length : advection_length_["<<dir<< "] : " << advection_length_[dir] << finl;
289 advection_length_[dir]+= (advection_velocity_[dir]*dt);
290 Cout << "update_advection_length : advection_length_["<<dir<< "] : " << advection_length_[dir] << finl;
291 }
292}
293
298
299int init_forcage_THI::activate_forcage(const int current_time_step, const double current_time)
300{
301 int stop(0);
302 int no_stop(get_type_forcage());
303
304 // J'ai l'impression qu'on peut faire plus malin. Mais bon je ne vois pas trop
305 if ((forcage_ts_stop < 0 ) && (forcage_t_stop < 0))
306 return no_stop;
307 else if ((forcage_ts_stop < 0) && (forcage_t_stop > current_time))
308 {
309 return no_stop;
310 }
311 else if ((forcage_ts_stop > current_time_step) && (forcage_t_stop < 0))
312 {
313 return no_stop;
314 }
315 else if ((forcage_ts_stop > current_time_step) && (forcage_t_stop > current_time))
316 {
317 return no_stop;
318 }
319 else
320 {
321 return stop;
322 }
323}
This class encapsulates all the information related to the eulerian mesh for TrioIJK.
Definition Domaine_IJK.h:47
int get_offset_local(int direction) const
Returns the local offset in requested direction.
double get_domain_length(int direction) const
Returns the length of the entire domain in requested direction.
double get_origin(int direction) const
Returns the coordinate of the first node (global) of the mesh in the requested direction.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
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
@ REQUIRED
Definition Param.h:115
Classe de base des flux de sortie.
Definition Sortie.h:52
ArrOfDouble advection_length_
ArrOfDouble get_b_flt()
void update_advection_length(double dt)
void compute_initial_chouippe(int nproc_tot, const Domaine_IJK &my_geom, int my_ni, int my_nj, int my_nk, const Domaine_IJK &my_splitting, Nom nom_sauvegarde)
ArrOfDouble advection_velocity_
Random_process random_
void update_advection_velocity(ArrOfDouble &value)
void compute_THI_force(const int time_iteration, const double tstep, const double current_time, const Domaine_IJK &my_splitting)
IJK_Field_vector3_double & get_force_ph2()
int activate_forcage(const int current_time_step, const double current_time)
IJK_Field_vector3_double get_force_ph()