TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Perte_Charge_Circulaire_VEF_P1NC.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 <Perte_Charge_Circulaire_VEF_P1NC.h>
17#include <Motcle.h>
18#include <Equation_base.h>
19
20#include <Fluide_Incompressible.h>
21#include <Probleme_base.h>
22#include <Domaine.h>
23#include <Sous_domaine_VF.h>
24#include <Domaine_VEF.h>
25#include <Matrice_Morse.h>
26#include <Schema_Temps_base.h>
27#include <TRUSTTrav.h>
28#include <Param.h>
29
30Implemente_instanciable(Perte_Charge_Circulaire_VEF_P1NC,"Perte_Charge_Circulaire_VEF_P1NC",Perte_Charge_VEF);
31// XD perte_charge_circulaire source_base perte_charge_circulaire BRACE New pressure loss.
32// XD attr lambda chaine lambda_u REQ Function f(Re_tot, Re_long, t, x, y, z) for loss coefficient in the longitudinal
33// XD_CONT direction
34// XD attr diam_hydr champ_don_base diam_hydr REQ Hydraulic diameter value.
35// XD attr sous_zone chaine sous_zone OPT Optional sub-area where pressure loss applies.
36
38{
39 return s << que_suis_je() << finl;
40}
41
43{
45 if (v->nb_comp()!=dimension)
46 {
47 Cerr << "The direction field must be defined with " << dimension << " components" << finl;
48 exit();
49 }
50 return s;
51}
52
54{
56 param.ajouter_non_std("lambda_ortho",(this),Param::REQUIRED); // XD_ADD_P chaine
57 // XD_CONT function: Function f(Re_tot, Re_ortho, t, x, y, z) for loss coefficient in transverse direction
58 param.ajouter("diam_hydr_ortho",&diam_hydr_ortho,Param::REQUIRED); // XD_ADD_P champ_don_base
59 // XD_CONT Transverse hydraulic diameter value.
60 param.ajouter("direction",&v,Param::REQUIRED); // XD_ADD_P champ_don_base
61 // XD_CONT Field which indicates the direction of the pressure loss.
62}
63
65{
66 if (mot=="lambda")
67 {
68 lambda.addVar("Re_tot");
69 lambda.addVar("Re_long");
71 return 1;
72 }
73 else if (mot=="lambda_ortho")
74 {
75 Nom tmp;
76 is >> tmp;
77 Cerr << "Reading and interpreting the function " << tmp << " ... ";
78 lambda_ortho.setNbVar(3+dimension);
79 lambda_ortho.setString(tmp);
80 lambda_ortho.addVar("Re_tot");
81 lambda_ortho.addVar("Re_ortho");
82 lambda_ortho.addVar("t");
83 lambda_ortho.addVar("x");
84 if (dimension>1)
85 lambda_ortho.addVar("y");
86 if (dimension>2)
87 lambda_ortho.addVar("z");
88 lambda_ortho.parseString();
89 Cerr << " Ok" << finl;
90 return 1;
91 }
92 else
93 {
95 }
96}
97
98
99////////////////////////////////////////////////////////////////
100// //
101// Main function: pressure drop coefficients //
102// //
103////////////////////////////////////////////////////////////////
104
105void Perte_Charge_Circulaire_VEF_P1NC::coeffs_perte_charge(const DoubleVect& u, const DoubleVect& pos,
106 double t, double norme_u, double dh, double nu, double reynolds,double& coeff_ortho,double& coeff_long,double& u_l,DoubleVect& av_valeur) const
107{
108
109 // Compute dh_ortho
110 double dh_ortho=diam_hydr_ortho->valeur_a_compo(pos,0);
111
112 // Compute u.d/||d||
113 // Compute v and ||v||^2
114 av_valeur.resize(dimension);
115
116 v->valeur_a(pos,av_valeur);
117 // normalize v
118 {
119 double vcarre=0;
120 for (int dim=0; dim<dimension; dim++)
121 vcarre+=av_valeur[dim]*av_valeur[dim];
122 av_valeur/=sqrt(vcarre);
123 }
124 // Compute u.v/||v||
125 u_l=0;
126
127 for (int dim=0; dim<dimension; dim++)
128 u_l+=u[dim]*av_valeur[dim];
129
130 double u_ortho=sqrt(std::max(norme_u*norme_u-u_l*u_l,0.0));
131 // compute Re_l and Re_ortho
132 // Compute the Reynolds number
133 /* PL: To avoid a possible division by zero, we replace:
134 double nu=norme_u*dh/reynolds;
135 double Re_l=std::fabs(u_l)*dh/nu; */
136 // By:
137 double Re_l=dh*std::fabs(u_l)/nu;
138 if(Re_l<1e-10) Re_l=1e-10;
139 // PL: To avoid a possible division by zero, we replace:
140 /* double Re_ortho=u_ortho*dh_ortho/nu; */
141 // By:
142 double Re_ortho=dh_ortho*u_ortho/nu;
143 if (Re_ortho<1e-10) Re_ortho=1e-10;
144 // Compute lambda
145 lambda.setVar(0,reynolds);
146 lambda.setVar(1,Re_l);
147 lambda.setVar(3,t);
148 lambda.setVar(4,pos[0]);
149 if (dimension>1)
150 lambda.setVar(5,pos[1]);
151 if (dimension>2)
152 lambda.setVar(6,pos[2]);
153
154 // Compute lambda_ortho
155 lambda_ortho.setVar(0,reynolds);
156 lambda_ortho.setVar(1,Re_ortho);
157 lambda_ortho.setVar(2,t);
158 lambda_ortho.setVar(3,pos[0]);
159 if (dimension>1)
160 lambda_ortho.setVar(4,pos[1]);
161 if (dimension>2)
162 lambda_ortho.setVar(5,pos[2]);
163 double l_ortho=lambda_ortho.eval(); // To avoid evaluating the parser twice
164 double l_long=lambda.eval();
165 coeff_ortho=l_ortho*u_ortho/2./dh_ortho;
166 coeff_long=l_long *std::fabs(u_l) /2./dh ;
167}
168/*
169 void Perte_Charge_Circulaire_VEF_P1NC::perte_charge(const DoubleVect& u, const DoubleVect& pos,
170 double t, double norme_u, double dh, double reynolds,DoubleVect& p_charge) const
171 {
172 double coeff_ortho,coeff_long,u_l; //DoubleVect v_valeur(dimension);
173 calculer_coeffs(u,pos,t,norme_u,dh,reynolds, coeff_ortho, coeff_long,u_l,v_valeur) ;
174 // Compute the result
175 for (int dim=0;dim<dimension;dim++)
176 p_charge[dim] =
177 -coeff_ortho * (u[dim]-u_l*v_valeur[dim])
178 -coeff_long * u_l*v_valeur[dim];
179 }
180
181 void Perte_Charge_Circulaire_VEF_P1NC::coef_implicite_perte_charge(const DoubleVect& u, const DoubleVect& pos,
182 double t, double norme_u, double dh, double reynolds,DoubleVect& p_charge) const
183 {
184 double coeff_ortho,coeff_long,u_l; //DoubleVect v_valeur(dimension);
185 calculer_coeffs(u,pos,t,norme_u,dh,reynolds, coeff_ortho, coeff_long,u_l,v_valeur) ;
186 // Compute the result
187
188 for (int dim=0;dim<dimension;dim++)
189 {
190 //p_charge[dim] =
191 // -coeff_ortho * (u[dim]-u_l*v_valeur[dim])
192 // -coeff_long * u_l*v_valeur[dim];
193 // du_l/u[dim]= v_valeur[dim]
194
195 p_charge[dim] =
196 coeff_ortho * (1-v_valeur[dim]*v_valeur[dim])
197 +coeff_long *v_valeur[dim]*v_valeur[dim];
198 }
199 }
200
201
202
203
204 void Perte_Charge_Circulaire_VEF_P1NC::contribuer_a_avec(const DoubleTab& inco, Matrice_Morse& matrice) const
205 {
206 if (pas_implicite_) return;
207 // To be factorized later....
208 // copy of Perte_Charge_VEF::ajouter
209 // Shortcuts
210 const Champ_Don_base& nu=le_fluide->viscosite_cinematique(); // kinematic viscosity
211 const DoubleTab& xv=le_dom_VEF->xv() ; // face centers of gravity
212 const DoubleTab& vit=la_vitesse->valeurs();
213 // Otherwise segfault at the initialization of ssz when there is no sub-domain!
214 const Sous_domaine_VF& ssz=sous_domaine?le_sous_domaine_dis.valeur():Sous_domaine_VF();
215 const Domaine_VEF& zvef=le_dom_VEF.valeur();
216
217 // Parameters for perte_charge()
218 static DoubleVect u(dimension);
219 double norme_u;
220 double dh_valeur;
221 double reynolds;
222 static DoubleVect p_charge(dimension);
223 static DoubleVect pos(dimension);
224
225 // Optimizations for cases where nu or diam_hydr are constant
226 bool nu_constant=sub_type(Champ_Uniforme,nu)?true:false;
227 double nu_valeur;
228 //if (nu_constant)
229 ////nu_valeur=nu(0,0);
230
231 bool dh_constant=sub_type(Champ_Uniforme,diam_hydr.valeur())?true:false;
232 //if (dh_constant)
233 ////dh_valeur=diam_hydr(0,0);
234
235 // Current time
236 double t=equation().schema_temps().temps_courant();
237
238 // Number of faces to process.
239 int max_faces=sous_domaine?
240 ssz.les_faces().size() :
241 zvef.nb_faces_tot();
242
243 for (int face=0;face<max_faces;face++) {
244
245 // index of the face in domaine_VEF
246 int la_face=sous_domaine?
247 ssz.les_faces()[face] :
248 face;
249
250 // Retrieve velocity at the face and compute its magnitude
251 norme_u=0;
252 for (int dim=0;dim<dimension;dim++) {
253 u[dim]=vit(la_face,dim);
254 norme_u+=u[dim]*u[dim];
255 }
256 norme_u=sqrt(norme_u) ;
257
258 // Compute position
259 for (int i=0;i<dimension;i++)
260 pos[i]=xv(la_face,i);
261
262 // Compute nu
263 if (!nu_constant) {
264 nu_valeur=nu.valeur_a_compo(pos,0);
265 } else nu_valeur=nu(0,0);
266
267 // Compute hydraulic diameter
268 if (!dh_constant) {
269 dh_valeur=diam_hydr->valeur_a_compo(pos,0);
270 }
271 else dh_valeur=diam_hydr(0,0);
272
273 // Compute Reynolds number
274 reynolds=norme_u*dh_valeur/nu_valeur;
275 // Lambda is often undefined for Re->0
276 if (reynolds < 1.e-10)
277 reynolds=1e-10;
278
279 // Compute the integration volume
280 double volume=sous_domaine?
281 ssz.volumes_entrelaces(face) :
282 zvef.volumes_entrelaces(la_face);
283 volume*=zvef.porosite_face(la_face);
284
285 // end of copy....
286
287
288 coef_implicite_perte_charge (u,pos,t,norme_u,dh_valeur,reynolds,p_charge);
289 for (int dim=0;dim<dimension;dim++) {
290 int n0=la_face*dimension+dim;
291 matrice.coef(n0,n0) += p_charge[dim]*volume;
292 }
293
294 }
295 // test
296 if (0)
297 {
298 DoubleTrav resu(inco);
299 ajouter(resu);
300 //Cerr<<" test0 " <<max_abs(resu)<<finl<<resu<<finl;
301 matrice.ajouter_multvect(inco,resu);
302 equation().solv_masse().appliquer(resu);
303 Cerr<<" test " <<mp_max_abs_vect(resu)<<finl;
304 }
305 }
306*/
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
friend class Entree
Definition Objet_U.h:71
static int dimension
Definition Objet_U.h:94
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
Helper class to factorize the readOn method of Objet_U classes.
Definition Param.h:112
void ajouter(const char *keyword, const int *value, Param::Nature nat=Param::OPTIONAL)
Register an integer parameter.
Definition Param.cpp:364
@ REQUIRED
Definition Param.h:115
void ajouter_non_std(const char *keyword, const Objet_U *value, Param::Nature nat=Param::OPTIONAL)
Register a keyword handled by Objet_U::lire_motcle_non_standard.
Definition Param.cpp:489
Anisotropic pressure drop (along a unit vector v and in the plane orthogonal to this vector).
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
void coeffs_perte_charge(const DoubleVect &u, const DoubleVect &pos, double t, double norme_u, double dh, double nu, double reynolds, double &coeff_ortho, double &coeff_long, double &u_l, DoubleVect &v_valeur) const override
Implements the effective computation of the pressure drop at a given location.
Factorizes the common functionality of several pressure drop operators in VEF, velocity at faces.
int lire_motcle_non_standard(const Motcle &, Entree &) override
Reads non-simple-type parameters of an Objet_U from an input stream.
virtual void set_param(Param &param) 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
void resize(_SIZE_, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
Definition TRUSTVect.tpp:91