OGS
HeatConductionFEM.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 <vector>
7
22
23namespace ProcessLib
24{
25namespace HeatConduction
26{
27const unsigned NUM_NODAL_DOF = 1;
28
32{
33public:
34 virtual std::vector<double> const& getIntPtHeatFlux(
35 const double t,
36 std::vector<GlobalVector*> const& x,
37 std::vector<NumLib::LocalToGlobalIndexMap const*> const& dof_table,
38 std::vector<double>& cache) const = 0;
39};
40
41template <typename ShapeFunction, int GlobalDim>
43{
46
48 ShapeMatricesType, ShapeFunction::NPOINTS, NUM_NODAL_DOF, GlobalDim>;
49
53
54public:
58 MeshLib::Element const& element,
59 std::size_t const local_matrix_size,
60 NumLib::GenericIntegrationMethod const& integration_method,
61 bool is_axially_symmetric,
62 HeatConductionProcessData const& process_data)
63 : _element(element),
64 _process_data(process_data),
65 _integration_method(integration_method),
67 NumLib::initShapeMatrices<ShapeFunction, ShapeMatricesType,
68 GlobalDim>(
69 element, is_axially_symmetric, _integration_method))
70 {
71 // This assertion is valid only if all nodal d.o.f. use the same shape
72 // matrices.
73 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
74 (void)local_matrix_size;
75 }
76
77 void assemble(double const t, double const dt,
78 std::vector<double> const& local_x,
79 std::vector<double> const& /*local_x_prev*/,
80 std::vector<double>& local_M_data,
81 std::vector<double>& local_K_data,
82 std::vector<double>& /*local_b_data*/) override
83 {
84 auto const local_matrix_size = local_x.size();
85 // This assertion is valid only if all nodal d.o.f. use the same shape
86 // matrices.
87 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
88
90 local_M_data, local_matrix_size, local_matrix_size);
92 local_K_data, local_matrix_size, local_matrix_size);
93
94 unsigned const n_integration_points =
95 _integration_method.getNumberOfPoints();
96
97 auto const& medium =
98 *_process_data.media_map.getMedium(_element.getID());
100
101 for (unsigned ip = 0; ip < n_integration_points; ip++)
102 {
103 auto const& sm = _shape_matrices[ip];
105 std::nullopt, _element.getID(),
109 sm.N))};
110
111 auto const& wp = _integration_method.getWeightedPoint(ip);
112
113 // get the local temperature and put it in the variable array for
114 // access in MPL
115 double T_int_pt = 0.0;
116 NumLib::shapeFunctionInterpolate(local_x, sm.N, T_int_pt);
117 vars.temperature = T_int_pt;
118
120 medium
121 .property(
123 .value(vars, pos, t, dt));
124 auto const specific_heat_capacity =
125 medium
127 specific_heat_capacity)
128 .template value<double>(vars, pos, t, dt);
129 auto const density =
131 .template value<double>(vars, pos, t, dt);
132
133 local_K.noalias() += sm.dNdx.transpose() * k * sm.dNdx * sm.detJ *
134 wp.getWeight() * sm.integralMeasure;
135 local_M.noalias() += sm.N.transpose() * density *
136 specific_heat_capacity * sm.N * sm.detJ *
137 wp.getWeight() * sm.integralMeasure;
138 }
139 if (_process_data.mass_lumping)
140 {
141 local_M = local_M.colwise().sum().eval().asDiagonal();
142 }
143 }
144
145 void assembleWithJacobian(double const t, double const dt,
146 std::vector<double> const& local_x,
147 std::vector<double> const& local_x_prev,
148 std::vector<double>& local_rhs_data,
149 std::vector<double>& local_Jac_data) override
150 {
151 auto const local_matrix_size = local_x.size();
152 // This assertion is valid only if all nodal d.o.f. use the same shape
153 // matrices.
154 assert(local_matrix_size == ShapeFunction::NPOINTS * NUM_NODAL_DOF);
155
156 auto x = Eigen::Map<NodalVectorType const>(local_x.data(),
157 local_matrix_size);
158
159 auto x_prev = Eigen::Map<NodalVectorType const>(local_x_prev.data(),
160 local_matrix_size);
161
163 local_Jac_data, local_matrix_size, local_matrix_size);
165 local_rhs_data, local_matrix_size);
166
167 NodalMatrixType laplace =
168 NodalMatrixType::Zero(local_matrix_size, local_matrix_size);
169 NodalMatrixType storage =
170 NodalMatrixType::Zero(local_matrix_size, local_matrix_size);
171
172 unsigned const n_integration_points =
173 _integration_method.getNumberOfPoints();
174
175 auto const& medium =
176 *_process_data.media_map.getMedium(_element.getID());
178
179 for (unsigned ip = 0; ip < n_integration_points; ip++)
180 {
181 auto const& sm = _shape_matrices[ip];
183 std::nullopt, _element.getID(),
187 sm.N))};
188
189 double const w =
190 _integration_method.getWeightedPoint(ip).getWeight() * sm.detJ *
191 sm.integralMeasure;
192
193 // get the local temperature and put it in the variable array for
194 // access in MPL
195 double T_int_pt = 0.0;
196 NumLib::shapeFunctionInterpolate(local_x, sm.N, T_int_pt);
197 vars.temperature = T_int_pt;
198
200 medium
201 .property(
203 .value(vars, pos, t, dt));
204 auto const specific_heat_capacity =
205 medium
207 specific_heat_capacity)
208 .template value<double>(vars, pos, t, dt);
209 auto const density =
211 .template value<double>(vars, pos, t, dt);
212
213 laplace.noalias() += sm.dNdx.transpose() * k * sm.dNdx * w;
214 storage.noalias() +=
215 sm.N.transpose() * density * specific_heat_capacity * sm.N * w;
216 }
217 if (_process_data.mass_lumping)
218 {
219 storage = storage.colwise().sum().eval().asDiagonal();
220 }
221
222 local_Jac.noalias() += laplace + storage / dt;
223 local_rhs.noalias() -= laplace * x + storage * (x - x_prev) / dt;
224 }
225
226 Eigen::Map<const Eigen::RowVectorXd> getShapeMatrix(
227 const unsigned integration_point) const override
228 {
229 auto const& N = _shape_matrices[integration_point].N;
230
231 // assumes N is stored contiguously in memory
232 return Eigen::Map<const Eigen::RowVectorXd>(N.data(), N.size());
233 }
234
235 std::vector<double> const& getIntPtHeatFlux(
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 override
240 {
241 int const process_id = 0; // monolithic case.
242 auto const indices =
243 NumLib::getIndices(_element.getID(), *dof_table[process_id]);
244 assert(!indices.empty());
245 auto const& local_x = x[process_id]->get(indices);
246
247 auto const T_nodal_values = Eigen::Map<const NodalVectorType>(
248 local_x.data(), ShapeFunction::NPOINTS);
249
250 unsigned const n_integration_points =
251 _integration_method.getNumberOfPoints();
252
253 auto const& medium =
254 *_process_data.media_map.getMedium(_element.getID());
256
257 double const dt = std::numeric_limits<double>::quiet_NaN();
258 cache.clear();
259 auto cache_mat = MathLib::createZeroedMatrix<
260 Eigen::Matrix<double, GlobalDim, Eigen::Dynamic, Eigen::RowMajor>>(
261 cache, GlobalDim, n_integration_points);
262
263 for (unsigned ip = 0; ip < n_integration_points; ip++)
264 {
265 auto const& sm = _shape_matrices[ip];
266
268 std::nullopt, _element.getID(),
272 sm.N))};
273
274 // get the local temperature and put it in the variable array for
275 // access in MPL
276 vars.temperature = sm.N.dot(T_nodal_values);
277
279 medium
280 .property(
282 .value(vars, pos, t, dt));
283
284 // heat flux only computed for output.
285 cache_mat.col(ip).noalias() = -k * sm.dNdx * T_nodal_values;
286 }
287
288 return cache;
289 }
290
291private:
294
296 std::vector<ShapeMatrices, Eigen::aligned_allocator<ShapeMatrices>>
298};
299
300} // namespace HeatConduction
301} // namespace ProcessLib
EigenFixedShapeMatrixPolicy< ShapeFunction, GlobalDim > ShapeMatrixPolicyType
virtual std::vector< double > const & getIntPtHeatFlux(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const =0
HeatConductionProcessData const & _process_data
typename LocalAssemblerTraits::LocalVector NodalVectorType
typename ShapeMatricesType::GlobalDimVectorType GlobalDimVectorType
std::vector< double > const & getIntPtHeatFlux(const double t, std::vector< GlobalVector * > const &x, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_table, std::vector< double > &cache) const override
void assembleWithJacobian(double const t, double const dt, std::vector< double > const &local_x, std::vector< double > const &local_x_prev, std::vector< double > &local_rhs_data, std::vector< double > &local_Jac_data) 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 > &) override
typename ShapeMatricesType::ShapeMatrices ShapeMatrices
ProcessLib::LocalAssemblerTraits< ShapeMatricesType, ShapeFunction::NPOINTS, NUM_NODAL_DOF, GlobalDim > LocalAssemblerTraits
LocalAssemblerData(MeshLib::Element const &element, std::size_t const local_matrix_size, NumLib::GenericIntegrationMethod const &integration_method, bool is_axially_symmetric, HeatConductionProcessData const &process_data)
ShapeMatrixPolicyType< ShapeFunction, GlobalDim > ShapeMatricesType
std::vector< ShapeMatrices, Eigen::aligned_allocator< ShapeMatrices > > _shape_matrices
Eigen::Map< const Eigen::RowVectorXd > getShapeMatrix(const unsigned integration_point) const override
Provides the shape matrix at the given integration point.
NumLib::GenericIntegrationMethod const & _integration_method
typename LocalAssemblerTraits::LocalMatrix NodalMatrixType
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 &)
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)
detail::LocalAssemblerTraitsFixed< ShpPol, NNodes, NodalDOF, Dim > LocalAssemblerTraits
NumLib::ShapeMatrices< NodalRowVectorType, DimNodalMatrixType, DimMatrixType, GlobalDimNodalMatrixType > ShapeMatrices
VectorType< GlobalDim > GlobalDimVectorType
Matrix< NNodes *NodalDOF, NNodes *NodalDOF > LocalMatrix