OGS 6.1.0-1721-g6382411ad
HeatTransportBHEProcess.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
15 
18 
21 
22 namespace ProcessLib
23 {
24 namespace HeatTransportBHE
25 {
27  MeshLib::Mesh& mesh,
28  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
29  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
30  unsigned const integration_order,
31  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>&&
32  process_variables,
33  HeatTransportBHEProcessData&& process_data,
34  SecondaryVariableCollection&& secondary_variables,
35  NumLib::NamedFunctionCaller&& named_function_caller)
36  : Process(mesh, std::move(jacobian_assembler), parameters,
37  integration_order, std::move(process_variables),
38  std::move(secondary_variables), std::move(named_function_caller)),
39  _process_data(std::move(process_data)),
40  _bheMeshData(getBHEDataInMesh(mesh))
41 {
42  if (_bheMeshData.BHE_mat_IDs.size() !=
44  {
45  OGS_FATAL(
46  "The number of the given BHE properties (%d) are not consistent "
47  "with the number of BHE groups in the mesh (%d).",
49  _bheMeshData.BHE_mat_IDs.size());
50  }
51 
52  auto material_ids = MeshLib::materialIDs(mesh);
53  if (material_ids == nullptr)
54  {
55  OGS_FATAL("Not able to get material IDs! ");
56  }
57 
59 
60  // create a map from a material ID to a BHE ID
61  for (int i = 0; i < static_cast<int>(_bheMeshData.BHE_mat_IDs.size()); i++)
62  {
63  // fill in the map structure
65  i;
66  }
67 }
68 
70 {
71  // Create single component dof in every of the mesh's nodes.
73  std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
74 
75  //
76  // Soil temperature variable defined on the whole mesh.
77  //
79  std::make_unique<MeshLib::MeshSubset>(_mesh, _mesh.getNodes());
80  std::vector<MeshLib::MeshSubset> all_mesh_subsets{*_mesh_subset_soil_nodes};
81 
82  std::vector<std::vector<MeshLib::Element*> const*> vec_var_elements;
83  vec_var_elements.push_back(&(_mesh.getElements()));
84 
85  std::vector<int> vec_n_components{
86  1}; // one component for the soil temperature variable.
87 
88  //
89  // BHE nodes with BHE type dependend number of variables.
90  //
91  int const n_BHEs = _process_data._vec_BHE_property.size();
92  assert(n_BHEs == static_cast<int>(_bheMeshData.BHE_mat_IDs.size()));
93  assert(n_BHEs == static_cast<int>(_bheMeshData.BHE_nodes.size()));
94  assert(n_BHEs == static_cast<int>(_bheMeshData.BHE_elements.size()));
95 
96  // the BHE nodes need to be cherry-picked from the vector
97  for (int i = 0; i < n_BHEs; i++)
98  {
99  auto const number_of_unknowns = apply_visitor(
100  [](auto const& bhe) { return bhe.number_of_unknowns; },
102  auto const& bhe_nodes = _bheMeshData.BHE_nodes[i];
103  auto const& bhe_elements = _bheMeshData.BHE_elements[i];
104 
105  // All the BHE nodes have additional variables.
106  _mesh_subset_BHE_nodes.push_back(
107  std::make_unique<MeshLib::MeshSubset const>(_mesh, bhe_nodes));
108 
109  std::generate_n(
110  std::back_inserter(all_mesh_subsets),
111  // Here the number of components equals to the
112  // number of unknowns on the BHE
113  number_of_unknowns,
114  [& ms = _mesh_subset_BHE_nodes.back()]() { return *ms; });
115 
116  vec_n_components.push_back(number_of_unknowns);
117  vec_var_elements.push_back(&bhe_elements);
118  }
119 
121  std::make_unique<NumLib::LocalToGlobalIndexMap>(
122  std::move(all_mesh_subsets),
123  vec_n_components,
124  vec_var_elements,
126 
127  // in case of debugging the dof table, activate the following line
128  // std::cout << *_local_to_global_index_map << "\n";
129 }
130 
132  NumLib::LocalToGlobalIndexMap const& dof_table,
133  MeshLib::Mesh const& mesh,
134  unsigned const integration_order)
135 {
136  // Quick access map to BHE's through element ids.
137  std::unordered_map<std::size_t, BHE::BHETypes*> element_to_bhe_map;
138  int const n_BHEs = _process_data._vec_BHE_property.size();
139  for (int i = 0; i < n_BHEs; i++)
140  {
141  auto const& bhe_elements = _bheMeshData.BHE_elements[i];
142  for (auto const& e : bhe_elements)
143  {
144  element_to_bhe_map[e->getID()] =
146  }
147  }
148 
149  assert(mesh.getDimension() == 3);
152  mesh.getElements(), dof_table, _local_assemblers, element_to_bhe_map,
153  mesh.isAxiallySymmetric(), integration_order, _process_data);
154 
155  // Create BHE boundary conditions for each of the BHEs
157 }
158 
160  GlobalVector const& x,
161  GlobalMatrix& M,
162  GlobalMatrix& K,
163  GlobalVector& b)
164 {
165  DBUG("Assemble HeatTransportBHE process.");
166 
167  const int process_id = 0;
168  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
169 
170  std::vector<std::reference_wrapper<NumLib::LocalToGlobalIndexMap>>
171  dof_table = {std::ref(*_local_to_global_index_map)};
172  // Call global assembler for each local assembly item.
175  pv.getActiveElementIDs(), dof_table, t, x, M, K, b,
177 }
178 
180  const double /*t*/, GlobalVector const& /*x*/, GlobalVector const& /*xdot*/,
181  const double /*dxdot_dx*/, const double /*dx_dx*/, GlobalMatrix& /*M*/,
182  GlobalMatrix& /*K*/, GlobalVector& /*b*/, GlobalMatrix& /*Jac*/)
183 {
184  OGS_FATAL(
185  "HeatTransportBHE: analytical Jacobian assembly is not implemented");
186 }
187 
189  const double t, GlobalVector const& x, int const process_id)
190 {
191  DBUG("Compute heat flux for HeatTransportBHE process.");
192 
193  ProcessLib::ProcessVariable const& pv = getProcessVariables(process_id)[0];
197  getDOFTable(process_id), t, x, _coupled_solutions);
198 }
199 
201  std::vector<std::vector<MeshLib::Node*>> const& all_bhe_nodes)
202 {
203  const int process_id = 0;
204  auto& bcs = _boundary_conditions[process_id];
205 
206  int const n_BHEs = static_cast<int>(_process_data._vec_BHE_property.size());
207 
208  // for each BHE
209  for (int bhe_i = 0; bhe_i < n_BHEs; bhe_i++)
210  {
211  auto const& bhe_nodes = all_bhe_nodes[bhe_i];
212  // find the variable ID
213  // the soil temperature is 0-th variable
214  // the BHE temperature is therefore bhe_i + 1
215  const int variable_id = bhe_i + 1;
216 
217  // Bottom and top nodes w.r.t. the z coordinate.
218  auto const bottom_top_nodes = std::minmax_element(
219  begin(bhe_nodes), end(bhe_nodes),
220  [&](auto const& a, auto const& b) {
221  return a->getCoords()[2] < b->getCoords()[2];
222  });
223  auto const bc_bottom_node_id = (*bottom_top_nodes.first)->getID();
224  auto const bc_top_node_id = (*bottom_top_nodes.second)->getID();
225 
226  auto get_global_bhe_bc_indices =
227  [&](std::size_t const node_id,
228  std::pair<int, int> const& in_out_component_id) {
229  return std::make_pair(
230  _local_to_global_index_map->getGlobalIndex(
231  {_mesh.getID(), MeshLib::MeshItemType::Node, node_id},
232  variable_id, in_out_component_id.first),
233  _local_to_global_index_map->getGlobalIndex(
235  variable_id, in_out_component_id.second));
236  };
237 
238  auto createBCs = [&](auto& bhe) {
239  for (auto const& in_out_component_id :
240  bhe.inflow_outflow_bc_component_ids)
241  {
242  // Top, inflow.
243  bcs.addBoundaryCondition(
245  get_global_bhe_bc_indices(bc_top_node_id,
246  in_out_component_id),
247  bhe));
248 
249  // Bottom, outflow.
250  bcs.addBoundaryCondition(
252  get_global_bhe_bc_indices(bc_bottom_node_id,
253  in_out_component_id)));
254  }
255  };
256  apply_visitor(createBCs, _process_data._vec_BHE_property[bhe_i]);
257  }
258 }
259 } // namespace HeatTransportBHE
260 } // namespace ProcessLib
MeshLib::Mesh & _mesh
Definition: Process.h:261
virtual NumLib::LocalToGlobalIndexMap const & getDOFTable(const int) const
Definition: Process.h:115
std::unique_ptr< BHEBottomDirichletBoundaryCondition > createBHEBottomDirichletBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices)
virtual void computeSecondaryVariable(std::size_t const mesh_item_id, NumLib::LocalToGlobalIndexMap const &dof_table, const double t, GlobalVector const &x, CoupledSolutionsForStaggeredScheme const *coupled_xs)
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_all_nodes
Definition: Process.h:262
std::vector< std::vector< MeshLib::Element * > > BHE_elements
Definition: MeshUtils.h:36
static void executeSelectedMemberOnDereferenced(Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
std::vector< std::reference_wrapper< ProcessVariable > > const & getProcessVariables(const int process_id) const
Definition: Process.h:123
std::unique_ptr< BHEInflowDirichletBoundaryCondition< BHEType > > createBHEInflowDirichletBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices, BHEType &bhe)
std::size_t getID() const
Get id of the mesh.
Definition: Mesh.h:123
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition: Mesh.h:105
void assemble(std::size_t const mesh_item_id, LocalAssemblerInterface &local_assembler, std::vector< std::reference_wrapper< NumLib::LocalToGlobalIndexMap >> const &dof_tables, double const t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, CoupledSolutionsForStaggeredScheme const *const cpl_xs)
std::vector< BoundaryConditionCollection > _boundary_conditions
Definition: Process.h:305
void assembleWithJacobianConcreteProcess(const double t, GlobalVector const &x, GlobalVector const &xdot, const double dxdot_dx, const double dx_dx, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b, GlobalMatrix &Jac) override
bool isAxiallySymmetric() const
Definition: Mesh.h:137
std::unique_ptr< NumLib::LocalToGlobalIndexMap > _local_to_global_index_map
Definition: Process.h:264
void createBHEBoundaryConditionTopBottom(std::vector< std::vector< MeshLib::Node *>> const &all_bhe_nodes)
Builds expression trees of named functions dynamically at runtime.
void computeSecondaryVariableConcrete(double const t, GlobalVector const &x, int const process_id) override
std::vector< std::unique_ptr< HeatTransportBHELocalAssemblerInterface > > _local_assemblers
static void executeSelectedMemberDereferenced(Object &object, Method method, Container const &container, std::vector< std::size_t > const &active_container_ids, Args &&... args)
void initializeConcreteProcess(NumLib::LocalToGlobalIndexMap const &dof_table, MeshLib::Mesh const &mesh, unsigned const integration_order) override
Process specific initialization called by initialize().
std::unique_ptr< MeshLib::MeshSubset const > _mesh_subset_soil_nodes
void createLocalAssemblers(std::vector< MeshLib::Element *> const &mesh_elements, NumLib::LocalToGlobalIndexMap const &dof_table, std::vector< std::unique_ptr< LocalAssemblerInterface >> &local_assemblers, ExtraCtorArgs &&... extra_ctor_args)
std::vector< std::vector< MeshLib::Node * > > BHE_nodes
Definition: MeshUtils.h:37
std::vector< std::unique_ptr< MeshLib::MeshSubset const > > _mesh_subset_BHE_nodes
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:352
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition: Mesh.h:108
CoupledSolutionsForStaggeredScheme * _coupled_solutions
Definition: Process.h:279
Handles configuration of several secondary variables from the project file.
void assembleConcreteProcess(const double t, GlobalVector const &x, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b) override
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition: Mesh.h:81
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
HeatTransportBHEProcess(MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< std::unique_ptr< ParameterBase >> const &parameters, unsigned const integration_order, std::vector< std::vector< std::reference_wrapper< ProcessVariable >>> &&process_variables, HeatTransportBHEProcessData &&process_data, SecondaryVariableCollection &&secondary_variables, NumLib::NamedFunctionCaller &&named_function_caller)
BHEMeshData getBHEDataInMesh(MeshLib::Mesh const &mesh)
Definition: MeshUtils.cpp:49
VectorMatrixAssembler _global_assembler
Definition: Process.h:273
Ordering data by component type.
std::vector< std::size_t > & getActiveElementIDs() const