2 * IsothermalTwoFluid.cxx
4 * Created on: Sep 16, 2014
8 #include "IsothermalTwoFluid.hxx"
12 IsothermalTwoFluid::IsothermalTwoFluid(pressureEstimate pEstimate, int dim){
16 _dragCoeffs=vector<double>(2,0);
18 if (pEstimate==around1bar300K)//EOS at 1 bar and 300K
20 cout<<"Fluid is air-water mixture around 1 bar and 300 K (27°C)"<<endl;
21 *_runLogFile<<"Fluid is air-water mixture around 1 bar and 300 K (27°C)"<<endl;
22 _Temperature=300;//Constant temperature of the model
23 _internalEnergy1=2.22e5;//nitrogen internal energy at 1bar, 300K
24 _internalEnergy2=1.12e5;//water internal energy at 1 bar, 300K
25 _fluides[0] = new StiffenedGas(1.4,743,_Temperature,_internalEnergy1); //ideal gas law for nitrogen at pressure 1 bar and temperature 27°C, c_v=743
26 _fluides[1] = new StiffenedGas(996,1e5,_Temperature,_internalEnergy2,1501,4130); //stiffened gas law for water at pressure 1 bar and temperature 27°C
28 else//EOS at 155 bars and 618K
30 cout<<"Fluid is water-Gas mixture around saturation point 155 bars and 618 K (345°C)"<<endl;
31 *_runLogFile<<"Fluid is water-Gas mixture around saturation point 155 bars and 618 K (345°C)"<<endl;
32 _Temperature=618;//Constant temperature of the model
33 _internalEnergy1=2.44e6;//Gas internal energy at saturation at 155 bar
34 _internalEnergy2=1.6e6;//water internal energy at saturation at 155 bar
35 _fluides[0] = new StiffenedGas(102,1.55e7,_Temperature,_internalEnergy1, 433,3633); //stiffened gas law for Gas at pressure 155 bar and temperature 345°C:
36 _fluides[1] = new StiffenedGas(594,1.55e7,_Temperature,_internalEnergy2, 621,3100); //stiffened gas law for water at pressure 155 bar and temperature 345°C:
41 void IsothermalTwoFluid::initialize(){
42 cout<<"Initialising the isothermal two-fluid model"<<endl;
43 *_runLogFile<<"Initialising the isothermal two-fluid model"<<endl;
45 _Uroe = new double[_nVar+1];
47 _guessalpha = _VV(0,0);
49 _gravite = vector<double>(_nVar,0);//Not to be confused with _GravityField3d (size _Ndim). _gravite (size _Nvar) is usefull for dealing with source term and implicitation of gravity vector
50 for(int i=0; i<_Ndim; i++)
52 _gravite[i+1]=_GravityField3d[i];
53 _gravite[i+1 +_Ndim+1]=_GravityField3d[i];
55 _GravityImplicitationMatrix = new PetscScalar[_nVar*_nVar];
58 _Vitesse1=Field("Gas velocity",CELLS,_mesh,3);//Forcement en dimension 3 pour le posttraitement des lignes de courant
59 _Vitesse2=Field("Liquid velocity",CELLS,_mesh,3);//Forcement en dimension 3 pour le posttraitement des lignes de courant
61 if(_entropicCorrection)
62 _entropicShift=vector<double>(3,0);
64 ProblemFluid::initialize();
67 void IsothermalTwoFluid::convectionState( const long &i, const long &j, const bool &IsBord){
68 //sortie: WRoe en (alpha, p, u1, u2, dm1,dm2,dalpha1,dp)z
69 //entree: _conservativeVars en (alpha1 rho1, alpha1 rho1 u1, alpha2 rho2, alpha2 rho2 u2)
71 // _l always inside the domain (index i)
72 // _r is maybe the boundary cell (negative index)
73 // _l and _r are primative vectors (alp, P, u1, u2)
76 for(int k=1; k<_nVar; k++)
77 _idm[k] = _idm[k-1] + 1;
78 VecGetValues(_conservativeVars, _nVar, _idm, _Ui);
81 for(int k=1; k<_nVar; k++)
82 _idm[k] = _idm[k-1] + 1;
84 VecGetValues(_Uext, _nVar, _idm, _Uj);
86 VecGetValues(_conservativeVars, _nVar, _idm, _Uj);
87 if(_verbose && _nbTimeStep%_freqSave ==0)
89 cout<<"Convection Left state cell " << i<< ": "<<endl;
90 for(int k =0; k<_nVar; k++)
92 cout<<"Convection Right state cell " << j<< ": "<<endl;
93 for(int k =0; k<_nVar; k++)
96 // if(_Ui[0]<-(_precision) || _Uj[0]<-(_precision) || _Ui[_Ndim+1]<-(_precision) || _Uj[_Ndim+1]<-(_precision))
98 // cout<<"!!!!!!!!!!!!!!!!!!!!!!!! Masse partielle negative, arret de calcul!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"<<endl;
99 // cout<< "valeurs a gauche: "<<_Ui[0]<<", "<<_Ui[_Ndim+1]<<"valeurs a droite: "<<_Uj[0]<<", "<<_Uj[_Ndim+1]<<endl;
100 // throw CdmathException(" Masse partielle negative, arret de calcul");
104 _Ui[0]=max(0.,_Ui[0]);// mass1 a gauche
105 _Uj[0]=max(0.,_Uj[0]);// mass1 a droite
106 _Ui[_Ndim+1]=max(0.,_Ui[_Ndim+1]);// mass2 a gauche
107 _Uj[_Ndim+1]=max(0.,_Uj[_Ndim+1]);// mass2 a droite
110 PetscScalar ri1, ri2, rj1, rj2, xi, xj;
112 for(int k=1; k<_nVar; k++)
113 _idm[k] = _idm[k-1] + 1;
114 VecGetValues(_primitiveVars, _nVar, _idm, _l);
116 if(_verbose && _nbTimeStep%_freqSave ==0)
118 cout<<"Etat de Roe, etat primitif gauche: "<<endl;
119 for(int i =0; i<_nVar; i++)
123 // boundary : compute the _r
129 // inside the domain : extract from the primative vector
133 for(int k=1; k<_nVar; k++)
134 _idm[k] = _idm[k-1] + 1;
135 VecGetValues(_primitiveVars, _nVar, _idm, _r);
138 if(_verbose && _nbTimeStep%_freqSave ==0)
140 cout<<"Etat de Roe, etat primitif droite: "<<endl;
141 for(int i =0; i<_nVar; i++)
145 // Using Toumi linearisation (read in the article of Toumi) : alpha^{Roe}_l
146 if(2-_l[0]-_r[0] > _precision)
147 _Uroe[0] = 1- 2*(1-_l[0])*(1-_r[0])/(2-_l[0]-_r[0]);
148 // Using an average : (alp_l + alp_r)/2 : suggestion of Michael (no theory)
150 _Uroe[0] = (_l[0]+_r[0])/2;
151 // Pressure is computed as function of alp and P_l, P_r (Toumi article)
152 if(_l[0]+_r[0] > _precision)
153 _Uroe[1] = (_l[1]*_l[0]+_r[1]*_r[0])/(_l[0]+_r[0]);
155 _Uroe[1] = (_l[1]*(1-_l[0])+_r[1]*(1-_r[0]))/(2-_l[0]-_r[0]);
156 // i :left, j : right (U is normally conservative variable)
157 ri1 = sqrt(_Ui[0]); ri2 = sqrt(_Ui[_Ndim+1]);
158 rj1 = sqrt(_Uj[0]); rj2 = sqrt(_Uj[_Ndim+1]);
159 // Roe average formula of the velocities
160 for(int k=0;k<_Ndim;k++)
164 // avoid dividing by zero, if mass is zero, do not consider the distribution of such a phase
165 if(ri1>_precision && rj1>_precision)
166 _Uroe[2+k] = (xi/ri1 + xj/rj1)/(ri1 + rj1);
167 else if(ri1<_precision && rj1>_precision)
168 _Uroe[2+k] = xj/_Uj[0];
169 else if(ri1>_precision && rj1<_precision)
170 _Uroe[2+k] = xi/_Ui[0];
172 _Uroe[2+k] =(_Ui[k+1+_Ndim+1]/ri2 + _Uj[k+1+_Ndim+1]/rj2)/(ri2 + rj2);
174 xi = _Ui[k+1+_Ndim+1];
175 xj = _Uj[k+1+_Ndim+1];
176 if(ri2>_precision && rj2>_precision)
177 _Uroe[2+k+_Ndim] = (xi/ri2 + xj/rj2)/(ri2 + rj2);
178 else if(ri2<_precision && rj2>_precision)
179 _Uroe[2+k+_Ndim] = xj/_Uj[_Ndim+1];
180 else if(ri2>_precision && rj2<_precision)
181 _Uroe[2+k+_Ndim] = xi/_Ui[_Ndim+1];
183 _Uroe[2+k+_Ndim] = (xi/ri1 + xj/rj1)/(ri1 + rj1);
185 if(_verbose && _nbTimeStep%_freqSave ==0)
187 cout<<"Etat de Roe calcule: "<<endl;
188 for(int k=0;k<_nVar; k++)//At this point _Uroe[_nVar] is not yet set
189 cout<< _Uroe[k]<<endl;
193 void IsothermalTwoFluid::diffusionStateAndMatrices(const long &i,const long &j, const bool &IsBord){
194 //sortie: matrices et etat de diffusion (m_v, q_v, m_l, q_l)
196 for(int k=1; k<_nVar; k++)
197 _idm[k] = _idm[k-1] + 1;
199 VecGetValues(_conservativeVars, _nVar, _idm, _Ui);
201 for(int k=1; k<_nVar; k++)
202 _idm[k] = _idm[k-1] + 1;
205 VecGetValues(_Uextdiff, _nVar, _idm, _Uj);
207 VecGetValues(_conservativeVars, _nVar, _idm, _Uj);
209 for(int k=0; k<_nVar; k++)
210 _Udiff[k] = (_Ui[k]+_Uj[k])/2;
212 for (int i = 0; i<_Ndim;i++)
213 q_2+=_Udiff[i+1]*_Udiff[i+1];
215 if(_timeScheme==Implicit)
217 for(int i=0; i<_nVar*_nVar;i++)
219 double mu1 = _fluides[0]->getViscosity(_Temperature);
220 double mu2 = _fluides[1]->getViscosity(_Temperature);
221 for(int idim=1;idim<_Ndim+1;idim++)
223 _Diffusion[idim*_nVar] = mu1*_Udiff[idim]/(_Udiff[0]*_Udiff[0]);
224 _Diffusion[idim*_nVar+idim] = -mu1/_Udiff[0];
225 _Diffusion[(idim+_Ndim+1)*_nVar] = mu2*_Udiff[idim+_Ndim+1]/(_Udiff[_Ndim+1]*_Udiff[_Ndim+1]);
226 _Diffusion[(idim+_Ndim+1)*_nVar+idim+_Ndim+1] = -mu2/_Udiff[_Ndim+1];
231 void IsothermalTwoFluid::convectionMatrices()
233 //entree: URoe = alpha, p, u1, u2 + ajout dpi pour calcul flux ultérieur
234 //sortie: matrices Roe+ et Roe- +Roe si scheme centre
236 if(_timeScheme==Implicit && _usePrimitiveVarsInNewton)
237 throw CdmathException("Implicitation with primitive variables not yet available for IsothermalTwoFluid model");
240 complex< double > tmp;
241 double u1_n, u1_2, u2_n, u2_2, u_r2;
246 for(int i=0;i<_Ndim;i++)
248 u1_2 += _Uroe[2+i]*_Uroe[2+i];
249 u1_n += _Uroe[2+i]*_vec_normal[i];
250 u2_2 += _Uroe[2+i+_Ndim]*_Uroe[2+i+_Ndim];
251 u2_n += _Uroe[2+i+_Ndim]*_vec_normal[i];
252 u_r2 += (_Uroe[2+i]-_Uroe[2+i+_Ndim])*(_Uroe[2+i]-_Uroe[2+i+_Ndim]);
254 //Ancienne construction Mat Roe (Dm1,Dm2,Dalp,Dp)
255 double alpha = _Uroe[0];
257 double rho1 = _fluides[0]->getDensity(p, _Temperature);
258 double rho2 = _fluides[1]->getDensity(p, _Temperature);
259 double dpi1 = intPressDef(alpha, u_r2, rho1, rho2);
261 double invcsq1 = 1/_fluides[0]->vitesseSonTemperature(_Temperature,rho1);
263 double invcsq2 = 1/_fluides[1]->vitesseSonTemperature(_Temperature,rho2);
265 double g2 = 1/(alpha*rho2*invcsq1+(1-alpha)*rho1*invcsq2);
266 double g2press=g2, g2alpha=g2;
267 //saving dpi value for flux calculation later
270 /***********Calcul des valeurs propres ********/
271 vector< double > pol_car= Polynoms::polynome_caracteristique(alpha, 1-alpha, u1_n, u2_n, rho1, rho2,invcsq1,invcsq2, dpi1, dpi2, g2press, g2alpha, g2,_precision);
272 for(int ct=0;ct<4;ct++){
273 if (abs(pol_car[ct])<_precision*_precision)
276 if(_verbose && _nbTimeStep%_freqSave ==0)
278 cout<<"pol caract= "<<endl;
279 for(int i =0; i<5; i++)
280 cout<<pol_car[i]<<" ";
282 cout<<"alpha= "<<alpha<<", p= " << p << ", rho1= " << rho1<< ", rho2= " << rho2<< ", c1= " <<sqrt(1/invcsq1)<<
283 ", c2= " <<sqrt(1/invcsq2)<<endl;
284 cout<< "u1_n= "<<u1_n<<", u2_n= "<<u2_n<< ", dpi1= "<<dpi1<< ", dpi2= "<<dpi2<< endl;
286 vector< complex<double> > valeurs_propres = getRacines(pol_car);
288 //On ajoute les valeurs propres triviales
291 if( !Polynoms::belongTo(u1_n,valeurs_propres, _precision) )
292 valeurs_propres.push_back(u1_n);//vp vapor energy
293 if( !Polynoms::belongTo(u2_n,valeurs_propres, _precision) )
294 valeurs_propres.push_back(u2_n);//vp liquid energy
296 bool doubleeigenval = norm(valeurs_propres[0] - valeurs_propres[1])<_precision;//norm= suqare of the magnitude
299 valeurs_propres[0] = valeurs_propres[valeurs_propres.size()-1];
300 valeurs_propres.pop_back();
303 int taille_vp = Polynoms::new_tri_selectif(valeurs_propres,valeurs_propres.size(),_precision);//valeurs_propres.size();//
306 for(int i =0; i<taille_vp; i++)
307 if(fabs(valeurs_propres[i].real())>_maxvploc)
308 _maxvploc=fabs(valeurs_propres[i].real());
312 int existVpCplx = 0,pos_conj;
314 for (int ct=0; ct<taille_vp; ct++) {
315 vp_imag_iter = valeurs_propres[ct].imag();
316 if ( fabs(vp_imag_iter) > _precision ) {
318 if ( _part_imag_max < fabs(vp_imag_iter))
319 _part_imag_max = fabs(vp_imag_iter);
320 //On cherhe le conjugue
322 while(pos_conj<taille_vp && fabs(valeurs_propres[pos_conj].imag()+vp_imag_iter)>_precision)
324 if(pos_conj!=ct+1 && pos_conj<taille_vp )
326 tmp=valeurs_propres[ct+1];
327 valeurs_propres[ct+1]=valeurs_propres[pos_conj];
328 valeurs_propres[pos_conj] = tmp;
336 //on ordonne les deux premieres valeurs
338 if(valeurs_propres[1].real()<valeurs_propres[0].real())
340 tmp=valeurs_propres[0];
341 valeurs_propres[0]=valeurs_propres[1];
342 valeurs_propres[1]=tmp;
345 if(_verbose && _nbTimeStep%_freqSave ==0)
347 cout<<" Vp apres tri " << valeurs_propres.size()<<endl;
348 for(int ct =0; ct<taille_vp; ct++)
349 cout<< "("<<valeurs_propres[ct].real()<< ", " <<valeurs_propres[ct].imag() <<") ";
353 /******** Construction de la matrice de Roe *********/
355 for(int i=0; i<_nVar*_nVar;i++)
358 for(int idim=0; idim<_Ndim;idim++)
360 _Aroe[1+idim]=_vec_normal[idim];
361 _Aroe[1+idim+_Ndim+1]=0;
362 _Aroe[(_Ndim+1)*_nVar+1+idim]=0;
363 _Aroe[(_Ndim+1)*_nVar+1+idim+_Ndim+1]=_vec_normal[idim];
366 for(int idim=0; idim<_Ndim;idim++)
368 //premiere colonne (masse gaz)
369 _Aroe[ (1+idim)*_nVar]= (alpha *rho2*g2press+dpi1*(1-alpha)*invcsq2*g2alpha)*_vec_normal[idim] - u1_n*_Uroe[2+idim];
370 _Aroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar]=((1-alpha)*rho2*g2press-dpi2*(1-alpha)*invcsq2*g2alpha)*_vec_normal[idim];
371 //colonnes intermediaires
372 for(int jdim=0; jdim<_Ndim;jdim++)
374 _Aroe[ (1+idim)*_nVar + jdim + 1] = _Uroe[ 2+idim]*_vec_normal[jdim];
375 _Aroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar + jdim + 1+_Ndim+1] = _Uroe[_Ndim+2+idim]*_vec_normal[jdim];
378 _Aroe[ (1+idim)*_nVar + idim + 1] += u1_n;
379 _Aroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar + _Ndim+1+ idim + 1] += u2_n;
380 //troisieme colonne (masse liquide)
381 _Aroe[ (1+idim)*_nVar + _Ndim+1]= (alpha *rho1*g2press-dpi1*alpha*invcsq1*g2alpha)*_vec_normal[idim];
382 _Aroe[(_Ndim+1)*_nVar+(1+idim)*_nVar + _Ndim+1]=((1-alpha)*rho1*g2press+dpi2*alpha*invcsq1*g2alpha)*_vec_normal[idim] - u2_n*_Uroe[1+idim+_Ndim+1];
385 /******* Construction des matrices de decentrement *****/
386 if(_spaceScheme == centered){
387 if(_entropicCorrection)
388 throw CdmathException("IsothermalTwoFluid::convectionMatrices: entropic scheme not available for centered scheme");
389 for(int i=0; i<_nVar*_nVar;i++)
392 if( _spaceScheme ==staggered){
393 if(_entropicCorrection)//To do: study entropic correction for staggered
394 throw CdmathException("IsothermalTwoFluid::convectionMatrices: entropic scheme not yet available for staggered scheme");
395 /******** Construction du decentrement du type decale *********/
397 for(int i=0; i<_nVar*_nVar;i++)
400 for(int idim=0; idim<_Ndim;idim++)
402 _absAroe[1+idim]=_vec_normal[idim];
403 _absAroe[1+idim+_Ndim+1]=0;
404 _absAroe[(_Ndim+1)*_nVar+1+idim]=0;
405 _absAroe[(_Ndim+1)*_nVar+1+idim+_Ndim+1]=_vec_normal[idim];
408 for(int idim=0; idim<_Ndim;idim++)
410 //premiere colonne (masse gaz)
411 _absAroe[ (1+idim)*_nVar]= (-alpha *rho2*g2press+dpi1*(1-alpha)*invcsq2*g2alpha)*_vec_normal[idim] - u1_n*_Uroe[2+idim];
412 _absAroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar]=(-(1-alpha)*rho2*g2press-dpi2*(1-alpha)*invcsq2*g2alpha)*_vec_normal[idim];
413 //colonnes intermediaires
414 for(int jdim=0; jdim<_Ndim;jdim++)
416 _absAroe[ (1+idim)*_nVar + jdim + 1] = _Uroe[ 2+idim]*_vec_normal[jdim];
417 _absAroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar + jdim + 1+_Ndim+1] = _Uroe[_Ndim+2+idim]*_vec_normal[jdim];
420 _absAroe[ (1+idim)*_nVar + idim + 1] += u1_n;
421 _absAroe[(_Ndim+1)*_nVar+ (1+idim)*_nVar + _Ndim+1+ idim + 1] += u2_n;
422 //troisieme colonne (masse liquide)
423 _absAroe[ (1+idim)*_nVar + _Ndim+1]= (-alpha *rho1*g2press-dpi1*alpha*invcsq1*g2alpha)*_vec_normal[idim];
424 _absAroe[(_Ndim+1)*_nVar+(1+idim)*_nVar + _Ndim+1]=(-(1-alpha)*rho1*g2press+dpi2*alpha*invcsq1*g2alpha)*_vec_normal[idim] - u2_n*_Uroe[1+idim+_Ndim+1];
427 double signu1,signu2;
441 for(int i=0; i<(1+_Ndim)*_nVar;i++){
442 _absAroe[i] *= signu1;
443 _absAroe[i+(1+_Ndim)*_nVar] *= signu2;
446 if(_spaceScheme==upwind || _spaceScheme ==lowMach)
448 vector< complex< double > > y (taille_vp,0);
449 for( int i=0 ; i<taille_vp ; i++)
450 y[i] = Polynoms::abs_generalise(valeurs_propres[i]);
452 if(_entropicCorrection)
454 entropicShift(_vec_normal);
455 y[0] +=_entropicShift[0];
456 y[taille_vp-1] +=_entropicShift[2];
457 for( int i=1 ; i<taille_vp-1 ; i++)
458 y[i] +=_entropicShift[1];
461 Polynoms::abs_par_interp_directe(taille_vp,valeurs_propres, _Aroe, _nVar,_precision, _absAroe,y);
462 if( _spaceScheme ==pressureCorrection){
463 for( int i=0 ; i<_Ndim ; i++)
464 for( int j=0 ; j<_Ndim ; j++){
465 _absAroe[(1+i)*_nVar+1+j]-=alpha*(valeurs_propres[1].real()-valeurs_propres[0].real())/2*_vec_normal[i]*_vec_normal[j];
466 _absAroe[(2+_Ndim+i)*_nVar+2+_Ndim+j]-=(1-alpha)*(valeurs_propres[1].real()-valeurs_propres[0].real())/2*_vec_normal[i]*_vec_normal[j];
469 else if( _spaceScheme ==lowMach){
470 double M=max(fabs(u1_2),fabs(u2_2))/_maxvploc;
471 for( int i=0 ; i<_Ndim ; i++)
472 for( int j=0 ; j<_Ndim ; j++){
473 _absAroe[(1+i)*_nVar+1+j]-=(1-M)*alpha*(valeurs_propres[1].real()-valeurs_propres[0].real())/2*_vec_normal[i]*_vec_normal[j];
474 _absAroe[(2+_Ndim+i)*_nVar+2+_Ndim+j]-=(1-M)*(1-alpha)*(valeurs_propres[1].real()-valeurs_propres[0].real())/2*_vec_normal[i]*_vec_normal[j];
479 //Calcul de la matrice signe pour VFFC, VFRoe et décentrement des termes source
480 vector< complex< double > > valeurs_propres_dist(taille_vp,0);
481 for( int i=0 ; i<taille_vp ; i++)
482 valeurs_propres_dist[i] = valeurs_propres[i];
484 if(_entropicCorrection || _spaceScheme ==pressureCorrection || _spaceScheme ==lowMach){
485 InvMatriceRoe( valeurs_propres_dist);
486 Polynoms::matrixProduct(_absAroe, _nVar, _nVar, _invAroe, _nVar, _nVar, _signAroe);
488 else if (_spaceScheme==upwind)//upwind sans entropic
489 SigneMatriceRoe( valeurs_propres_dist);
490 else if (_spaceScheme==centered)//centre sans entropic
492 for(int i=0; i<_nVar*_nVar;i++)
495 else if(_spaceScheme ==staggered )
497 double signu1,signu2;
510 for(int i=0; i<_nVar*_nVar;i++)
512 _signAroe[0] = signu1;
513 _signAroe[(1+_Ndim)*_nVar +1+_Ndim] = signu2;
514 for(int i=2; i<_nVar-1;i++){
515 _signAroe[i*_nVar+i] = -signu1;
516 _signAroe[(i+1+_Ndim)*_nVar+i+1+_Ndim] = -signu2;
520 throw CdmathException("IsothermalTwoFluid::convectionMatrices: well balanced option not treated");
522 for(int i=0; i<_nVar*_nVar;i++)
524 _AroeMinus[i] = (_Aroe[i]-_absAroe[i])/2;
525 _AroePlus[i] = (_Aroe[i]+_absAroe[i])/2;
527 if(_timeScheme==Implicit && _usePrimitiveVarsInNewton)//Implicitation using primitive variables
528 for(int i=0; i<_nVar*_nVar;i++)
529 _AroeMinusImplicit[i] = (_AroeImplicit[i]-_absAroeImplicit[i])/2;
531 for(int i=0; i<_nVar*_nVar;i++)
532 _AroeMinusImplicit[i] = _AroeMinus[i];
534 if(_verbose && _nbTimeStep%_freqSave ==0)
536 cout<<endl<<"Matrice de Roe"<<endl;
537 for(int i=0; i<_nVar;i++)
539 for(int j=0; j<_nVar;j++)
540 cout << _Aroe[i*_nVar+j]<< " , ";
543 cout<<"Valeur absolue matrice de Roe"<<endl;
544 for(int i=0; i<_nVar;i++){
545 for(int j=0; j<_nVar;j++)
546 cout<<_absAroe[i*_nVar+j]<<" , ";
549 cout<<endl<<"Matrice _AroeMinus"<<endl;
550 for(int i=0; i<_nVar;i++)
552 for(int j=0; j<_nVar;j++)
553 cout << _AroeMinus[i*_nVar+j]<< " , ";
556 cout<<endl<<"Matrice _AroePlus"<<endl;
557 for(int i=0; i<_nVar;i++)
559 for(int j=0; j<_nVar;j++)
560 cout << _AroePlus[i*_nVar+j]<< " , ";
566 void IsothermalTwoFluid::setBoundaryState(string nameOfGroup, const int &j,double *normale){
567 //To do controle signe des vitesses pour CL entree/sortie
570 for(k=1; k<_nVar; k++)
571 _idm[k] = _idm[k-1] + 1;
573 VecGetValues(_conservativeVars, _nVar, _idm, _externalStates);//On initialise l'état fantôme avec l'état interne
574 double q1_n=0, q2_n=0;//quantité de mouvement normale à la face limite
575 for(k=0; k<_Ndim; k++){
576 q1_n+=_externalStates[(k+1)]*normale[k];
577 q2_n+=_externalStates[(k+1+1+_Ndim)]*normale[k];
580 if(_verbose && _nbTimeStep%_freqSave ==0)
582 cout << "Boundary conditions for group "<< nameOfGroup<< ", inner cell j= "<<j << " face unit normal vector "<<endl;
583 for(k=0; k<_Ndim; k++){
584 cout<<normale[k]<<", ";
588 if (_limitField[nameOfGroup].bcType==Wall){
590 //Pour la convection, inversion du sens des vitesses
591 for(k=0; k<_Ndim; k++){
592 _externalStates[(k+1)]-= 2*q1_n*normale[k];
593 _externalStates[(k+1+1+_Ndim)]-= 2*q2_n*normale[k];
597 for(k=1; k<_nVar; k++)
598 _idm[k] = _idm[k-1] + 1;
600 VecAssemblyBegin(_Uext);
601 VecSetValues(_Uext, _nVar, _idm, _externalStates, INSERT_VALUES);
602 VecAssemblyEnd(_Uext);
604 //Pour la diffusion, paroi à vitesses imposees
605 _externalStates[1]=_externalStates[0]*_limitField[nameOfGroup].v_x[0];
606 _externalStates[2+_Ndim]=_externalStates[1+_Ndim]*_limitField[nameOfGroup].v_x[1];
609 _externalStates[2]=_externalStates[0]*_limitField[nameOfGroup].v_y[0];
610 _externalStates[3+_Ndim]=_externalStates[1+_Ndim]*_limitField[nameOfGroup].v_y[1];
613 _externalStates[3]=_externalStates[0]*_limitField[nameOfGroup].v_z[0];
614 _externalStates[4+_Ndim]=_externalStates[1+_Ndim]*_limitField[nameOfGroup].v_z[1];
617 VecAssemblyBegin(_Uextdiff);
618 VecSetValues(_Uextdiff, _nVar, _idm, _externalStates, INSERT_VALUES);
619 VecAssemblyEnd(_Uextdiff);
621 else if (_limitField[nameOfGroup].bcType==Neumann){
623 for(k=1; k<_nVar; k++)
624 _idm[k] = _idm[k-1] + 1;
626 VecAssemblyBegin(_Uext);
627 VecSetValues(_Uext, _nVar, _idm, _externalStates, INSERT_VALUES);
628 VecAssemblyEnd(_Uext);
630 VecAssemblyBegin(_Uextdiff);
631 VecSetValues(_Uextdiff, _nVar, _idm, _externalStates, INSERT_VALUES);
632 VecAssemblyEnd(_Uextdiff);
634 else if (_limitField[nameOfGroup].bcType==Inlet){
636 for(k=1; k<_nVar; k++)
637 _idm[k] = _idm[k-1] + 1;
639 VecGetValues(_primitiveVars, _nVar, _idm, _Vj);
640 double alpha=_limitField[nameOfGroup].alpha;
641 double pression=_Vj[1];
642 double T=_Temperature;
643 double rho_v=_fluides[0]->getDensity(pression,T);
644 double rho_l=_fluides[1]->getDensity(pression,T);
645 _externalStates[0]=alpha*rho_v;
646 _externalStates[1]=alpha*rho_v*(_limitField[nameOfGroup].v_x[0]);
647 _externalStates[1+_Ndim]=(1-alpha)*rho_l;
648 _externalStates[2+_Ndim]=(1-alpha)*rho_l*(_limitField[nameOfGroup].v_x[1]);
651 _externalStates[2]=_externalStates[0]*_limitField[nameOfGroup].v_y[0];
652 _externalStates[3+_Ndim]=_externalStates[1+_Ndim]*_limitField[nameOfGroup].v_y[1];
655 _externalStates[3]=_externalStates[0]*_limitField[nameOfGroup].v_z[0];
656 _externalStates[4+_Ndim]=_externalStates[1+_Ndim]*_limitField[nameOfGroup].v_z[1];
660 for(k=1; k<_nVar; k++)
661 _idm[k] = _idm[k-1] + 1;
662 VecAssemblyBegin(_Uext);
663 VecAssemblyBegin(_Uextdiff);
664 VecSetValues(_Uext, _nVar, _idm, _externalStates, INSERT_VALUES);
665 VecSetValues(_Uextdiff, _nVar, _idm, _externalStates, INSERT_VALUES);
666 VecAssemblyEnd(_Uext);
667 VecAssemblyEnd(_Uextdiff);
669 else if (_limitField[nameOfGroup].bcType==InletPressure){
670 //Computation of the hydrostatic contribution : scalar product between gravity vector and position vector
671 Cell Cj=_mesh.getCell(j);
672 double hydroPress=Cj.x()*_GravityField3d[0];
674 hydroPress+=Cj.y()*_GravityField3d[1];
676 hydroPress+=Cj.z()*_GravityField3d[2];
678 hydroPress*=_externalStates[0]+_externalStates[_Ndim];//multiplication by rho the total density
680 //Building the external state
682 for(k=1; k<_nVar; k++)
683 _idm[k] = _idm[k-1] + 1;
685 VecGetValues(_primitiveVars, _nVar, _idm, _Vj);
686 double pression=_limitField[nameOfGroup].p+hydroPress;
687 double alpha=_limitField[nameOfGroup].alpha;
688 double T=_Temperature;
689 double rho_v=_fluides[0]->getDensity(pression,T);
690 double rho_l=_fluides[1]->getDensity(pression,T);
691 _externalStates[0]=alpha*rho_v;
692 _externalStates[1+_Ndim]=(1-alpha)*rho_l;
694 for(k=1;k<1+_Ndim;k++){
695 _externalStates[k]=_externalStates[0]*_Vj[1+k];
696 _externalStates[k+1+_Ndim]=_externalStates[1+_Ndim]*_Vj[k+1+_Ndim];
699 for(k=1; k<_nVar; k++)
700 _idm[k] = _idm[k-1] + 1;
701 VecAssemblyBegin(_Uext);
702 VecAssemblyBegin(_Uextdiff);
703 VecSetValues(_Uext, _nVar, _idm, _externalStates, INSERT_VALUES);
704 VecSetValues(_Uextdiff, _nVar, _idm, _externalStates, INSERT_VALUES);
705 VecAssemblyEnd(_Uext);
706 VecAssemblyEnd(_Uextdiff);
708 if(_verbose && _nbTimeStep%_freqSave ==0)
710 cout<<"Etat fantôme InletPressure"<<endl;
711 for(int k=0;k<_nVar;k++)
712 cout<<_externalStates[k]<<endl;
715 else if (_limitField[nameOfGroup].bcType==Outlet){
717 for(k=1; k<_nVar; k++)
718 _idm[k] = _idm[k-1] + 1;
720 //Computation of the hydrostatic contribution : scalar product between gravity vector and position vector
721 Cell Cj=_mesh.getCell(j);
722 double hydroPress=Cj.x()*_GravityField3d[0];
724 hydroPress+=Cj.y()*_GravityField3d[1];
726 hydroPress+=Cj.z()*_GravityField3d[2];
728 hydroPress*=_externalStates[0]+_externalStates[_Ndim];//multiplication by rho the total density
730 //Building the external state
731 VecGetValues(_primitiveVars, _nVar, _idm,_Vj);
732 double pression_int=_Vj[1];
733 double pression_ext=_limitField[nameOfGroup].p+hydroPress;
734 double T=_Vj[_nVar-1];
735 double rho_v_int=_fluides[0]->getDensity(pression_int,T);
736 double rho_l_int=_fluides[1]->getDensity(pression_int,T);
737 double rho_v_ext=_fluides[0]->getDensity(pression_ext,T);
738 double rho_l_ext=_fluides[1]->getDensity(pression_ext,T);
740 for(k=0;k<1+_Ndim;k++){
741 _externalStates[k]*=rho_v_ext/rho_v_int;
742 _externalStates[k+1+_Ndim]*=rho_l_ext/rho_l_int;
745 for(k=1; k<_nVar; k++)
746 _idm[k] = _idm[k-1] + 1;
747 VecAssemblyBegin(_Uext);
748 VecAssemblyBegin(_Uextdiff);
749 VecSetValues(_Uext, _nVar, _idm, _externalStates, INSERT_VALUES);
750 VecSetValues(_Uextdiff, _nVar, _idm, _externalStates, INSERT_VALUES);
751 VecAssemblyEnd(_Uext);
752 VecAssemblyEnd(_Uextdiff);
755 cout<<"!!!!!!!!!!!!!!!!! Error IsothermalTwoFluid::setBoundaryState !!!!!!!!!!"<<endl;
756 cout<<"!!!!!!!!!!!!! Boundary condition not set for boundary named"<<nameOfGroup<< ", _limitField[nameOfGroup].bcType= "<<_limitField[nameOfGroup].bcType<<endl;
757 cout<<"Accepted boundary condition are Neumann, Wall, Inlet, and Outlet"<<endl;
758 throw CdmathException("Unknown boundary condition");
762 void IsothermalTwoFluid::addDiffusionToSecondMember
768 double mu1 = _fluides[0]->getViscosity(_Temperature);
769 double mu2 = _fluides[1]->getViscosity(_Temperature);
774 //extraction des valeurs
776 for(int k=1; k<_nVar; k++)
777 _idm[k] = _idm[k-1] + 1;
779 VecGetValues(_primitiveVars, _nVar, _idm, _Vi);
780 if (_verbose && _nbTimeStep%_freqSave ==0)
782 cout << "Contribution diffusion: variables primitives maille " << i<<endl;
783 for(int q=0; q<_nVar; q++)
785 cout << _Vi[q] << endl;
791 for(int k=0; k<_nVar; k++)
792 _idm[k] = _nVar*j + k;
793 VecGetValues(_primitiveVars, _nVar, _idm, _Vj);
797 for(int k=0; k<_nVar; k++)
800 VecGetValues(_Uextdiff, _nVar, _idm, _phi);
801 consToPrim(_phi,_Vj);
804 if (_verbose && _nbTimeStep%_freqSave ==0)
806 cout << "Contribution diffusion: variables primitives maille " <<j <<endl;
807 for(int q=0; q<_nVar; q++)
809 cout << _Vj[q] << endl;
815 double alpha=(_Vj[0]+_Vi[0])/2;
816 //on n'a pas de contribution sur la masse
819 //contribution visqueuse sur la quantite de mouvement
820 for(int k=1; k<_Ndim+1; k++)
822 _phi[k] = _inv_dxi*2/(1/_inv_dxi+1/_inv_dxj)*alpha*mu1*(_Vj[k] - _Vi[k]);//attention car primitif=alpha p u1 u2
823 _phi[k+_Ndim+1] = _inv_dxi*2/(1/_inv_dxi+1/_inv_dxj)*(1-alpha)*mu2*(_Vj[1+k+_Ndim] - _Vi[1+k+_Ndim]);
827 VecSetValuesBlocked(_b, 1, _idm, _phi, ADD_VALUES);
829 if(_verbose && _nbTimeStep%_freqSave ==0)
831 cout << "Contribution diffusion au 2nd membre pour la maille " << i << ": "<<endl;
832 for(int q=0; q<_nVar; q++)
834 cout << _phi[q] << endl;
841 //On change de signe pour l'autre contribution
842 for(int k=0; k<_nVar; k++)
843 _phi[k] *= -_inv_dxj/_inv_dxi;
846 VecSetValuesBlocked(_b, 1, _idm, _phi, ADD_VALUES);
849 if(_verbose && _nbTimeStep%_freqSave ==0)
851 cout << "Contribution diffusion au 2nd membre pour la maille " << j << ": "<<endl;
852 for(int q=0; q<_nVar; q++)
854 cout << _phi[q] << endl;
858 if(_timeScheme==Implicit)
860 cout << "Matrice de diffusion D, pour le couple (" << i << "," << j<< "):" << endl;
861 for(int i=0; i<_nVar; i++)
863 for(int j=0; j<_nVar; j++)
864 cout << _Diffusion[i*_nVar+j]<<", ";
872 void IsothermalTwoFluid::sourceVector(PetscScalar * Si,PetscScalar * Ui,PetscScalar * Vi, int i)
874 double m1=Ui[0],m2=Ui[1+_Ndim],alpha=Vi[0], P=Vi[1];
875 double norm_ur=0, Gamma;
876 for(int k=0; k<_Ndim; k++)
877 norm_ur+=(Vi[2+k]-Vi[2+k+_Ndim])*(Vi[2+k]-Vi[2+k+_Ndim]);
878 norm_ur=sqrt(norm_ur);
880 if(i>=0 &&_Temperature>_Tsat && alpha<1-_precision)
881 Gamma=_heatPowerField(i)/_latentHeat;
884 for(int k=1; k<_Ndim+1; k++)
886 //cout<<"Vi[1+"<<k+_Ndim<<"]="<<Vi[1+k+_Ndim]<<endl;
887 Si[k] =_gravite[k]*m1 -_dragCoeffs[0]*norm_ur*(Vi[1+k]-Vi[1+k+_Ndim])+ Gamma*Vi[1+k+_Ndim];//interfacial velocity= ul
888 Si[k+_Ndim+1] =_gravite[k+_Ndim+1]*m2 + _dragCoeffs[0]*norm_ur*(Vi[1+k]-Vi[1+k+_Ndim])- Gamma*Vi[1+k+_Ndim];
890 if(true){//heated boiling
894 else if (P<_Psat && alpha<1-_precision){//flash boiling
895 Si[0]=-_dHsatl_over_dp*_dp_over_dt(i)/_latentHeat;
896 Si[1+_Ndim]=_dHsatl_over_dp*_dp_over_dt(i)/_latentHeat;
903 if(_timeScheme==Implicit)
905 for(int i=0; i<_nVar*_nVar;i++)
906 _GravityImplicitationMatrix[i] = 0;
907 for(int i=0; i<_nVar/2;i++)
908 _GravityImplicitationMatrix[i*_nVar]=-_gravite[i];
909 for(int i=_nVar/2; i<_nVar;i++)
910 _GravityImplicitationMatrix[i*_nVar+_nVar/2]=-_gravite[i];
913 if(_verbose && _nbTimeStep%_freqSave ==0)
915 cout<<"IsothermalTwoFluid::sourceVector"<<endl;
917 for(int k=0;k<_nVar;k++)
921 for(int k=0;k<_nVar;k++)
925 for(int k=0;k<_nVar;k++)
928 if(_timeScheme==Implicit)
929 displayMatrix(_GravityImplicitationMatrix, _nVar, "Gravity implicitation matrix");
932 void IsothermalTwoFluid::pressureLossVector(PetscScalar * pressureLoss, double K, PetscScalar * Ui, PetscScalar * Vi, PetscScalar * Uj, PetscScalar * Vj)
934 double norm_u1=0, u1_n=0, norm_u2=0, u2_n=0, m1, m2;
935 for(int i=0;i<_Ndim;i++){
936 u1_n += _Uroe[2+i] *_vec_normal[i];
937 u2_n += _Uroe[2+i+_Ndim]*_vec_normal[i];
940 pressureLoss[1+_Ndim]=0;
942 for(int i=0;i<_Ndim;i++)
943 norm_u1 += Vi[1+i]*Vi[1+i];
944 norm_u1=sqrt(norm_u1);
946 for(int i=0;i<_Ndim;i++)
947 pressureLoss[1+i]=-K*m1*norm_u1*Vi[1+i];
950 for(int i=0;i<_Ndim;i++)
951 norm_u1 += Vj[1+i]*Vj[1+i];
952 norm_u1=sqrt(norm_u1);
954 for(int i=0;i<_Ndim;i++)
955 pressureLoss[1+i]=-K*m1*norm_u1*Vj[1+i];
958 for(int i=0;i<_Ndim;i++)
959 norm_u2 += Vi[2+i+_Ndim]*Vi[2+i+_Ndim];
960 norm_u2=sqrt(norm_u2);
962 for(int i=0;i<_Ndim;i++)
963 pressureLoss[2+i+_Ndim]=-K*m2*norm_u2*Vi[2+i+_Ndim];
966 for(int i=0;i<_Ndim;i++)
967 norm_u2 += Vj[2+i+_Ndim]*Vj[2+i+_Ndim];
968 norm_u2=sqrt(norm_u2);
970 for(int i=0;i<_Ndim;i++)
971 pressureLoss[2+i+_Ndim]=-K*m2*norm_u2*Vj[2+i+_Ndim];
973 if(_verbose && _nbTimeStep%_freqSave ==0)
975 cout<<"IsothermalTwoFluid::pressureLossVector K= "<<K<<endl;
977 for(int k=0;k<_nVar;k++)
981 for(int k=0;k<_nVar;k++)
985 for(int k=0;k<_nVar;k++)
989 for(int k=0;k<_nVar;k++)
992 cout<<"pressureLoss="<<endl;
993 for(int k=0;k<_nVar;k++)
994 cout<<pressureLoss[k]<<", ";
999 void IsothermalTwoFluid::porosityGradientSourceVector()
1001 double u1_ni=0, u1_nj=0, u2_ni=0, u2_nj=0, rho1i, rho2i, rho1j, rho2j, pi=_Vi[1], pj=_Vj[1], pij1, pij2, alphaij=_Uroe[0];
1002 for(int i=0;i<_Ndim;i++) {
1003 u1_ni += _Vi[2+i]*_vec_normal[i];
1004 u2_ni += _Vi[2+_Ndim+i]*_vec_normal[i];
1005 u1_nj += _Vj[2+i]*_vec_normal[i];
1006 u2_nj += _Vj[2+_Ndim+i]*_vec_normal[i];
1008 _porosityGradientSourceVector[0]=0;
1009 _porosityGradientSourceVector[1+_Ndim]=0;
1010 rho1i = _fluides[0]->getDensity(pi, _Temperature);
1011 rho2i = _fluides[1]->getDensity(pi, _Temperature);
1012 rho1j = _fluides[0]->getDensity(pj, _Temperature);
1013 rho2j = _fluides[1]->getDensity(pj, _Temperature);
1014 pij1=(pi+pj)/2+rho1i*rho1j/2/(rho1i+rho1j)*(u1_ni-u1_nj)*(u1_ni-u1_nj);
1015 pij2=(pi+pj)/2+rho2i*rho2j/2/(rho2i+rho2j)*(u2_ni-u2_nj)*(u2_ni-u2_nj);
1016 for(int i=0;i<_Ndim;i++){
1017 _porosityGradientSourceVector[1+i] =alphaij*pij1*(_porosityi-_porosityj)*2/(1/_inv_dxi+1/_inv_dxj);
1018 _porosityGradientSourceVector[2+_Ndim+i]=alphaij*pij2*(_porosityi-_porosityj)*2/(1/_inv_dxi+1/_inv_dxj);
1022 /* Funtion of equations of states */
1023 double IsothermalTwoFluid::ecartPression(double m1,double m2, double alpha, double e1, double e2){
1024 if(alpha>_precision*_precision&& alpha<1-_precision*_precision)
1025 return _fluides[0]->getPressure((m1/alpha)*e1,m1/alpha) - _fluides[1]->getPressure((m2/(1-alpha))*e2,m2/(1-alpha));
1026 else if(alpha<=_precision*_precision)
1028 //cout<<"Warning ecartPression, alpha close to 0"<<endl;
1029 // if(m1<_precision*_precision*_precision)
1032 return alpha/_precision*_precision;
1036 //cout<<"Warning ecartPression, alpha close to 1"<<endl;
1037 // if(m2<_precision*_precision*_precision)
1040 return -(1-alpha)/_precision*_precision;
1044 double IsothermalTwoFluid::ecartPressionDerivee(double m1,double m2, double alpha, double e1, double e2){
1045 if(alpha>_precision*_precision && alpha<1-_precision*_precision )
1046 return -(m1/alpha)/alpha*e1*_fluides[0]->getPressureDerivativeRhoE() - (m2/(1-alpha))/(1-alpha)*e2*_fluides[1]->getPressureDerivativeRhoE();
1047 else if (alpha<_precision*_precision)
1048 return -1/_precision*_precision;
1050 return 1/_precision*_precision;
1053 double IsothermalTwoFluid::intPressDef(double alpha, double u_r2, double rho1, double rho2)
1055 return _intPressCoeff*alpha*(1-alpha)*rho1*rho2*u_r2/( alpha*rho2+(1-alpha)*rho1)
1056 +alpha*(1-alpha)*rho1*rho2*u_r2/((alpha*rho2+(1-alpha)*rho1)*(alpha*rho2+(1-alpha)*rho1)*(alpha*rho2+(1-alpha)*rho1)*(alpha*rho2+(1-alpha)*rho1))*u_r2
1057 *(alpha*alpha*rho2-(1-alpha)*(1-alpha)*rho1)
1058 *(alpha*alpha*rho2*rho2/(_fluides[0]->vitesseSonTemperature(_Temperature,rho1)*_fluides[0]->vitesseSonTemperature(_Temperature,rho1))
1059 -(1-alpha)*(1-alpha)*rho1*rho1/(_fluides[1]->vitesseSonTemperature(_Temperature,rho2)*_fluides[1]->vitesseSonTemperature(_Temperature,rho2)));
1062 void IsothermalTwoFluid::entropicShift(double* n)
1064 vector< double > pol_car;
1067 double u1_n = 0, u1_2 = 0, u2_n = 0, u2_2 = 0, u_r2 = 0;
1068 for(int i=0;i<_Ndim;i++)
1070 u1_2 += _l[2+i]*_l[2+i];
1071 u1_n += _l[2+i]*n[i];
1072 u2_2 += _l[1+i+1+_Ndim]*_l[1+i+1+_Ndim];
1073 u2_n += _l[1+i+1+_Ndim]*n[i];
1074 u_r2 += (_l[2+i]-_l[1+i+1+_Ndim])*(_l[2+i]-_l[1+i+1+_Ndim]);
1076 double alpha = _l[0];
1078 double rho1 = _fluides[0]->getDensity(p, _Temperature);
1079 double rho2 = _fluides[1]->getDensity(p, _Temperature);
1080 double dpi1 = intPressDef(alpha, u_r2, rho1, rho2);
1082 double invcsq1 = 1/_fluides[0]->vitesseSonTemperature(_Temperature,rho1);
1084 double invcsq2 = 1/_fluides[1]->vitesseSonTemperature(_Temperature,rho2);
1087 pol_car= Polynoms::polynome_caracteristique(alpha, 1-alpha, u1_n, u2_n, rho1, rho2, invcsq1, invcsq2, dpi1, dpi2);
1088 for(int ct=0;ct<4;ct++){
1089 if (abs(pol_car[ct])<_precision*_precision)
1092 vector< complex<double> > vp_left = getRacines(pol_car);
1093 int taille_vp_left = Polynoms::new_tri_selectif(vp_left,vp_left.size(),_precision);
1095 if(_verbose && _nbTimeStep%_freqSave ==0)
1097 cout<<"Entropic shift left eigenvalues: "<<endl;
1098 for(unsigned int ct =0; ct<vp_left.size(); ct++)
1099 cout<<"("<< vp_left[ct].real()<< ", " <<vp_left[ct].imag() << ")";
1107 for(int i=0;i<_Ndim;i++)
1109 u1_2 += _r[2+i]*_r[2+i];
1110 u1_n += _r[2+i]*n[i];
1111 u2_2 += _r[1+i+1+_Ndim]*_r[1+i+1+_Ndim];
1112 u2_n += _r[1+i+1+_Ndim]*n[i];
1113 u_r2 += (_r[2+i]-_r[1+i+1+_Ndim])*(_r[2+i]-_r[1+i+1+_Ndim]);
1117 rho1 = _fluides[0]->getDensity(p, _Temperature);
1118 rho2 = _fluides[1]->getDensity(p, _Temperature);
1119 dpi1 = intPressDef(alpha, u_r2, rho1, rho2);
1121 invcsq1 = 1/_fluides[0]->vitesseSonTemperature(_Temperature,rho1);
1123 invcsq2 = 1/_fluides[1]->vitesseSonTemperature(_Temperature,rho2);
1126 pol_car= Polynoms::polynome_caracteristique(alpha, 1-alpha, u1_n, u2_n, rho1, rho2, invcsq1, invcsq2, dpi1, dpi2);
1127 for(int ct=0;ct<4;ct++){
1128 if (abs(pol_car[ct])<_precision*_precision)
1131 vector< complex<double> > vp_right = getRacines(pol_car);
1132 int taille_vp_right = Polynoms::new_tri_selectif(vp_right,vp_right.size(),_precision);
1134 if(_verbose && _nbTimeStep%_freqSave ==0)
1136 cout<<"Entropic shift right eigenvalues: "<<endl;
1137 for(unsigned int ct =0; ct<vp_right.size(); ct++)
1138 cout<<"("<<vp_right[ct].real()<< ", " <<vp_right[ct].imag() <<")";
1141 _entropicShift[0] = abs(vp_left[0]-vp_right[0]);
1142 _entropicShift[2] = abs(vp_left[taille_vp_left-1]-vp_right[taille_vp_right-1]);
1143 _entropicShift[1]=0;
1144 for(int i=1;i<min(taille_vp_right-1,taille_vp_left-1);i++)
1145 _entropicShift[1] = max(_entropicShift[1],abs(vp_left[i]-vp_right[i]));
1146 if(_verbose && _nbTimeStep%_freqSave ==0)
1148 cout<<"eigenvalue jumps "<<endl;
1149 cout<< _entropicShift[0] << ", " << _entropicShift[1] << ", "<< _entropicShift[2] <<endl;
1153 void IsothermalTwoFluid::computeScaling(double maxvp)
1155 // double alphaScaling;
1156 // if(_guessalpha>_precision && _guessalpha<1-_precision)
1157 // alphaScaling=_guessalpha;
1159 // alphaScaling=0.5;
1161 _blockDiag[0]=1;//alphaScaling;
1162 _invBlockDiag[0]=1;//_blockDiag[0];
1163 _blockDiag[1+_Ndim]=1;//-alphaScaling;
1164 _invBlockDiag[1+_Ndim]=1.0;//_blockDiag[1+_Ndim];
1165 for(int q=1; q<_Ndim+1; q++)
1167 _blockDiag[q]=1/(maxvp*maxvp);
1168 _invBlockDiag[q]=1;//_blockDiag[q];
1169 _blockDiag[q+1+_Ndim]=1/(maxvp*maxvp);
1170 _invBlockDiag[q+1+_Ndim]=1;//_blockDiag[q+1+_Ndim];
1174 void IsothermalTwoFluid::jacobian(const int &j, string nameOfGroup,double * normale)
1177 for(k=0; k<_nVar*_nVar;k++)
1178 _Jcb[k] = 0;//No implicitation at this stage
1180 // loop on boundaries
1181 if (_limitField[nameOfGroup].bcType==Wall)
1183 for(k=0; k<_nVar;k++)
1184 _Jcb[k*_nVar + k] = 1;
1185 for(k=1; k<1+_Ndim;k++)
1186 for(int l=1; l<1+_Ndim;l++){
1187 _Jcb[k*_nVar + l] -= 2*normale[k-1]*normale[l-1];
1188 _Jcb[(k+1+_Ndim)*_nVar + l+1+_Ndim] -= 2*normale[k-1]*normale[l-1];
1192 else if (_limitField[nameOfGroup].bcType==Inlet)
1195 _Jcb[(1+_Ndim)*_nVar +1+_Ndim] = 1;
1196 _Jcb[_nVar]=_limitField[nameOfGroup].v_x[0];
1197 _Jcb[(2+_Ndim)*_nVar +1+_Ndim] =_limitField[nameOfGroup].v_x[1];
1200 _Jcb[2*_nVar]=_limitField[nameOfGroup].v_y[0];
1201 _Jcb[(3+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_y[1];
1204 _Jcb[3*_nVar]=_limitField[nameOfGroup].v_z[0];
1205 _Jcb[(4+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_z[1];
1210 // not wall, not inlet
1211 else if (_limitField[nameOfGroup].bcType==Outlet){
1213 for(k=1; k<_nVar;k++)
1214 {_idm[k] = _idm[k-1] + 1;}
1215 VecGetValues(_conservativeVars, _nVar, _idm, _phi);
1216 VecGetValues(_primitiveVars, _nVar, _idm, _externalStates);
1218 else if (_limitField[nameOfGroup].bcType!=Neumann && _limitField[nameOfGroup].bcType!=InletPressure)// not wall, not inlet, not outlet
1220 cout << "group named "<<nameOfGroup << " : unknown boundary condition" << endl;
1221 throw CdmathException("IsothermalTwoFluid::jacobianDiff: This boundary condition is not treated");
1225 void IsothermalTwoFluid::jacobianDiff(const int &j, string nameOfGroup)
1229 for(k=0; k<_nVar*_nVar;k++)
1231 if (_limitField[nameOfGroup].bcType==Wall){
1233 _JcbDiff[(1+_Ndim)*_nVar +1+_Ndim] = 1;
1234 _JcbDiff[_nVar]=_limitField[nameOfGroup].v_x[0];
1235 _JcbDiff[(2+_Ndim)*_nVar +1+_Ndim] =_limitField[nameOfGroup].v_x[1];
1238 _JcbDiff[2*_nVar]=_limitField[nameOfGroup].v_y[0];
1239 _JcbDiff[(3+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_y[1];
1243 _JcbDiff[3*_nVar]=_limitField[nameOfGroup].v_z[0];
1244 _JcbDiff[(4+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_z[1];
1247 } else if (_limitField[nameOfGroup].bcType==Inlet){
1250 _JcbDiff[(1+_Ndim)*_nVar +1+_Ndim] = 1;
1251 _JcbDiff[_nVar]=_limitField[nameOfGroup].v_x[0];
1252 _JcbDiff[(2+_Ndim)*_nVar +1+_Ndim] =_limitField[nameOfGroup].v_x[1];
1255 _JcbDiff[2*_nVar]=_limitField[nameOfGroup].v_y[0];
1256 _JcbDiff[(3+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_y[1];
1260 _JcbDiff[3*_nVar]=_limitField[nameOfGroup].v_z[0];
1261 _JcbDiff[(4+_Ndim)*_nVar +1+_Ndim]= _limitField[nameOfGroup].v_z[1];
1265 } else if (_limitField[nameOfGroup].bcType==Outlet){
1267 //extraction de l etat courant et primitives
1269 for(k=1; k<_nVar;k++)
1270 {_idm[k] = _idm[k-1] + 1;}
1271 VecGetValues(_conservativeVars, _nVar, _idm, _phi);
1272 VecGetValues(_primitiveVars, _nVar, _idm, _externalStates);
1275 else if (_limitField[nameOfGroup].bcType!=Neumann && _limitField[nameOfGroup].bcType!=InletPressure){
1276 cout<<"Condition limite non traitee pour le bord "<<nameOfGroup<< endl;
1277 throw CdmathException("IsothermalTwoFluid::jacobianDiff: Condition limite non traitee");
1281 void IsothermalTwoFluid::primToCons(const double *P, const int &i, double *W, const int &j){
1284 W[j*_nVar] = P[i*_nVar]*_fluides[0]->getDensity(P[i*_nVar+1],_Temperature);
1285 W[j*_nVar+1+_Ndim] = (1-P[i*_nVar])*_fluides[1]->getDensity(P[i*_nVar+1],_Temperature);
1286 for(int k=0; k<_Ndim; k++)
1288 W[j*_nVar+(k+1)] = W[j*_nVar]*P[i*_nVar+(k+2)];
1289 W[j*_nVar+(k+1)+1+_Ndim] = W[j*_nVar+1+_Ndim]*P[i*_nVar+(k+2)+_Ndim];
1294 void IsothermalTwoFluid::consToPrim(const double *Wcons, double* Wprim,double porosity)//To do: treat porosity
1299 double m2=Wcons[_Ndim+1];
1300 double e1 = _internalEnergy1;
1301 double e2 = _internalEnergy2;
1303 _minm1=min(m1,_minm1);
1304 _minm2=min(m2,_minm2);
1305 if(m1<-_precision || m2<-_precision)
1307 if(fabs(m1)<_precision*_precision)
1310 Wprim[1]=_fluides[1]->getPressure(m2*e2,m2);
1312 for(int idim=0; idim<_Ndim; idim++)
1314 Wprim[2+_Ndim+idim] = Wcons[2+_Ndim+idim]/Wcons[1+_Ndim];
1315 Wprim[2+idim] = Wprim[2+_Ndim+idim];
1318 else if(fabs(m2)<_precision*_precision)
1321 Wprim[1]=_fluides[0]->getPressure(m1*e1,m1);
1322 for(int idim=0; idim<_Ndim; idim++)
1324 Wprim[2+idim] = Wcons[1+idim]/Wcons[0];
1325 Wprim[2+_Ndim+idim] = Wprim[2+idim];
1330 for(int idim=0; idim<_Ndim; idim++)
1332 Wprim[2+idim] = Wcons[1+idim]/Wcons[0];
1333 Wprim[2+_Ndim+idim] = Wcons[2+_Ndim+idim]/Wcons[1+_Ndim];
1335 double alphanewton, alphainf=0, alphasup=1;
1336 int iterMax=50, iter=0;
1338 double dp=ecartPression( m1, m2, _guessalpha, e1, e2);
1339 double dpprim=ecartPressionDerivee( m1, m2, _guessalpha, e1, e2);
1341 while(fabs(dp)>1e3*_precision && iter<iterMax)
1345 // alphainf = _guessalpha;
1347 // alphansup = _guessalpha;
1349 // _guessalpha = (alphainf+alphansup)/2;
1352 alphainf = _guessalpha;
1354 alphasup = _guessalpha;
1356 alphanewton = _guessalpha-dp/dpprim;
1358 if(alphanewton<=alphainf)
1360 _guessalpha = (9*alphainf+alphasup)/10;
1361 //cout<< "dichotomie"<<endl;
1363 else if(alphanewton>=alphasup)
1365 _guessalpha = (alphainf+9*alphasup)/10;
1366 //cout<< "dichotomie"<<endl;
1369 _guessalpha=alphanewton;
1372 if(_verbose && _nbTimeStep%_freqSave ==0)
1373 cout<<"consToPrim diphasique iter= " <<iter<<" dp= " << dp<<" dpprim= " << dpprim<< " _guessalpha= " << _guessalpha<<endl;
1374 dp=ecartPression( m1, m2, _guessalpha, e1, e2);
1375 dpprim=ecartPressionDerivee( m1, m2, _guessalpha, e1, e2);
1379 if(_verbose && _nbTimeStep%_freqSave ==0)
1384 _err_press_max = max(_err_press_max,fabs(dp/1.e5));
1385 // if(_guessalpha>0.5)
1391 Wprim[1]=_fluides[0]->getPressure((m1/_guessalpha)*e1,m1/_guessalpha);
1393 Wprim[1]=_fluides[1]->getPressure((m2/(1-_guessalpha))*e2,m2/(1-_guessalpha));
1394 Wprim[0]=_guessalpha;
1397 cout << "pressure = "<< Wprim[1] << " < 0 " << endl;
1398 cout << "Conservative state = ";
1399 for(int k=0; k<_nVar; k++){
1400 cout<<Wcons[k]<<", ";
1403 *_runLogFile<< "IsothermalTwoFluid::consToPrim: negative pressure = "<< Wprim[1] << " < 0 " << endl;
1404 throw CdmathException("IsothermalTwoFluid::consToPrim: negative pressure");
1408 Vector IsothermalTwoFluid::convectionFlux(Vector U,Vector V, Vector normale, double porosity){
1410 cout<<"Ucons"<<endl;
1412 cout<<"Vprim"<<endl;
1416 double phim1=U(0);//phi alpha1 rho1
1417 double phim2=U(1+_Ndim);//phi alpha2 rho2
1418 Vector phiq1(_Ndim),phiq2(_Ndim);//phi alpha1 rho1 u1, phi alpha2 rho2 u2
1419 for(int i=0;i<_Ndim;i++){
1421 phiq2(i)=U(2+_Ndim+i);
1424 double pression=V(1);
1425 Vector vitesse1(_Ndim),vitesse2(_Ndim);
1426 for(int i=0;i<_Ndim;i++){
1428 vitesse2(i)=V(2+_Ndim+i);
1431 double vitesse1n=vitesse1*normale;
1432 double vitesse2n=vitesse2*normale;
1434 double alpha_roe = _Uroe[0];//Toumi formula
1435 // interfacial pressure term (hyperbolic correction)
1436 double dpi = _Uroe[_nVar];
1439 F(0)=phim1*vitesse1n;
1440 F(1+_Ndim)=phim2*vitesse2n;
1441 for(int i=0;i<_Ndim;i++){
1442 F(1+i)=phim1*vitesse1n*vitesse1(i)+(alpha_roe*pression+dpi*alpha)*porosity*normale(i);
1443 F(2+_Ndim+i)=phim2*vitesse2n*vitesse2(i)+((1-alpha_roe)*pression-dpi*alpha)*normale(i)*porosity;
1447 cout<<"Flux F(U,V)"<<endl;
1454 Vector IsothermalTwoFluid::staggeredVFFCFlux()
1456 if(_spaceScheme!=staggered || _nonLinearFormulation!=VFFC)
1457 throw CdmathException("IsothermalTwoFluid::staggeredVFFCFlux: staggeredVFFCFlux method should be called only for VFFC formulation and staggered upwinding");
1458 else//_spaceScheme==staggered
1461 double alpha_roe = _Uroe[0];//Toumi formula
1462 // interfacial pressure term (hyperbolic correction)
1463 double dpi = _Uroe[_nVar];
1465 double u1ijn=0, u2ijn=0, phialphaq1n=0, phialphaq2n=0;
1466 for(int idim=0;idim<_Ndim;idim++){//URoe = alpha, p, u1, u2, dpi
1467 u1ijn+=_vec_normal[idim]*_Uroe[2+idim];
1468 u2ijn+=_vec_normal[idim]*_Uroe[2+_Ndim+idim];
1472 for(int idim=0;idim<_Ndim;idim++)
1473 phialphaq1n+=_vec_normal[idim]*_Ui[1+idim];//phi alpha rho u n
1475 for(int idim=0;idim<_Ndim;idim++)
1476 Fij(1+idim)=phialphaq1n*_Vi[2+idim]+(alpha_roe*_Vj[1]*_porosityj+dpi*_Vi[0]*_porosityi)*_vec_normal[idim];
1480 for(int idim=0;idim<_Ndim;idim++)
1481 phialphaq2n+=_vec_normal[idim]*_Uj[1+idim];//phi alpha rho u n
1483 for(int idim=0;idim<_Ndim;idim++)
1484 Fij(1+idim)=phialphaq2n*_Vj[2+idim]+(alpha_roe*_Vi[1]*_porosityi+dpi*_Vj[0]*_porosityj)*_vec_normal[idim];
1489 for(int idim=0;idim<_Ndim;idim++)
1490 phialphaq2n+=_vec_normal[idim]*_Ui[2+_Ndim+idim];//phi alpha rho u n
1491 Fij(1+_Ndim)=phialphaq2n;
1492 for(int idim=0;idim<_Ndim;idim++)
1493 Fij(2+_Ndim+idim)=phialphaq2n*_Vi[2+_Ndim+idim]+((1-alpha_roe)*_Vj[1]*_porosityj-dpi*_Vi[0]*_porosityi)*_vec_normal[idim];
1497 for(int idim=0;idim<_Ndim;idim++)
1498 phialphaq2n+=_vec_normal[idim]*_Uj[2+_Ndim+idim];//phi alpha rho u n
1499 Fij(1+_Ndim)=phialphaq2n;
1500 for(int idim=0;idim<_Ndim;idim++)
1501 Fij(2+_Ndim+idim)=phialphaq2n*_Vj[2+_Ndim+idim]+((1-alpha_roe)*_Vi[1]*_porosityi-dpi*_Vj[0]*_porosityj)*_vec_normal[idim];
1507 void IsothermalTwoFluid::applyVFRoeLowMachCorrections(bool isBord, string groupname)
1509 if(_nonLinearFormulation!=VFRoe)
1510 throw CdmathException("IsothermalTwoFluid::applyVFRoeLowMachCorrections: applyVFRoeLowMachCorrections method should be called only for VFRoe formulation");
1511 else//_nonLinearFormulation==VFRoe
1513 if(_spaceScheme==lowMach){
1514 double u1_2=0, u2_2=0;
1515 for(int i=0;i<_Ndim;i++){
1516 u1_2 += _Uroe[2+i]*_Uroe[2+i];
1517 u2_2 += _Uroe[2+i+_Ndim]*_Uroe[2+i+_Ndim];
1520 double c = _maxvploc;//mixture sound speed
1521 double M=max(sqrt(u1_2),sqrt(u2_2))/c;//Mach number
1522 _Vij[1]=M*_Vij[1]+(1-M)*(_Vi[1]+_Vj[1])/2;
1523 primToCons(_Vij,0,_Uij,0);
1525 else if(_spaceScheme==pressureCorrection)
1527 if(_pressureCorrectionOrder>2)
1528 throw CdmathException("IsothermalTwoFluid::applyVFRoeLowMachCorrections pressure correction order can be only 1 or 2 for Isothermal two-fluid model");
1530 double norm_uij=0, uij_n=0, ui_n=0, uj_n=0;//mean velocities
1531 double rho1 = _fluides[0]->getDensity(_Uroe[1],_Temperature);
1532 double rho2 = _fluides[1]->getDensity(_Uroe[1],_Temperature);
1533 double m1=_Uroe[0]*rho1, m2=(1-_Uroe[0])*rho2;
1535 for(int i=0;i<_Ndim;i++)
1537 norm_uij += (m1*_Uroe[2+i]+m2*_Uroe[2+i+_Ndim])*(m1*_Uroe[2+i]+m2*_Uroe[2+i+_Ndim]);
1538 uij_n += (m1*_Uroe[2+i]+m2*_Uroe[2+i+_Ndim])*_vec_normal[i];
1539 ui_n += _Vi[2+i]*_vec_normal[i];
1540 uj_n += _Vj[2+i]*_vec_normal[i];
1542 norm_uij=sqrt(norm_uij)/rhom;
1544 if(norm_uij>_precision)//avoid division by zero
1545 _Vij[1]=(_Vi[1]+_Vj[1])/2 + uij_n/norm_uij*(_Vj[1]-_Vi[1])/4 - rhom*norm_uij*(uj_n-ui_n)/4;
1547 _Vij[1]=(_Vi[1]+_Vj[1])/2 - rhom*norm_uij*(uj_n-ui_n)/4;
1550 else if(_spaceScheme==staggered)
1553 double rho1 = _fluides[0]->getDensity(_Uroe[1],_Uroe[_nVar-1]);
1554 double rho2 = _fluides[1]->getDensity(_Uroe[1],_Uroe[_nVar-1]);
1555 double m1=_Uroe[0]*rho1, m2=(1-_Uroe[0])*rho2;
1557 for(int i=0;i<_Ndim;i++)
1558 qij_n += (m1*_Uroe[2+i]+m2*_Uroe[2+i+_Ndim])*_vec_normal[i];
1563 for(int i=0;i<_Ndim;i++)
1565 _Vij[2+i] =_Vi[2+i];
1566 _Vij[2+i+_Ndim] =_Vi[2+i+_Ndim];
1572 for(int i=0;i<_Ndim;i++)
1574 _Vij[2+i] =_Vj[2+i];
1575 _Vij[2+i+_Ndim] =_Vj[2+i+_Ndim];
1578 primToCons(_Vij,0,_Uij,0);
1583 void IsothermalTwoFluid::testConservation()
1585 double SUM, DELTA, x;
1587 for(int i=0; i<_nVar; i++)
1591 cout << "Masse totale phase " << 0 <<" (kg): ";
1592 else if( i == 1+_Ndim)
1593 cout << "Masse totale phase " << 1 <<" (kg): ";
1597 cout << "Quantite de mouvement totale phase 0 (kg.m.s^-1): ";
1599 cout << "Quantite de mouvement totale phase 1 (kg.m.s^-1): ";
1605 for(int j=0; j<_Nmailles; j++)
1607 VecGetValues(_old, 1, &I, &x);//on recupere la valeur du champ
1608 SUM += x*_mesh.getCell(j).getMeasure();
1609 VecGetValues(_newtonVariation, 1, &I, &x);//on recupere la variation du champ
1610 DELTA += x*_mesh.getCell(j).getMeasure();
1613 if(fabs(SUM)>_precision)
1614 cout << SUM<< ", variation relative: " << fabs(DELTA /SUM) << endl;
1616 cout << " a une somme nulle, variation absolue: " << fabs(DELTA) << endl;
1620 void IsothermalTwoFluid::save(){
1621 string prim(_path+"/IsothermalTwoFluidPrim_");
1622 string cons(_path+"/IsothermalTwoFluidCons_");
1627 for (long i = 0; i < _Nmailles; i++){
1628 /* j = 0 : void fraction
1630 j = 2, 3, 4: velocity phase 1
1631 j = 5, 6, 7: velocity phase 2 */
1632 for (int j = 0; j < _nVar; j++){
1634 VecGetValues(_primitiveVars,1,&Ii,&_VV(i,j));
1637 if(_saveConservativeField){
1638 for (long i = 0; i < _Nmailles; i++){
1639 for (int j = 0; j < _nVar; j++){
1641 // cout<<"i= "<<i<< " j= "<<j<<" UU(i,j)= "<<_UU(i,j)<<endl;
1642 VecGetValues(_conservativeVars,1,&Ii,&_UU(i,j));
1645 _UU.setTime(_time,_nbTimeStep);
1647 _VV.setTime(_time,_nbTimeStep);
1648 if (_nbTimeStep ==0 || _restartWithNewFileName){
1649 string prim_suppress ="rm -rf "+prim+"_*";
1650 string cons_suppress ="rm -rf "+cons+"_*";
1651 system(prim_suppress.c_str());//Nettoyage des précédents calculs identiques
1652 system(cons_suppress.c_str());//Nettoyage des précédents calculs identiques
1653 _VV.setInfoOnComponent(0,"Void_fraction");
1654 _VV.setInfoOnComponent(1,"Pressure_(Pa)");
1655 _VV.setInfoOnComponent(2,"Velocity1_x_m/s");
1657 _VV.setInfoOnComponent(3,"Velocity1_y_m/s");
1659 _VV.setInfoOnComponent(4,"Velocity1_z_m/s");
1661 _VV.setInfoOnComponent(2+_Ndim,"Velocity2_x_m/s");
1663 _VV.setInfoOnComponent(3+_Ndim,"Velocity2_y_m/s");
1665 _VV.setInfoOnComponent(4+_Ndim,"Velocity2_z_m/s");
1680 if(_saveConservativeField){
1681 _UU.setInfoOnComponent(0,"Partial_density1");// (kg/m^3)
1682 _UU.setInfoOnComponent(1,"Momentum1_x");// phase1 (kg/m^2/s)
1684 _UU.setInfoOnComponent(2,"Momentum1_y");// phase1 (kg/m^2/s)
1686 _UU.setInfoOnComponent(3,"Momentum1_z");// phase1 (kg/m^2/s)
1688 _UU.setInfoOnComponent(1+_Ndim,"Partial_density2");// phase2 (kg/m^3)
1689 _UU.setInfoOnComponent(2+_Ndim,"Momentum2_x");// phase2 (kg/m^2/s)
1691 _UU.setInfoOnComponent(3+_Ndim,"Momentum2_y");// phase2 (kg/m^2/s)
1693 _UU.setInfoOnComponent(4+_Ndim,"Momentum2_z");// phase2 (kg/m^2/s)
1713 _VV.writeVTK(prim,false);
1716 _VV.writeMED(prim,false);
1723 if(_saveConservativeField){
1727 _UU.writeVTK(cons,false);
1730 _UU.writeMED(cons,false);
1739 for (long i = 0; i < _Nmailles; i++){
1740 // j = 0 : concentration, j=1 : pressure; j = _nVar - 1: temperature; j = 2,..,_nVar-2: velocity
1741 for (int j = 0; j < _Ndim; j++)//On récupère les composantes de vitesse
1744 VecGetValues(_primitiveVars,1,&Ii,&_Vitesse1(i,j));
1745 Ii=i*_nVar +2+j+_Ndim;
1746 VecGetValues(_primitiveVars,1,&Ii,&_Vitesse2(i,j));
1748 for (int j = _Ndim; j < 3; j++){//On met à zero les composantes de vitesse si la dimension est <3
1753 _Vitesse1.setTime(_time,_nbTimeStep);
1754 _Vitesse2.setTime(_time,_nbTimeStep);
1755 if (_nbTimeStep ==0 || _restartWithNewFileName){
1756 _Vitesse1.setInfoOnComponent(0,"Velocity_x_(m/s)");
1757 _Vitesse1.setInfoOnComponent(1,"Velocity_y_(m/s)");
1758 _Vitesse1.setInfoOnComponent(2,"Velocity_z_(m/s)");
1760 _Vitesse2.setInfoOnComponent(0,"Velocity_x_(m/s)");
1761 _Vitesse2.setInfoOnComponent(1,"Velocity_y_(m/s)");
1762 _Vitesse2.setInfoOnComponent(2,"Velocity_z_(m/s)");
1767 _Vitesse1.writeVTK(prim+"_GasVelocity");
1768 _Vitesse2.writeVTK(prim+"_LiquidVelocity");
1771 _Vitesse1.writeMED(prim+"_GasVelocity");
1772 _Vitesse2.writeMED(prim+"_LiquidVelocity");
1775 _Vitesse1.writeCSV(prim+"_GasVelocity");
1776 _Vitesse2.writeCSV(prim+"_LiquidVelocity");
1784 _Vitesse1.writeVTK(prim+"_GasVelocity",false);
1785 _Vitesse2.writeVTK(prim+"_LiquidVelocity",false);
1788 _Vitesse1.writeMED(prim+"_GasVelocity",false);
1789 _Vitesse2.writeMED(prim+"_LiquidVelocity",false);
1792 _Vitesse1.writeCSV(prim+"_GasVelocity");
1793 _Vitesse2.writeCSV(prim+"_LiquidVelocity");
1799 if (_restartWithNewFileName)
1800 _restartWithNewFileName=false;