OGS
HeatTransportBHELocalAssemblerBHE-impl.h
Go to the documentation of this file.
1 
11 #pragma once
12 
17 
18 namespace ProcessLib
19 {
20 namespace HeatTransportBHE
21 {
23 {
24  constexpr int global_dim = 3;
25  constexpr int element_dim = 1;
26 
27  assert(e.getDimension() == element_dim);
28  const MeshLib::ElementCoordinatesMappingLocal ele_local_coord(e,
29  global_dim);
30  return ele_local_coord.getRotationMatrixToGlobal()
31  .template topLeftCorner<global_dim, element_dim>();
32 }
33 
34 template <typename ShapeFunction, typename IntegrationMethod, typename BHEType>
37  BHEType const& bhe,
38  bool const is_axially_symmetric,
39  unsigned const integration_order,
40  HeatTransportBHEProcessData& process_data)
41  : _process_data(process_data),
42  _integration_method(integration_order),
43  _bhe(bhe),
44  _element_id(e.getID()),
45  _rotation_matrix_1D_to_3D(compute1Dto3DRotationMatrix(e))
46 {
47  // need to make sure that the BHE elements are one-dimensional
48  assert(e.getDimension() == 1);
49 
50  unsigned const n_integration_points =
51  _integration_method.getNumberOfPoints();
52 
53  _ip_data.reserve(n_integration_points);
54  _secondary_data.N.resize(n_integration_points);
55 
56  auto const shape_matrices =
58  3 /* GlobalDim */>(e, is_axially_symmetric,
60 
61  // ip data initialization
62  for (unsigned ip = 0; ip < n_integration_points; ip++)
63  {
64  auto const& sm = shape_matrices[ip];
65  // create the class IntegrationPointDataBHE in place
66  _ip_data.push_back(
67  {sm.N, sm.dNdx,
68  _integration_method.getWeightedPoint(ip).getWeight() *
69  sm.integralMeasure * sm.detJ});
70 
71  _secondary_data.N[ip] = sm.N;
72  }
73 
74  // calculate the element direction vector
75  auto const p0 =
76  Eigen::Map<Eigen::Vector3d const>(e.getNode(0)->getCoords(), 3);
77  auto const p1 =
78  Eigen::Map<Eigen::Vector3d const>(e.getNode(1)->getCoords(), 3);
79 
80  _element_direction = (p1 - p0).normalized();
81 
85  static constexpr int max_num_thermal_exchange_terms = 5;
86  // formulate the local BHE R matrix
87  for (int idx_bhe_unknowns = 0; idx_bhe_unknowns < bhe_unknowns;
88  idx_bhe_unknowns++)
89  {
90  typename ShapeMatricesType::template MatrixType<
92  matBHE_loc_R = ShapeMatricesType::template MatrixType<
96  // Loop over Gauss points
97  for (unsigned ip = 0; ip < n_integration_points; ip++)
98  {
99  auto const& N = _ip_data[ip].N;
100  auto const& w = _ip_data[ip].integration_weight;
101 
102  auto const& R = _bhe.thermalResistance(idx_bhe_unknowns);
103  // calculate mass matrix for current unknown
104  matBHE_loc_R += N.transpose() * N * (1 / R) * w;
105  } // end of loop over integration point
106 
107  // The following assembly action is according to Diersch (2013) FEFLOW
108  // book please refer to M.127 and M.128 on page 955 and 956
109  // The if check is absolutely necessary because
110  // (i) In the CXA and CXC case, there are 3 exchange terms,
111  // and it is the same as the number of unknowns;
112  // (ii) In the 1U case, there are 4 exchange terms,
113  // and it is again same as the number of unknowns;
114  // (iii) In the 2U case, there are 5 exchange terms,
115  // and it is less than the number of unknowns (8).
116  if (idx_bhe_unknowns < max_num_thermal_exchange_terms)
117  {
118  _bhe.template assembleRMatrices<ShapeFunction::NPOINTS>(
119  idx_bhe_unknowns, matBHE_loc_R, _R_matrix, _R_pi_s_matrix,
120  _R_s_matrix);
121  }
122  } // end of loop over BHE unknowns
123 
124  // debugging
125  // std::string sep =
126  // "\n----------------------------------------\n";
127  // Eigen::IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
128  // std::cout << "_R_matrix: \n" << sep;
129  // std::cout << _R_matrix.format(CleanFmt) << sep;
130  // std::cout << "_R_s_matrix: \n" << sep;
131  // std::cout << _R_s_matrix.format(CleanFmt) << sep;
132  // std::cout << "_R_pi_s_matrix: \n" << sep;
133  // std::cout << _R_pi_s_matrix.format(CleanFmt) << sep;
134 }
135 
136 template <typename ShapeFunction, typename IntegrationMethod, typename BHEType>
137 void HeatTransportBHELocalAssemblerBHE<ShapeFunction, IntegrationMethod,
138  BHEType>::
139  assemble(
140  double const /*t*/, double const /*dt*/,
141  std::vector<double> const& /*local_x*/,
142  std::vector<double> const& /*local_xdot*/,
143  std::vector<double>& local_M_data, std::vector<double>& local_K_data,
144  std::vector<double>& /*local_b_data*/) // local b vector is not touched
145 {
146  auto local_M = MathLib::createZeroedMatrix<BheLocalMatrixType>(
147  local_M_data, local_matrix_size, local_matrix_size);
148  auto local_K = MathLib::createZeroedMatrix<BheLocalMatrixType>(
149  local_K_data, local_matrix_size, local_matrix_size);
150 
151  unsigned const n_integration_points =
152  _integration_method.getNumberOfPoints();
153 
154  auto const& pipe_heat_capacities = _bhe.pipeHeatCapacities();
155  auto const& pipe_heat_conductions = _bhe.pipeHeatConductions();
156  auto const& pipe_advection_vectors =
157  _bhe.pipeAdvectionVectors(_element_direction);
158  auto const& cross_section_areas = _bhe.crossSectionAreas();
159 
160  // the mass and conductance matrix terms
161  for (unsigned ip = 0; ip < n_integration_points; ip++)
162  {
163  auto& ip_data = _ip_data[ip];
164 
165  auto const& w = ip_data.integration_weight;
166  auto const& N = ip_data.N;
167  auto const& dNdx = ip_data.dNdx;
168 
169  // looping over all unknowns.
170  for (int idx_bhe_unknowns = 0; idx_bhe_unknowns < bhe_unknowns;
171  idx_bhe_unknowns++)
172  {
173  // get coefficient of mass from corresponding BHE.
174  auto const& mass_coeff = pipe_heat_capacities[idx_bhe_unknowns];
175  auto const& lambda = pipe_heat_conductions[idx_bhe_unknowns];
176  auto const& advection_vector =
177  pipe_advection_vectors[idx_bhe_unknowns];
178 
179  // R^T * v, 3D to 1D:
180  double const advection_coefficient =
181  _rotation_matrix_1D_to_3D.dot(advection_vector);
182 
183  auto const& A = cross_section_areas[idx_bhe_unknowns];
184 
185  int const single_bhe_unknowns_index =
186  bhe_unknowns_index +
187  single_bhe_unknowns_size * idx_bhe_unknowns;
188  // local M
189  local_M
190  .template block<single_bhe_unknowns_size,
191  single_bhe_unknowns_size>(
192  single_bhe_unknowns_index, single_bhe_unknowns_index)
193  .noalias() += N.transpose() * N * mass_coeff * A * w;
194 
195  // local K
196  // laplace part
197  local_K
198  .template block<single_bhe_unknowns_size,
199  single_bhe_unknowns_size>(
200  single_bhe_unknowns_index, single_bhe_unknowns_index)
201  .noalias() += dNdx.transpose() * dNdx * lambda * A * w;
202  // advection part
203  int constexpr element_dim = 1;
204  local_K
205  .template block<single_bhe_unknowns_size,
206  single_bhe_unknowns_size>(
207  single_bhe_unknowns_index, single_bhe_unknowns_index)
208  .noalias() +=
209  advection_coefficient * N.transpose() *
210  dNdx.template topLeftCorner<element_dim,
211  ShapeFunction::NPOINTS>() *
212  A * w;
213  }
214  }
215 
216  // add the R matrix to local_K
217  local_K.template block<bhe_unknowns_size, bhe_unknowns_size>(
218  bhe_unknowns_index, bhe_unknowns_index) += _R_matrix;
219 
220  // add the R_pi_s matrix to local_K
221  local_K
222  .template block<bhe_unknowns_size, soil_temperature_size>(
223  bhe_unknowns_index, soil_temperature_index)
224  .noalias() += _R_pi_s_matrix;
225  local_K
226  .template block<soil_temperature_size, bhe_unknowns_size>(
227  soil_temperature_index, bhe_unknowns_index)
228  .noalias() += _R_pi_s_matrix.transpose();
229 
230  // add the R_s matrix to local_K
231  local_K
232  .template block<soil_temperature_size, soil_temperature_size>(
233  soil_temperature_index, soil_temperature_index)
234  .noalias() += _bhe.number_of_grout_zones * _R_s_matrix;
235 
236  // debugging
237  // std::string sep = "\n----------------------------------------\n";
238  // Eigen::IOFormat CleanFmt(4, 0, ", ", "\n", "[", "]");
239  // std::cout << local_K.format(CleanFmt) << sep;
240  // std::cout << local_M.format(CleanFmt) << sep;
241 }
242 } // namespace HeatTransportBHE
243 } // namespace ProcessLib
const T * getCoords() const
Definition: TemplatePoint.h:75
const RotationMatrix & getRotationMatrixToGlobal() const
return a rotation matrix converting to global coordinates
virtual const Node * getNode(unsigned idx) const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
ShapeMatricesType::template MatrixType< soil_temperature_size, soil_temperature_size > _R_s_matrix
ShapeMatricesType::template MatrixType< bhe_unknowns_size, soil_temperature_size > _R_pi_s_matrix
std::vector< IntegrationPointDataBHE< ShapeMatricesType >, Eigen::aligned_allocator< IntegrationPointDataBHE< ShapeMatricesType > > > _ip_data
ShapeMatricesType::template MatrixType< bhe_unknowns_size, bhe_unknowns_size > _R_matrix
HeatTransportBHELocalAssemblerBHE(HeatTransportBHELocalAssemblerBHE const &)=delete
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)
Eigen::Vector3d compute1Dto3DRotationMatrix(MeshLib::Element const &e)
std::vector< ShapeMatrixType, Eigen::aligned_allocator< ShapeMatrixType > > N
Definition: SecondaryData.h:28