Salome HOME
Some code factoring
[tools/solverlab.git] / CoreFlows / Models / inc / ProblemFluid.hxx
1 //============================================================================
2 // Name        : ProblemCoreFlows
3 // Author      : M. Ndjinga
4 // Version     :
5 // Copyright   : CEA Saclay 2014
6 // Description : Generic class for thermal hydraulics problems
7 //============================================================================
8
9 /*! \class ProblemFluid ProblemFluid.hxx "ProblemFluid.hxx"
10  *  \brief Factorises the methods that are common to the non scalar models (fluid models)
11  *  \details Common functions to fluid models
12  */
13 #ifndef PROBLEMFLUID_HXX_
14 #define PROBLEMFLUID_HXX_
15
16 #include "Fluide.h"
17 #include "ProblemCoreFlows.hxx"
18 #include "utilitaire_algebre.h"
19
20 using namespace std;
21
22 //! enumeration SpaceScheme
23 /*! Several numerical schemes are available */
24 enum SpaceScheme
25 {
26         upwind,/**<  classical full upwinding scheme (first order in space) */
27         centered,/**<  centered scheme (second order in space) */
28         pressureCorrection,/**<  include a pressure correction in the upwind scheme to increase precision at low Mach numbers */
29         lowMach,/**<  include an upwinding proportional to the Mach numer scheme to increase precision at low Mach numbers */
30         staggered,/**<  scheme inspired by staggered discretisations */
31 };
32
33 //! enumeration NonLinearFormulation
34 /*! the formulation used to compute the non viscous fluxes */
35 enum NonLinearFormulation
36 {
37         Roe,/**< Ph. Roe non linear formulation is used */
38         VFRoe,/**< Masella, Faille and Gallouet non linear formulation is used */
39         VFFC,/**< Ghidaglia, Kumbaro and Le Coq non linear formulation is used */
40         reducedRoe,/**< compacted formulation of Roe scheme without computation of the fluxes */
41 };
42
43 //! enumeration phaseType
44 /*! The material phase can be Gas or liquid  */
45 enum phaseType
46 {
47         Liquid,/**< Material considered is Liquid */
48         Gas/**< Material considered is Gas */
49 };
50
51 //! enumeration BoundaryType
52 /*! Boundary condition type  */
53 enum BoundaryType       {Wall, InnerWall, Inlet, InletPressure, InletRotationVelocity, InletEnthalpy, Outlet, Neumann, NoTypeSpecified};
54 /** \struct LimitField
55  * \brief value of some fields on the boundary  */
56 struct LimitField{
57         LimitField(){bcType=NoTypeSpecified; p=0; v_x=vector<double> (0,0); v_y=vector<double> (0,0); v_z=vector<double> (0,0); T=0; h=0; alpha=0;      conc=0;}
58         LimitField(BoundaryType _bcType,        double _p,      vector<double> _v_x, vector<double> _v_y, vector<double> _v_z,
59                         double _T,      double _h,      double _alpha,  double _conc){
60                 bcType=_bcType; p=_p; v_x=_v_x; v_y=_v_y; v_z=_v_z;     T=_T; h=_h; alpha=_alpha;       conc=_conc;
61         }
62
63         BoundaryType bcType;
64         double p;//For outlet (fluid models)
65         vector<double> v_x; vector<double> v_y; vector<double> v_z;//For wall and inlet (fluid models)
66         double T; //for wall and inlet (DriftModel and FiveEqsTwoFluid) and for Dirichlet (DiffusionEquation)
67         double h; //for inlet (TransportEquation)
68         double alpha; //For inlet (IsothermalTwoFluid and FiveEqsTwoFluid)
69         double conc;//For inlet (DriftModel)
70 };
71
72 class ProblemFluid: public ProblemCoreFlows
73 {
74
75 public :
76         /**\fn
77          * \brief constructeur de la classe ProblemFluid
78          */
79         ProblemFluid(MPI_Comm comm = MPI_COMM_WORLD);
80
81         //Gestion du calcul (interface ICoCo)
82
83         /** \fn initialize
84          * \brief Alocates memory and checks that the mesh, the boundary and the intitial data are set
85          * \Details It is a pure virtual function overloaded y each model.
86          * @param  void
87          *  */
88         virtual void initialize();
89
90         /** \fn terminate
91          * \brief empties the memory
92          * @param void
93          *  */
94         virtual void terminate();
95
96         /** \fn initTimeStep
97          * \brief Sets a new time step dt to be solved later
98          *  @param  dt is  the value of the time step
99          *  \return false if dt <0 et True otherwise
100          *                         */
101         bool initTimeStep(double dt);
102
103         /** \fn computeTimeStep
104          * \brief Proposes a value for the next time step to be solved using mesh data and cfl coefficient
105          *  \return  double dt the proposed time step
106          *  \return  bool stop, true if the calculation should not be continued (stationary state, maximum time or time step numer reached)
107          *  */
108         double computeTimeStep(bool & stop);
109
110         /** \fn abortTimeStep
111          * \brief Reset the time step dt to 0
112          *  */
113         void abortTimeStep();
114
115         /** \fn iterateTimeStep
116          * \brief calls computeNewtonVariation to perform one Newton iteration and tests the convergence
117          * @param
118          * @return boolean ok is true is the newton iteration gave a physically acceptable result
119          * */
120         virtual bool iterateTimeStep(bool &ok);
121
122         /** \fn save
123          * \brief saves the current results in MED or VTK files
124          * \details It is a pure virtual function overloaded in each model
125          * @param  void
126          */
127         virtual void save()=0;
128
129         /** \fn validateTimeStep
130          * \brief Validates the solution computed y solveTimeStep
131          * \details updates the currens time t=t+dt, save unknown fields, resets the time step dt to 0, tests the stationnarity.
132          * c It is a pure virtual function overloaded in each model
133          * @param  void
134          *  */
135         virtual void validateTimeStep();
136
137         /** \fn solveTimeStep
138          * \brief calcule les valeurs inconnues au pas de temps +1 .
139          *  \details c'est une fonction virtuelle, qui surcharge  celle de la classe ProblemCoreFlows
140          *  @param  void
141          *  \return Renvoie false en cas de problème durant le calcul (valeurs non physiques..)
142          *  */
143         virtual bool solveTimeStep();//
144
145         /* Boundary conditions */
146         /** \fn setNeumannBoundaryCondition
147          * \brief adds a new boundary condition of type Neumann
148          * \details
149          * \param [in] string the name of the boundary
150          * \param [out] void
151          *  */
152         void setNeumannBoundaryCondition(string groupName){
153                 _limitField[groupName]=LimitField(Neumann,-1,vector<double>(_Ndim,0),vector<double>(_Ndim,0),vector<double>(_Ndim,0),-1,-1,-1,-1);
154         };
155
156         /** \fn setOutletBoundaryCondition
157          * \brief Adds a new boundary condition of type Outlet
158          * \details
159          * \param [in] string : the name of the boundary
160          * \param [in] double : the value of the pressure at the boundary
161          * \param [out] void
162          *  */
163         void setOutletBoundaryCondition(string groupName,double Pressure){
164                 _limitField[groupName]=LimitField(Outlet,Pressure,vector<double>(_nbPhases,0),vector<double>(_nbPhases,0),vector<double>(_nbPhases,0),-1,-1,-1,-1);
165         };
166
167         /** \fn setOutletBoundaryCondition
168          * \brief Adds a new boundary condition of type Outlet taking into account the hydrostatic pressure variations
169          * \details The pressure is not constant on the boundary but varies linearly with a slope given by the gravity vector
170          * \param [in] string : the name of the boundary
171          * \param [in] double : the value of the pressure at the boundary
172          * \param [in] vector<double> : reference_point position on the boundary where the value Pressure will be imposed
173          * \param [out] void
174          *  */
175         void setOutletBoundaryCondition(string groupName,double referencePressure, vector<double> reference_point){
176                 /* On the boundary we have P-Pref=rho g\cdot(x-xref) */
177                 _gravityReferencePoint=reference_point;
178                 _limitField[groupName]=LimitField(Outlet,referencePressure,vector<double>(_nbPhases,0),vector<double>(_nbPhases,0),vector<double>(_nbPhases,0),-1,-1,-1,-1);
179         };
180
181         /** \fn setBoundaryFields
182          * \brief met à jour  _limitField  ( le type de condition limite )
183          * \details
184          * \param [in] string
185          * \param [out] void
186          *  */
187         void setBoundaryFields(map<string, LimitField> boundaryFields){
188                 _limitField = boundaryFields;
189         };
190
191         /** \fn setViscosity
192          * \brief sets the vector of viscosity coefficients
193          * @param viscosite is a vector of size equal to the number of phases and containing the viscosity of each phase
194          * @return throws an exception if the input vector size is not equal to the number of phases
195          *       * */
196         void setViscosity(vector<double> viscosite){
197                 if(_nbPhases!= viscosite.size())
198                         throw CdmathException("ProblemFluid::setViscosity: incorrect vector size vs number of phases");
199                 for(int i=0;i<_nbPhases;i++)
200                         _fluides[i]->setViscosity(viscosite[i]);
201         };
202
203         /** \fn setConductivity
204          * \brief sets the vector of conductivity coefficients
205          * @param conductivite is a vector of size equal to the number of phases and containing the conductivity of each phase
206          * @return throws an exception if the input vector size is not equal to the number of phases
207          * */
208         void setConductivity(vector<double> conductivite){
209                 if(_nbPhases!= conductivite.size())
210                         throw CdmathException("ProblemFluid::setConductivity: incorrect vector size vs number of phases");
211                 for(int i=0;i<_nbPhases;i++)
212                         _fluides[i]->setConductivity(conductivite[i]);
213         };
214
215         /** \fn setGravity
216          * \brief sets the gravity force in the model
217          * @param gravite is a vector of size equal to the space dimension
218          *                               * */
219         void setGravity(vector<double> gravite){
220                 _GravityField3d = gravite;
221         };
222
223         /** \fn setDragCoeffs
224          * \brief Sets the drag coefficients
225          * @param dragCoeffs is a  vector of size equal to the number of phases and containing the value of the friction coefficient of each phase
226          * @return throws an exception if the input vector size is not equal to the numer of phases
227          * */
228         void setDragCoeffs(vector<double> dragCoeffs){
229                 if(_nbPhases!= dragCoeffs.size())
230                         throw CdmathException("ProblemFluid::setDragCoeffs: incorrect vector size vs number of phases");
231                 for(int i=0;i<_nbPhases;i++)
232                 {
233                         _fluides[i]->setDragCoeffs(dragCoeffs[i]);
234                         _dragCoeffs[i]=dragCoeffs[i];
235                 }
236         };
237
238         /** \fn getNumberOfPhases
239          * \brief The numer of phase (one or two) depending on the model considered
240          * @param void
241          * @return the number of phases considered in the model
242          * */
243         int getNumberOfPhases() const {
244                 return _nbPhases;
245         };
246
247         /** \fn testConservation
248          * \brief Teste et affiche la conservation de masse et de la quantité de mouvement
249          * \Details la fonction est virtuelle pure, on la surcharge dans chacun des modèles
250          * @param void
251          * */
252         virtual void testConservation()=0;
253
254         /** \fn saveVelocity
255          * \brief saves the velocity field in a separate 3D file so that paraview can display the streamlines
256          * @param bool
257          * */
258         void saveVelocity(bool save_v=true){
259                 _saveVelocity=save_v;
260         }
261
262         /** \fn saveConservativeField
263          * \brief saves the conservative fields (density, momentum etc...)
264          * */
265         void saveConservativeField(bool save=true){
266                 _saveConservativeField=save;
267         }
268         /** \fn setEntropicCorrection
269          * \brief include an entropy correction to avoid non entropic solutions
270          * @param boolean that is true if entropy correction should be applied
271          * */
272         void setEntropicCorrection(bool entropyCorr){
273                 _entropicCorrection=entropyCorr;
274         }
275
276         /** \fn setPressureCorrectionOrder
277          * \brief In case a pressure correction scheme is set by a call to setNumericalScheme(pressureCorrection) this function allows the setting of the type of pressure correction to be used
278          * @param int the order of the pressure correction
279         * \details The following treatment is applied depending on the value of the input parameter order
280         * \details 1 -> no pressure correction (pressure correction is applied nowhere in the domain), standard upwind scheme instead is used
281         * \details 2 -> standard pressure correction is applied everywhere in the domain, even at the boundary faces
282         * \details 3 -> standard pressure correction is applied only inside the domain (not at the boundary faces)
283         * \details 4 -> no pressure correction (pressure correction is applied nowhere in the domain), no Riemann problem at wall boundaries (boundary pressure = inner pressure)
284         * \details 5 -> standard pressure correction is applied everywhere in the domain, no Riemann problem at the boundary (boundary pressure = inner pressure)
285         * \details 6 -> standard pressure correction is applied inside the domain and a special pressure correction involving gravity is applied at the boundary, no Riemann problem at wall boundaries (boundary pressure = inner pressure+ source term)
286         * */
287         void setPressureCorrectionOrder(int order){
288                 if( order >6 || order <1)
289                         throw CdmathException("ProblemFluid::setPressureCorrectionOrder Pressure correction order must be an integer between 1 and 4");
290                 else
291                         _pressureCorrectionOrder=order;
292
293                 if(order==1)
294                         _spaceScheme=upwind;
295         }
296
297         // Petsc resolution
298
299         /** \fn setLinearSolver
300          * \brief sets the linear solver and preconditioner
301          * \details virtuelle function overloaded by intanciable classes
302          * @param kspType linear solver type (GMRES or BICGSTAB)
303          * @param pcType preconditioner (ILU,LU or NONE)
304          * @param scaling performs a bancing of the system matrix before calling th preconditioner
305          */
306         void setLinearSolver(linearSolver kspType, preconditioner pcType, double maxIts=50, bool scaling=false)
307         {
308                 ProblemCoreFlows::setLinearSolver(kspType, pcType, maxIts);
309                 _isScaling= scaling;
310         };
311
312         /** \fn setLatentHeat
313          * \brief Sets the value of the latent heat
314          * @param double L, the value of the latent heat
315          * */
316         void setLatentHeat(double L){
317                 _latentHeat=L;
318         }
319
320         /** \fn getLatentHeat
321          * \brief returns the value of the latent heat
322          * @param double L, the value of the latent heat
323          * */
324         double getLatentHeat() const{
325                 return _latentHeat;
326         }
327
328         /** \fn setSatTemp
329          * \brief sets the saturation temperature
330          * @param  Tsat double corresponds to saturation temperature
331          * */
332         void setSatTemp(double Tsat){
333                 _Tsat=Tsat;
334         }
335
336         /** \fn setSatTemp
337          * \brief sets the saturation temperature
338          * @param  Tsat double corresponds to saturation temperature
339          * */
340         double getSatTemp() const {
341                 return _Tsat;
342         }
343
344         /** \fn setSatPressure
345          * \brief sets the saturation pressure
346          * @param  Psat double corresponds to saturation pressure
347          * */
348         void setSatPressure(double Psat, double dHsatl_over_dp=0.05){
349                 _Psat=Psat;
350                 _dHsatl_over_dp=dHsatl_over_dp;
351         }
352
353         /** \fn setPorosityField
354          * \brief set the porosity field;
355          * @param [in] Field porosity field (field on CELLS)
356          * */
357         void setPorosityField(Field Porosity);
358
359         /** \fn getPorosityField
360          * \brief returns the porosity field;
361          * @param
362          * */
363         Field getPorosityField() const {
364                 return _porosityField;
365         }
366
367         /** \fn setPorosityFieldFile
368          * \brief set the porosity field
369          * \details
370          * \param [in] string fileName (including file path)
371          * \param [in] string fieldName
372          * \param [out] void
373          *  */
374         void setPorosityField(string fileName, string fieldName);
375
376         /** \fn setPressureLossField
377          * \brief set the pressure loss coefficients field;
378          * @param [in] Field pressure loss field (field on FACES)
379          * */
380         void setPressureLossField(Field PressureLoss);
381         
382         /** \fn setPressureLossField
383          * \brief set the pressure loss coefficient field
384          * \details localised friction force
385          * \param [in] string fileName (including file path)
386          * \param [in] string fieldName
387          * \param [out] void
388          *  */
389         void setPressureLossField(string fileName, string fieldName);
390
391         /** \fn setSectionField
392          * \brief set the cross section field;
393          * @param [in] Field cross section field (field on CELLS)
394          * */
395         void setSectionField(Field sectionField);
396         
397         /** \fn setSectionField
398          * \brief set the cross section field
399          * \details for variable cross section pipe network
400          * \param [in] string fileName (including file path)
401          * \param [in] string fieldName
402          * \param [out] void
403          *  */
404         void setSectionField(string fileName, string fieldName);
405
406         /** \fn setNonLinearFormulation
407          * \brief sets the formulation used for the computation of non viscous fluxes
408          * \details Roe, VFRoe, VFFC
409          * \param [in] enum NonLinearFormulation
410          * \param [out] void
411          *  */
412         void setNonLinearFormulation(NonLinearFormulation nonLinearFormulation){
413                 //if(nonLinearFormulation != Roe && nonLinearFormulation != VFRoe && nonLinearFormulation != VFFC && nonLinearFormulation!=reducedRoe)
414                 //      throw CdmathException("nonLinearFormulation should be either Roe, VFRoe or VFFC");//extra security for swig binding
415                 _nonLinearFormulation=nonLinearFormulation;
416         }
417
418         /** \fn getNonLinearFormulation
419          * \brief returns the formulation used for the computation of non viscous fluxes
420          * \details Roe, VFRoe, VFFC
421          * \param [in] void
422          * \param [out] enum NonLinearFormulation
423          *  */
424         NonLinearFormulation getNonLinearFormulation() const{
425                 return _nonLinearFormulation;
426         }
427
428         /** \fn usePrimitiveVarsInNewton
429          * \brief use Primitive Vars instead of conservative vars In Newton scheme for implicit schemes
430          * \param [in] bool
431          *  */
432         void usePrimitiveVarsInNewton(bool usePrimitiveVarsInNewton){
433                 _usePrimitiveVarsInNewton=usePrimitiveVarsInNewton;
434         }
435
436         /** \fn getSpaceScheme
437          * \brief returns the  space scheme name
438          * \param [in] void
439          * \param [out] enum SpaceScheme(upwind, centred, pressureCorrection, pressureCorrection, staggered)
440          *  */
441         SpaceScheme getSpaceScheme() const;
442
443         /** \fn setNumericalScheme
444          * \brief sets the numerical method (upwind vs centered and explicit vs implicit)
445          * \details
446          * \param [in] SpaceScheme
447          * \param [in] TimeScheme
448          * \param [out] void
449          *  */
450         void setNumericalScheme(SpaceScheme scheme, TimeScheme method=Explicit);
451
452         /* ICoCo code coupling interface */
453         /*
454         virtual  Field& getInputFieldTemplate(const string& name)=0;//Renvoie le format de champs attendu (maillage, composantes etc)
455         virtual vector<string> getOutputFieldsNames()=0 ;//liste tous les champs que peut fournir le code pour le postraitement
456         virtual Field& getOutputField(const string& nameField )=0;//Renvoie un champs pour le postraitement
457          */
458         /** Set input fields to prepare the simulation or coupling **/
459         vector<string> getInputFieldsNames();
460         void setInputField(const string& nameField, Field& inputField );//supply of a required input field
461         
462         Field getConservativeField() const ;
463         Field getPrimitiveField() const;
464
465 protected :
466         /** Number of phases in the fluid **/
467         int _nbPhases;
468         /** Field of conservative variables (the primitive variables are defined in the mother class ProblemCoreFlows **/
469         Field  _UU;
470         /** Field of interfacial states of the VFRoe scheme **/
471         Field _UUstar, _VVstar;
472
473         SpaceScheme _spaceScheme;
474         /** the formulation used to compute the non viscous fluxes **/
475         NonLinearFormulation _nonLinearFormulation;
476
477         /** PETSc nonlinear solver and line search **/
478         SNES _snes;
479         SNESLineSearch _linesearch;
480         PetscViewer _monitorLineSearch;
481
482         map<string, LimitField> _limitField;
483
484         /** boolean used to specify that an entropic correction should be used **/
485         bool _entropicCorrection;
486         /** Vector containing the eigenvalue jumps for the entropic correction **/
487         vector<double> _entropicShift;
488         /** In case a pressure correction scheme is used some more option regarding the type of pressure correction **/
489         int _pressureCorrectionOrder;
490
491         /** Fluid equation of state **/
492         vector< Fluide* > _fluides;
493         //!Viscosity coefficients 
494         vector<double> _viscosite;
495         //!Conductivity coefficients 
496         vector<double> _conductivite;
497
498         /** Source terms **/
499         vector<double> _gravite, _GravityField3d, _gravityReferencePoint, _dragCoeffs;//_GravityField3d has size _Ndim whereas _gravite has size _Nvar and is usefull for dealing with source term and implicitation of gravity vector
500         double _latentHeat, _Tsat,_Psat,_dHsatl_over_dp;
501         Field _porosityField, _pressureLossField, _dp_over_dt, _sectionField;
502         bool _porosityFieldSet, _pressureLossFieldSet, _sectionFieldSet;
503         double _porosityi, _porosityj;//porosity of the left and right states around an interface
504
505         /** User options **/
506         bool _isScaling;
507         bool _saveVelocity;/* In order to display streamlines with paraview */
508         bool _saveConservativeField;/* Save conservative fields such as density or momentum for instance */
509         bool _saveInterfacialField;/* Save interfacial fields of the VFRoe scheme */
510         bool _usePrimitiveVarsInNewton;
511
512         // Variables du schema numerique 
513         Vec _conservativeVars, _newtonVariation, _bScaling,_old, _primitiveVars, _Uext,_Uextdiff ,_vecScaling,_invVecScaling, _Vext;
514         //courant state vector, vector computed at next time step, second member of the equation
515         PetscScalar *_AroePlus, *_AroeMinus,*_Jcb,*_JcbDiff, *_a, *_blockDiag,  *_invBlockDiag,*_Diffusion, *_GravityImplicitationMatrix;
516         PetscScalar *_Aroe, *_absAroe, *_signAroe, *_invAroe;
517         PetscScalar *_AroeMinusImplicit,*_AroePlusImplicit,*_AroeImplicit,*_absAroeImplicit;//negative part of the roe matrix used in the implicit scheme matrix
518         PetscScalar * _primToConsJacoMat; //Jacobian matrix of the prim-->cons function
519         PetscScalar *_phi, *_Ui, *_Uj,  *_Vi, *_Vj,  *_Si, *_Sj, * _pressureLossVector, * _porosityGradientSourceVector, *_externalStates;
520         double *_Uroe, *_Udiff, *_temp, *_l, *_r,  *_vec_normal;
521         double * _Uij, *_Vij;//Conservative and primitive interfacial states of the VFRoe scheme
522         int *_idm, *_idn;
523         double _inv_dxi,_inv_dxj;//diametre des cellules i et j autour d'une face
524         double _err_press_max,_part_imag_max,_minm1,_minm2;
525         int _nbMaillesNeg, _nbVpCplx;
526         bool _isBoundary;// la face courante est elle une face de bord ?
527         double _maxvploc;
528
529         bool solveNewtonPETSc();//Use PETSc Newton methods to solve time step
530
531         /** \fn computeNewtonVariation
532          * \brief Builds and solves the linear system to obtain the variation Ukp1-Uk in a Newton scheme
533          * @param void
534          * */
535         virtual void computeNewtonVariation();
536
537         /** \fn computeNewtonRHS
538          * \brief Builds the right hand side F_X(X) of the linear system in the Newton method to obtain the variation Ukp1-Uk
539          * @param void
540          * */
541         void computeNewtonRHS( Vec X, Vec F_X);
542
543         /** \fn computeSnesRHS
544          * \brief Static function calling computeNewtonRHS to match PETSc nonlinear solver (SNES) structure
545          * @param void
546          * */
547         static int computeSnesRHS(SNES snes, Vec X, Vec F_X, void *ctx);
548
549         /** \fn computeNewtonJacobian
550          * \brief Static function calling computeNewtonJacobian to match PETSc nonlinear solver (SNES) structure
551          * @param void
552          * */
553         void computeNewtonJacobian( Vec X, Mat A);
554
555         /** \fn computeSnesJacobian
556          * \brief Builds the matrix A(X) of the linear system in the Newton method to obtain the variation Ukp1-Uk
557          * @param void
558          * */
559         static int computeSnesJacobian(SNES snes, Vec X, Mat A, Mat Aapprox, void *ctx);
560
561         /** \fn convectionState
562          * \brief calcule l'etat de Roe entre deux cellules voisinnes
563          * \Details c'ets une fonction virtuelle, on la surcharge dans chacun des modèles
564          * @param i,j : entiers correspondant aux numéros des cellules à gauche et à droite de l'interface
565          * @param IsBord : est un booléen qui nous dit si la cellule voisine est sur le bord ou pas
566          * */
567         virtual void convectionState(const long &i, const long &j, const bool &IsBord)=0;
568
569         /** \fn convectionMatrices
570          * \brief calcule la matrice de convection de l'etat interfacial entre deux cellules voisinnes
571          * \Details convectionMatrices est une fonction virtuelle pure, on la surcharge dans chacun des modèles
572          * */
573         virtual void convectionMatrices()=0;
574
575         /** \fn diffusionStateAndMatrices
576          * \brief calcule la matrice de diffusion de l'etat interface pour la diffusion
577          * \Details est une fonction virtuelle pure, on la surcharge dans chacun eds modèles
578          * @param i,j : entier correspondent aux indices des cellules  à gauche et droite respectivement
579          * @param IsBord: bollean telling if (i,j) is a boundary face
580          * @return
581          * */
582         virtual void diffusionStateAndMatrices(const long &i,const long &j, const bool &IsBord)=0;
583
584         /** \fn addSourceTermToSecondMember
585          * \brief Adds the contribution of source terms to the right hand side of the system: gravity,
586          *  phase change, heat power and friction
587          * @param i,j : left and right cell number
588          * @param nbNeighboursi, integer giving the number of neighbours of cell i
589          * @param nbNeighboursj, integer giving the number of neighbours of cell j
590          * @param boolean isBoundary is true for a boundary face (i,j) and false otherwise
591          * @param double mesureFace the lenght or area of the face
592          * */
593         void addSourceTermToSecondMember(const int i, int nbNeighboursi,const int j, int nbNeighboursj,bool isBoundary, int ij, double mesureFace);
594
595         /** \fn sourceVector
596          * \brief Computes the source term (at the exclusion of pressure loss terms)
597          * \Details pure virtual function, overloaded by each model
598          * @param Si output vector containing the source  term
599          * @param Ui, Vi input conservative and primitive vectors
600          * @param i the cell number. Used to read the power field
601          * @return
602          * */
603         virtual void sourceVector(PetscScalar * Si,PetscScalar * Ui,PetscScalar * Vi, int i)=0;
604
605         /** \fn convectionFlux
606          * \brief Computes the convection flux F(U) projected on a vector n
607          * @param U is the conservative variable vector 
608          * @param V is the primitive variable vector
609          * @param normal is a unit vector giving the direction where the convection flux matrix F(U) is projected
610          * @param porosity is the ration of the volume occupied by the fluid in the cell (default value is 1)
611          * @return The convection flux projected in the direction given by the normal vector: F(U)*normal */
612         virtual Vector convectionFlux(Vector U,Vector V, Vector normale, double porosity)=0;
613
614         /** \fn pressureLossVector
615          * \brief Computes the contribution of pressure loss terms in the source term
616          * \Details pure virtual function, overloaded by each model
617          * @param pressureLoss output vector containing the pressure loss contributions
618          * @param K, input pressure loss coefficient
619          * @param Ui input primitive vectors
620          * @param Vi input conservative vectors
621          * @param Uj input primitive vectors
622          * @param Vj input conservative vectors
623          * @return
624          * */
625         virtual void pressureLossVector(PetscScalar * pressureLoss, double K, PetscScalar * Ui, PetscScalar * Vi, PetscScalar * Uj, PetscScalar * Vj)=0;
626
627         /** \fn porosityGradientSourceVector
628          * \brief Computes the contribution of the porosity variation in the source term
629          * \Details pure virtual function, overloaded by each model
630          * @param porosityGradientVector output vector containing the porosity variation contributions to the source term
631          * @param Ui input primitive vectors celli
632          * @param Vi input conservative vectors celli
633          * @param porosityi input porosity value celli
634          * @param deltaxi input diameter celli
635          * @param Uj input primitive vectors cellj
636          * @param Vj input conservative vectors cellj
637          * @param porosityj input porosity value cellj
638          * @param deltaxj input diameter cellj
639          * @return
640          * */
641         virtual void porosityGradientSourceVector()=0;
642
643         /** \fn jacobian
644          * \brief Calcule la jacobienne de la ConditionLimite convection
645          * \Details est une fonction virtuelle pure, qu'on surcharge dans chacun des modèles
646          * @param j entier , l'indice de la cellule sur le bord
647          * @param nameOfGroup  : chaine de caractères, correspond au type de la condition limite
648          * */
649         virtual void jacobian(const int &j, string nameOfGroup,double * normale)=0;
650
651         /** \fn jacobianDiff
652          * \brief Calcule la jacobienne de la CL de diffusion
653          * \Details est une fonction virtuelle pure, qu'on surcharge dans chacun des modèles
654          * @param j entier , l'indice de la cellule sur le bord
655          * @param nameOfGroup  : chaine de caractères, correspond au type de la condition limite
656          * */
657         virtual void jacobianDiff(const int &j, string nameOfGroup)=0;
658
659         /** \fn setBoundaryState
660          * \brief Calcule l'etat fictif a la frontiere
661          * \Details est une fonction virtuelle pure, qu'on surcharge dans chacun des modèles
662          * @param j entier , l'indice de la cellule sur le bord
663          * @param nameOfGroup  : chaine de caractères, correspond au type de la condition limite
664          * @param normale est un vecteur de double correspond au vecteur normal à l'interface
665          * @return
666          * */
667         virtual void setBoundaryState(string nameOfGroup, const int &j,double *normale)=0;
668
669         /** \fn addDiffusionToSecondMember
670          * \brief Compute the contribution of the diffusion operator to the right hand side of the system
671          * \Details this function is pure virtual, and overloaded in each physical model class
672          * @param i left cell number
673          * @param j right cell number
674          * @param boolean isBoundary is true for a boundary face (i,j) and false otherwise
675          * */
676         virtual void addDiffusionToSecondMember(const int &i,const int &j,bool isBoundary)=0;
677
678         //!Computes the interfacial flux for the VFFC formulation of the staggered upwinding
679         virtual Vector staggeredVFFCFlux()=0;
680         //!Compute the corrected interfacial state for lowMach, pressureCorrection and staggered versions of the VFRoe formulation
681         virtual void applyVFRoeLowMachCorrections(bool isBord, string groupname="")=0;
682
683         //remplit les vecteurs de scaling
684         /** \fn computeScaling
685          * \brief Special preconditioner based on a matrix scaling strategy
686          * \Details pure  virtual function overloaded in every model class
687          * @param offset double , correspond à la plus grande valeur propre
688          * @return
689          * */
690         virtual void computeScaling(double offset) =0;
691
692         // Fonctions utilisant la loi d'etat 
693
694         /** \fn consToPrim
695          * \brief computes the primitive vector state from a conservative vector state
696          * \Details ure virtual, implemented by each model
697          * @param Ucons : conservative variable vector
698          * @pram Vprim : primitive variable vector
699          * @param porosity is the porosity coefficient in case of a porous modeling
700          * */
701         virtual void consToPrim(const double *Ucons, double* Vprim,double porosity=1) = 0;
702
703         /** \fn primToCons
704          * \brief computes the conservative vector state from a primitive vector state
705          * \Details pure virtual, implemented by each model
706          * @param U : conservative variable vector, may contain several states
707          * @pram V : primitive variable vector, may contain several states
708          * @param i : index of the conservative state in the vector U
709          * @param j : index of the primitive state in the vector V
710          *       */
711         virtual void primToCons(const double *V, const int &i, double *U, const int &j)=0;
712
713         /** \fn primToConsJacobianMatrix
714          * \brief computes the jacobian matrix of the cons->prim function
715          * \Details pure virtual, implemented by each model
716          * @pram V : primitive vector state
717          *       */
718         //void primToConsJacobianMatrix(double *V)=0;
719
720         /** \fn getRacines
721          * \brief Computes the roots of a polynomial
722          * @param polynome is a vector containing the coefficients of the polynom
723          * @return vector containing the roots (complex numbers)
724          * */
725         vector< complex<double> > getRacines(vector< double > polynome);
726
727         // Some supplement functions ---------------------------------------------------------------------------------------------
728
729         /** \fn addConvectionToSecondMember
730          * \brief Adds the contribution of the convection to the system right hand side for a face (i,j) inside the domain
731          * @param i left cell number
732          * @param j right cell number
733          * @param isBord is a boolean that is true if the interface (i,j) is a boundary interface
734          * @param groupname : is a string that may be used when isBord is true to specify which boundary the face (i,j) belongs to
735          * */
736         virtual void addConvectionToSecondMember(const int &i,const int &j,bool isBord, string groupname="");
737
738         /** \fn updatePrimitives
739          * \brief updates the global primitive vector from the global conservative vector
740          * @param void
741          * */
742         void updatePrimitives();
743
744         /** \fn updateConservatives
745          * \brief updates the global conservative vector from the global primitive vector
746          * @param void
747          * */
748         void updateConservatives();
749
750         /** \fn AbsMatriceRoe
751          * \brief Computes the absolute value of the Roe matrix
752          * @param valeurs_propres_dist is the vector of distinct eigenvalues of the Roe matrix
753          * */
754         void AbsMatriceRoe(vector< complex<double> > valeurs_propres_dist);
755
756         /** \fn SigneMatriceRoe
757          * \brief Computes the sign of the Roe matrix
758          * @param valeurs_propres_dist is the vector of distinct eigenvalues of the Roe matrix
759          * */
760         void SigneMatriceRoe(vector< complex<double> > valeurs_propres_dist);
761
762         /** \fn InvMatriceRoe
763          * \brief Computes the inverse of the Roe matrix
764          * @param valeurs_propres_dist is the vector of distinct eigenvalues of the Roe matrix
765          * */
766         void InvMatriceRoe(vector< complex<double> > valeurs_propres_dist);
767
768         /** \fn entropicShift
769          * \brief computes the eigenvalue jumps for the entropy correction
770          * @param normal vector n to the interface between the two cells _l and _r
771          * */
772         virtual void entropicShift(double* n)=0;
773
774 };
775
776 #endif /* PROBLEMFLUID_HXX_ */