67 const std::string& bhe_type,
68 const std::vector<int>& bhe_ids_of_this_bhe,
70 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
72 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
75 std::map<int, BHE::BHETypes>& bhes_map)
80 OGS_FATAL(
"Unknown BHE type: {:s}", bhe_type);
82 for (
auto const&
id : bhe_ids_of_this_bhe)
84 if (id < 0 || id >=
static_cast<int>(bhe_mesh_data.
BHE_nodes.size()))
87 "BHE id {:d} is out of range. The mesh contains {:d} "
88 "BHE(s) (valid ids: 0 to {:d}).",
90 static_cast<int>(bhe_mesh_data.
BHE_nodes.size()) - 1);
92 std::pair<std::map<int, BHE::BHETypes>::iterator,
bool> result;
93 if (
id == bhe_ids_of_this_bhe[0])
95 result = bhes_map.try_emplace(
96 id, bhe_creator_it->second(bhe_config, parameters, curves));
103 auto const& first_bhe =
104 bhes_map.find(bhe_ids_of_this_bhe[0])->second;
105 result = bhes_map.try_emplace(
id, first_bhe);
110 "BHE with id '{:d}' is already present in the list! Check for "
111 "duplicate definitions of BHE ids.",
118 std::string
const& name,
120 std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
121 std::vector<ProcessVariable>
const& variables,
122 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
123 unsigned const integration_order,
125 std::map<std::string,
126 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>>
const&
128 std::map<
int, std::shared_ptr<MaterialPropertyLib::Medium>>
const& media)
133 DBUG(
"Create HeatTransportBHE Process.");
139 std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
148 std::vector<std::reference_wrapper<ProcessVariable>> per_process_variables;
150 for (std::string
const& pv_name : range)
152 if (pv_name !=
"temperature_soil" &&
153 pv_name.find(
"temperature_BHE") == std::string::npos)
156 "Found a process variable name '{}'. It should be "
157 "'temperature_soil' or 'temperature_BHE_X'",
160 auto variable = std::find_if(variables.cbegin(), variables.cend(),
162 { return v.getName() == pv_name; });
164 if (variable == variables.end())
167 "Could not find process variable '{:s}' in the provided "
168 "variables list for config tag <{:s}>.",
169 pv_name,
"process_variable");
171 DBUG(
"Found process variable '{:s}' for config tag <{:s}>.",
172 variable->getName(),
"process_variable");
174 per_process_variables.emplace_back(
177 process_variables.push_back(std::move(per_process_variables));
186 auto const& bhe_configs =
190 auto const using_server_communication =
194 auto const mass_lumping =
198 auto const using_algebraic_bc =
202 auto const weighting_factor =
206 auto const is_linear =
211 if (!using_algebraic_bc)
214 "You specified that the process simulated by OGS is linear. "
215 "With that optimization the process will be assembled only "
216 "once and the non-linear solver will only do iterations per "
217 "time step to fulfill the BHE boundary conditions. No other "
218 "non-linearities will be resolved and OGS will not detect if "
219 "there are any non-linearities. It is your responsibility to "
220 "ensure that the assembled equation systems are linear, "
221 "indeed! There is no safety net!");
226 "You specified that the process simulated by OGS is linear. "
227 "With that optimization the process will be assembled only "
228 "once and the non-linear solver will do only one iteration per "
229 "time step. No non-linearities will be resolved and OGS will "
230 "not detect if there are any non-linearities. It is your "
231 "responsibility to ensure that the assembled equation systems "
232 "are linear, indeed! There is no safety net!");
236 std::map<int, BHE::BHETypes> bhes_map;
238 int bhe_iterator = 0;
241 auto const& bhe_config :
243 bhe_configs.getConfigSubtreeList(
"borehole_heat_exchanger"))
245 auto const bhe_id_string =
247 bhe_config.getConfigAttribute<std::string>(
248 "id", std::to_string(bhe_iterator));
250 std::vector<int> bhe_ids_of_this_bhe;
252 if (bhe_id_string ==
"*")
254 int const size =
static_cast<int>(bhe_mesh_data.BHE_mat_IDs.size());
255 bhe_ids_of_this_bhe.resize(size);
256 std::iota(bhe_ids_of_this_bhe.begin(), bhe_ids_of_this_bhe.end(),
261 bhe_ids_of_this_bhe =
266 const std::string bhe_type =
268 bhe_config.getConfigParameter<std::string>(
"type");
271 parameters, curves, bhe_mesh_data, bhes_map);
275 if (
static_cast<int>(bhes_map.size()) - 1 != bhes_map.rbegin()->first)
278 "The maximum given BHE id '{:d}' did not match the number of given "
279 "BHE definitions '{:d}'. The BHE ids needs to be defined starting "
280 "from 0, so the maximum BHE id needs to be number of BHE "
281 "definitions minus 1. After all definitions there are no gaps "
282 "allowed between the given ids.",
283 bhes_map.rbegin()->first, bhes_map.size());
286 std::vector<BHE::BHETypes> bhes;
287 bhes.reserve(bhes_map.size());
288 std::ranges::copy(bhes_map | std::views::values, std::back_inserter(bhes));
296 auto const using_tespy =
297 visit([](
auto const& bhe) {
return bhe.use_python_bcs; }, bhes[0]);
302 if (using_tespy || using_server_communication)
305 pybind11::object scope =
306 pybind11::module::import(
"__main__").attr(
"__dict__");
308 if (!scope.contains(
"bc_bhe"))
310 "Function 'bc_bhe' is not defined in the python script file, "
311 "or there was no python script file specified.");
317 if (py_object ==
nullptr)
319 "Not able to access the correct bc pointer from python script "
323 py_object->dataframe_network = py_object->initializeDataContainer();
324 if (!py_object->isOverriddenEssential())
327 "Method `initializeDataContainer' not overridden in Python "
331 std::get<3>(py_object->dataframe_network).clear();
357 std::move(media_map), std::move(bhes), py_object, using_tespy,
358 using_server_communication, mass_lumping,
359 {using_algebraic_bc, weighting_factor}, is_linear);
365 return std::make_unique<HeatTransportBHEProcess>(
366 std::move(name), mesh, std::move(jacobian_assembler), parameters,
367 integration_order, std::move(process_variables),
368 std::move(process_data), std::move(secondary_variables),
369 std::move(bhe_mesh_data));
void createAndInsertBHE(const std::string &bhe_type, const std::vector< int > &bhe_ids_of_this_bhe, const BaseLib::ConfigTree &bhe_config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > ¶meters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, BHEMeshData const &bhe_mesh_data, std::map< int, BHE::BHETypes > &bhes_map)
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 > > ¶meters, 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)