LCOV - code coverage report
Current view: top level - include/kernels - PorousFlowDarcyBase.h (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 1 1 100.0 %
Date: 2017-11-21 14:47:27 Functions: 1 2 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 POROUSFLOWDARCYBASE_H
       9             : #define POROUSFLOWDARCYBASE_H
      10             : 
      11             : #include "Kernel.h"
      12             : #include "PorousFlowDictator.h"
      13             : 
      14             : class PorousFlowDarcyBase;
      15             : 
      16             : template <>
      17             : InputParameters validParams<PorousFlowDarcyBase>();
      18             : 
      19             : /**
      20             :  * Darcy advective flux.
      21             :  * A fully-updwinded version is implemented, where the mobility
      22             :  * of the upstream nodes is used.
      23             :  * Alternately, after some number of upwind-downwind swaps,
      24             :  * another type of handling of the mobility may be employed
      25             :  * (see fallback_scheme, below)
      26             :  */
      27         255 : class PorousFlowDarcyBase : public Kernel
      28             : {
      29             : public:
      30             :   PorousFlowDarcyBase(const InputParameters & parameters);
      31             : 
      32             : protected:
      33             :   virtual void timestepSetup() override;
      34             :   virtual Real computeQpResidual() override;
      35             :   virtual void computeResidual() override;
      36             :   virtual void computeJacobian() override;
      37             :   virtual void computeOffDiagJacobian(unsigned int jvar) override;
      38             : 
      39             :   /// the Darcy part of the flux (this is the non-upwinded part)
      40             :   virtual Real darcyQp(unsigned int ph) const;
      41             : 
      42             :   /// Jacobian of the Darcy part of the flux
      43             :   virtual Real darcyQpJacobian(unsigned int jvar, unsigned int ph) const;
      44             : 
      45             :   /** The mobility of the fluid.  For multi-component Darcy flow
      46             :    * this is mass_fraction * fluid_density * relative_permeability / fluid_viscosity
      47             :    * @param nodenum The node-number to evaluate the mobility for
      48             :    * @param phase the fluid phase number
      49             :    */
      50             :   virtual Real mobility(unsigned nodenum, unsigned phase) const;
      51             : 
      52             :   /** The derivative of mobility with respect to PorousFlow variable pvar
      53             :    * @param nodenum The node-number to evaluate the mobility for
      54             :    * @param phase the fluid phase number
      55             :    * @param pvar the PorousFlow variable pvar
      56             :    */
      57             :   virtual Real dmobility(unsigned nodenum, unsigned phase, unsigned pvar) const;
      58             : 
      59             :   enum class JacRes
      60             :   {
      61             :     CALCULATE_RESIDUAL = 0,
      62             :     CALCULATE_JACOBIAN = 1
      63             :   };
      64             : 
      65             :   /**
      66             :    * Computation of the residual and Jacobian.
      67             :    *
      68             :    * If res_or_jac=CALCULATE_JACOBIAN then the residual
      69             :    * gets calculated anyway (becuase we have to know which
      70             :    * nodes are upwind and which are downwind) except we
      71             :    * don't actually need to store the residual in
      72             :    * _assembly.residualBlock and we don't need to save in save_in.
      73             :    *
      74             :    * If res_or_jac=CALCULATE_RESIDUAL then we don't have
      75             :    * to do all the Jacobian calculations.
      76             :    *
      77             :    * @param res_or_jac Whether to calculate the residual or the jacobian.
      78             :    * @param jvar PorousFlow variable to take derivatives wrt to
      79             :    */
      80             :   void computeResidualAndJacobian(JacRes res_or_jac, unsigned int jvar);
      81             : 
      82             :   /// Permeability of porous material
      83             :   const MaterialProperty<RealTensorValue> & _permeability;
      84             : 
      85             :   /// d(permeabiity)/d(porous-flow variable)
      86             :   const MaterialProperty<std::vector<RealTensorValue>> & _dpermeability_dvar;
      87             : 
      88             :   /// d(permeabiity)/d(grad(porous-flow variable))
      89             :   const MaterialProperty<std::vector<std::vector<RealTensorValue>>> & _dpermeability_dgradvar;
      90             : 
      91             :   /// Fluid density for each phase (at the node)
      92             :   const MaterialProperty<std::vector<Real>> & _fluid_density_node;
      93             : 
      94             :   /// Derivative of the fluid density for each phase wrt PorousFlow variables (at the node)
      95             :   const MaterialProperty<std::vector<std::vector<Real>>> & _dfluid_density_node_dvar;
      96             : 
      97             :   /// Fluid density for each phase (at the qp)
      98             :   const MaterialProperty<std::vector<Real>> & _fluid_density_qp;
      99             : 
     100             :   /// Derivative of the fluid density for each phase wrt PorousFlow variables (at the qp)
     101             :   const MaterialProperty<std::vector<std::vector<Real>>> & _dfluid_density_qp_dvar;
     102             : 
     103             :   /// Viscosity of each component in each phase
     104             :   const MaterialProperty<std::vector<Real>> & _fluid_viscosity;
     105             : 
     106             :   /// Derivative of the fluid viscosity for each phase wrt PorousFlow variables
     107             :   const MaterialProperty<std::vector<std::vector<Real>>> & _dfluid_viscosity_dvar;
     108             : 
     109             :   /// Nodal pore pressure in each phase
     110             :   const MaterialProperty<std::vector<Real>> & _pp;
     111             : 
     112             :   /// Gradient of the pore pressure in each phase
     113             :   const MaterialProperty<std::vector<RealGradient>> & _grad_p;
     114             : 
     115             :   /// Derivative of Grad porepressure in each phase wrt grad(PorousFlow variables)
     116             :   const MaterialProperty<std::vector<std::vector<Real>>> & _dgrad_p_dgrad_var;
     117             : 
     118             :   /// Derivative of Grad porepressure in each phase wrt PorousFlow variables
     119             :   const MaterialProperty<std::vector<std::vector<RealGradient>>> & _dgrad_p_dvar;
     120             : 
     121             :   /// PorousFlow UserObject
     122             :   const PorousFlowDictator & _porousflow_dictator;
     123             : 
     124             :   /// The number of fluid phases
     125             :   const unsigned int _num_phases;
     126             : 
     127             :   /// Gravity. Defaults to 9.81 m/s^2
     128             :   const RealVectorValue _gravity;
     129             : 
     130             :   /**
     131             :    * If the number of upwind-downwind swaps is less than this amount then
     132             :    * full upwinding is used.  Otherwise the fallback scheme is employed
     133             :    */
     134             :   const unsigned _full_upwind_threshold;
     135             : 
     136             :   /**
     137             :    * If full upwinding is failing due to nodes swapping between upwind
     138             :    * and downwind in successive nonlinear iterations (within one timestep
     139             :    * and element) a fallback scheme is used instead.
     140             :    * QUICK: use the nodal mobilities, as in full upwinding, but do not
     141             :    * attempt to conserve fluid mass.
     142             :    * HARMONIC: assign the harmonic mean of the mobilities to the entire
     143             :    * element.
     144             :    */
     145             :   const enum class FallbackEnum { QUICK, HARMONIC } _fallback_scheme;
     146             : 
     147             :   /**
     148             :    * The Darcy flux.  When multiplied by the mobility, this is the
     149             :    * mass flux of fluid moving out of a node.  This multiplication occurs
     150             :    * during the formation of the residual and Jacobian.
     151             :    * _proto_flux[num_phases][num_nodes]
     152             :    */
     153             :   std::vector<std::vector<Real>> _proto_flux;
     154             : 
     155             :   /**
     156             :    * Derivative of _proto_flux with respect to nodal variables.
     157             :    * This gets modified with the mobility and its derivative during
     158             :    * computation of MOOSE's Jacobian
     159             :    */
     160             :   std::vector<std::vector<std::vector<Real>>> _jacobian;
     161             : 
     162             :   /**
     163             :    * Number of nonlinear iterations (in this timestep and this element)
     164             :    * that a node is an upwind node for a given fluid phase.
     165             :    * _num_upwinds[element_number][phase][node_number_in_element]
     166             :    */
     167             :   std::unordered_map<unsigned, std::vector<std::vector<unsigned>>> _num_upwinds;
     168             : 
     169             :   /**
     170             :    * Number of nonlinear iterations (in this timestep and this element)
     171             :    * that a node is an downwind node for a given fluid phase.
     172             :    * _num_upwinds[element_number][phase][node_number_in_element]
     173             :    */
     174             :   std::unordered_map<unsigned, std::vector<std::vector<unsigned>>> _num_downwinds;
     175             : 
     176             :   /**
     177             :    * Calculate the residual or Jacobian using full upwinding
     178             :    * @param res_or_jac whether to compute the residual or jacobian
     179             :    * @param ph fluid phase number
     180             :    * @param pvar differentiate wrt to this PorousFlow variable (when computing the jacobian)
     181             :    */
     182             :   void fullyUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
     183             : 
     184             :   /**
     185             :    * Calculate the residual or Jacobian using the nodal mobilities,
     186             :    * but without conserving fluid mass.
     187             :    * @param res_or_jac whether to compute the residual or jacobian
     188             :    * @param ph fluid phase number
     189             :    * @param pvar differentiate wrt to this PorousFlow variable (when computing the jacobian)
     190             :    */
     191             :   void quickUpwind(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
     192             : 
     193             :   /**
     194             :    * Calculate the residual or Jacobian by using the harmonic mean
     195             :    * of the nodal mobilities for the entire element
     196             :    * @param res_or_jac whether to compute the residual or jacobian
     197             :    * @param ph fluid phase number
     198             :    * @param pvar differentiate wrt to this PorousFlow variable (when computing the jacobian)
     199             :    */
     200             :   void harmonicMean(JacRes res_or_jac, unsigned int ph, unsigned int pvar);
     201             : };
     202             : 
     203             : #endif // POROUSFLOWDARCYBASE_H

Generated by: LCOV version 1.11