OGS
CreateHeatTransportBHEProcess.cpp
Go to the documentation of this file.
1
12
13#include <pybind11/pybind11.h>
14
15#include <vector>
16
17#include "BHE/BHETypes.h"
18#include "BHE/CreateBHE1PType.h"
20#include "BHE/CreateBHEUType.h"
23#include "ParameterLib/Utils.h"
25
26namespace ProcessLib
27{
28namespace HeatTransportBHE
29{
30std::unique_ptr<Process> createHeatTransportBHEProcess(
31 std::string const& name,
32 MeshLib::Mesh& mesh,
33 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
34 std::vector<ProcessVariable> const& variables,
35 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
36 unsigned const integration_order,
37 BaseLib::ConfigTree const& config,
38 std::map<std::string,
39 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
40 curves,
41 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
42{
44 config.checkConfigParameter("type", "HEAT_TRANSPORT_BHE");
45
46 DBUG("Create HeatTransportBHE Process.");
47
49
51 auto const pv_config = config.getConfigSubtree("process_variables");
52 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
53 process_variables;
54
55 // reading primary variables for each
56 // BHE----------------------------------------------------------
58 auto range =
60 pv_config.getConfigParameterList<std::string>("process_variable");
61 std::vector<std::reference_wrapper<ProcessVariable>> per_process_variables;
62
63 for (std::string const& pv_name : range)
64 {
65 if (pv_name != "temperature_soil" &&
66 pv_name.find("temperature_BHE") == std::string::npos)
67 {
69 "Found a process variable name '{}'. It should be "
70 "'temperature_soil' or 'temperature_BHE_X'",
71 pv_name);
72 }
73 auto variable = std::find_if(variables.cbegin(), variables.cend(),
74 [&pv_name](ProcessVariable const& v)
75 { return v.getName() == pv_name; });
76
77 if (variable == variables.end())
78 {
80 "Could not find process variable '{:s}' in the provided "
81 "variables list for config tag <{:s}>.",
82 pv_name, "process_variable");
83 }
84 DBUG("Found process variable '{:s}' for config tag <{:s}>.",
85 variable->getName(), "process_variable");
86
87 per_process_variables.emplace_back(
88 const_cast<ProcessVariable&>(*variable));
89 }
90 process_variables.push_back(std::move(per_process_variables));
91 // end of reading primary variables for each
92 // BHE----------------------------------------------------------
93
95 // reading BHE parameters --------------------------------------------------
96 std::vector<BHE::BHETypes> bhes;
97
98 auto const& bhe_configs =
100 config.getConfigSubtree("borehole_heat_exchangers");
101
102 auto const using_server_communication =
104 config.getConfigParameter<bool>("use_server_communication", false);
105
106 for (
107 auto const& bhe_config :
109 bhe_configs.getConfigSubtreeList("borehole_heat_exchanger"))
110 {
111 // read in the parameters
112 const std::string bhe_type =
114 bhe_config.getConfigParameter<std::string>("type");
115
116 if (bhe_type == "1U")
117 {
118 bhes.emplace_back(
119 BHE::createBHEUType<BHE::BHE_1U>(bhe_config, curves));
120 continue;
121 }
122
123 if (bhe_type == "CXA")
124 {
125 bhes.emplace_back(
126 BHE::createBHECoaxial<BHE::BHE_CXA>(bhe_config, curves));
127 continue;
128 }
129
130 if (bhe_type == "CXC")
131 {
132 bhes.emplace_back(
133 BHE::createBHECoaxial<BHE::BHE_CXC>(bhe_config, curves));
134 continue;
135 }
136
137 if (bhe_type == "2U")
138 {
139 bhes.emplace_back(
140 BHE::createBHEUType<BHE::BHE_2U>(bhe_config, curves));
141 continue;
142 }
143
144 if (bhe_type == "1P")
145 {
146 bhes.emplace_back(
147 BHE::createBHE1PType<BHE::BHE_1P>(bhe_config, curves));
148 continue;
149 }
150 OGS_FATAL("Unknown BHE type '{:s}'.", bhe_type);
151 }
152 // end of reading BHE parameters -------------------------------------------
153
154 auto media_map =
156
157 // find if bhe uses python boundary condition
158 auto const using_tespy =
159 visit([](auto const& bhe) { return bhe.use_python_bcs; }, bhes[0]);
160
163 // create a pythonBoundaryCondition object
164 if (using_tespy || using_server_communication)
165 {
166 // Evaluate Python code in scope of main module
167 pybind11::object scope =
168 pybind11::module::import("__main__").attr("__dict__");
169
170 if (!scope.contains("bc_bhe"))
171 OGS_FATAL(
172 "Function 'bc_bhe' is not defined in the python script file, "
173 "or there was no python script file specified.");
174
175 py_object =
176 scope["bc_bhe"]
178
179 if (py_object == nullptr)
180 OGS_FATAL(
181 "Not able to access the correct bc pointer from python script "
182 "file specified.");
183
184 // create BHE network dataframe from Python
185 py_object->dataframe_network = py_object->initializeDataContainer();
186 if (!py_object->isOverriddenEssential())
187 {
188 DBUG(
189 "Method `initializeDataContainer' not overridden in Python "
190 "script.");
191 }
192 // clear ogs bc_node_id memory in dataframe
193 std::get<3>(py_object->dataframe_network).clear(); // ogs_bc_node_id
194
195 // here calls the tespyHydroSolver to get the pipe flow velocity in bhe
196 // network
197 /* for 2U type the flowrate initialization process below causes conflict
198 // replace the value in flow velocity Matrix _u
199 auto const tespy_flow_rate = std::get<4>(py_object->dataframe_network);
200 const std::size_t n_bhe = tespy_flow_rate.size();
201 if (bhes.size() != n_bhe)
202 OGS_FATAL(
203 "The number of BHEs defined in OGS and TESPy are not the "
204 "same!");
205
206 for (std::size_t idx_bhe = 0; idx_bhe < n_bhe; idx_bhe++)
207 {
208 // the flow_rate in OGS should be updated from the flow_rate
209 // computed by TESPy.
210 auto update_flow_rate = [&](auto& bhe) {
211 bhe.updateHeatTransferCoefficients(tespy_flow_rate[idx_bhe]);
212 };
213 visit(update_flow_rate, bhes[idx_bhe]);
214 }
215 */
216 }
217
218 HeatTransportBHEProcessData process_data(
219 std::move(media_map), std::move(bhes), py_object, using_tespy,
220 using_server_communication);
221
222 SecondaryVariableCollection secondary_variables;
223
224 ProcessLib::createSecondaryVariables(config, secondary_variables);
225
226 return std::make_unique<HeatTransportBHEProcess>(
227 std::move(name), mesh, std::move(jacobian_assembler), parameters,
228 integration_order, std::move(process_variables),
229 std::move(process_data), std::move(secondary_variables));
230}
231} // namespace HeatTransportBHE
232} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
T getConfigParameter(std::string const &param) const
ConfigTree getConfigSubtree(std::string const &root) const
Range< ValueIterator< T > > getConfigParameterList(std::string const &param) const
void checkConfigParameter(std::string const &param, std::string_view const value) const
Handles configuration of several secondary variables from the project file.
MaterialSpatialDistributionMap createMaterialSpatialDistributionMap(std::map< int, std::shared_ptr< Medium > > const &media, MeshLib::Mesh const &mesh)
std::unique_ptr< Process > createHeatTransportBHEProcess(std::string const &name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, unsigned const integration_order, BaseLib::ConfigTree const &config, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, std::map< int, std::shared_ptr< MaterialPropertyLib::Medium > > const &media)
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)