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