OGS
MonolithicHTFEM.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
4#pragma once
5
6#include <Eigen/Core>
7#include <typeinfo>
8#include <vector>
9
10#include "HTFEM.h"
11#include "HTProcessData.h"
22
23namespace ProcessLib
24{
25namespace HT
26{
27const unsigned NUM_NODAL_DOF = 2;
28
29template <typename ShapeFunction, int GlobalDim>
30class MonolithicHTFEM : public HTFEM<ShapeFunction, GlobalDim>
31{
34
35 using LocalMatrixType = typename ShapeMatricesType::template MatrixType<
36 NUM_NODAL_DOF * ShapeFunction::NPOINTS,
37 NUM_NODAL_DOF * ShapeFunction::NPOINTS>;
39 typename ShapeMatricesType::template VectorType<NUM_NODAL_DOF *
40 ShapeFunction::NPOINTS>;
41
45
48
49public:
51 std::size_t const local_matrix_size,
52 NumLib::GenericIntegrationMethod const& integration_method,
53 bool is_axially_symmetric,
54 HTProcessData const& process_data)
55 : HTFEM<ShapeFunction, GlobalDim>(
56 element, local_matrix_size, integration_method,
57 is_axially_symmetric, process_data, NUM_NODAL_DOF)
58 {
59 }
60
61 void assemble(double const t, double const dt,
62 std::vector<double> const& local_x,
63 std::vector<double> const& /*local_x_prev*/,
64 std::vector<double>& local_M_data,
65 std::vector<double>& local_K_data,
66 std::vector<double>& local_b_data) override
67 {
68 auto const local_matrix_size = local_x.size();
69 // This assertion is valid only if all nodal d.o.f. use the same shape
70 // matrices.
71 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
72
74 local_M_data, local_matrix_size, local_matrix_size);
76 local_K_data, local_matrix_size, local_matrix_size);
78 local_b_data, local_matrix_size);
79
80 auto KTT = local_K.template block<temperature_size, temperature_size>(
82 auto MTT = local_M.template block<temperature_size, temperature_size>(
84 auto Kpp = local_K.template block<pressure_size, pressure_size>(
86 auto Mpp = local_M.template block<pressure_size, pressure_size>(
88 auto MpT = local_M.template block<pressure_size, temperature_size>(
90 auto Bp = local_b.template block<pressure_size, 1>(pressure_index, 0);
91
93
94 auto const& process_data = this->_process_data;
95
96 auto p_nodal_values = Eigen::Map<const NodalVectorType>(
97 &local_x[pressure_index], pressure_size);
98
99 auto const& medium =
100 *process_data.media_map.getMedium(this->_element.getID());
101 auto const& liquid_phase =
103 auto const& solid_phase =
105
106 bool const has_solid_thermal_expansivity = solid_phase.hasProperty(
108
109 auto const& b =
110 process_data
111 .projected_specific_body_force_vectors[this->_element.getID()];
112
114
115 unsigned const n_integration_points =
116 this->_integration_method.getNumberOfPoints();
117
118 std::vector<GlobalDimVectorType> ip_flux_vector;
119 double average_velocity_norm = 0.0;
120 ip_flux_vector.reserve(n_integration_points);
121
122 auto const& Ns =
123 process_data.shape_matrix_cache
124 .template NsHigherOrder<typename ShapeFunction::MeshElement>();
125
126 for (unsigned ip(0); ip < n_integration_points; ip++)
127 {
128 auto const& ip_data = this->_ip_data[ip];
129 auto const& dNdx = ip_data.dNdx;
130 auto const& N = Ns[ip];
131 auto const& w = ip_data.integration_weight;
132
134 std::nullopt, this->_element.getID(),
138 this->_element, N))};
139
140 double T_int_pt = 0.0;
141 double p_int_pt = 0.0;
142 // Order matters: First T, then P!
143 NumLib::shapeFunctionInterpolate(local_x, N, T_int_pt, p_int_pt);
144
145 vars.temperature = T_int_pt;
146 vars.liquid_phase_pressure = p_int_pt;
147
148 vars.liquid_saturation = 1.0;
149 auto const specific_storage =
151 .template value<double>(vars, pos, t, dt);
152
153 auto const porosity =
155 .template value<double>(vars, pos, t, dt);
156 vars.porosity = porosity;
157
158 auto const intrinsic_permeability =
160 medium
161 .property(
163 .value(vars, pos, t, dt));
164
165 auto const specific_heat_capacity_fluid =
166 liquid_phase
168 .template value<double>(vars, pos, t, dt);
169
170 // Use the fluid density model to compute the density
171 auto const fluid_density =
172 liquid_phase
174 .template value<double>(vars, pos, t, dt);
175
176 vars.density = fluid_density;
177
178 // Use the viscosity model to compute the viscosity
179 auto const viscosity =
180 liquid_phase
182 .template value<double>(vars, pos, t, dt);
183 GlobalDimMatrixType K_over_mu = intrinsic_permeability / viscosity;
184
185 GlobalDimVectorType const velocity =
186 process_data.has_gravity
187 ? GlobalDimVectorType(-K_over_mu * (dNdx * p_nodal_values -
188 fluid_density * b))
189 : GlobalDimVectorType(-K_over_mu * dNdx * p_nodal_values);
190
191 // matrix assembly
192 GlobalDimMatrixType const thermal_conductivity_dispersivity =
194 vars, fluid_density, specific_heat_capacity_fluid, velocity,
195 pos, t, dt);
196
197 KTT.noalias() +=
198 dNdx.transpose() * thermal_conductivity_dispersivity * dNdx * w;
199
200 ip_flux_vector.emplace_back(velocity * fluid_density *
201 specific_heat_capacity_fluid);
202 average_velocity_norm += velocity.norm();
203
204 NtN.noalias() = N.transpose() * N;
205
206 MTT.noalias() +=
207 (w * this->getHeatEnergyCoefficient(
208 vars, porosity, fluid_density,
209 specific_heat_capacity_fluid, pos, t, dt)) *
210 NtN;
211
212 double const scaling_factor =
213 process_data.is_volume_balance_equation_type ? 1.0
214 : fluid_density;
215
216 Kpp.noalias() +=
217 (scaling_factor * w) * dNdx.transpose() * K_over_mu * dNdx;
218
219 double const dfluid_density_dp =
220 liquid_phase
222 .template dValue<double>(
223 vars,
225 pos, t, dt);
226
227 Mpp.noalias() += (scaling_factor * w *
228 (porosity * dfluid_density_dp / fluid_density +
229 specific_storage)) *
230 NtN;
231 if (process_data.has_gravity)
232 {
233 Bp += (scaling_factor * w * fluid_density) * dNdx.transpose() *
234 K_over_mu * b;
235 }
236
237 // Add the thermal expansion term
238 {
239 double const eff_thermal_expansivity =
241 t, dt, pos, vars, medium, liquid_phase, solid_phase,
242 has_solid_thermal_expansivity, specific_storage);
243 MpT.noalias() -=
244 (scaling_factor * w * eff_thermal_expansivity) * NtN;
245 }
246 }
247
249 process_data.stabilizer, this->_ip_data,
250 process_data.shape_matrix_cache, ip_flux_vector,
251 average_velocity_norm / static_cast<double>(n_integration_points),
252 KTT);
253 }
254
255 std::vector<double> const& getIntPtDarcyVelocity(
256 double const t,
257 std::vector<GlobalVector*> const& x,
258 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
259 std::vector<double>& cache) const override
260 {
261 int const process_id = 0; // monolithic case.
262 auto const indices =
263 NumLib::getIndices(this->_element.getID(), *dof_table[process_id]);
264 assert(!indices.empty());
265 auto const& local_x = x[process_id]->get(indices);
266
267 return this->getIntPtDarcyVelocityLocal(t, local_x, cache);
268 }
269
270private:
271 using HTFEM<ShapeFunction, GlobalDim>::pressure_index;
272 using HTFEM<ShapeFunction, GlobalDim>::pressure_size;
273 using HTFEM<ShapeFunction, GlobalDim>::temperature_index;
274 using HTFEM<ShapeFunction, GlobalDim>::temperature_size;
275};
276
277} // namespace HT
278} // namespace ProcessLib
EigenFixedShapeMatrixPolicy< ShapeFunction, GlobalDim > ShapeMatrixPolicyType
std::vector< double > const & getIntPtDarcyVelocityLocal(const double t, std::vector< double > const &local_x, std::vector< double > &cache) const
Definition HTFEM.h:339
NumLib::GenericIntegrationMethod const & _integration_method
Definition HTFEM.h:270
static const int temperature_index
Definition HTFEM.h:424
static const int temperature_size
Definition HTFEM.h:425
double getHeatEnergyCoefficient(MaterialPropertyLib::VariableArray const &vars, const double porosity, const double fluid_density, const double specific_heat_capacity_fluid, ParameterLib::SpatialPosition const &pos, double const t, double const dt)
Definition HTFEM.h:273
HTFEM(MeshLib::Element const &element, std::size_t const local_matrix_size, NumLib::GenericIntegrationMethod const &integration_method, bool const is_axially_symmetric, HTProcessData const &process_data, const unsigned dof_per_node)
Definition HTFEM.h:108
static const int pressure_size
Definition HTFEM.h:423
GlobalDimMatrixType getThermalConductivityDispersivity(MaterialPropertyLib::VariableArray const &vars, const double fluid_density, const double specific_heat_capacity_fluid, const GlobalDimVectorType &velocity, ParameterLib::SpatialPosition const &pos, double const t, double const dt)
Definition HTFEM.h:298
MeshLib::Element const & _element
Definition HTFEM.h:267
HTProcessData const & _process_data
Definition HTFEM.h:268
std::vector< IntegrationPointData< GlobalDimNodalMatrixType > > _ip_data
Definition HTFEM.h:271
static const int pressure_index
Definition HTFEM.h:422
typename ShapeMatricesType::NodalMatrixType NodalMatrixType
typename ShapeMatricesType::template MatrixType< NUM_NODAL_DOF *ShapeFunction::NPOINTS, NUM_NODAL_DOF *ShapeFunction::NPOINTS > LocalMatrixType
typename ShapeMatricesType::template VectorType< NUM_NODAL_DOF * ShapeFunction::NPOINTS > LocalVectorType
typename ShapeMatricesType::ShapeMatrices ShapeMatrices
typename ShapeMatricesType::NodalRowVectorType NodalRowVectorType
MonolithicHTFEM(MeshLib::Element const &element, std::size_t const local_matrix_size, NumLib::GenericIntegrationMethod const &integration_method, bool is_axially_symmetric, HTProcessData const &process_data)
typename ShapeMatricesType::GlobalDimVectorType GlobalDimVectorType
std::vector< double > const & getIntPtDarcyVelocity(double const 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 &, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data) override
typename ShapeMatricesType::NodalVectorType NodalVectorType
ShapeMatrixPolicyType< ShapeFunction, GlobalDim > ShapeMatricesType
typename ShapeMatricesType::GlobalDimMatrixType GlobalDimMatrixType
constexpr Eigen::Matrix< double, GlobalDim, GlobalDim > formEigenTensor(MaterialPropertyLib::PropertyDataType const &values)
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 &)
void assembleAdvectionMatrix(IPData const &ip_data_vector, NumLib::ShapeMatrixCache const &shape_matrix_cache, std::vector< FluxVectorType > const &ip_flux_vector, Eigen::MatrixBase< Derived > &laplacian_matrix)
std::vector< GlobalIndexType > getIndices(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table)
std::array< double, 3 > interpolateCoordinates(MeshLib::Element const &e, typename ShapeMatricesType::ShapeMatrices::ShapeType const &N)
double evalEffectiveThermalExpansivity(double const t, double const dt, ParameterLib::SpatialPosition const &pos, MaterialPropertyLib::VariableArray const &vars, MaterialPropertyLib::Medium const &medium, MaterialPropertyLib::Phase const &liquid_phase, MaterialPropertyLib::Phase const &solid_phase, bool const has_solid_thermal_expansivity, double const specific_storage)
Definition HTFEM.cpp:43
const unsigned NUM_NODAL_DOF
NumLib::ShapeMatrices< NodalRowVectorType, DimNodalMatrixType, DimMatrixType, GlobalDimNodalMatrixType > ShapeMatrices
MatrixType< ShapeFunction::NPOINTS, ShapeFunction::NPOINTS > NodalMatrixType
MatrixType< GlobalDim, GlobalDim > GlobalDimMatrixType
VectorType< GlobalDim > GlobalDimVectorType
VectorType< ShapeFunction::NPOINTS > NodalVectorType
RowVectorType< ShapeFunction::NPOINTS > NodalRowVectorType