Salome HOME
Some code factoring
[tools/solverlab.git] / CoreFlows / Models / inc / StationaryDiffusionEquation.hxx
index 7b8ced5239d4a2e677eb3034384adb8a3c764738..1365b2357bf89fdc3f2a4afcc6fe3918490d1845 100755 (executable)
@@ -6,7 +6,7 @@
  * \date June 2019
  * \brief Stationary heat diffusion equation solved with either finite elements or finite volume method. 
  * -\lambda\Delta T=\Phi + \lambda_{sf} (T_{fluid}-T)
- * Dirichlet (imposed temperature) or Neumann (imposed normal flux) boundary conditions
+ * Dirichlet (imposed temperature) or Neumann (imposed normal flux) boundary conditions.
  * */
 //============================================================================
 
  *  \details see \ref StationaryDiffusionEqPage for more details
  * -\lambda\Delta T=\Phi(T) + \lambda_{sf} (T_{fluid}-T)
  */
 #ifndef StationaryDiffusionEquation_HXX_
 #define StationaryDiffusionEquation_HXX_
 
 #include "ProblemCoreFlows.hxx"
 
-/* for the laplacian spectrum */
-#include <slepceps.h>
-#include <slepcsvd.h>
-
 using namespace std;
 
-//! enumeration BoundaryType
 /*! Boundary condition type  */
 enum BoundaryTypeStationaryDiffusion   { NeumannStationaryDiffusion, DirichletStationaryDiffusion, NoneBCStationaryDiffusion};
 
@@ -50,17 +46,17 @@ public :
        /** \fn StationaryDiffusionEquation
                         * \brief Constructor for the temperature diffusion in a solid
                         * \param [in] int : space dimension
+                        * \param [in] bool : numerical method
                         * \param [in] double : solid conductivity
                         *  */
 
-       StationaryDiffusionEquation( int dim,bool FECalculation=true,double lambda=1);
+       StationaryDiffusionEquation( int dim,bool FECalculation=true,double lambda=1,MPI_Comm comm = MPI_COMM_WORLD);
 
     void setMesh(const Mesh &M);
     void setFileName(string fileName){
        _fileName = fileName;
     }
     bool solveStationaryProblem();
-    Field getOutputTemperatureField();
     
     //Linear system and spectrum
     void setLinearSolver(linearSolver kspType, preconditioner pcType);
@@ -91,16 +87,45 @@ public :
        void setDirichletBoundaryCondition(string groupName,double Temperature){
                _limitField[groupName]=LimitFieldStationaryDiffusion(DirichletStationaryDiffusion,Temperature,-1);
        };
+       /** \fn setDirichletBoundaryCondition
+                        * \brief adds a new boundary condition of type Dirichlet
+                        * \details Reads the boundary field in a med file
+                        * \param [in] string : the name of the boundary
+                        * \param [in] string : the file name
+                        * \param [in] string : the field name
+                        * \param [in] int : the time step number
+                        * \param [in] int : int corresponding to the enum CELLS or NODES
+                        * \param [out] void
+                        *  */
+       void setDirichletBoundaryCondition(string groupName, string fileName, string fieldName, int timeStepNumber, int order, int meshLevel, int field_support_type);
+       void setDirichletBoundaryCondition(string groupName, Field bc_field){
+               _limitField[groupName]=LimitFieldStationaryDiffusion(DirichletStationaryDiffusion, 0, -1);
+       };
 
        /** \fn setNeumannBoundaryCondition
                         * \brief adds a new boundary condition of type Neumann
                         * \details
                         * \param [in] string : the name of the boundary
+                        * \param [in] double : outward normal flux
                         * \param [out] void
                         *  */
        void setNeumannBoundaryCondition(string groupName, double normalFlux=0){
                _limitField[groupName]=LimitFieldStationaryDiffusion(NeumannStationaryDiffusion,-1, normalFlux);
        };
+       /** \fn setNeumannBoundaryCondition
+                        * \brief adds a new boundary condition of type Neumann
+                        * \details Reads the boundary field in a med file
+                        * \param [in] string : the name of the boundary
+                        * \param [in] string : the file name
+                        * \param [in] string : the field name
+                        * \param [in] int : the time step number
+                        * \param [in] int : int corresponding to the enum CELLS or NODES 
+                        * \param [out] void
+                        *  */
+       void setNeumannBoundaryCondition(string groupName, string fileName, string fieldName, int timeStepNumber, int order, int meshLevel, int field_support_type);
+       void setNeumannBoundaryCondition(string groupName, Field bc_field){
+               _limitField[groupName]=LimitFieldStationaryDiffusion(NeumannStationaryDiffusion,-1, 0);
+       };
 
        void setDirichletValues(map< int, double> dirichletBoundaryValues);
        void setNeumannValues  (map< int, double>   neumannBoundaryValues);
@@ -108,33 +133,26 @@ public :
        void setConductivity(double conductivite){
                _conductivity=conductivite;
        };
