LCOV - code coverage report
Current view: top level - src/actions - PorousFlowSinglePhaseBase.C (source / functions) Hit Total Coverage
Test: porous_flow Test Coverage Lines: 174 181 96.1 %
Date: 2017-11-16 18:50:22 Functions: 6 6 100.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             : #include "PorousFlowSinglePhaseBase.h"
       8             : 
       9             : #include "FEProblem.h"
      10             : #include "Conversion.h"
      11             : #include "libmesh/string_to_enum.h"
      12             : 
      13             : template <>
      14             : InputParameters
      15          73 : validParams<PorousFlowSinglePhaseBase>()
      16             : {
      17          73 :   InputParameters params = validParams<PorousFlowActionBase>();
      18         219 :   params.addParam<bool>("add_darcy_aux", true, "Add AuxVariables that record Darcy velocity");
      19         219 :   params.addParam<bool>("add_stress_aux", true, "Add AuxVariables that record effective stress");
      20         219 :   params.addParam<bool>("use_brine", false, "Use PorousFlowBrine material for the fluid phase");
      21         219 :   params.addRequiredParam<NonlinearVariableName>("porepressure",
      22          73 :                                                  "The name of the porepressure variable");
      23         219 :   MooseEnum coupling_type("Hydro ThermoHydro HydroMechanical ThermoHydroMechanical", "Hydro");
      24         219 :   params.addParam<MooseEnum>("coupling_type",
      25             :                              coupling_type,
      26             :                              "The type of simulation.  For simulations involving Mechanical "
      27             :                              "deformations, you will need to supply the correct Biot coefficient.  "
      28             :                              "For simulations involving Thermal flows, you will need an associated "
      29          73 :                              "ConstantThermalExpansionCoefficient Material");
      30         219 :   MooseEnum simulation_type_choice("steady transient", "transient");
      31         219 :   params.addParam<MooseEnum>("simulation_type",
      32             :                              simulation_type_choice,
      33          73 :                              "Whether a transient or steady-state simulation is being performed");
      34         219 :   params.addParam<UserObjectName>("fp",
      35             :                                   "use_brine_material",
      36             :                                   "The name of the user object for fluid "
      37          73 :                                   "properties. Not required if use_brine is true.");
      38         219 :   params.addCoupledVar("mass_fraction_vars",
      39             :                        "List of variables that represent the mass fractions.  With only one fluid "
      40             :                        "component, this may be left empty.  With N fluid components, the format is "
      41             :                        "'f_0 f_1 f_2 ... f_(N-1)'.  That is, the N^th component need not be "
      42             :                        "specified because f_N = 1 - (f_0 + f_1 + ... + f_(N-1)).  It is best "
      43             :                        "numerically to choose the N-1 mass fraction variables so that they "
      44             :                        "represent the fluid components with small concentrations.  This Action "
      45             :                        "will associated the i^th mass fraction variable to the equation for the "
      46             :                        "i^th fluid component, and the pressure variable to the N^th fluid "
      47          73 :                        "component.");
      48         219 :   params.addParam<unsigned>("nacl_index",
      49             :                             0,
      50             :                             "Index of NaCl variable in mass_fraction_vars, for "
      51          73 :                             "calculating brine properties. Only required if use_brine is true.");
      52         219 :   params.addParam<Real>(
      53             :       "biot_coefficient",
      54             :       1.0,
      55          73 :       "The Biot coefficient (relevant only for mechanically-coupled simulations)");
      56         146 :   params.addClassDescription("Base class for single-phase simulations");
      57          73 :   return params;
      58             : }
      59             : 
      60          73 : PorousFlowSinglePhaseBase::PorousFlowSinglePhaseBase(const InputParameters & params)
      61             :   : PorousFlowActionBase(params),
      62             :     _pp_var(getParam<NonlinearVariableName>("porepressure")),
      63         146 :     _coupling_type(getParam<MooseEnum>("coupling_type").getEnum<CouplingTypeEnum>()),
      64         146 :     _simulation_type(getParam<MooseEnum>("simulation_type").getEnum<SimulationTypeChoiceEnum>()),
      65         146 :     _fp(getParam<UserObjectName>("fp")),
      66         219 :     _biot_coefficient(getParam<Real>("biot_coefficient")),
      67         219 :     _add_darcy_aux(getParam<bool>("add_darcy_aux")),
      68         219 :     _add_stress_aux(getParam<bool>("add_stress_aux")),
      69         219 :     _use_brine(getParam<bool>("use_brine")),
      70         876 :     _nacl_index(getParam<unsigned>("nacl_index"))
      71             : {
      72         146 :   if ((_coupling_type == CouplingTypeEnum::ThermoHydro ||
      73         106 :        _coupling_type == CouplingTypeEnum::ThermoHydroMechanical) &&
      74          33 :       _temperature_var.size() != 1)
      75             :     mooseError("PorousFlowSinglePhaseBase: You need to specify a temperature variable to perform "
      76           0 :                "non-isothermal simulations");
      77             : 
      78          80 :   if (_use_brine && !params.isParamValid("mass_fraction_vars"))
      79             :     mooseError("PorousFlowSinglePhaseBase: You need to specify at least one component in "
      80           1 :                "mass_fraction_vars if use_brine is true");
      81             : 
      82          72 :   if (_use_brine && _nacl_index >= _num_mass_fraction_vars)
      83             :     mooseError(
      84           1 :         "PorousFlowSinglePhaseBase: nacl_index must be less than length of mass_fraction_vars");
      85             : 
      86         137 :   if (!_use_brine && _fp == "use_brine_material")
      87           1 :     mooseError("PorousFlowSinglePhaseBase: You need to specify fp if use_brine is false");
      88             : 
      89          70 :   if (_coupling_type == CouplingTypeEnum::HydroMechanical ||
      90             :       _coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
      91             :   {
      92         100 :     _objects_to_add.push_back("StressDivergenceTensors");
      93         100 :     _objects_to_add.push_back("Gravity");
      94         100 :     _objects_to_add.push_back("PorousFlowEffectiveStressCoupling");
      95             :   }
      96          70 :   if (_coupling_type == CouplingTypeEnum::ThermoHydro ||
      97             :       _coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
      98             :   {
      99          60 :     _objects_to_add.push_back("PorousFlowHeatConduction");
     100          30 :     if (_simulation_type == SimulationTypeChoiceEnum::TRANSIENT)
     101          30 :       _objects_to_add.push_back("PorousFlowEnergyTimeDerivative");
     102             :   }
     103          70 :   if (_coupling_type == CouplingTypeEnum::ThermoHydroMechanical &&
     104             :       _simulation_type == SimulationTypeChoiceEnum::TRANSIENT)
     105          20 :     _objects_to_add.push_back("PorousFlowHeatVolumetricExpansion");
     106          70 :   if (_add_darcy_aux)
     107         130 :     _objects_to_add.push_back("PorousFlowDarcyVelocityComponent");
     108          70 :   if (_add_stress_aux && (_coupling_type == CouplingTypeEnum::HydroMechanical ||
     109             :                           _coupling_type == CouplingTypeEnum::ThermoHydroMechanical))
     110         100 :     _objects_to_add.push_back("StressAux");
     111          70 : }
     112             : 
     113             : void
     114          70 : PorousFlowSinglePhaseBase::act()
     115             : {
     116          70 :   PorousFlowActionBase::act();
     117             : 
     118         140 :   if ((_coupling_type == CouplingTypeEnum::HydroMechanical ||
     119         120 :        _coupling_type == CouplingTypeEnum::ThermoHydroMechanical) &&
     120          50 :       _current_task == "add_kernel")
     121             :   {
     122          39 :     for (unsigned i = 0; i < _ndisp; ++i)
     123             :     {
     124          58 :       std::string kernel_name = "PorousFlowUnsaturated_grad_stress" + Moose::stringify(i);
     125          29 :       std::string kernel_type = "StressDivergenceTensors";
     126          29 :       if (_coord_system == Moose::COORD_RZ)
     127             :         kernel_type = "StressDivergenceRZTensors";
     128          58 :       InputParameters params = _factory.getValidParams(kernel_type);
     129          87 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     130          58 :       params.set<std::vector<VariableName>>("displacements") = _coupled_displacements;
     131          29 :       if (_coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
     132             :       {
     133          28 :         params.set<std::vector<VariableName>>("temperature") = _temperature_var;
     134          28 :         params.set<std::string>("thermal_eigenstrain_name") =
     135          28 :             getParam<std::string>("thermal_eigenstrain_name");
     136             :       }
     137          58 :       params.set<unsigned>("component") = i;
     138         116 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     139          29 :       _problem->addKernel(kernel_type, kernel_name, params);
     140             : 
     141          29 :       if (_gravity(i) != 0)
     142             :       {
     143           0 :         kernel_name = "PorousFlowUnsaturated_gravity" + Moose::stringify(i);
     144             :         kernel_type = "Gravity";
     145           0 :         params = _factory.getValidParams(kernel_type);
     146           0 :         params.set<NonlinearVariableName>("variable") = _displacements[i];
     147           0 :         params.set<Real>("value") = _gravity(i);
     148           0 :         params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     149           0 :         _problem->addKernel(kernel_type, kernel_name, params);
     150             :       }
     151             : 
     152          87 :       kernel_name = "PorousFlowUnsaturated_EffStressCoupling" + Moose::stringify(i);
     153             :       kernel_type = "PorousFlowEffectiveStressCoupling";
     154          29 :       params = _factory.getValidParams(kernel_type);
     155          87 :       params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
     156          87 :       params.set<NonlinearVariableName>("variable") = _displacements[i];
     157          58 :       params.set<Real>("biot_coefficient") = _biot_coefficient;
     158          58 :       params.set<unsigned>("component") = i;
     159         116 :       params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
     160          29 :       _problem->addKernel(kernel_type, kernel_name, params);
     161             :     }
     162             :   }
     163             : 
     164         140 :   if ((_coupling_type == CouplingTypeEnum::ThermoHydro ||
     165         100 :        _coupling_type == CouplingTypeEnum::ThermoHydroMechanical) &&
     166          30 :       _current_task == "add_kernel")
     167             :   {
     168           6 :     std::string kernel_name = "PorousFlowUnsaturated_HeatConduction";
     169           6 :     std::string kernel_type = "PorousFlowHeatConduction";
     170          12 :     InputParameters params = _factory.getValidParams(kernel_type);
     171          24 :     params.set<NonlinearVariableName>("variable") = _temperature_var[0];
     172          18 :     params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
     173           6 :     _problem->addKernel(kernel_type, kernel_name, params);
     174             : 
     175           6 :     if (_simulation_type == SimulationTypeChoiceEnum::TRANSIENT)
     176             :     {
     177             :       kernel_name = "PorousFlowUnsaturated_EnergyTimeDerivative";
     178             :       kernel_type = "PorousFlowEnergyTimeDerivative";
     179           3 :       params = _factory.getValidParams(kernel_type);
     180          12 :       params.set<NonlinearVariableName>("variable") = _temperature_var[0];
     181           9 :       params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
     182           3 :       _problem->addKernel(kernel_type, kernel_name, params);
     183             :     }
     184             :   }
     185             : 
     186         140 :   if (_coupling_type == CouplingTypeEnum::ThermoHydroMechanical &&
     187          80 :       _simulation_type == SimulationTypeChoiceEnum::TRANSIENT && _current_task == "add_kernel")
     188             :   {
     189           2 :     std::string kernel_name = "PorousFlowUnsaturated_HeatVolumetricExpansion";
     190           2 :     std::string kernel_type = "PorousFlowHeatVolumetricExpansion";
     191           4 :     InputParameters params = _factory.getValidParams(kernel_type);
     192           6 :     params.set<UserObjectName>("PorousFlowDictator") = _dictator_name;
     193           8 :     params.set<NonlinearVariableName>("variable") = _temperature_var[0];
     194           2 :     _problem->addKernel(kernel_type, kernel_name, params);
     195             :   }
     196             : 
     197             :   // add Materials
     198         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowTemperature_qp"))
     199          70 :     addTemperatureMaterial(false);
     200         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowTemperature_nodal"))
     201          40 :     addTemperatureMaterial(true);
     202         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowMassFraction_qp"))
     203          15 :     addMassFractionMaterial(false);
     204         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowMassFraction_nodal"))
     205          40 :     addMassFractionMaterial(true);
     206             : 
     207         140 :   const bool compute_rho_mu_qp = _deps.dependsOn(_objects_to_add, "PorousFlowDensity_qp") ||
     208          70 :                                  _deps.dependsOn(_objects_to_add, "PorousFlowViscosity_qp");
     209         140 :   const bool compute_e_qp = _deps.dependsOn(_objects_to_add, "PorousFlowInternalEnergy_qp");
     210         140 :   const bool compute_h_qp = _deps.dependsOn(_objects_to_add, "PorousFlowEnthalpy_qp");
     211          70 :   if (compute_rho_mu_qp || compute_e_qp || compute_h_qp)
     212             :   {
     213          70 :     if (_use_brine)
     214             :     {
     215           5 :       const std::string nacl_name = _mass_fraction_vars[_nacl_index];
     216          15 :       addBrineMaterial(nacl_name, false, 0, compute_rho_mu_qp, compute_e_qp, compute_h_qp);
     217             :     }
     218             :     else
     219          65 :       addSingleComponentFluidMaterial(false, 0, compute_rho_mu_qp, compute_e_qp, compute_h_qp, _fp);
     220             :   }
     221         170 :   const bool compute_rho_mu_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowDensity_nodal") ||
     222         130 :                                     _deps.dependsOn(_objects_to_add, "PorousFlowViscosity_nodal");
     223         140 :   const bool compute_e_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowInternalEnergy_nodal");
     224         140 :   const bool compute_h_nodal = _deps.dependsOn(_objects_to_add, "PorousFlowEnthalpy_nodal");
     225          70 :   if (compute_rho_mu_nodal || compute_e_nodal || compute_h_nodal)
     226             :   {
     227          40 :     if (_use_brine)
     228             :     {
     229           5 :       const std::string nacl_name = _mass_fraction_vars[_nacl_index];
     230          15 :       addBrineMaterial(nacl_name, true, 0, compute_rho_mu_nodal, compute_e_nodal, compute_h_nodal);
     231             :     }
     232             :     else
     233          35 :       addSingleComponentFluidMaterial(
     234          35 :           true, 0, compute_rho_mu_nodal, compute_e_nodal, compute_h_nodal, _fp);
     235             :   }
     236             : 
     237          70 :   if (compute_rho_mu_qp)
     238             :   {
     239          70 :     joinDensity(false);
     240          70 :     joinViscosity(false);
     241             :   }
     242          70 :   if (compute_rho_mu_nodal)
     243             :   {
     244          40 :     joinDensity(true);
     245          40 :     joinViscosity(true);
     246             :   }
     247          70 :   if (compute_e_qp)
     248          25 :     joinInternalEnergy(false);
     249          70 :   if (compute_e_nodal)
     250          15 :     joinInternalEnergy(true);
     251          70 :   if (compute_h_qp)
     252          25 :     joinEnthalpy(false);
     253          70 :   if (compute_h_nodal)
     254           5 :     joinEnthalpy(true);
     255             : 
     256         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowRelativePermeability_qp"))
     257          65 :     joinRelativePermeability(false);
     258         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowRelativePermeability_nodal"))
     259          25 :     joinRelativePermeability(true);
     260             : 
     261         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowEffectiveFluidPressure_qp"))
     262          70 :     addEffectiveFluidPressureMaterial(false);
     263         140 :   if (_deps.dependsOn(_objects_to_add, "PorousFlowEffectiveFluidPressure_nodal"))
     264          35 :     addEffectiveFluidPressureMaterial(true);
     265             : 
     266             :   // add AuxVariables and AuxKernels
     267          70 :   if (_add_darcy_aux)
     268          65 :     addDarcyAux(_gravity);
     269          70 :   if (_add_stress_aux && (_coupling_type == CouplingTypeEnum::HydroMechanical ||
     270             :                           _coupling_type == CouplingTypeEnum::ThermoHydroMechanical))
     271          50 :     addStressAux();
     272          70 : }
     273             : 
     274             : void
     275          14 : PorousFlowSinglePhaseBase::addDictator()
     276             : {
     277             :   std::string uo_name = _dictator_name;
     278          14 :   std::string uo_type = "PorousFlowDictator";
     279          28 :   InputParameters params = _factory.getValidParams(uo_type);
     280          28 :   std::vector<VariableName> pf_vars = _mass_fraction_vars;
     281          14 :   pf_vars.push_back(_pp_var);
     282          14 :   if (_coupling_type == CouplingTypeEnum::ThermoHydro ||
     283             :       _coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
     284           6 :     pf_vars.push_back(_temperature_var[0]);
     285          14 :   if (_coupling_type == CouplingTypeEnum::HydroMechanical ||
     286             :       _coupling_type == CouplingTypeEnum::ThermoHydroMechanical)
     287          10 :     pf_vars.insert(pf_vars.end(), _coupled_displacements.begin(), _coupled_displacements.end());
     288          28 :   params.set<std::vector<VariableName>>("porous_flow_vars") = pf_vars;
     289          28 :   params.set<unsigned int>("number_fluid_phases") = 1;
     290          28 :   params.set<unsigned int>("number_fluid_components") = _num_mass_fraction_vars + 1;
     291          42 :   _problem->addUserObject(uo_type, uo_name, params);
     292        2513 : }

Generated by: LCOV version 1.11