OGS
RichardsComponentTransportFEM-impl.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
9
10namespace ProcessLib
11{
13{
14template <typename ShapeFunction, int GlobalDim>
16 MeshLib::Element const& element,
17 std::size_t const local_matrix_size,
18 NumLib::GenericIntegrationMethod const& integration_method,
19 bool is_axially_symmetric,
20 RichardsComponentTransportProcessData const& process_data,
21 ProcessVariable const& transport_process_variable)
22 : _element(element),
23 _process_data(process_data),
24 _integration_method(integration_method),
25 _transport_process_variable(transport_process_variable)
26{
27 // This assertion is valid only if all nodal d.o.f. use the same shape
28 // matrices.
29 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
30 (void)local_matrix_size;
31
32 unsigned const n_integration_points =
33 _integration_method.getNumberOfPoints();
34 _ip_data.reserve(n_integration_points);
35
36 auto const shape_matrices =
38 element, is_axially_symmetric, _integration_method);
39
40 for (unsigned ip = 0; ip < n_integration_points; ip++)
41 {
42 auto const& sm = shape_matrices[ip];
43 double const integration_factor = sm.integralMeasure * sm.detJ;
44 _ip_data.emplace_back(
45 sm.N, sm.dNdx,
46 _integration_method.getWeightedPoint(ip).getWeight() *
47 integration_factor,
48 sm.N.transpose() * sm.N * integration_factor *
49 _integration_method.getWeightedPoint(ip).getWeight());
50 }
51}
52
53template <typename ShapeFunction, int GlobalDim>
55 double const t, double const dt, std::vector<double> const& local_x,
56 std::vector<double> const& /*local_x_prev*/,
57 std::vector<double>& local_M_data, std::vector<double>& local_K_data,
58 std::vector<double>& local_b_data)
59{
60 auto const local_matrix_size = local_x.size();
61 // This assertion is valid only if all nodal d.o.f. use the same shape
62 // matrices.
63 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
64
66 local_M_data, local_matrix_size, local_matrix_size);
68 local_K_data, local_matrix_size, local_matrix_size);
70 local_b_data, local_matrix_size);
71
72 unsigned const n_integration_points =
73 _integration_method.getNumberOfPoints();
74
75 auto p_nodal_values = Eigen::Map<const NodalVectorType>(
76 &local_x[pressure_index], pressure_size);
77
78 auto const& b = _process_data.specific_body_force;
79
81
82 GlobalDimMatrixType const& I(
83 GlobalDimMatrixType::Identity(GlobalDim, GlobalDim));
84
85 // Get material properties
86 auto const& medium = *_process_data.media_map.getMedium(_element.getID());
87 auto const& phase = medium.phase("AqueousLiquid");
88 auto const& component =
89 phase.component(_transport_process_variable.getName());
90
91 auto KCC = local_K.template block<concentration_size, concentration_size>(
93 auto MCC = local_M.template block<concentration_size, concentration_size>(
95 auto Kpp = local_K.template block<pressure_size, pressure_size>(
97 auto Mpp = local_M.template block<pressure_size, pressure_size>(
99 auto Bp = local_b.template block<pressure_size, 1>(pressure_index, 0);
100
101 for (std::size_t ip(0); ip < n_integration_points; ++ip)
102 {
103 auto const& ip_data = _ip_data[ip];
104 auto const& N = ip_data.N;
105 auto const& dNdx = ip_data.dNdx;
106 auto const& w = ip_data.integration_weight;
107
109 std::nullopt, _element.getID(),
112 _element, N))};
113
114 double C_int_pt = 0.0;
115 double p_int_pt = 0.0;
116 // Order matters: First C, then p!
117 NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
118
119 vars.capillary_pressure = -p_int_pt;
121 .template value<double>(vars, pos, t, dt);
122
123 double const dSw_dpc =
125 .template dValue<double>(
127 pos, t, dt);
128
129 vars.concentration = C_int_pt;
130 vars.liquid_phase_pressure = p_int_pt;
131 // setting pG to 1 atm
132 // TODO : rewrite equations s.t. p_L = pG-p_cap
133 vars.gas_phase_pressure = 1.0e5;
134
135 // \todo the argument to getValue() has to be changed for non
136 // constant storage model
137 auto const specific_storage =
139 .template value<double>(vars, pos, t, dt);
140 // \todo the first argument has to be changed for non constant
141 // porosity model
142 auto const porosity =
144 .template value<double>(vars, pos, t, dt);
145
146 auto const retardation_factor =
148 .template value<double>(vars, pos, t, dt);
149
150 auto const solute_dispersivity_transverse =
152 .template value<double>(vars, pos, t, dt);
153 auto const solute_dispersivity_longitudinal =
155 .template value<double>(vars, pos, t, dt);
156
157 // Use the fluid density model to compute the density
158 auto const density = phase[MaterialPropertyLib::PropertyType::density]
159 .template value<double>(vars, pos, t, dt);
160 vars.density = density;
161
162 auto const decay_rate =
164 .template value<double>(vars, pos, t, dt);
165 auto const pore_diffusion_coefficient =
168 .value(vars, pos, t, dt));
169
172 vars, pos, t, dt));
173 vars.liquid_saturation = Sw;
174 auto const k_rel =
176 .template value<double>(vars, pos, t, dt);
177 // Use the viscosity model to compute the viscosity
179 .template value<double>(vars, pos, t, dt);
180 auto const K_times_k_rel_over_mu = K * (k_rel / mu);
181
182 GlobalDimVectorType const velocity =
183 _process_data.has_gravity
184 ? GlobalDimVectorType(-K_times_k_rel_over_mu *
185 (dNdx * p_nodal_values - density * b))
186 : GlobalDimVectorType(-K_times_k_rel_over_mu * dNdx *
187 p_nodal_values);
188
189 double const velocity_magnitude = velocity.norm();
190 GlobalDimMatrixType const hydrodynamic_dispersion =
191 velocity_magnitude != 0.0
193 porosity * pore_diffusion_coefficient +
194 solute_dispersivity_transverse * velocity_magnitude * I +
195 (solute_dispersivity_longitudinal -
196 solute_dispersivity_transverse) /
197 velocity_magnitude * velocity * velocity.transpose())
198 : GlobalDimMatrixType(porosity * pore_diffusion_coefficient +
199 solute_dispersivity_transverse *
200 velocity_magnitude * I);
201
202 // matrix assembly
203 KCC.noalias() +=
204 (dNdx.transpose() * hydrodynamic_dispersion * dNdx +
205 N.transpose() * velocity.transpose() * dNdx +
206 N.transpose() * decay_rate * porosity * retardation_factor * N) *
207 w;
208 MCC.noalias() += w * N.transpose() * porosity * retardation_factor * N;
209 Kpp.noalias() += w * dNdx.transpose() * K_times_k_rel_over_mu * dNdx;
210 // \TODO Extend to pressure dependent density.
211 double const drhow_dp(0.0);
212 Mpp.noalias() += (specific_storage * Sw + porosity * Sw * drhow_dp -
213 porosity * dSw_dpc) *
214 ip_data.mass_operator;
215
216 if (_process_data.has_gravity)
217 {
218 Bp += w * density * dNdx.transpose() * K_times_k_rel_over_mu * b;
219 }
220 /* with Oberbeck-Boussing assumption density difference only exists
221 * in buoyancy effects */
222 }
223}
224
225template <typename ShapeFunction, int GlobalDim>
226std::vector<double> const&
228 const double t,
229 std::vector<GlobalVector*> const& x,
230 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
231 std::vector<double>& cache) const
232{
233 unsigned const n_integration_points =
234 _integration_method.getNumberOfPoints();
235
236 constexpr int process_id = 0; // monolithic scheme
237 auto const indices =
238 NumLib::getIndices(_element.getID(), *dof_table[process_id]);
239 assert(!indices.empty());
240 auto const local_x = x[process_id]->get(indices);
241
242 cache.clear();
243 auto cache_mat = MathLib::createZeroedMatrix<
244 Eigen::Matrix<double, GlobalDim, Eigen::Dynamic, Eigen::RowMajor>>(
245 cache, GlobalDim, n_integration_points);
246
248
249 // Get material properties
250 auto const& medium = *_process_data.media_map.getMedium(_element.getID());
251 auto const& phase = medium.phase("AqueousLiquid");
252
253 auto const p_nodal_values = Eigen::Map<const NodalVectorType>(
254 &local_x[ShapeFunction::NPOINTS], ShapeFunction::NPOINTS);
255
256 for (unsigned ip = 0; ip < n_integration_points; ++ip)
257 {
258 auto const& ip_data = _ip_data[ip];
259 auto const& N = ip_data.N;
260 auto const& dNdx = ip_data.dNdx;
261
263 std::nullopt, _element.getID(),
266 _element, N))};
267
268 auto const dt = std::numeric_limits<double>::quiet_NaN();
271 vars, pos, t, dt));
273 .template value<double>(vars, pos, t, dt);
274
275 double C_int_pt = 0.0;
276 double p_int_pt = 0.0;
277 NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
278
279 // saturation
280 vars.capillary_pressure = -p_int_pt;
282 .template value<double>(vars, pos, t, dt);
283
284 vars.liquid_saturation = Sw;
285 auto const k_rel =
287 .template value<double>(vars, pos, t, dt);
288
289 cache_mat.col(ip).noalias() = -dNdx * p_nodal_values;
290 if (_process_data.has_gravity)
291 {
292 vars.concentration = C_int_pt;
293 vars.liquid_phase_pressure = p_int_pt;
294 auto const rho_w = phase[MaterialPropertyLib::PropertyType::density]
295 .template value<double>(vars, pos, t, dt);
296 auto const b = _process_data.specific_body_force;
297 // here it is assumed that the vector b is directed 'downwards'
298 cache_mat.col(ip).noalias() += rho_w * b;
299 }
300 cache_mat.col(ip).noalias() = k_rel / mu * (K * cache_mat.col(ip));
301 }
302 return cache;
303}
304
305template <typename ShapeFunction, int GlobalDim>
306Eigen::Map<const Eigen::RowVectorXd>
308 const unsigned integration_point) const
309{
310 auto const& N = _ip_data[integration_point].N;
311
312 // assumes N is stored contiguously in memory
313 return Eigen::Map<const Eigen::RowVectorXd>(N.data(), N.size());
314}
315
316template <typename ShapeFunction, int GlobalDim>
317std::vector<double> const&
319 const double t,
320 std::vector<GlobalVector*> const& x,
321 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
322 std::vector<double>& cache) const
323{
325
326 auto const& medium = *_process_data.media_map.getMedium(_element.getID());
327
328 unsigned const n_integration_points =
329 _integration_method.getNumberOfPoints();
330
331 constexpr int process_id = 0; // monolithic scheme
332 auto const indices =
333 NumLib::getIndices(_element.getID(), *dof_table[process_id]);
334 assert(!indices.empty());
335 auto const local_x = x[process_id]->get(indices);
336
337 cache.clear();
338 auto cache_vec = MathLib::createZeroedVector<
339 Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>>(
340 cache, n_integration_points);
341
342 for (unsigned ip = 0; ip < n_integration_points; ++ip)
343 {
344 auto const& ip_data = _ip_data[ip];
345 auto const& N = ip_data.N;
346
348 std::nullopt, _element.getID(),
351 _element, N))};
352
353 double C_int_pt = 0.0;
354 double p_int_pt = 0.0;
355 NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
356
357 // saturation
358 vars.capillary_pressure = -p_int_pt;
359 auto const dt = std::numeric_limits<double>::quiet_NaN();
361 .template value<double>(vars, pos, t, dt);
362 cache_vec[ip] = Sw;
363 }
364
365 return cache;
366}
367
368} // namespace RichardsComponentTransport
369} // namespace ProcessLib
std::vector< IntegrationPointData< NodalRowVectorType, GlobalDimNodalMatrixType, NodalMatrixType >, Eigen::aligned_allocator< IntegrationPointData< NodalRowVectorType, GlobalDimNodalMatrixType, NodalMatrixType > > > _ip_data
typename ShapeMatricesType::GlobalDimVectorType GlobalDimVectorType
ShapeMatrixPolicyType< ShapeFunction, GlobalDim > ShapeMatricesType
LocalAssemblerData(MeshLib::Element const &element, std::size_t const local_matrix_size, NumLib::GenericIntegrationMethod const &integration_method, bool is_axially_symmetric, RichardsComponentTransportProcessData const &process_data, ProcessVariable const &transport_process_variable)
std::vector< double > const & getIntPtSaturation(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const override
std::vector< double > const & getIntPtDarcyVelocity(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const override
void assemble(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_x_prev, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data) override
typename ShapeMatricesType::GlobalDimMatrixType GlobalDimMatrixType
Eigen::Map< const Eigen::RowVectorXd > getShapeMatrix(const unsigned integration_point) const override
Provides the shape matrix at the given integration point.
constexpr Eigen::Matrix< double, GlobalDim, GlobalDim > formEigenTensor(MaterialPropertyLib::PropertyDataType const &values)
@ longitudinal_dispersivity
used to compute the hydrodynamic dispersion tensor.
@ transversal_dispersivity
used to compute the hydrodynamic dispersion tensor.
@ retardation_factor
specify retardation factor used in component transport process.
Eigen::Map< Vector > createZeroedVector(std::vector< double > &data, Eigen::VectorXd::Index size)
Eigen::Map< Matrix > createZeroedMatrix(std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
void shapeFunctionInterpolate(const NodalValues &, const ShapeMatrix &)
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::vector< typename ShapeMatricesType::ShapeMatrices, Eigen::aligned_allocator< typename ShapeMatricesType::ShapeMatrices > > initShapeMatrices(MeshLib::Element const &e, bool const is_axially_symmetric, IntegrationMethod const &integration_method)
std::array< double, 3 > interpolateCoordinates(MeshLib::Element const &e, typename ShapeMatricesType::ShapeMatrices::ShapeType const &N)