-       void setFluidTemperatureField(Field coupledTemperatureField){
-               _fluidTemperatureField=coupledTemperatureField;
-               _fluidTemperatureFieldSet=true;
-       };
-       void setFluidTemperature(double fluidTemperature){
-       _fluidTemperature=fluidTemperature;
-       }
-       Field& getRodTemperatureField(){
-               return _VV;
-       }
-       Field& getFluidTemperatureField(){
-               return _fluidTemperatureField;
-       }
        void setDiffusiontensor(Matrix DiffusionTensor){
                _DiffusionTensor=DiffusionTensor;
        };
 
+
+       //get input fields to prepare the simulation or coupling
+       vector<string> getInputFieldsNames();
+       void setInputField(const string& nameField, Field& inputField );//supply of a required input field
+       
+       void setFluidTemperatureField(Field coupledTemperatureField);
+       void setFluidTemperature(double fluidTemperature){      _fluidTemperature=fluidTemperature;     }
+       Field& getFluidTemperatureField(){      return _fluidTemperatureField;  }
+       
        /** \fn setHeatPowerField
         * \brief set the heat power field (variable in space)
         * \details
         * \param [in] Field
         * \param [out] void
         *  */
-       void setHeatPowerField(Field heatPower){
-               _heatPowerField=heatPower;
-               _heatPowerFieldSet=true;
-       }
+       void setHeatPowerField(Field heatPower);
 
        /** \fn setHeatPowerField
         * \brief set the heat power field (variable in space)
@@ -143,10 +161,36 @@ public :
         * \param [in] string fieldName
         * \param [out] void
         *  */
-       void setHeatPowerField(string fileName, string fieldName){
-               _heatPowerField=Field(fileName, CELLS,fieldName);
-               _heatPowerFieldSet=true;
+       void setHeatPowerField(string fileName, string fieldName, int iteration = 0, int order = 0, int meshLevel=0);
+
+       /** \fn getHeatPowerField
+        * \brief returns the heat power field
+        * \details
+        * \param [in] void
+        * \param [out] Field
+        *  */
+       Field getHeatPowerField(){
+               return _heatPowerField;
        }
+       //get output fields names for postprocessing or coupling
+       vector<string> getOutputFieldsNames() ;//liste tous les champs que peut fournir le code pour le postraitement
+       Field&         getOutputField(const string& nameField );//Renvoie un champs pour le postraitement
+
+    Field& getOutputTemperatureField();
+       Field& getRodTemperatureField();
+
+       /** \fn setVerbose
+        * \brief Updates display options
+        * \details
+        * \param [in] bool
+        * \param [in] bool
+        * \param [out] void
+        *  */
+       void setVerbose(bool verbose,  bool system=false)
+       {
+               _verbose = verbose;
+               _system = system;
+       };
 
 protected :
        //Main unknown field
@@ -189,6 +233,8 @@ protected :
        Vector _normale;
        Matrix _DiffusionTensor;
        Vec _deltaT, _Tk, _Tkm1, _b0;
+       Vec _Tk_seq; // Local sequential copy of the parallel vector _Tk, used for saving result files
+
        double _dt_src;
     
        //Heat transfert variables
@@ -207,6 +253,7 @@ protected :
 
        double computeRHS(bool & stop);
        double computeDiffusionMatrixFV(bool & stop);
+       double computeDiffusionMatrixFE(bool & stop);
 
     /************ Data for FE calculation *************/
     bool _FECalculation;
@@ -218,18 +265,18 @@ protected :
     std::vector< int > _boundaryNodeIds;/* List of boundary nodes */
     std::vector< int > _dirichletNodeIds;/* List of boundary nodes with Dirichlet BC */
 
-    /*********** Functions for finite element method ***********/
-    Vector gradientNodal(Matrix M, vector< double > v);//gradient of nodal shape functions
-       double computeDiffusionMatrixFE(bool & stop);
-    int fact(int n);
-    int unknownNodeIndex(int globalIndex, std::vector< int > dirichletNodes) const;
-    int globalNodeIndex(int unknownIndex, std::vector< int > dirichletNodes) const;
-
     /********* Possibility to set a boundary field as DirichletNeumann boundary condition *********/
     bool _dirichletValuesSet;
     bool _neumannValuesSet;
     std::map< int, double> _dirichletBoundaryValues;
     std::map< int, double> _neumannBoundaryValues;
+
+       /**** MPI related variables ***/
+       PetscMPIInt    _mpi_size;        /* size of communicator */
+       PetscMPIInt    _mpi_rank;        /* processor rank */
+       VecScatter _scat;                       /* For the distribution of a local vector */
+       int _globalNbUnknowns, _localNbUnknowns;
+       int _d_nnz, _o_nnz;                     /* local and "non local" numbers of non zeros corfficients */
 };
 
 #endif /* StationaryDiffusionEquation_HXX_ */