OGS
BHEInflowPythonBoundaryCondition.h
Go to the documentation of this file.
1 
11 #pragma once
12 #ifdef OGS_USE_PYTHON
13 #include <pybind11/pybind11.h>
14 #endif // OGS_USE_PYTHON
15 #include <algorithm>
16 #include <iostream>
17 #include <vector>
18 
20 #include "BaseLib/Error.h"
28 
29 namespace ProcessLib
30 {
32 template <typename BHEType>
34 {
35 public:
37  std::pair<GlobalIndexType, GlobalIndexType>&& in_out_global_indices,
38  BHEType& bhe,
40  : _in_out_global_indices(std::move(in_out_global_indices)),
41  _bhe(bhe),
42  _py_bc_object(py_bc_object)
43  {
44  const auto g_idx_T_out =
45  static_cast<int>(_in_out_global_indices.second);
46 
47  // store the bc node ids to BHE network dataframe
48  std::get<3>(_py_bc_object.dataframe_network).emplace_back(g_idx_T_out);
49  }
50 
52  const double t, const GlobalVector& /* x */,
53  NumLib::IndexValueVector<GlobalIndexType>& bc_values) const override
54  {
55  bc_values.ids.resize(1);
56  bc_values.values.resize(1);
57  auto const& data_exchange = _py_bc_object.dataframe_network;
58  // get the number of all boundary nodes
59  const std::size_t n_bc_nodes = std::get<3>(data_exchange).size();
60 
61  // get T_in bc_id
62  bc_values.ids[0] = _in_out_global_indices.first;
63 
64  // get T_out bc_id
65  auto const boundary_node_id = _in_out_global_indices.second;
66 
67  // return T_in from currently BHE dataframe column 2,
68  // update flowrate and HeatTransferCoefficients for each BHE
69  for (std::size_t i = 0; i < n_bc_nodes; i++)
70  {
71  // auto pair_flag_value =
72  // _bc_data.bc_object->getDirichletBCValue(boundary_node_id);
73  auto const dataframe_node_id = std::get<3>(data_exchange);
74  auto const dataframe_Tin_val = std::get<1>(data_exchange);
75  auto const dataframe_BHE_flowrate = std::get<4>(data_exchange);
76  if (dataframe_node_id[i] == boundary_node_id)
77  {
78  bc_values.values[0] = dataframe_Tin_val[i];
79  _bhe.updateHeatTransferCoefficients(dataframe_BHE_flowrate[i]);
80  break;
81  }
82  }
83 
84  // store the current time to network dataframe
85  std::get<0>(_py_bc_object.dataframe_network) = t;
86  }
87 
88 private:
89  std::pair<GlobalIndexType, GlobalIndexType> const _in_out_global_indices;
90  BHEType& _bhe;
92 };
93 
94 template <typename BHEType>
95 std::unique_ptr<BHEInflowPythonBoundaryCondition<BHEType>>
97  std::pair<GlobalIndexType, GlobalIndexType>&& in_out_global_indices,
98  BHEType& bhe,
100 
101 {
102  DBUG("Constructing BHEInflowPythonBoundaryCondition.");
103 
104  // In case of partitioned mesh the boundary could be empty, i.e. there is no
105  // boundary condition.
106 #ifdef USE_PETSC
107  // For this special boundary condition the boundary condition is not empty
108  // if the global indices are non-negative.
109  if (in_out_global_indices.first < 0 && in_out_global_indices.second < 0)
110  {
111  return nullptr;
112  }
113  // If only one of the global indices (in or out) is negative the
114  // implementation is not valid.
115  if (in_out_global_indices.first < 0 || in_out_global_indices.second < 0)
116  {
117  OGS_FATAL(
118  "The partition cuts the BHE into two independent parts. This "
119  "behaviour is not implemented.");
120  }
121 #endif // USE_PETSC
122  return std::make_unique<BHEInflowPythonBoundaryCondition<BHEType>>(
123  std::move(in_out_global_indices), bhe, py_bc_object);
124 }
125 } // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
Global vector based on Eigen vector.
Definition: EigenVector.h:26
std::tuple< double, std::vector< double >, std::vector< double >, std::vector< int >, std::vector< double > > dataframe_network
A boundary condition whose values are computed by a Python script.
BHEInflowPythonBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices, BHEType &bhe, BHEInflowPythonBoundaryConditionPythonSideInterface &py_bc_object)
BHEInflowPythonBoundaryConditionPythonSideInterface & _py_bc_object
void getEssentialBCValues(const double t, const GlobalVector &, NumLib::IndexValueVector< GlobalIndexType > &bc_values) const override
Writes the values of essential BCs to bc_values.
std::pair< GlobalIndexType, GlobalIndexType > const _in_out_global_indices
std::unique_ptr< BHEInflowPythonBoundaryCondition< BHEType > > createBHEInflowPythonBoundaryCondition(std::pair< GlobalIndexType, GlobalIndexType > &&in_out_global_indices, BHEType &bhe, BHEInflowPythonBoundaryConditionPythonSideInterface &py_bc_object)
std::vector< IndexType > ids
std::vector< double > values