OGS
HeatTransportBHELocalAssemblerBHE-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
4#pragma once
5
9
10namespace ProcessLib
11{
12namespace HeatTransportBHE
13{
14template <typename ShapeFunction, typename BHEType>
17 MeshLib::Element const& e,
18 NumLib::GenericIntegrationMethod const& integration_method,
19 BHEType const& bhe,
20 bool const is_axially_symmetric,
21 HeatTransportBHEProcessData& process_data)
22 : _process_data(process_data),
23 _integration_method(integration_method),
24 _bhe(bhe),
25 _element_id(e.getID())
26{
27 // need to make sure that the BHE elements are one-dimensional
28 assert(e.getDimension() == 1);
29
30 unsigned const n_integration_points =
31 _integration_method.getNumberOfPoints();
32
33 _ip_data.reserve(n_integration_points);
34 _secondary_data.N.resize(n_integration_points);
35
36 auto const shape_matrices =
38 3 /* GlobalDim */>(e, is_axially_symmetric,
40
41 // ip data initialization
42 for (unsigned ip = 0; ip < n_integration_points; ip++)
43 {
44 auto const& sm = shape_matrices[ip];
45 // create the class IntegrationPointDataBHE in place
46 _ip_data.push_back(
47 {sm.N, sm.dNdx,
48 _integration_method.getWeightedPoint(ip).getWeight() *
49 sm.integralMeasure * sm.detJ});
50
51 _secondary_data.N[ip] = sm.N;
52 }
53
54 // calculate the element direction vector
55 auto const& p0 = e.getNode(0)->asEigenVector3d();
56 auto const& p1 = e.getNode(1)->asEigenVector3d();
57
58 _element_direction = (p1 - p0).normalized();
59
63 static constexpr int max_num_thermal_exchange_terms = 5;
64 // formulate the local BHE R matrix
65 for (int idx_bhe_unknowns = 0; idx_bhe_unknowns < bhe_unknowns;
66 idx_bhe_unknowns++)
67 {
68 typename ShapeMatricesType::template MatrixType<
70 matBHE_loc_R = ShapeMatricesType::template MatrixType<
74 // Loop over Gauss points
75 for (unsigned ip = 0; ip < n_integration_points; ip++)
76 {
77 auto const& N = _ip_data[ip].N;
78 auto const& w = _ip_data[ip].integration_weight;
79
80 auto const& R = _bhe.thermalResistance(idx_bhe_unknowns);
81 // calculate mass matrix for current unknown
82 matBHE_loc_R += N.transpose() * N * (1 / R) * w;
83 } // end of loop over integration point
84
85 // The following assembly action is according to Diersch (2013) FEFLOW
86 // book please refer to M.127 and M.128 on page 955 and 956
87 // The if check is absolutely necessary because
88 // (i) In the CXA and CXC case, there are 3 exchange terms,
89 // and it is the same as the number of unknowns;
90 // (ii) In the 1U case, there are 4 exchange terms,
91 // and it is again same as the number of unknowns;
92 // (iii) In the 2U case, there are 5 exchange terms,
93 // and it is less than the number of unknowns (8).
94 if (idx_bhe_unknowns < max_num_thermal_exchange_terms)
95 {
96 _bhe.template assembleRMatrices<ShapeFunction::NPOINTS>(
97 idx_bhe_unknowns, matBHE_loc_R, _R_matrix, _R_pi_s_matrix,
99 }
100 } // end of loop over BHE unknowns
101
102 // debugging
103 // std::string sep =
104 // "\n----------------------------------------\n";
105 // Eigen::IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
106 // std::cout << "_R_matrix: \n" << sep;
107 // std::cout << _R_matrix.format(CleanFmt) << sep;
108 // std::cout << "_R_s_matrix: \n" << sep;
109 // std::cout << _R_s_matrix.format(CleanFmt) << sep;
110 // std::cout << "_R_pi_s_matrix: \n" << sep;
111 // std::cout << _R_pi_s_matrix.format(CleanFmt) << sep;
112}
113
114template <typename ShapeFunction, typename BHEType>
116 double const /*t*/, double const /*dt*/,
117 std::vector<double> const& /*local_x*/,
118 std::vector<double> const& /*local_x_prev*/,
119 std::vector<double>& local_M_data, std::vector<double>& local_K_data,
120 std::vector<double>& /*local_b_data*/) // local b vector is not touched
121{
123 local_M_data, local_matrix_size, local_matrix_size);
125 local_K_data, local_matrix_size, local_matrix_size);
126
127 unsigned const n_integration_points =
128 _integration_method.getNumberOfPoints();
129
130 auto const& pipe_heat_capacities = _bhe.pipeHeatCapacities();
131 auto const& pipe_heat_conductions = _bhe.pipeHeatConductions();
132 auto const& pipe_advection_vectors =
133 _bhe.pipeAdvectionVectors(_element_direction);
134 auto const& cross_section_areas = _bhe.crossSectionAreas();
135
136 // the mass and conductance matrix terms
137 for (unsigned ip = 0; ip < n_integration_points; ip++)
138 {
139 auto& ip_data = _ip_data[ip];
140
141 auto const& w = ip_data.integration_weight;
142 auto const& N = ip_data.N;
143 auto const& dNdx = ip_data.dNdx;
144
145 // looping over all unknowns.
146 for (int idx_bhe_unknowns = 0; idx_bhe_unknowns < bhe_unknowns;
147 idx_bhe_unknowns++)
148 {
149 // get coefficient of mass from corresponding BHE.
150 auto const& mass_coeff = pipe_heat_capacities[idx_bhe_unknowns];
151 auto const& lambda = pipe_heat_conductions[idx_bhe_unknowns];
152 auto const& advection_vector =
153 pipe_advection_vectors[idx_bhe_unknowns];
154 auto const& A = cross_section_areas[idx_bhe_unknowns];
155
156 int const single_bhe_unknowns_index =
158 single_bhe_unknowns_size * idx_bhe_unknowns;
159 // local M
160 local_M
161 .template block<single_bhe_unknowns_size,
163 single_bhe_unknowns_index, single_bhe_unknowns_index)
164 .noalias() += N.transpose() * N * mass_coeff * A * w;
165
166 // local K
167 // laplace part
168 local_K
169 .template block<single_bhe_unknowns_size,
171 single_bhe_unknowns_index, single_bhe_unknowns_index)
172 .noalias() += dNdx.transpose() * dNdx * lambda * A * w;
173 // advection part
174 local_K
175 .template block<single_bhe_unknowns_size,
177 single_bhe_unknowns_index, single_bhe_unknowns_index)
178 .noalias() +=
179 N.transpose() * advection_vector.transpose() * dNdx * A * w;
180 }
181 }
182
183 // add the R matrix to local_K
184 local_K.template block<bhe_unknowns_size, bhe_unknowns_size>(
186
187 // add the R_pi_s matrix to local_K
188 local_K
189 .template block<bhe_unknowns_size, soil_temperature_size>(
191 .noalias() += _R_pi_s_matrix;
192 local_K
193 .template block<soil_temperature_size, bhe_unknowns_size>(
195 .noalias() += _R_pi_s_matrix.transpose();
196
197 // add the R_s matrix to local_K
198 local_K
199 .template block<soil_temperature_size, soil_temperature_size>(
201 .noalias() += _bhe.number_of_grout_zones * _R_s_matrix;
202
203 // debugging
204 // std::string sep = "\n----------------------------------------\n";
205 // Eigen::IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
206 // std::cout << local_K.format(CleanFmt) << sep;
207 // std::cout << local_M.format(CleanFmt) << sep;
208}
209
210template <typename ShapeFunction, typename BHEType>
212 assembleWithJacobian(double const t, double const dt,
213 std::vector<double> const& local_x,
214 std::vector<double> const& local_x_prev,
215 std::vector<double>& local_rhs_data,
216 std::vector<double>& local_Jac_data)
217{
218 auto const local_matrix_size = local_x.size();
219 // initialize x and x_prev
220 auto x =
221 Eigen::Map<BheLocalVectorType const>(local_x.data(), local_matrix_size);
222 auto x_prev = Eigen::Map<BheLocalVectorType const>(local_x_prev.data(),
224 // initialize local_Jac and local_rhs
226 local_Jac_data, local_matrix_size, local_matrix_size);
228 local_rhs_data, local_matrix_size);
229
230 std::vector<double> local_M_data;
231 std::vector<double> local_K_data;
232 assemble(t, dt, local_x, local_x_prev, local_M_data, local_K_data,
233 local_rhs_data /*not going to be used*/);
234
235 // convert to matrix
237 local_M_data, local_matrix_size, local_matrix_size);
239 local_K_data, local_matrix_size, local_matrix_size);
240
241 // Jac matrix and rhs vector operation
242 local_Jac.noalias() += local_K + local_M / dt;
243 local_rhs.noalias() -= local_K * x + local_M * (x - x_prev) / dt;
244
245 local_M.setZero();
246 local_K.setZero();
247}
248} // namespace HeatTransportBHE
249} // namespace ProcessLib
Eigen::Vector3d const & asEigenVector3d() const
Definition Point3d.h:55
virtual const Node * getNode(unsigned idx) const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
ShapeMatricesType::template MatrixType< bhe_unknowns_size, bhe_unknowns_size > _R_matrix
ShapeMatricesType::template MatrixType< soil_temperature_size, soil_temperature_size > _R_s_matrix
std::vector< IntegrationPointDataBHE< ShapeMatricesType >, Eigen::aligned_allocator< IntegrationPointDataBHE< ShapeMatricesType > > > _ip_data
ShapeMatricesType::template MatrixType< bhe_unknowns_size, soil_temperature_size > _R_pi_s_matrix
void assemble(double const, double const, std::vector< double > const &, std::vector< double > const &, std::vector< double > &, std::vector< double > &, std::vector< double > &) 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
HeatTransportBHELocalAssemblerBHE(HeatTransportBHELocalAssemblerBHE const &)=delete
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)
Eigen::Map< const Matrix > toMatrix(std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
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)