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