LCOV - code coverage report
Current view: top level - include/materials - PorousFlowFluidStateFlashBase.h (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 2 2 100.0 %
Date: 2017-11-18 13:30:36 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /****************************************************************/
       2             : /* MOOSE - Multiphysics Object Oriented Simulation Environment  */
       3             : /*                                                              */
       4             : /*          All contents are licensed under LGPL V2.1           */
       5             : /*             See LICENSE for full restrictions                */
       6             : /****************************************************************/
       7             : 
       8             : #ifndef POROUSFLOWFLUIDSTATEFLASHBASE_H
       9             : #define POROUSFLOWFLUIDSTATEFLASHBASE_H
      10             : 
      11             : #include "PorousFlowVariableBase.h"
      12             : 
      13             : class PorousFlowFluidStateFlashBase;
      14             : class PorousFlowCapillaryPressure;
      15             : 
      16             : template <>
      17             : InputParameters validParams<PorousFlowFluidStateFlashBase>();
      18             : 
      19             : /**
      20             :  * Base class for fluid states using a persistent set of primary variables for
      21             :  * the mutliphase, multicomponent case.
      22             :  *
      23             :  * Primary variables are: gas pressure, total mass fraction
      24             :  * of a component summed over all phases (and optionally temperature in a
      25             :  * non-isothermal case).
      26             :  *
      27             :  * The total mass fraction of component i summed over all phases, z_i,
      28             :  * is defined as (for two phases)
      29             :  *
      30             :  * z_i = (S_g rho_g y_i + S_l rho_l x_i) / (S_g rho_g + S_l rho_l)
      31             :  *
      32             :  * where S is saturation, rho is density, and the subscripts correspond to gas
      33             :  * and liquid phases, respectively, and y_i and x_i are the mass fractions of
      34             :  * the ith component in the gas and liquid phase, respectively.
      35             :  *
      36             :  * Depending on the phase conditions, the primary variable z_i can represent either
      37             :  * a mass fraction (when only a single phase is present), or a saturation when
      38             :  * two phases are present, and hence it is a persistent variable.
      39             :  *
      40             :  * The PorousFlow kernels expect saturation and mass fractions (as well as pressure
      41             :  * and temperature), so these must be calculated from z_i once the state of the
      42             :  * system is determined.
      43             :  *
      44             :  * A compositional flash calculation using the Rachford-Rice equation is solved
      45             :  * to determine vapor fraction (gas saturation), and subsequently the composition
      46             :  * of each phase.
      47             :  */
      48          72 : class PorousFlowFluidStateFlashBase : public PorousFlowVariableBase
      49             : {
      50             : public:
      51             :   PorousFlowFluidStateFlashBase(const InputParameters & parameters);
      52             : 
      53             : protected:
      54             :   virtual void initQpStatefulProperties() override;
      55             :   virtual void computeQpProperties() override;
      56             : 
      57             :   /// Data structure to pass calculated thermophysical properties
      58         144 :   struct FluidStateProperties
      59             :   {
      60             :     Real pressure;
      61             :     Real saturation;
      62             :     Real fluid_density;
      63             :     Real fluid_viscosity;
      64             :     std::vector<Real> mass_fraction;
      65             :     Real dsaturation_dp;
      66             :     Real dsaturation_dT;
      67             :     Real dsaturation_dz;
      68             :     Real dfluid_density_dp;
      69             :     Real dfluid_density_dT;
      70             :     Real dfluid_density_dz;
      71             :     Real dfluid_viscosity_dp;
      72             :     Real dfluid_viscosity_dT;
      73             :     Real dfluid_viscosity_dz;
      74             :     std::vector<Real> dmass_fraction_dp;
      75             :     std::vector<Real> dmass_fraction_dT;
      76             :     std::vector<Real> dmass_fraction_dz;
      77             :   };
      78             : 
      79             :   /// Size material property vectors and initialise with zeros
      80             :   void setMaterialVectorSize() const;
      81             : 
      82             :   /**
      83             :    * Calculates all required thermophysical properties and derivatives for each phase
      84             :    * and fluid component. Must override in all derived classes.
      85             :    */
      86             :   virtual void thermophysicalProperties() = 0;
      87             : 
      88             :   /**
      89             :    * Rachford-Rice equation for vapor fraction. Can be solved analytically for two
      90             :    * components in two phases, but must be solved iteratively using a root finding
      91             :    * algorithm for more components. This equation has the nice property
      92             :    * that it is monotonic in the interval [0,1], so that only a small number of
      93             :    * iterations are typically required to find the root.
      94             :    *
      95             :    * The Rachford-Rice equation can also be used to check whether the phase state
      96             :    * is two phase, single phase gas, or single phase liquid.
      97             :    * Evaluate f(v), the Rachford-Rice equation evaluated at the vapor mass fraction.
      98             :    *
      99             :    * If f(0) < 0, then the mixture is below the bubble point, and only a single phase
     100             :    * liquid can exist
     101             :    *
     102             :    * If f(1) > 0, then the mixture is above the dew point, and only a single phase gas exists.
     103             :    *
     104             :    * If f(0) >= 0 and f(1) <= 0, the mixture is between the bubble and dew points, and both
     105             :    * gas and liquid phases exist.
     106             :    *
     107             :    * @param x vapor fraction
     108             :    * @param Ki equilibrium constants
     109             :    * @return f(x)
     110             :    */
     111             :   Real rachfordRice(Real x, std::vector<Real> & Ki) const;
     112             : 
     113             :   /**
     114             :    * Derivative of Rachford-Rice equation wrt vapor fraction.
     115             :    * Has the nice property that it is strictly negative in the interval [0,1]
     116             :    *
     117             :    * @param x vapor fraction
     118             :    * @param Ki equilibrium constants
     119             :    * @return f'(x)
     120             :    */
     121             :   Real rachfordRiceDeriv(Real x, std::vector<Real> & Ki) const;
     122             : 
     123             :   /**
     124             :    * Solves Rachford-Rice equation to provide vapor mass fraction. For two components,
     125             :    * the analytical solution is used, while for cases with more than two components,
     126             :    * a Newton-Raphson iterative solution is calculated.
     127             :    *
     128             :    * @param Ki equilibrium constants
     129             :    * @return vapor mass fraction
     130             :    */
     131             :   Real vaporMassFraction(std::vector<Real> & Ki) const;
     132             : 
     133             :   /// Porepressure
     134             :   const VariableValue & _gas_porepressure;
     135             :   /// Gradient of porepressure (only defined at the qps)
     136             :   const VariableGradient & _gas_gradp_qp;
     137             :   /// Moose variable number of the gas porepressure
     138             :   const unsigned int _gas_porepressure_varnum;
     139             :   /// PorousFlow variable number of the gas porepressure
     140             :   const unsigned int _pvar;
     141             :   /// Total mass fraction(s) of the gas component(s) summed over all phases
     142             :   std::vector<const VariableValue *> _z;
     143             :   /// Gradient(s) of total mass fraction(s) of the gas component(s) (only defined at the qps)
     144             :   std::vector<const VariableGradient *> _gradz_qp;
     145             :   /// Moose variable number of z
     146             :   std::vector<unsigned int> _z_varnum;
     147             :   /// PorousFlow variable number of z
     148             :   std::vector<unsigned int> _zvar;
     149             :   /// Number of coupled total mass fractions. Should be _num_phases - 1
     150             :   const unsigned int _num_z_vars;
     151             :   /// Phase number of the aqueous phase
     152             :   const unsigned int _aqueous_phase_number;
     153             :   /// Phase number of the gas phase
     154             :   const unsigned int _gas_phase_number;
     155             :   /// Fluid component number of the aqueous component
     156             :   const unsigned int _aqueous_fluid_component;
     157             :   /// Fluid component number of the gas phase
     158             :   const unsigned int _gas_fluid_component;
     159             :   /// Temperature
     160             :   const MaterialProperty<Real> & _temperature;
     161             :   /// Gradient of temperature (only defined at the qps)
     162             :   const MaterialProperty<RealGradient> & _gradT_qp;
     163             :   /// Derivative of temperature wrt PorousFlow variables
     164             :   const MaterialProperty<std::vector<Real>> & _dtemperature_dvar;
     165             :   /// Mass fraction matrix
     166             :   MaterialProperty<std::vector<std::vector<Real>>> & _mass_frac;
     167             :   /// Gradient of the mass fraction matrix (only defined at the qps)
     168             :   MaterialProperty<std::vector<std::vector<RealGradient>>> * _grad_mass_frac_qp;
     169             :   /// Derivative of the mass fraction matrix with respect to the Porous Flow variables
     170             :   MaterialProperty<std::vector<std::vector<std::vector<Real>>>> & _dmass_frac_dvar;
     171             :   /// Old value of saturation
     172             :   const MaterialProperty<std::vector<Real>> & _saturation_old;
     173             : 
     174             :   /// Fluid density of each phase
     175             :   MaterialProperty<std::vector<Real>> & _fluid_density;
     176             :   /// Derivative of the fluid density for each phase wrt PorousFlow variables
     177             :   MaterialProperty<std::vector<std::vector<Real>>> & _dfluid_density_dvar;
     178             :   /// Viscosity of each phase
     179             :   MaterialProperty<std::vector<Real>> & _fluid_viscosity;
     180             :   /// Derivative of the fluid viscosity for each phase wrt PorousFlow variables
     181             :   MaterialProperty<std::vector<std::vector<Real>>> & _dfluid_viscosity_dvar;
     182             : 
     183             :   /// Conversion from degrees Celsius to degrees Kelvin
     184             :   const Real _T_c2k;
     185             :   /// Universal gas constant (J/mol/K)
     186             :   const Real _R;
     187             :   /// Maximum number of iterations for the Newton-Raphson iterations
     188             :   const Real _nr_max_its;
     189             :   /// Tolerance for Newton-Raphson iterations
     190             :   const Real _nr_tol;
     191             :   /// Flag to indicate whether to calculate stateful properties
     192             :   bool _is_initqp;
     193             :   /// FluidStateProperties data structure
     194             :   std::vector<FluidStateProperties> _fsp;
     195             :   /// Capillary pressure UserObject
     196             :   const PorousFlowCapillaryPressure & _pc_uo;
     197             : };
     198             : 
     199             : #endif // POROUSFLOWFLUIDSTATEFLASHBASE_H

Generated by: LCOV version 1.11