https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PorousFlowPorosityVinsomeWesterveld.C
Go to the documentation of this file.
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
11#include "libmesh/utility.h"
12#include "libmesh/dense_matrix.h"
13#include "libmesh/dense_vector.h"
14
15#include <algorithm>
16#include <array>
17#include <cmath>
18
20
21namespace
22{
29void
30expMoments(const Real s, std::array<Real, 3> & mu)
31{
32 if (s > 1.0)
33 {
34 const Real e = std::exp(-s);
35 mu[0] = -std::expm1(-s);
36 mu[1] = 1.0 - e * (1.0 + s);
37 mu[2] = 2.0 - e * (2.0 + s * (2.0 + s));
38 }
39 else
40 {
41 Real s_power = 1.0;
42 for (unsigned int k = 0; k < 3; ++k)
43 {
44 s_power *= s;
45 Real term = s_power / (k + 1.0);
46 Real sum = term;
47 for (unsigned int n = 1; n < 30 && term > 1.0E-17 * sum; ++n)
48 {
49 term *= s / (k + 1.0 + n);
50 sum += term;
51 }
52 mu[k] = std::exp(-s) * sum;
53 }
54 }
55}
56}
57
60{
62 params.addRequiredParam<Real>(
63 "thermal_opening_coeff",
64 "Change in porosity per unit heat content of the adjacent matrix. The heat content, "
65 "I = int (T - matrix_reference_temperature) dz, has units K.m, so when porosity represents "
66 "the aperture of a lower-dimensional fracture this coefficient has units 1/K. Porosity "
67 "changes by -thermal_opening_coeff * I, so cooling (I < 0) opens the fracture when this "
68 "coefficient is positive");
70 "matrix_thermal_diffusivity",
71 "matrix_thermal_diffusivity > 0",
72 "Thermal diffusivity of the matrix adjacent to the "
73 "fracture (thermal conductivity divided by "
74 "volumetric heat capacity), m^2/s. This is the diffusivity in the "
75 "direction normal to the fracture (or the matrix is "
76 "assumed isotropic), and it is assumed constant");
78 "matrix_reference_temperature",
79 "Undisturbed temperature of the matrix adjacent to the fracture. This should usually be a "
80 "linear-lagrange variable or a constant");
81 params.addParam<Real>(
82 "vw_start_time",
83 0.0,
84 "Time at which the temperature at the fracture face first starts to change "
85 "(for instance, when injection begins). The matrix adjacent to the fracture "
86 "is at matrix_reference_temperature at this time, and the thermal-opening "
87 "term is zero before it");
88 params.addRangeCheckedParam<Real>(
89 "matrix_thickness",
90 "matrix_thickness > 0",
91 "Thickness of the matrix layer next to the fracture, for instance half the spacing between "
92 "parallel fractures. If given, the far side of the layer is insulated, so the heat content, "
93 "and hence the thermal opening, is bounded. If not given, the matrix is semi-infinite");
95 "This Material calculates porosity (usually the aperture of a lower-dimensional fracture) "
96 "using the PorousFlowPorosityLinear relationship plus a thermal-opening term proportional to "
97 "the heat content of the adjacent matrix, which is computed using the semi-analytic method "
98 "of Vinsome and Westerveld (1980)");
99 return params;
100}
101
103 const InputParameters & parameters)
104 : PorousFlowPorosityLinear(parameters),
105 _thermal_opening_coeff(getParam<Real>("thermal_opening_coeff")),
106 _kappa(getParam<Real>("matrix_thermal_diffusivity")),
107 _T_matrix_ref(nodalOrQpValue("matrix_reference_temperature")),
108 _start_time(getParam<Real>("vw_start_time")),
109 _finite_thickness(isParamValid("matrix_thickness")),
110 _matrix_thickness(_finite_thickness ? getParam<Real>("matrix_thickness") : 0.0),
111 _theta(_nodal_material ? declareProperty<Real>("PorousFlow_vw_theta_nodal")
112 : declareProperty<Real>("PorousFlow_vw_theta_qp")),
113 _theta_old(_nodal_material ? getMaterialPropertyOld<Real>("PorousFlow_vw_theta_nodal")
114 : getMaterialPropertyOld<Real>("PorousFlow_vw_theta_qp")),
115 _heat_content(_nodal_material ? declareProperty<Real>("PorousFlow_vw_heat_content_nodal")
116 : declareProperty<Real>("PorousFlow_vw_heat_content_qp")),
117 _heat_content_old(_nodal_material
118 ? getMaterialPropertyOld<Real>("PorousFlow_vw_heat_content_nodal")
119 : getMaterialPropertyOld<Real>("PorousFlow_vw_heat_content_qp")),
120 _profile_matrix(3, 3),
121 _profile_rhs(3),
122 _profile_drhs(3),
123 _profile_sol(3),
124 _profile_dsol(3)
125{
126}
127
128void
130{
133 mooseError("PorousFlowPorosityVinsomeWesterveld: a temperature Material is required");
134}
135
136void
138{
140 // The matrix starts at its reference temperature
141 _theta[_qp] = 0.0;
142 _heat_content[_qp] = 0.0;
143}
144
145void
147{
149
150 const Real theta = (*_temperature)[_qp] - _T_matrix_ref[_qp];
151 _theta[_qp] = theta;
152
153 // dI/dT, used for the Jacobian (equal to dI/dtheta, because theta = T - T_matrix_ref)
154 Real dI_dT = 0.0;
155
156 const Real time = _t - _start_time;
157 if (time <= 0.0)
158 {
159 // Before vw_start_time the matrix is undisturbed, so any difference between the fracture-face
160 // temperature and matrix_reference_temperature at vw_start_time is treated as a step change
161 _theta[_qp] = 0.0;
162 _heat_content[_qp] = 0.0;
163 }
164 else if (!_finite_thickness || _matrix_thickness > 12.5 * std::sqrt(_kappa * time))
165 {
166 // If matrix_thickness is not given, or s = 2L / d > 50 (see below), so that exp(-s) < 2E-22
167 // and the insulated end has no effect, the semi-infinite formulae are used
168 const Real a = _kappa * std::min(_dt, time);
169 // Vinsome and Westerveld (1980): the profile is
170 // (theta + p z + q z^2) exp(-z / d), with d = sqrt(kappa t) / 2.
171 // Imposing the heat-conduction equation at z = 0 and the energy balance
172 // dI/dt = kappa * (theta / d - p) over the time step gives p and I below.
173 const Real d = 0.5 * std::sqrt(_kappa * time);
174 const Real denom = 3.0 * d * d + a;
175 const Real p = (a * theta / d + _heat_content_old[_qp] -
176 Utility::pow<3>(d) * (theta - _theta_old[_qp]) / a) /
177 denom;
178 _heat_content[_qp] = _heat_content_old[_qp] + a * (theta / d - p);
179
180 const Real dp_dT = (a / d - Utility::pow<3>(d) / a) / denom;
181 dI_dT = a * (1.0 / d - dp_dT);
182 }
183 else
184 {
185 // Matrix layer 0 <= z <= L with an insulated end at z = L. The profile is
186 // P(z) exp(-z / d) + P(2L - z) exp(-(2L - z) / d), with P(z) = A + B z + C z^2 and
187 // d = sqrt(kappa t) / 2, which is symmetric about z = L, so dT/dz = 0 there. With b = B d,
188 // c = C d^2, s = 2L / d and e = exp(-s), the heat content of the layer is
189 // I = d (mu0 A + mu1 b + mu2 c), where mu_k = int_0^s x^k exp(-x) dx. (A, b, c) solve a 3x3
190 // linear system, discretised in time using backward Euler, whose rows are:
191 // row 0: the fracture-face temperature, T(0, t) - T_ref = theta
192 // row 1: the heat-conduction equation at z = 0, kappa d^2T/dz^2 = (theta - theta_old) / dt,
193 // multiplied by d^2 / kappa
194 // row 2: energy conservation, I - I_old = -kappa dt dT/dz at z = 0, divided by d
195 // Here ap = kappa dt / d^2 = 4 dt / t
196 const Real d = 0.5 * std::sqrt(_kappa * time);
197 const Real s = 2.0 * _matrix_thickness / d;
198 const Real time_step = std::min(_dt, time);
199 if (s < 1.0E-5)
200 {
201 // The layer is much thinner than d, so its temperature is almost uniform and the three
202 // terms of P become indistinguishable, making the linear system singular. The thin-layer
203 // limit, I = L theta - L^3 (theta - theta_old) / (3 kappa dt), is used instead
204 const Real c3 = Utility::pow<3>(_matrix_thickness) / (3.0 * _kappa * time_step);
205 _heat_content[_qp] = _matrix_thickness * theta - c3 * (theta - _theta_old[_qp]);
206 dI_dT = _matrix_thickness - c3;
207 }
208 else
209 {
210 const Real ap = 4.0 * time_step / time;
211 const Real e = std::exp(-s);
212 expMoments(s, _mu);
213 const std::array<Real, 3> & mu = _mu;
214 // resize zeroes the matrix and clears the LU decomposition from the previous quadpoint
215 DenseMatrix<Real> & m = _profile_matrix;
216 m.resize(3, 3);
217 m(0, 0) = 1.0 + e;
218 m(0, 1) = s * e;
219 m(0, 2) = s * s * e;
220 m(1, 0) = 1.0 + e;
221 m(1, 1) = -2.0 + e * (s - 2.0);
222 m(1, 2) = 2.0 + e * (2.0 + s * (s - 4.0));
223 // Row 2 is written in a form that avoids cancellation when s is small
224 m(2, 0) = mu[0] * (1.0 - ap);
225 m(2, 1) = mu[1] + ap * (mu[0] + s * e);
226 m(2, 2) = mu[2] - ap * s * e * (2.0 - s);
227 DenseVector<Real> & rhs = _profile_rhs;
228 rhs(0) = theta;
229 rhs(1) = (theta - _theta_old[_qp]) / ap;
230 rhs(2) = _heat_content_old[_qp] / d;
231 DenseVector<Real> & drhs = _profile_drhs;
232 drhs(0) = 1.0;
233 drhs(1) = 1.0 / ap;
234 drhs(2) = 0.0;
235 DenseVector<Real> & x = _profile_sol;
236 DenseVector<Real> & dx = _profile_dsol;
237 // lu_solve uses partial pivoting, and the second call reuses the LU decomposition
238 m.lu_solve(rhs, x);
239 m.lu_solve(drhs, dx);
240 _heat_content[_qp] = d * (mu[0] * x(0) + mu[1] * x(1) + mu[2] * x(2));
241 dI_dT = d * (mu[0] * dx(0) + mu[1] * dx(1) + mu[2] * dx(2));
242 }
243 }
244
246 for (unsigned int pvar = 0; pvar < _num_var; ++pvar)
247 (*_dporosity_dvar)[_qp][pvar] -=
248 _thermal_opening_coeff * dI_dT * (*_dtemperature_dvar)[_qp][pvar];
249}
const std::vector< double > x
const double mu
const Real p
void mooseError(Args &&... args)
registerMooseObject("PorousFlowApp", PorousFlowPorosityVinsomeWesterveld)
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const unsigned int _num_var
Number of PorousFlow variables.
MaterialProperty< std::vector< Real > > *const _dporosity_dvar
d(porosity)/d(PorousFlow variable)
GenericMaterialProperty< Real, is_ad > & _porosity
Computed porosity at the nodes or quadpoints.
Material designed to provide the porosity in PorousFlow simulations porosity_ref + P_coeff * (P - P_r...
virtual void initQpStatefulProperties() override
static InputParameters validParams()
const MaterialProperty< std::vector< Real > > * _dtemperature_dvar
virtual void initialSetup() override
virtual void computeUnboundedPorosityQp()
Computes porosity and its derivatives at the current node or quadrature point, without applying the p...
const MaterialProperty< Real > * _temperature
Porosity (typically the aperture of a lower-dimensional fracture) given by the PorousFlowPorosityLine...
virtual void computeUnboundedPorosityQp() override
Computes porosity and its derivatives at the current node or quadrature point, without applying the p...
const VariableValue & _T_matrix_ref
Undisturbed (reference) matrix temperature.
const Real _kappa
Thermal diffusivity of the matrix in the direction normal to the fracture (m^2/s),...
const Real _matrix_thickness
Thickness of the matrix layer that contributes to the opening (used if _finite_thickness)
const Real _thermal_opening_coeff
Change of porosity per unit matrix heat content (units 1/K when porosity is an aperture)
const MaterialProperty< Real > & _heat_content_old
Old value of the heat content.
const MaterialProperty< Real > & _theta_old
Old value of theta.
const Real _start_time
Time at which the matrix temperature profile is undisturbed.
DenseMatrix< Real > _profile_matrix
For a matrix layer of finite thickness: the linear system for the profile coefficients,...
const bool _finite_thickness
Whether only a layer of finite thickness next to the fracture contributes to the opening.
std::array< Real, 3 > _mu
For a matrix layer of finite thickness: the moments mu_k = int_0^s x^k exp(-x) dx (k = 0,...
MaterialProperty< Real > & _theta
Temperature change at the fracture face, theta = T - T_matrix_ref.
MaterialProperty< Real > & _heat_content
Heat content of the adjacent matrix, I = int (T - T_matrix_ref) dz.
PorousFlowPorosityVinsomeWesterveld(const InputParameters &parameters)
void resize(const unsigned int new_m, const unsigned int new_n)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real