OGS
RichardsFlowFEM.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <vector>
14 
16 #include "MaterialLib/MPL/Medium.h"
27 #include "ParameterLib/Parameter.h"
31 
32 namespace ProcessLib
33 {
34 namespace RichardsFlow
35 {
36 template <typename NodalRowVectorType, typename GlobalDimNodalMatrixType,
37  typename NodalMatrixType>
39 {
40  IntegrationPointData(NodalRowVectorType const& N_,
41  GlobalDimNodalMatrixType const& dNdx_,
42  double const& integration_weight_,
43  NodalMatrixType const mass_operator_)
44  : N(N_),
45  dNdx(dNdx_),
46  integration_weight(integration_weight_),
47  mass_operator(mass_operator_)
48  {
49  }
50 
51  NodalRowVectorType const N;
52  GlobalDimNodalMatrixType const dNdx;
53  double const integration_weight;
54  NodalMatrixType const mass_operator;
55 
57 };
58 const unsigned NUM_NODAL_DOF = 1;
59 
63 {
64 public:
65  virtual std::vector<double> const& getIntPtSaturation(
66  const double t,
67  std::vector<GlobalVector*> const& x,
68  std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
69  std::vector<double>& cache) const = 0;
70 
71  virtual std::vector<double> const& getIntPtDarcyVelocity(
72  const double t,
73  std::vector<GlobalVector*> const& x,
74  std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
75  std::vector<double>& cache) const = 0;
76 };
77 
78 template <typename ShapeFunction, typename IntegrationMethod, int GlobalDim>
80 {
83 
85  ShapeMatricesType, ShapeFunction::NPOINTS, NUM_NODAL_DOF, GlobalDim>;
86 
94 
95 public:
97  std::size_t const local_matrix_size,
98  bool is_axially_symmetric,
99  unsigned const integration_order,
100  RichardsFlowProcessData const& process_data)
101  : _element(element),
102  _process_data(process_data),
103  _integration_method(integration_order),
104  _saturation(
105  std::vector<double>(_integration_method.getNumberOfPoints()))
106  {
107  // This assertion is valid only if all nodal d.o.f. use the same shape
108  // matrices.
109  assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
110  (void)local_matrix_size;
111 
112  unsigned const n_integration_points =
113  _integration_method.getNumberOfPoints();
114  _ip_data.reserve(n_integration_points);
115 
116  auto const shape_matrices =
118  GlobalDim>(element, is_axially_symmetric,
120 
121  for (unsigned ip = 0; ip < n_integration_points; ip++)
122  {
123  auto const& sm = shape_matrices[ip];
124  const double integration_factor = sm.integralMeasure * sm.detJ;
125  _ip_data.emplace_back(
126  sm.N, sm.dNdx,
127  _integration_method.getWeightedPoint(ip).getWeight() *
128  integration_factor,
129  sm.N.transpose() * sm.N * integration_factor *
130  _integration_method.getWeightedPoint(ip).getWeight());
131  }
132  }
133 
134  void assemble(double const t, double const dt,
135  std::vector<double> const& local_x,
136  std::vector<double> const& /*local_xdot*/,
137  std::vector<double>& local_M_data,
138  std::vector<double>& local_K_data,
139  std::vector<double>& local_b_data) override
140  {
141  auto const local_matrix_size = local_x.size();
142  // This assertion is valid only if all nodal d.o.f. use the same shape
143  // matrices.
144  assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
145 
146  auto local_M = MathLib::createZeroedMatrix<NodalMatrixType>(
147  local_M_data, local_matrix_size, local_matrix_size);
148  auto local_K = MathLib::createZeroedMatrix<NodalMatrixType>(
149  local_K_data, local_matrix_size, local_matrix_size);
150  auto local_b = MathLib::createZeroedVector<NodalVectorType>(
151  local_b_data, local_matrix_size);
152 
153  unsigned const n_integration_points =
154  _integration_method.getNumberOfPoints();
156  pos.setElementID(_element.getID());
157 
158  auto const& medium =
159  *_process_data.media_map->getMedium(_element.getID());
160  auto const& liquid_phase = medium.phase("AqueousLiquid");
162  vars[static_cast<int>(MaterialPropertyLib::Variable::temperature)] =
163  medium
164  .property(
166  .template value<double>(vars, pos, t, dt);
167 
168  for (unsigned ip = 0; ip < n_integration_points; ip++)
169  {
170  pos.setIntegrationPoint(ip);
171  double p_int_pt = 0.0;
172  NumLib::shapeFunctionInterpolate(local_x, _ip_data[ip].N, p_int_pt);
173 
174  vars[static_cast<int>(
176  vars[static_cast<int>(
178 
179  auto const permeability =
180  MaterialPropertyLib::formEigenTensor<GlobalDim>(
181  medium.property(MaterialPropertyLib::permeability)
182  .value(vars, pos, t, dt));
183 
184  auto const porosity =
186  .template value<double>(vars, pos, t, dt);
187 
188  double const Sw =
189  medium
191  .template value<double>(vars, pos, t, dt);
192  _saturation[ip] = Sw;
193  vars[static_cast<int>(
195 
196  double const dSw_dpc =
197  medium
199  .template dValue<double>(
201  pos, t, dt);
202 
203  auto const drhow_dp =
204  liquid_phase
206  .template dValue<double>(
208  pos, t, dt);
209  auto const storage =
211  .template value<double>(vars, pos, t, dt);
212  double const mass_mat_coeff =
213  storage * Sw + porosity * Sw * drhow_dp - porosity * dSw_dpc;
214 
215  local_M.noalias() += mass_mat_coeff * _ip_data[ip].mass_operator;
216 
217  double const k_rel =
218  medium
221  .template value<double>(vars, pos, t, dt);
222 
223  auto const mu =
224  liquid_phase.property(MaterialPropertyLib::viscosity)
225  .template value<double>(vars, pos, t, dt);
226  local_K.noalias() += _ip_data[ip].dNdx.transpose() * permeability *
227  _ip_data[ip].dNdx *
228  _ip_data[ip].integration_weight * (k_rel / mu);
229 
231  {
232  auto const rho_w =
233  liquid_phase
235  .template value<double>(vars, pos, t, dt);
236  auto const& body_force = _process_data.specific_body_force;
237  assert(body_force.size() == GlobalDim);
238  NodalVectorType gravity_operator =
239  _ip_data[ip].dNdx.transpose() * permeability * body_force *
240  _ip_data[ip].integration_weight;
241  local_b.noalias() += (k_rel / mu) * rho_w * gravity_operator;
242  }
243  }
245  {
246  for (int idx_ml = 0; idx_ml < local_M.cols(); idx_ml++)
247  {
248  double const mass_lump_val = local_M.col(idx_ml).sum();
249  local_M.col(idx_ml).setZero();
250  local_M(idx_ml, idx_ml) = mass_lump_val;
251  }
252  } // end of mass lumping
253  }
254 
255  Eigen::Map<const Eigen::RowVectorXd> getShapeMatrix(
256  const unsigned integration_point) const override
257  {
258  auto const& N = _ip_data[integration_point].N;
259 
260  // assumes N is stored contiguously in memory
261  return Eigen::Map<const Eigen::RowVectorXd>(N.data(), N.size());
262  }
263 
264  std::vector<double> const& getIntPtSaturation(
265  const double /*t*/,
266  std::vector<GlobalVector*> const& /*x*/,
267  std::vector<NumLib::LocalToGlobalIndexMap const*> const& /*dof_table*/,
268  std::vector<double>& /*cache*/) const override
269  {
270  assert(!_saturation.empty());
271  return _saturation;
272  }
273 
274  std::vector<double> const& getIntPtDarcyVelocity(
275  const double t,
276  std::vector<GlobalVector*> const& x,
277  std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
278  std::vector<double>& cache) const override
279  {
280  // TODO (tf) Temporary value not used by current material models. Need
281  // extension of secondary variable interface
282  double const dt = std::numeric_limits<double>::quiet_NaN();
283 
284  constexpr int process_id = 0; // monolithic scheme.
285  auto const indices =
286  NumLib::getIndices(_element.getID(), *dof_table[process_id]);
287  assert(!indices.empty());
288  auto const local_x = x[process_id]->get(indices);
289 
291  pos.setElementID(_element.getID());
292 
293  auto const& medium =
294  *_process_data.media_map->getMedium(_element.getID());
295  auto const& liquid_phase = medium.phase("AqueousLiquid");
296 
298  vars[static_cast<int>(MaterialPropertyLib::Variable::temperature)] =
299  medium
300  .property(
302  .template value<double>(vars, pos, t, dt);
303 
304  auto const p_nodal_values = Eigen::Map<const NodalVectorType>(
305  &local_x[0], ShapeFunction::NPOINTS);
306 
307  unsigned const n_integration_points =
308  _integration_method.getNumberOfPoints();
309 
310  cache.clear();
311  auto cache_vec = MathLib::createZeroedMatrix<
312  Eigen::Matrix<double, GlobalDim, Eigen::Dynamic, Eigen::RowMajor>>(
313  cache, GlobalDim, n_integration_points);
314 
315  for (unsigned ip = 0; ip < n_integration_points; ++ip)
316  {
317  double p_int_pt = 0.0;
318  NumLib::shapeFunctionInterpolate(local_x, _ip_data[ip].N, p_int_pt);
319  vars[static_cast<int>(
321  vars[static_cast<int>(
323 
324  double const Sw =
325  medium
327  .template value<double>(vars, pos, t, dt);
328  vars[static_cast<int>(
330 
331  auto const permeability =
332  MaterialPropertyLib::formEigenTensor<GlobalDim>(
333  medium.property(MaterialPropertyLib::permeability)
334  .value(vars, pos, t, dt));
335 
336  double const k_rel =
337  medium
340  .template value<double>(vars, pos, t, dt);
341  auto const mu =
342  liquid_phase.property(MaterialPropertyLib::viscosity)
343  .template value<double>(vars, pos, t, dt);
344  auto const K_mat_coeff = permeability * (k_rel / mu);
345  cache_vec.col(ip).noalias() =
346  -K_mat_coeff * _ip_data[ip].dNdx * p_nodal_values;
348  {
349  auto const rho_w =
350  liquid_phase
352  .template value<double>(vars, pos, t, dt);
353  auto const& body_force = _process_data.specific_body_force;
354  assert(body_force.size() == GlobalDim);
355  // here it is assumed that the vector body_force is directed
356  // 'downwards'
357  cache_vec.col(ip).noalias() += K_mat_coeff * rho_w * body_force;
358  }
359  }
360 
361  return cache;
362  }
363 
364 private:
367 
368  IntegrationMethod const _integration_method;
369  std::vector<
372  Eigen::aligned_allocator<IntegrationPointData<
375  std::vector<double> _saturation;
376 };
377 
378 } // namespace RichardsFlow
379 } // namespace ProcessLib
Definition of the PiecewiseLinearInterpolation class.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
void setElementID(std::size_t element_id)
void setIntegrationPoint(unsigned integration_point)
void assemble(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data) override
typename ShapeMatricesType::NodalVectorType NodalVectorType
typename ShapeMatricesType::GlobalDimMatrixType GlobalDimMatrixType
typename ShapeMatricesType::NodalMatrixType NodalMatrixType
RichardsFlowProcessData const & _process_data
LocalAssemblerData(MeshLib::Element const &element, std::size_t const local_matrix_size, bool is_axially_symmetric, unsigned const integration_order, RichardsFlowProcessData const &process_data)
typename ShapeMatricesType::NodalRowVectorType NodalRowVectorType
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
std::vector< double > const & getIntPtSaturation(const double, std::vector< GlobalVector * > const &, std::vector< NumLib::LocalToGlobalIndexMap const * > const &, std::vector< double > &) const override
typename ShapeMatricesType::ShapeMatrices ShapeMatrices
typename ShapeMatricesType::GlobalDimNodalMatrixType GlobalDimNodalMatrixType
Eigen::Map< const Eigen::RowVectorXd > getShapeMatrix(const unsigned integration_point) const override
Provides the shape matrix at the given integration point.
ShapeMatrixPolicyType< ShapeFunction, GlobalDim > ShapeMatricesType
typename ShapeMatricesType::GlobalDimVectorType GlobalDimVectorType
virtual 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 =0
virtual 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 =0
std::array< VariableType, static_cast< int >(Variable::number_of_variables)> VariableArray
Definition: VariableType.h:108
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)
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)
const unsigned NUM_NODAL_DOF
MatrixType< ShapeFunction::NPOINTS, ShapeFunction::NPOINTS > NodalMatrixType
NumLib::ShapeMatrices< NodalRowVectorType, DimNodalMatrixType, DimMatrixType, GlobalDimNodalMatrixType > ShapeMatrices
MatrixType< GlobalDim, ShapeFunction::NPOINTS > GlobalDimNodalMatrixType
MatrixType< GlobalDim, GlobalDim > GlobalDimMatrixType
VectorType< GlobalDim > GlobalDimVectorType
VectorType< ShapeFunction::NPOINTS > NodalVectorType
RowVectorType< ShapeFunction::NPOINTS > NodalRowVectorType
IntegrationPointData(NodalRowVectorType const &N_, GlobalDimNodalMatrixType const &dNdx_, double const &integration_weight_, NodalMatrixType const mass_operator_)
std::unique_ptr< MaterialPropertyLib::MaterialSpatialDistributionMap > media_map