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