OGS
CreateHeatTransportBHEProcess.cpp
Go to the documentation of this file.
1
12
13#include <algorithm>
14#include <pybind11/pybind11.h>
15
16#include <vector>
17
18#include "BHE/BHETypes.h"
19#include "BHE/CreateBHE1PType.h"
21#include "BHE/CreateBHEUType.h"
24#include "ParameterLib/Utils.h"
26
27namespace ProcessLib
28{
29namespace HeatTransportBHE
30{
31std::unique_ptr<Process> createHeatTransportBHEProcess(
32 std::string const& name,
33 MeshLib::Mesh& mesh,
34 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
35 std::vector<ProcessVariable> const& variables,
36 std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
37 unsigned const integration_order,
38 BaseLib::ConfigTree const& config,
39 std::map<std::string,
40 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
41 curves,
42 std::map<int, std::shared_ptr<MaterialPropertyLib::Medium>> const& media)
43{
45 config.checkConfigParameter("type", "HEAT_TRANSPORT_BHE");
46
47 DBUG("Create HeatTransportBHE Process.");
48
50
52 auto const pv_config = config.getConfigSubtree("process_variables");
53 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
54 process_variables;
55
56 // reading primary variables for each
57 // BHE----------------------------------------------------------
59 auto range =
61 pv_config.getConfigParameterList<std::string>("process_variable");
62 std::vector<std::reference_wrapper<ProcessVariable>> per_process_variables;
63
64 for (std::string const& pv_name : range)
65 {
66 if (pv_name != "temperature_soil" &&
67 pv_name.find("temperature_BHE") == std::string::npos)
68 {
70 "Found a process variable name '{}'. It should be "
71 "'temperature_soil' or 'temperature_BHE_X'",
72 pv_name);
73 }
74 auto variable = std::find_if(variables.cbegin(), variables.cend(),
75 [&pv_name](ProcessVariable const& v)
76 { return v.getName() == pv_name; });
77
78 if (variable == variables.end())
79 {
81 "Could not find process variable '{:s}' in the provided "
82 "variables list for config tag <{:s}>.",
83 pv_name, "process_variable");
84 }
85 DBUG("Found process variable '{:s}' for config tag <{:s}>.",
86 variable->getName(), "process_variable");
87
88 per_process_variables.emplace_back(
89 const_cast<ProcessVariable&>(*variable));
90 }
91 process_variables.push_back(std::move(per_process_variables));
92 // end of reading primary variables for each
93 // BHE----------------------------------------------------------
94
96 // reading BHE parameters --------------------------------------------------
97 std::vector<BHE::BHETypes> bhes;
98
99 auto const& bhe_configs =
101 config.getConfigSubtree("borehole_heat_exchangers");
102
103 auto const using_server_communication =
105 config.getConfigParameter<bool>("use_server_communication", false);
106
107 auto const using_algebraic_bc =
109 config.getConfigParameter<bool>("use_algebraic_bc", false);
110
111 auto const weighting_factor =
113 config.getConfigParameter<float>("weighting_factor", 100.0);
114
115 auto const is_linear =
117 config.getConfigParameter<bool>("linear", false);
118 if (is_linear)
119 {
120 if (!using_algebraic_bc)
121 {
122 OGS_FATAL(
123 "You specified that the process simulated by OGS is linear. "
124 "For the Heat-Transport-BHE process this can only be done "
125 "together with setting the use_algebraic_bc option to true.")
126 }
127 else
128 {
129 WARN(
130 "You specified that the process simulated by OGS is linear. "
131 "With that optimization the process will be assembled only "
132 "once and the non-linear solver will do only one iteration per "
133 "time step. No non-linearities will be resolved and OGS will "
134 "not detect if there are any non-linearities. It is your "
135 "responsibility to ensure that the assembled equation systems "
136 "are linear, indeed! There is no safety net!");
137 }
138 }
139
140 for (
141 auto const& bhe_config :
143 bhe_configs.getConfigSubtreeList("borehole_heat_exchanger"))
144 {
145 // read in the parameters
146 const std::string bhe_type =
148 bhe_config.getConfigParameter<std::string>("type");
149
150 if (bhe_type == "1U")
151 {
152 bhes.emplace_back(
153 BHE::createBHEUType<BHE::BHE_1U>(bhe_config, curves));
154 continue;
155 }
156
157 if (bhe_type == "CXA")
158 {
159 bhes.emplace_back(
160 BHE::createBHECoaxial<BHE::BHE_CXA>(bhe_config, curves));
161 continue;
162 }
163
164 if (bhe_type == "CXC")
165 {
166 bhes.emplace_back(
167 BHE::createBHECoaxial<BHE::BHE_CXC>(bhe_config, curves));
168 continue;
169 }
170
171 if (bhe_type == "2U")
172 {
173 bhes.emplace_back(
174 BHE::createBHEUType<BHE::BHE_2U>(bhe_config, curves));
175 continue;
176 }
177
178 if (bhe_type == "1P")
179 {
180 bhes.emplace_back(
181 BHE::createBHE1PType<BHE::BHE_1P>(bhe_config, curves));
182 continue;
183 }
184 OGS_FATAL("Unknown BHE type '{:s}'.", bhe_type);
185 }
186 // end of reading BHE parameters -------------------------------------------
187
188 auto media_map =
190
191 // find if bhe uses python boundary condition
192 auto const using_tespy =
193 visit([](auto const& bhe) { return bhe.use_python_bcs; }, bhes[0]);
194
197 // create a pythonBoundaryCondition object
198 if (using_tespy || using_server_communication)
199 {
200 // Evaluate Python code in scope of main module
201 pybind11::object scope =
202 pybind11::module::import("__main__").attr("__dict__");
203
204 if (!scope.contains("bc_bhe"))
205 OGS_FATAL(
206 "Function 'bc_bhe' is not defined in the python script file, "
207 "or there was no python script file specified.");
208
209 py_object =
210 scope["bc_bhe"]
212
213 if (py_object == nullptr)
214 OGS_FATAL(
215 "Not able to access the correct bc pointer from python script "
216 "file specified.");
217
218 // create BHE network dataframe from Python
219 py_object->dataframe_network = py_object->initializeDataContainer();
220 if (!py_object->isOverriddenEssential())
221 {
222 DBUG(
223 "Method `initializeDataContainer' not overridden in Python "
224 "script.");
225 }
226 // clear ogs bc_node_id memory in dataframe
227 std::get<3>(py_object->dataframe_network).clear(); // ogs_bc_node_id
228
229 // here calls the tespyHydroSolver to get the pipe flow velocity in bhe
230 // network
231 /* for 2U type the flowrate initialization process below causes conflict
232 // replace the value in flow velocity Matrix _u
233 auto const tespy_flow_rate = std::get<4>(py_object->dataframe_network);
234 const std::size_t n_bhe = tespy_flow_rate.size();
235 if (bhes.size() != n_bhe)
236 OGS_FATAL(
237 "The number of BHEs defined in OGS and TESPy are not the "
238 "same!");
239
240 for (std::size_t idx_bhe = 0; idx_bhe < n_bhe; idx_bhe++)
241 {
242 // the flow_rate in OGS should be updated from the flow_rate
243 // computed by TESPy.
244 auto update_flow_rate = [&](auto& bhe) {
245 bhe.updateHeatTransferCoefficients(tespy_flow_rate[idx_bhe]);
246 };
247 visit(update_flow_rate, bhes[idx_bhe]);
248 }
249 */
250 }
251
252 HeatTransportBHEProcessData process_data(
253 std::move(media_map), std::move(bhes), py_object, using_tespy,
254 using_server_communication,
255 {using_algebraic_bc, weighting_factor, is_linear});
256
257 SecondaryVariableCollection secondary_variables;
258
259 ProcessLib::createSecondaryVariables(config, secondary_variables);
260
261 return std::make_unique<HeatTransportBHEProcess>(
262 std::move(name), mesh, std::move(jacobian_assembler), parameters,
263 integration_order, std::move(process_variables),
264 std::move(process_data), std::move(secondary_variables));
265}
266} // namespace HeatTransportBHE
267} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:26
void DBUG(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:30
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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)