Salome HOME
update CoreFlows
[tools/solverlab.git] / CoreFlows / Models / inc / DiffusionEquation.hxx
1 //============================================================================
2 /**
3  * \file DiffusionEquation.hxx
4  * \author Michael NDJINGA
5  * \version 1.0
6  * \date 24 March 2015
7  * \brief Heat diffusion equation
8  * */
9 //============================================================================
10
11 /*! \class DiffusionEquation DiffusionEquation.hxx "DiffusionEquation.hxx"
12  *  \brief Scalar heat equation for the Uranium rods temperature
13  *  \details see \ref DiffusionEqPage for more details
14  */
15 #ifndef DiffusionEquation_HXX_
16 #define DiffusionEquation_HXX_
17
18 #include "ProblemCoreFlows.hxx"
19 #include "Node.hxx"
20
21 using namespace std;
22
23 //! enumeration BoundaryType
24 /*! Boundary condition type  */
25 enum BoundaryTypeDiffusion      { NeumannDiffusion, DirichletDiffusion, NoneBCDiffusion};
26
27 /** \struct LimitField
28  * \brief value of some fields on the boundary  */
29 struct LimitFieldDiffusion{
30         LimitFieldDiffusion(){bcType=NoneBCDiffusion; T=0; normalFlux=0;}
31         LimitFieldDiffusion(BoundaryTypeDiffusion _bcType, double _T,   double _normalFlux){
32                 bcType=_bcType; T=_T; normalFlux=_normalFlux;
33         }
34
35         BoundaryTypeDiffusion bcType;
36         double T; //for Dirichlet
37         double normalFlux; //for Neumann
38 };
39
40 class DiffusionEquation: public ProblemCoreFlows
41 {
42
43 public :
44         /** \fn DiffusionEquation
45                          * \brief Constructor for the temperature diffusion in a solid
46                          * \param [in] int : space dimension
47                          * \param [in] double : solid density
48                          * \param [in] double : solid specific heat at constant pressure
49                          * \param [in] double : solid conductivity
50                          *  */
51
52         DiffusionEquation( int dim,bool FECalculation=true,double rho=10000,double cp=300,double lambda=5);
53
54         //Gestion du calcul
55         void initialize();
56         void terminate();//vide la mémoire et enregistre le résultat final
57         bool initTimeStep(double dt);
58         double computeTimeStep(bool & stop);//propose un pas de temps pour le calcul. Celà nécessite de discrétiser les opérateur (convection, diffusion, sources) et pour chacun d'employer la condition cfl. En cas de problème durant ce calcul (exemple t=tmax), renvoie stop=true
59         void abortTimeStep();//efface les inconnues calculées par solveTimeStep() et reinitialise dt à 0
60         bool iterateTimeStep(bool &ok);
61         void save();
62         void validateTimeStep();
63
64     /* Boundary conditions */
65         void setBoundaryFields(map<string, LimitFieldDiffusion> boundaryFields){
66                 _limitField = boundaryFields;
67     };
68         /** \fn setDirichletBoundaryCondition
69                          * \brief adds a new boundary condition of type Dirichlet
70                          * \details
71                          * \param [in] string : the name of the boundary
72                          * \param [in] double : the value of the temperature at the boundary
73                          * \param [out] void
74                          *  */
75         void setDirichletBoundaryCondition(string groupName,double Temperature){
76                 _limitField[groupName]=LimitFieldDiffusion(DirichletDiffusion,Temperature,-1);
77         };
78         /** \fn setNeumannBoundaryCondition
79                          * \brief adds a new boundary condition of type Neumann
80                          * \details
81                          * \param [in] string : the name of the boundary
82                          * \param [out] void
83                          *  */
84         void setNeumannBoundaryCondition(string groupName, double normalFlux=0){
85                 _limitField[groupName]=LimitFieldDiffusion(NeumannDiffusion,-1, normalFlux);
86         };
87
88         void setRodDensity(double rho){
89                 _rho=rho;
90         };
91         void setConductivity(double conductivite){
92                 _conductivity=conductivite;
93         };
94         void setFluidTemperatureField(Field coupledTemperatureField){
95                 _fluidTemperatureField=coupledTemperatureField;
96                 _fluidTemperatureFieldSet=true;
97         };
98
99         void setDiffusiontensor(Matrix DiffusionTensor){
100                 _DiffusionTensor=DiffusionTensor;
101         };
102
103         void setFluidTemperature(double fluidTemperature){
104         _fluidTemperature=fluidTemperature;
105         }
106
107         //get output fields for postprocessing or coupling
108         vector<string> getOutputFieldsNames() ;//liste tous les champs que peut fournir le code pour le postraitement
109         Field&         getOutputField(const string& nameField );//Renvoie un champs pour le postraitement
110
111         Field& getRodTemperatureField(){
112                 return _VV;
113         }
114         Field& getFluidTemperatureField(){
115                 return _fluidTemperatureField;
116         }
117
118 protected :
119         double computeDiffusionMatrix(bool & stop);
120         double computeDiffusionMatrixFV(bool & stop);
121         double computeRHS(bool & stop);
122
123         Field _fluidTemperatureField;
124         bool _fluidTemperatureFieldSet, _diffusionMatrixSet;
125         double _conductivity,_diffusivity, _fluidTemperature;
126         double _rho;
127         double _cp;
128         Vector _normale;
129         Matrix _DiffusionTensor;
130         Vec _Tn, _deltaT, _Tk, _Tkm1, _b0;
131         double _dt_diffusion, _dt_src;
132     
133     /************ Data for FE calculation *************/
134     bool _FECalculation;
135         int _NunknownNodes;/* number of unknown nodes for FE calculation */
136         int _NboundaryNodes;/* total number of boundary nodes */
137         int _NdirichletNodes;/* number of boundary nodes with Dirichlet BC for FE calculation */
138     std::vector< int > _boundaryNodeIds;/* List of boundary nodes */
139     std::vector< int > _dirichletNodeIds;/* List of boundary nodes with Dirichlet BC */
140
141     /*********** Functions for finite element method ***********/
142     Vector gradientNodal(Matrix M, vector< double > v);//gradient of nodal shape functions
143         double computeDiffusionMatrixFE(bool & stop);
144     int fact(int n);
145     int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes);
146     int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes);
147
148         TimeScheme _timeScheme;
149         map<string, LimitFieldDiffusion> _limitField;
150 };
151
152 #endif /* DiffusionEquation_HXX_ */