TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Champ_front_bruite.cpp
1/****************************************************************************
2* Copyright (c) 2023, 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_front_bruite.h>
17#include <Frontiere_dis_base.h>
18#include <Frontiere.h>
19#include <Motcle.h>
20
21Implemente_instanciable(Champ_front_bruite,"Champ_front_bruite",Ch_front_var_instationnaire_indep);
22// XD champ_front_bruite front_field_base champ_front_bruite NO_BRACE Field which is variable in time and space in a
23// XD_CONT random manner.
24// XD attr nb_comp entier nb_comp REQ Number of field components.
25// XD attr bloc bloc_lecture bloc REQ { [N val L val ] Moyenne m_1.....[m_i ] Amplitude A_1.....[A_ i ]}: Random nois:
26// XD_CONT If N and L are not defined, the ith component of the field varies randomly around an average value m_i with a
27// XD_CONT maximum amplitude A_i. NL2 White noise: If N and L are defined, these two additional parameters correspond to
28// XD_CONT L, the domain length and N, the number of nodes in the domain. Noise frequency will be between 2*Pi/L and
29// XD_CONT 2*Pi*N/(4*L). NL2 For example, formula for velocity: u=U0(t) v=U1(t)Uj(t)=Mj+2*Aj*bruit_blanc where
30// XD_CONT bruit_blanc (white_noise) is the formula given in the mettre_a_jour (update) method of the Champ_front_bruite
31// XD_CONT (noise_boundary_field) (Refer to the Champ_front_bruite.cpp file).
32
33/*! @brief Print to an output stream in the format: size
34 *
35 * value(0) ... value(i) ... value(size-1)
36 *
37 * @param (Sortie& os) an output stream
38 * @return (Sortie&) the modified output stream
39 */
41{
42 const DoubleTab& tab=valeurs();
43 os << tab.size() << " ";
44 for(int i=0; i<tab.size(); i++)
45 os << tab(0,i);
46 return os;
47}
48
49/*! @brief Read from an input stream in the format: number_of_components
50 *
51 * average average(0) ... average(number_of_components-1)
52 * average amplitude(0) ... amplitude(number_of_components-1)
53 *
54 * @param (Entree& is) an input stream
55 * @return (Entree&) the modified input stream
56 * @throws opening brace expected
57 * @throws unknown keyword at this location
58 * @throws closing brace expected
59 */
61{
62 int dim;
64 Motcle motlu;
65 Motcles les_mots(4);
66 les_mots[0]="moyenne";
67 les_mots[1]="amplitude";
68 les_mots[2]="L";
69 les_mots[3]="N";
70 is >> motlu;
71 if (motlu != "{")
72 {
73 Cerr << "Error while reading a Champ_front_bruite" << finl;
74 Cerr << "We expected a { instead of " << motlu << finl;
75 exit();
76 }
77 is >> motlu;
78 while (motlu!="}")
79 {
80 int rang=les_mots.search(motlu);
81 switch(rang)
82 {
83 case 0 :
84 {
85 moyenne.resize(dim);
86 fixer_nb_comp(dim);
87 for(int i=0; i<dim; i++)
88 is >> moyenne(i);
89 break;
90 }
91 case 1:
92 {
93 amplitude.resize(dim);
94 for(int i=0; i<dim; i++)
95 is >> amplitude(i);
96 break;
97 }
98 case 2:
99 {
100 is >> lx;
101 break;
102 }
103 case 3:
104 {
105 is >> nx;
106 break;
107 }
108 default :
109 {
110 Cerr << "Error while reading a Champ_front_bruite" << finl;
111 Cerr << motlu << "is not understand here "<< finl;
112 Cerr << "We were expecting a word from " << les_mots << finl;
113 exit();
114 }
115 }
116 is >> motlu;
117 }
118 return is;
119}
120
121
122/*! @brief Not implemented !!
123 *
124 * @param (Champ_front_base& ch)
125 * @return (Champ_front_base&)
126 */
131
132/*! @brief Update time and randomly redraw the noise values.
133 *
134 * @param (double temps) the update time
135 */
137{
138 const Frontiere& front=la_frontiere_dis->frontiere();
139 int nb_faces=front.nb_faces();
140 DoubleTab& tab=valeurs_au_temps(temps);
141
142 if (nx!=0)
143 {
144 //
145 // N!=0 white noise modelling (R. Howard)
146 //
147 double onde, bruit_blanc, pi, invx, d_x, tot_vel;
148 pi=2.*acos(0.);
149 invx=1./nx;
150 d_x=lx/nx;
151 for(int i=0; i<nb_faces; i++)
152 for(int j=0; j<nb_comp(); j++)
153 {
154 tot_vel=moyenne(j)+amplitude(j);
155 onde=0.;
156 for (int in_x=0; in_x<nx; in_x++)
157 onde=onde+sin((2.*pi*temps/(4*d_x+in_x*d_x)+(10.2*i+5.3*j))*tot_vel+5.6*pi);
158
159 bruit_blanc=onde*invx;
160 tab(i,j)=moyenne(j)+2.*amplitude(j)*bruit_blanc;
161 }
162 }
163 else
164 //
165 // N=0 so random noise modelling
166 //
167 for(int i=0; i<nb_faces; i++)
168 for(int j=0; j<nb_comp(); j++)
169 {
170 tab(i,j)=moyenne(j)+amplitude(j)*(-1.+2.*drand48());
171 }
173}
174
175
class Ch_front_var_instationnaire_indep This abstract class represents a field on a boundary,
int lire_dimension(Entree &, const Nom &)
Verification of the field dimension Returns the dimension of the field.
class Champ_front_base Base class for the hierarchy of boundary fields.
virtual DoubleTab & valeurs() override
Returns the array of field values.
class Champ_front_bruite Derived class of Champ_front_base representing noisy boundary fields:
void mettre_a_jour(double temps) override
Update time and randomly redraw the noise values.
Champ_front_base & affecter_(const Champ_front_base &ch) override
Not implemented !!
DoubleTab & valeurs_au_temps(double temps) override
Returns the values at the desired time.
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual void fixer_nb_comp(int i)
Sets the number of components of the field.
virtual int nb_comp() const
Definition Field_base.h:56
int_t nb_faces() const
Returns the number of faces of the boundary.
Definition Frontiere.h:59
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
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
_SIZE_ size() const
Definition TRUSTVect.tpp:45
virtual void echange_espace_virtuel(IsExchangeBlocking exchange_type=IsExchangeBlocking::DefaultBlocking, const std::string kernel_name="noname")