OGS
RichardsComponentTransportFEM-impl.h
Go to the documentation of this file.
1 
12 
14 #include "MaterialLib/MPL/Medium.h"
17 
18 namespace ProcessLib
19 {
20 namespace RichardsComponentTransport
21 {
22 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
25  MeshLib::Element const& element,
26  std::size_t const local_matrix_size,
27  bool is_axially_symmetric,
28  unsigned const integration_order,
29  RichardsComponentTransportProcessData const& process_data,
30  ProcessVariable const& transport_process_variable)
31  : _element_id(element.getID()),
32  _process_data(process_data),
33  _integration_method(integration_order),
34  _transport_process_variable(transport_process_variable)
35 {
36  // This assertion is valid only if all nodal d.o.f. use the same shape
37  // matrices.
38  assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
39  (void)local_matrix_size;
40 
41  unsigned const n_integration_points =
42  _integration_method.getNumberOfPoints();
43  _ip_data.reserve(n_integration_points);
44 
45  auto const shape_matrices =
46  NumLib::initShapeMatrices<ShapeFunction, ShapeMatricesType, GlobalDim>(
47  element, is_axially_symmetric, _integration_method);
48 
49  for (unsigned ip = 0; ip < n_integration_points; ip++)
50  {
51  auto const& sm = shape_matrices[ip];
52  double const integration_factor = sm.integralMeasure * sm.detJ;
53  _ip_data.emplace_back(
54  sm.N, sm.dNdx,
55  _integration_method.getWeightedPoint(ip).getWeight() *
56  integration_factor,
57  sm.N.transpose() * sm.N * integration_factor *
58  _integration_method.getWeightedPoint(ip).getWeight());
59  }
60 }
61 
62 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
64  double const t, double const dt, std::vector<double> const& local_x,
65  std::vector<double> const& /*local_xdot*/,
66  std::vector<double>& local_M_data, std::vector<double>& local_K_data,
67  std::vector<double>& local_b_data)
68 {
69  auto const local_matrix_size = local_x.size();
70  // This assertion is valid only if all nodal d.o.f. use the same shape
71  // matrices.
72  assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
73 
74  auto local_M = MathLib::createZeroedMatrix<LocalMatrixType>(
75  local_M_data, local_matrix_size, local_matrix_size);
76  auto local_K = MathLib::createZeroedMatrix<LocalMatrixType>(
77  local_K_data, local_matrix_size, local_matrix_size);
78  auto local_b = MathLib::createZeroedVector<LocalVectorType>(
79  local_b_data, local_matrix_size);
80 
81  unsigned const n_integration_points =
82  _integration_method.getNumberOfPoints();
83 
85  pos.setElementID(_element_id);
86 
87  auto p_nodal_values = Eigen::Map<const NodalVectorType>(
88  &local_x[pressure_index], pressure_size);
89 
90  auto const& b = _process_data.specific_body_force;
91 
93 
94  GlobalDimMatrixType const& I(
95  GlobalDimMatrixType::Identity(GlobalDim, GlobalDim));
96 
97  // Get material properties
98  auto const& medium = *_process_data.media_map->getMedium(_element_id);
99  auto const& phase = medium.phase("AqueousLiquid");
100  auto const& component =
101  phase.component(_transport_process_variable.getName());
102 
103  auto KCC = local_K.template block<concentration_size, concentration_size>(
104  concentration_index, concentration_index);
105  auto MCC = local_M.template block<concentration_size, concentration_size>(
106  concentration_index, concentration_index);
107  auto Kpp = local_K.template block<pressure_size, pressure_size>(
108  pressure_index, pressure_index);
109  auto Mpp = local_M.template block<pressure_size, pressure_size>(
110  pressure_index, pressure_index);
111  auto Bp = local_b.template block<pressure_size, 1>(pressure_index, 0);
112 
113  for (std::size_t ip(0); ip < n_integration_points; ++ip)
114  {
115  pos.setIntegrationPoint(ip);
116 
117  auto const& ip_data = _ip_data[ip];
118  auto const& N = ip_data.N;
119  auto const& dNdx = ip_data.dNdx;
120  auto const& w = ip_data.integration_weight;
121 
122  double C_int_pt = 0.0;
123  double p_int_pt = 0.0;
124  // Order matters: First C, then p!
125  NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
126 
127  vars[static_cast<int>(
129  auto const Sw = medium[MaterialPropertyLib::PropertyType::saturation]
130  .template value<double>(vars, pos, t, dt);
131 
132  double const dSw_dpc =
134  .template dValue<double>(
136  pos, t, dt);
137 
138  vars[static_cast<int>(MaterialPropertyLib::Variable::concentration)] =
139  C_int_pt;
140  vars[static_cast<int>(MaterialPropertyLib::Variable::phase_pressure)] =
141  p_int_pt;
142 
143  // \todo the argument to getValue() has to be changed for non
144  // constant storage model
145  auto const specific_storage =
147  .template value<double>(vars, pos, t, dt);
148  // \todo the first argument has to be changed for non constant
149  // porosity model
150  auto const porosity =
152  .template value<double>(vars, pos, t, dt);
153 
154  auto const retardation_factor =
156  .template value<double>(vars, pos, t, dt);
157 
158  auto const solute_dispersivity_transverse =
160  .template value<double>(vars, pos, t, dt);
161  auto const solute_dispersivity_longitudinal =
163  .template value<double>(vars, pos, t, dt);
164 
165  // Use the fluid density model to compute the density
166  auto const density = phase[MaterialPropertyLib::PropertyType::density]
167  .template value<double>(vars, pos, t, dt);
168  auto const decay_rate =
170  .template value<double>(vars, pos, t, dt);
171  auto const pore_diffusion_coefficient =
172  MaterialPropertyLib::formEigenTensor<GlobalDim>(
174  .value(vars, pos, t, dt));
175 
176  auto const K = MaterialPropertyLib::formEigenTensor<GlobalDim>(
178  vars, pos, t, dt));
179  vars[static_cast<int>(
181  auto const k_rel =
183  .template value<double>(vars, pos, t, dt);
184  // Use the viscosity model to compute the viscosity
185  auto const mu = phase[MaterialPropertyLib::PropertyType::viscosity]
186  .template value<double>(vars, pos, t, dt);
187  auto const K_times_k_rel_over_mu = K * (k_rel / mu);
188 
189  GlobalDimVectorType const velocity =
190  _process_data.has_gravity
191  ? GlobalDimVectorType(-K_times_k_rel_over_mu *
192  (dNdx * p_nodal_values - density * b))
193  : GlobalDimVectorType(-K_times_k_rel_over_mu * dNdx *
194  p_nodal_values);
195 
196  double const velocity_magnitude = velocity.norm();
197  GlobalDimMatrixType const hydrodynamic_dispersion =
198  velocity_magnitude != 0.0
200  porosity * pore_diffusion_coefficient +
201  solute_dispersivity_transverse * velocity_magnitude * I +
202  (solute_dispersivity_longitudinal -
203  solute_dispersivity_transverse) /
204  velocity_magnitude * velocity * velocity.transpose())
205  : GlobalDimMatrixType(porosity * pore_diffusion_coefficient +
206  solute_dispersivity_transverse *
207  velocity_magnitude * I);
208 
209  // matrix assembly
210  KCC.noalias() +=
211  (dNdx.transpose() * hydrodynamic_dispersion * dNdx +
212  N.transpose() * velocity.transpose() * dNdx +
213  N.transpose() * decay_rate * porosity * retardation_factor * N) *
214  w;
215  MCC.noalias() += w * N.transpose() * porosity * retardation_factor * N;
216  Kpp.noalias() += w * dNdx.transpose() * K_times_k_rel_over_mu * dNdx;
217  // \TODO Extend to pressure dependent density.
218  double const drhow_dp(0.0);
219  Mpp.noalias() += (specific_storage * Sw + porosity * Sw * drhow_dp -
220  porosity * dSw_dpc) *
221  ip_data.mass_operator;
222 
223  if (_process_data.has_gravity)
224  {
225  Bp += w * density * dNdx.transpose() * K_times_k_rel_over_mu * b;
226  }
227  /* with Oberbeck-Boussing assumption density difference only exists
228  * in buoyancy effects */
229  }
230 }
231 
232 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
233 std::vector<double> const&
236  const double t,
237  std::vector<GlobalVector*> const& x,
238  std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
239  std::vector<double>& cache) const
240 {
241  unsigned const n_integration_points =
242  _integration_method.getNumberOfPoints();
243 
244  constexpr int process_id = 0; // monolithic scheme
245  auto const indices =
246  NumLib::getIndices(_element_id, *dof_table[process_id]);
247  assert(!indices.empty());
248  auto const local_x = x[process_id]->get(indices);
249 
250  cache.clear();
251  auto cache_mat = MathLib::createZeroedMatrix<
252  Eigen::Matrix<double, GlobalDim, Eigen::Dynamic, Eigen::RowMajor>>(
253  cache, GlobalDim, n_integration_points);
254 
256  pos.setElementID(_element_id);
257 
259 
260  // Get material properties
261  auto const& medium = *_process_data.media_map->getMedium(_element_id);
262  auto const& phase = medium.phase("AqueousLiquid");
263 
264  auto const p_nodal_values = Eigen::Map<const NodalVectorType>(
265  &local_x[ShapeFunction::NPOINTS], ShapeFunction::NPOINTS);
266 
267  for (unsigned ip = 0; ip < n_integration_points; ++ip)
268  {
269  auto const& ip_data = _ip_data[ip];
270  auto const& N = ip_data.N;
271  auto const& dNdx = ip_data.dNdx;
272 
273  pos.setIntegrationPoint(ip);
274 
275  auto const dt = std::numeric_limits<double>::quiet_NaN();
276  auto const K = MaterialPropertyLib::formEigenTensor<GlobalDim>(
278  vars, pos, t, dt));
279  auto const mu = phase[MaterialPropertyLib::PropertyType::viscosity]
280  .template value<double>(vars, pos, t, dt);
281 
282  double C_int_pt = 0.0;
283  double p_int_pt = 0.0;
284  NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
285 
286  // saturation
287  vars[static_cast<int>(
289  auto const Sw = medium[MaterialPropertyLib::PropertyType::saturation]
290  .template value<double>(vars, pos, t, dt);
291 
292  vars[static_cast<int>(
294  auto const k_rel =
296  .template value<double>(vars, pos, t, dt);
297 
298  cache_mat.col(ip).noalias() = -dNdx * p_nodal_values;
299  if (_process_data.has_gravity)
300  {
301  vars[static_cast<int>(
303  vars[static_cast<int>(
305  auto const rho_w = phase[MaterialPropertyLib::PropertyType::density]
306  .template value<double>(vars, pos, t, dt);
307  auto const b = _process_data.specific_body_force;
308  // here it is assumed that the vector b is directed 'downwards'
309  cache_mat.col(ip).noalias() += rho_w * b;
310  }
311  cache_mat.col(ip).noalias() = k_rel / mu * (K * cache_mat.col(ip));
312  }
313  return cache;
314 }
315 
316 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
317 Eigen::Map<const Eigen::RowVectorXd>
319  const unsigned integration_point) const
320 {
321  auto const& N = _ip_data[integration_point].N;
322 
323  // assumes N is stored contiguously in memory
324  return Eigen::Map<const Eigen::RowVectorXd>(N.data(), N.size());
325 }
326 
327 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
328 std::vector<double> const&
331  const double t,
332  std::vector<GlobalVector*> const& x,
333  std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
334  std::vector<double>& cache) const
335 {
337  pos.setElementID(_element_id);
338 
340 
341  auto const& medium = *_process_data.media_map->getMedium(_element_id);
342 
343  unsigned const n_integration_points =
344  _integration_method.getNumberOfPoints();
345 
346  constexpr int process_id = 0; // monolithic scheme
347  auto const indices =
348  NumLib::getIndices(_element_id, *dof_table[process_id]);
349  assert(!indices.empty());
350  auto const local_x = x[process_id]->get(indices);
351 
352  cache.clear();
353  auto cache_vec = MathLib::createZeroedVector<LocalVectorType>(
354  cache, n_integration_points);
355 
356  for (unsigned ip = 0; ip < n_integration_points; ++ip)
357  {
358  auto const& ip_data = _ip_data[ip];
359  auto const& N = ip_data.N;
360 
361  double C_int_pt = 0.0;
362  double p_int_pt = 0.0;
363  NumLib::shapeFunctionInterpolate(local_x, N, C_int_pt, p_int_pt);
364 
365  // saturation
366  vars[static_cast<int>(
368  auto const dt = std::numeric_limits<double>::quiet_NaN();
369  auto const Sw = medium[MaterialPropertyLib::PropertyType::saturation]
370  .template value<double>(vars, pos, t, dt);
371  cache_vec[ip] = Sw;
372  }
373 
374  return cache;
375 }
376 
377 } // namespace RichardsComponentTransport
378 } // namespace ProcessLib
void setElementID(std::size_t element_id)
void setIntegrationPoint(unsigned integration_point)
typename ShapeMatricesType::GlobalDimMatrixType GlobalDimMatrixType
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
std::vector< IntegrationPointData< NodalRowVectorType, GlobalDimNodalMatrixType, NodalMatrixType >, Eigen::aligned_allocator< IntegrationPointData< NodalRowVectorType, GlobalDimNodalMatrixType, NodalMatrixType > > > _ip_data
void assemble(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_xdot, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data) override
LocalAssemblerData(MeshLib::Element const &element, std::size_t const local_matrix_size, bool is_axially_symmetric, unsigned const integration_order, RichardsComponentTransportProcessData const &process_data, ProcessVariable const &transport_process_variable)
typename ShapeMatricesType::GlobalDimVectorType GlobalDimVectorType
Eigen::Map< const Eigen::RowVectorXd > getShapeMatrix(const unsigned integration_point) const override
Provides the shape matrix at the given integration point.
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::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:108
@ longitudinal_dispersivity
used to compute the hydrodynamic dispersion tensor.
Definition: PropertyType.h:58
@ transversal_dispersivity
used to compute the hydrodynamic dispersion tensor.
Definition: PropertyType.h:100
@ retardation_factor
specify retardation factor used in component transport process.
Definition: PropertyType.h:81
Eigen::Map< Matrix > createZeroedMatrix(std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
Definition: EigenMapTools.h:32
void shapeFunctionInterpolate(const NodalValues &nodal_values, const ShapeMatrix &shape_matrix_N, double &interpolated_value, ScalarTypes &... interpolated_values)
Definition: Interpolation.h:79
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)