Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "PorousFlowFluidStateBaseMaterial.h" 11 : #include "PorousFlowCapillaryPressure.h" 12 : 13 : template <bool is_ad> 14 : InputParameters 15 6112 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::validParams() 16 : { 17 6112 : InputParameters params = PorousFlowVariableBase::validParams(); 18 12224 : MooseEnum unit_choice("Kelvin=0 Celsius=1", "Kelvin"); 19 12224 : params.addParam<MooseEnum>( 20 : "temperature_unit", unit_choice, "The unit of the temperature variable"); 21 12224 : params.addRequiredParam<UserObjectName>("capillary_pressure", 22 : "Name of the UserObject defining the capillary pressure"); 23 12224 : params.addPrivateParam<std::string>("pf_material_type", "fluid_state"); 24 6112 : params.addClassDescription("Base class for fluid state calculations using persistent primary " 25 : "variables and a vapor-liquid flash"); 26 6112 : return params; 27 6112 : } 28 : 29 : template <bool is_ad> 30 4770 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::PorousFlowFluidStateBaseMaterialTempl( 31 : const InputParameters & parameters) 32 : : PorousFlowVariableBaseTempl<is_ad>(parameters), 33 9408 : _T_c2k(this->template getParam<MooseEnum>("temperature_unit") == 0 ? 0.0 : 273.15), 34 4770 : _is_initqp(false), 35 4770 : _pc(this->template getUserObject<PorousFlowCapillaryPressure>("capillary_pressure")), 36 7617 : _sfx(_nodal_material ? "_nodal" : "_qp"), 37 9540 : _mass_frac(this->template declareGenericProperty<std::vector<std::vector<Real>>, is_ad>( 38 : "PorousFlow_mass_frac" + _sfx)), 39 4770 : _grad_mass_frac_qp( 40 4770 : _nodal_material 41 4770 : ? nullptr 42 7617 : : &this->template declareGenericProperty<std::vector<std::vector<RealGradient>>, is_ad>( 43 : "PorousFlow_grad_mass_frac" + _sfx)), 44 4770 : _dmass_frac_dvar( 45 : is_ad ? nullptr 46 8220 : : &this->template declareProperty<std::vector<std::vector<std::vector<Real>>>>( 47 : "dPorousFlow_mass_frac" + _sfx + "_dvar")), 48 9540 : _fluid_density(this->template declareGenericProperty<std::vector<Real>, is_ad>( 49 : "PorousFlow_fluid_phase_density" + _sfx)), 50 4770 : _dfluid_density_dvar(is_ad ? nullptr 51 8220 : : &this->template declareProperty<std::vector<std::vector<Real>>>( 52 : "dPorousFlow_fluid_phase_density" + _sfx + "_dvar")), 53 9540 : _fluid_viscosity(this->template declareGenericProperty<std::vector<Real>, is_ad>( 54 : "PorousFlow_viscosity" + _sfx)), 55 4770 : _dfluid_viscosity_dvar(is_ad ? nullptr 56 8220 : : &this->template declareProperty<std::vector<std::vector<Real>>>( 57 : "dPorousFlow_viscosity" + _sfx + "_dvar")), 58 9540 : _fluid_enthalpy(this->template declareGenericProperty<std::vector<Real>, is_ad>( 59 : "PorousFlow_fluid_phase_enthalpy" + _sfx)), 60 4770 : _dfluid_enthalpy_dvar(is_ad ? nullptr 61 8220 : : &this->template declareProperty<std::vector<std::vector<Real>>>( 62 : "dPorousFlow_fluid_phase_enthalpy" + _sfx + "_dvar")), 63 9540 : _fluid_internal_energy(this->template declareGenericProperty<std::vector<Real>, is_ad>( 64 : "PorousFlow_fluid_phase_internal_energy" + _sfx)), 65 4770 : _dfluid_internal_energy_dvar( 66 : is_ad ? nullptr 67 8220 : : &this->template declareProperty<std::vector<std::vector<Real>>>( 68 4770 : "dPorousFlow_fluid_phase_internal_energy" + _sfx + "_dvar")) 69 : { 70 : // Set the size of the FluidStateProperties vector 71 4770 : _fsp.resize(_num_phases, FluidStateProperties(_num_components)); 72 4770 : } 73 : 74 : template <> 75 : GenericReal<false> 76 23078518 : PorousFlowFluidStateBaseMaterialTempl<false>::genericValue(const ADReal & value) 77 : { 78 23078518 : return MetaPhysicL::raw_value(value); 79 : } 80 : 81 : template <> 82 : GenericReal<true> 83 4153776 : PorousFlowFluidStateBaseMaterialTempl<true>::genericValue(const ADReal & value) 84 : { 85 4153776 : return value; 86 : } 87 : 88 : template <bool is_ad> 89 : void 90 49681 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::initQpStatefulProperties() 91 : { 92 49681 : _is_initqp = true; 93 : // Set the size of pressure and saturation vectors 94 49681 : PorousFlowVariableBaseTempl<is_ad>::initQpStatefulProperties(); 95 : 96 : // Set the size of all other vectors 97 49681 : setMaterialVectorSize(); 98 : 99 49681 : thermophysicalProperties(); 100 : 101 : // Set the initial values of the properties at the nodes. 102 : // Note: not required for qp materials as no old values at the qps are requested 103 : // unless the material is AD (for the FV case there are no nodal materials) 104 32020 : if (_nodal_material || is_ad) 105 101013 : for (unsigned int ph = 0; ph < _num_phases; ++ph) 106 : { 107 67342 : _saturation[_qp][ph] = genericValue(_fsp[ph].saturation); 108 67342 : _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure); 109 67342 : _fluid_density[_qp][ph] = genericValue(_fsp[ph].density); 110 67342 : _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity); 111 67342 : _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy); 112 67342 : _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy); 113 : 114 198862 : for (unsigned int comp = 0; comp < _num_components; ++comp) 115 131520 : _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]); 116 : } 117 49681 : } 118 : 119 : template <bool is_ad> 120 : void 121 1633181 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::computeQpProperties() 122 : { 123 1633181 : _is_initqp = false; 124 : // Size pressure and saturation and prepare the derivative vectors 125 1633181 : PorousFlowVariableBaseTempl<is_ad>::computeQpProperties(); 126 : 127 : // Set the size of all other vectors 128 1633181 : setMaterialVectorSize(); 129 : 130 : // Calculate all required thermophysical properties 131 1633181 : thermophysicalProperties(); 132 : 133 4899141 : for (unsigned int ph = 0; ph < _num_phases; ++ph) 134 : { 135 3266094 : _saturation[_qp][ph] = genericValue(_fsp[ph].saturation); 136 3266094 : _porepressure[_qp][ph] = genericValue(_fsp[ph].pressure); 137 3266094 : _fluid_density[_qp][ph] = genericValue(_fsp[ph].density); 138 3266094 : _fluid_viscosity[_qp][ph] = genericValue(_fsp[ph].viscosity); 139 3266094 : _fluid_enthalpy[_qp][ph] = genericValue(_fsp[ph].enthalpy); 140 3266094 : _fluid_internal_energy[_qp][ph] = genericValue(_fsp[ph].internal_energy); 141 : 142 10235522 : for (unsigned int comp = 0; comp < _num_components; ++comp) 143 6969428 : _mass_frac[_qp][ph][comp] = genericValue(_fsp[ph].mass_fraction[comp]); 144 : } 145 1633047 : } 146 : 147 : template <bool is_ad> 148 : void 149 1682862 : PorousFlowFluidStateBaseMaterialTempl<is_ad>::setMaterialVectorSize() const 150 : { 151 1682862 : _fluid_density[_qp].resize(_num_phases, 0.0); 152 1682862 : _fluid_viscosity[_qp].resize(_num_phases, 0.0); 153 1682862 : _fluid_enthalpy[_qp].resize(_num_phases, 0.0); 154 1682862 : _fluid_internal_energy[_qp].resize(_num_phases, 0.0); 155 1682862 : _mass_frac[_qp].resize(_num_phases); 156 : 157 5048586 : for (unsigned int ph = 0; ph < _num_phases; ++ph) 158 3365724 : _mass_frac[_qp][ph].resize(_num_components); 159 : 160 : // Derivatives and gradients are not required in initQpStatefulProperties 161 1682862 : if (!_is_initqp) 162 : { 163 : // The gradient of the mass fractions are needed for qp materials and AD materials 164 1391231 : if (!_nodal_material || is_ad) 165 : { 166 935271 : (*_grad_mass_frac_qp)[_qp].resize(_num_phases); 167 : 168 2805813 : for (unsigned int ph = 0; ph < _num_phases; ++ph) 169 1870542 : (*_grad_mass_frac_qp)[_qp][ph].assign(_num_components, RealGradient()); 170 : } 171 : 172 : // No derivatives are required for AD materials 173 : if (!is_ad) 174 : { 175 1391231 : (*_dfluid_density_dvar)[_qp].resize(_num_phases); 176 1391231 : (*_dfluid_viscosity_dvar)[_qp].resize(_num_phases); 177 1391231 : (*_dfluid_enthalpy_dvar)[_qp].resize(_num_phases); 178 1391231 : (*_dfluid_internal_energy_dvar)[_qp].resize(_num_phases); 179 1391231 : (*_dmass_frac_dvar)[_qp].resize(_num_phases); 180 : 181 4173693 : for (unsigned int ph = 0; ph < _num_phases; ++ph) 182 : { 183 2782462 : (*_dfluid_density_dvar)[_qp][ph].assign(_num_pf_vars, 0.0); 184 2782462 : (*_dfluid_viscosity_dvar)[_qp][ph].assign(_num_pf_vars, 0.0); 185 2782462 : (*_dfluid_enthalpy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0); 186 2782462 : (*_dfluid_internal_energy_dvar)[_qp][ph].assign(_num_pf_vars, 0.0); 187 2782462 : (*_dmass_frac_dvar)[_qp][ph].resize(_num_components); 188 : 189 8784872 : for (unsigned int comp = 0; comp < _num_components; ++comp) 190 6002410 : (*_dmass_frac_dvar)[_qp][ph][comp].assign(_num_pf_vars, 0.0); 191 : } 192 : } 193 : } 194 1682862 : } 195 : 196 : template class PorousFlowFluidStateBaseMaterialTempl<false>; 197 : template class PorousFlowFluidStateBaseMaterialTempl<true>;