OGS
CreateFlowAndTemperatureControl.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include "BaseLib/Algorithm.h"
9#include "PowerWithCOP.h"
11
12namespace ProcessLib
13{
14namespace HeatTransportBHE
15{
16namespace BHE
17{
19 std::optional<BaseLib::ConfigTree> const& config,
20 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
21 std::map<std::string,
22 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
23 curves)
24{
27 auto const raw_power = config->getConfigParameter<std::string>("power");
28
29 auto const& power_param = ParameterLib::getNamedOrCreateInlineParameter(
30 raw_power, parameters, "power", "inline");
31
32 auto const& cop_curve = *BaseLib::getOrError(
33 curves,
37 config->getConfigParameter<std::string>("cop_curve"),
38 "Required cop curve not found.");
39
40 return PowerWithCOP{power_param, cop_curve};
41}
42
44 std::optional<BaseLib::ConfigTree> const& cooling_config,
45 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
46 std::map<std::string,
47 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
48 curves)
49{
50 if (
51 cooling_config->getConfigParameter<bool>("active", false))
52 {
53 return createPowerWithCOPStruct(cooling_config, parameters, curves);
54 }
55
56 auto const raw_power =
58 cooling_config->getConfigParameter<std::string>("power");
59
60 return ParameterLib::getNamedOrCreateInlineParameter(raw_power, parameters,
61 "power", "inline");
62}
63
65 std::optional<PowerWithCOP> const& heating,
66 std::optional<PowerWithCOP> const& hot_water,
67 std::optional<CoolingVariant> const& cooling,
68 ParameterLib::Parameter<double> const& flow_rate_param,
69 RefrigerantProperties const& refrigerant,
70 double const flow_rate_min,
71 double const power_min)
72{
73 if (std::holds_alternative<PowerWithCOP>(*cooling))
74 {
76 std::in_place_type<BuildingPowerHotWaterActiveCooling>,
77 *heating,
78 *hot_water,
79 std::get<PowerWithCOP>(*cooling),
80 flow_rate_param,
81 refrigerant.specific_heat_capacity,
82 refrigerant.density,
83 flow_rate_min,
84 power_min};
85 }
86
88 std::in_place_type<BuildingPowerHotWaterPassiveCooling>,
89 *heating,
90 *hot_water,
91 std::get<std::reference_wrapper<ParameterLib::Parameter<double>>>(
92 *cooling)
93 .get(),
94 flow_rate_param,
95 refrigerant.specific_heat_capacity,
96 refrigerant.density,
97 flow_rate_min,
98 power_min};
99}
100
102 std::optional<PowerWithCOP> const& heating,
103 std::optional<PowerWithCOP> const& /*hot_water*/,
104 std::optional<CoolingVariant> const& cooling,
105 ParameterLib::Parameter<double> const& flow_rate_param,
106 RefrigerantProperties const& refrigerant,
107 double const flow_rate_min,
108 double const power_min)
109{
110 if (std::holds_alternative<PowerWithCOP>(*cooling))
111 {
113 std::in_place_type<BuildingPowerActiveCooling>,
114 *heating,
115 std::get<PowerWithCOP>(*cooling),
116 flow_rate_param,
117 refrigerant.specific_heat_capacity,
118 refrigerant.density,
119 flow_rate_min,
120 power_min};
121 }
122
124 std::in_place_type<BuildingPowerPassiveCooling>,
125 *heating,
126 std::get<std::reference_wrapper<ParameterLib::Parameter<double>>>(
127 *cooling)
128 .get(),
129 flow_rate_param,
130 refrigerant.specific_heat_capacity,
131 refrigerant.density,
132 flow_rate_min,
133 power_min};
134}
135
137 std::optional<PowerWithCOP> const& /*heating*/,
138 std::optional<PowerWithCOP> const& hot_water,
139 std::optional<CoolingVariant> const& cooling,
140 ParameterLib::Parameter<double> const& flow_rate_param,
141 RefrigerantProperties const& refrigerant,
142 double const flow_rate_min,
143 double const power_min)
144{
145 if (std::holds_alternative<PowerWithCOP>(*cooling))
146 {
148 std::in_place_type<BuildingPowerActiveCooling>,
149 *hot_water,
150 std::get<PowerWithCOP>(*cooling),
151 flow_rate_param,
152 refrigerant.specific_heat_capacity,
153 refrigerant.density,
154 flow_rate_min,
155 power_min};
156 }
157
159 std::in_place_type<BuildingPowerPassiveCooling>,
160 *hot_water,
161 std::get<std::reference_wrapper<ParameterLib::Parameter<double>>>(
162 *cooling)
163 .get(),
164 flow_rate_param,
165 refrigerant.specific_heat_capacity,
166 refrigerant.density,
167 flow_rate_min,
168 power_min};
169}
170
172 std::optional<PowerWithCOP> const& /*heating*/,
173 std::optional<PowerWithCOP> const& /*hot_water*/,
174 std::optional<CoolingVariant> const& cooling,
175 ParameterLib::Parameter<double> const& flow_rate_param,
176 RefrigerantProperties const& refrigerant,
177 double const flow_rate_min,
178 double const power_min)
179{
180 if (std::holds_alternative<PowerWithCOP>(*cooling))
181 {
182 return FlowAndTemperatureControl{std::in_place_type<ActiveCooling>,
183 std::get<PowerWithCOP>(*cooling),
184 flow_rate_param,
185 refrigerant.specific_heat_capacity,
186 refrigerant.density,
187 flow_rate_min,
188 power_min};
189 }
190
192 std::in_place_type<Power>,
193 std::get<std::reference_wrapper<ParameterLib::Parameter<double>>>(
194 *cooling)
195 .get(),
196 flow_rate_param,
197 refrigerant.specific_heat_capacity,
198 refrigerant.density,
199 flow_rate_min,
200 power_min};
201}
202
204 std::optional<PowerWithCOP>, // heating
205 std::optional<PowerWithCOP>, // hot water
206 std::optional<CoolingVariant>, // cooling
207 ParameterLib::Parameter<double> const&, // flow rate param
209 double const, // flow rate min
210 double const)>; // power min
211
212const std::map<std::tuple<bool, bool, bool>, // heating, hot_water,
213 // cooling
216 {{true, true, true}, &createHeatingHotWaterCooling},
217 {{true, true, false},
218 [](std::optional<PowerWithCOP> const& heating,
219 std::optional<PowerWithCOP> const& hot_water,
220 std::optional<CoolingVariant> const& /*cooling*/,
221 auto const& flow_rate_param, auto const& refrigerant,
222 auto const flow_rate_min, auto const power_min)
223 {
225 std::in_place_type<BuildingPowerHotWater>,
226 *heating,
227 *hot_water,
228 flow_rate_param,
229 refrigerant.specific_heat_capacity,
230 refrigerant.density,
231 flow_rate_min,
232 power_min};
233 }},
234 {{true, false, true}, &createHeatingCooling},
235 {{false, true, true}, &createHotWaterCooling},
236 {{true, false, false},
237 [](std::optional<PowerWithCOP> const& heating,
238 std::optional<PowerWithCOP> const& /*hot_water*/,
239 std::optional<CoolingVariant> const& /*cooling*/,
240 auto const& flow_rate_param, auto const& refrigerant,
241 auto const flow_rate_min, auto const power_min)
242 {
244 std::in_place_type<BuildingPower>,
245 *heating,
246 flow_rate_param,
247 refrigerant.specific_heat_capacity,
248 refrigerant.density,
249 flow_rate_min,
250 power_min};
251 }},
252 {{false, true, false},
253 [](std::optional<PowerWithCOP> const& /*heating*/,
254 std::optional<PowerWithCOP> const& hot_water,
255 std::optional<CoolingVariant> const& /*cooling*/,
256 auto const& flow_rate_param, auto const& refrigerant,
257 auto const flow_rate_min, auto const power_min)
258 {
260 std::in_place_type<BuildingPower>,
261 *hot_water,
262 flow_rate_param,
263 refrigerant.specific_heat_capacity,
264 refrigerant.density,
265 flow_rate_min,
266 power_min};
267 }},
268 {{false, false, true}, &createCooling}};
269
271 std::optional<BaseLib::ConfigTree> const& heating_config,
272 std::optional<BaseLib::ConfigTree> const& hot_water_config,
273 std::optional<BaseLib::ConfigTree> const& cooling_config,
274 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
275 std::map<std::string,
276 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
277 curves,
278 ParameterLib::Parameter<double> const& flow_rate_param,
279 RefrigerantProperties const& refrigerant,
280 double const flow_rate_min,
281 double const power_min)
282{
283 std::optional<PowerWithCOP> building_heating_curves;
284 std::optional<PowerWithCOP> building_hot_water_curves;
285 std::optional<CoolingVariant> building_cooling_curves;
286
287 bool heating = false;
288 bool hot_water = false;
289 bool cooling = false;
290
291 if (heating_config)
292 {
293 building_heating_curves.emplace(
294 createPowerWithCOPStruct(heating_config, parameters, curves));
295 heating = true;
296 }
297 if (hot_water_config)
298 {
299 building_hot_water_curves.emplace(
300 createPowerWithCOPStruct(hot_water_config, parameters, curves));
301 hot_water = true;
302 }
303 if (cooling_config)
304 {
305 building_cooling_curves.emplace(
306 createCoolingVariant(cooling_config, parameters, curves));
307 cooling = true;
308 }
309 auto key = std::make_tuple(heating, hot_water, cooling);
310
311 auto it = advancedBuildingPower.find(key);
312 if (it == advancedBuildingPower.end())
313 OGS_FATAL(
314 "AdvancedBuildingPower combination is not "
315 "implemented.");
316 auto factory = it->second;
317
318 return factory(building_heating_curves,
319 building_hot_water_curves,
320 building_cooling_curves,
321 flow_rate_param,
322 refrigerant,
323 flow_rate_min,
324 power_min);
325}
327 BaseLib::ConfigTree const& config,
328 std::vector<std::unique_ptr<ParameterLib::ParameterBase>>& parameters,
329 std::map<std::string,
330 std::unique_ptr<MathLib::PiecewiseLinearInterpolation>> const&
331 curves,
332 RefrigerantProperties const& refrigerant)
333{
335 auto const type = config.getConfigParameter<std::string>("type");
336
337 auto const flow_rate_min =
339 config.getConfigParameter<double>("flow_rate_min", 1e-6);
341 auto const power_min = config.getConfigParameter<double>("power_min", 1e-3);
342 if (type == "InflowTemperature")
343 {
344 auto const raw_temperature =
346 config.getConfigParameter<std::string>("temperature");
347
348 auto const& temperature_param =
350 raw_temperature, parameters, "temperature", "inline");
351
352 auto const raw_flow_rate =
354 config.getConfigParameter<std::string>("flow_rate");
355
356 auto const& flow_rate_param =
358 raw_flow_rate, parameters, "flow_rate", "inline");
359
360 return InflowTemperature{temperature_param, flow_rate_param,
361 flow_rate_min};
362 }
363 if (type == "Power")
364 {
366 auto const raw_power = config.getConfigParameter<std::string>("power");
367
368 auto const& power_param = ParameterLib::getNamedOrCreateInlineParameter(
369 raw_power, parameters, "power", "inline");
370
371 auto const raw_flow_rate =
373 config.getConfigParameter<std::string>("flow_rate");
374
375 auto const& flow_rate_param =
377 raw_flow_rate, parameters, "flow_rate", "inline");
378
379 return Power{power_param,
380 flow_rate_param,
381 refrigerant.specific_heat_capacity,
382 refrigerant.density,
383 flow_rate_min,
384 power_min};
385 }
386
387 if (type == "BuildingPower")
388 {
390 auto const raw_power = config.getConfigParameter<std::string>("power");
391
392 auto const& power_param = ParameterLib::getNamedOrCreateInlineParameter(
393 raw_power, parameters, "power", "inline");
394
395 auto const& cop_curve = *BaseLib::getOrError(
396 curves,
398 config.getConfigParameter<std::string>("cop_curve"),
399 "Required cop curve not found.");
400
401 PowerWithCOP const building_power{power_param, cop_curve};
402
403 auto const raw_flow_rate =
405 config.getConfigParameter<std::string>("flow_rate");
406
407 auto const& flow_rate_param =
409 raw_flow_rate, parameters, "flow_rate", "inline");
410
411 return BuildingPower{building_power,
412 flow_rate_param,
413 refrigerant.specific_heat_capacity,
414 refrigerant.density,
415 flow_rate_min,
416 power_min};
417 }
418
419 if (type == "AdvancedBuildingPower")
420 {
421 // add a heating, hot water and cooling config as optional to handle
422 auto const& heating_config =
425 "heating"); // Optional, take care if it is not present
426
427 auto const& hot_water_config =
430 "hot_water"); // Optional, take care if it is not present
431
432 auto const& cooling_config =
435 "cooling"); // Optional, take care if it is not present
436
437 auto const raw_flow_rate =
439 config.getConfigParameter<std::string>("flow_rate");
440
441 auto const& flow_rate_param =
443 raw_flow_rate, parameters, "flow_rate", "inline");
444
446 heating_config, hot_water_config, cooling_config, parameters,
447 curves, flow_rate_param, refrigerant, flow_rate_min, power_min);
448 }
449 OGS_FATAL(
450 "FlowAndTemperatureControl type '{:s}' is not implemented. "
451 "InflowTemperature, Power, BuildingPower, and AdvancedBuildingPower "
452 "are currently supported and require parameters as input. With the "
453 "support of parameters all former available types can be achieved.",
454 type);
455}
456} // namespace BHE
457} // namespace HeatTransportBHE
458} // namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
std::optional< ConfigTree > getConfigSubtreeOptional(std::string const &root) const
T getConfigParameter(std::string const &param) const
OGS_NO_DANGLING Map::mapped_type & getOrError(Map &map, Key const &key, std::string const &error_message)
Definition Algorithm.h:111
Parameter< double > & getNamedOrCreateInlineParameter(std::string const &parameter_or_value, std::vector< std::unique_ptr< ParameterBase > > &parameters, std::string const &property_name, std::string const &inline_suffix)
std::function< FlowAndTemperatureControl( std::optional< PowerWithCOP >, std::optional< PowerWithCOP >, std::optional< CoolingVariant >, ParameterLib::Parameter< double > const &, RefrigerantProperties const &, double const, double const)> FactoryAdvancedBuildingPower
FlowAndTemperatureControl createHotWaterCooling(std::optional< PowerWithCOP > const &, std::optional< PowerWithCOP > const &hot_water, std::optional< CoolingVariant > const &cooling, ParameterLib::Parameter< double > const &flow_rate_param, RefrigerantProperties const &refrigerant, double const flow_rate_min, double const power_min)
CoolingVariant createCoolingVariant(std::optional< BaseLib::ConfigTree > const &cooling_config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)
FlowAndTemperatureControl createAdvancedBuildingPower(std::optional< BaseLib::ConfigTree > const &heating_config, std::optional< BaseLib::ConfigTree > const &hot_water_config, std::optional< BaseLib::ConfigTree > const &cooling_config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, ParameterLib::Parameter< double > const &flow_rate_param, RefrigerantProperties const &refrigerant, double const flow_rate_min, double const power_min)
const std::map< std::tuple< bool, bool, bool >, FactoryAdvancedBuildingPower > advancedBuildingPower
FlowAndTemperatureControl createHeatingHotWaterCooling(std::optional< PowerWithCOP > const &heating, std::optional< PowerWithCOP > const &hot_water, std::optional< CoolingVariant > const &cooling, ParameterLib::Parameter< double > const &flow_rate_param, RefrigerantProperties const &refrigerant, double const flow_rate_min, double const power_min)
FlowAndTemperatureControl createCooling(std::optional< PowerWithCOP > const &, std::optional< PowerWithCOP > const &, std::optional< CoolingVariant > const &cooling, ParameterLib::Parameter< double > const &flow_rate_param, RefrigerantProperties const &refrigerant, double const flow_rate_min, double const power_min)
FlowAndTemperatureControl createFlowAndTemperatureControl(BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves, RefrigerantProperties const &refrigerant)
std::variant< PowerWithCOP, std::reference_wrapper< ParameterLib::Parameter< double > > > CoolingVariant
FlowAndTemperatureControl createHeatingCooling(std::optional< PowerWithCOP > const &heating, std::optional< PowerWithCOP > const &, std::optional< CoolingVariant > const &cooling, ParameterLib::Parameter< double > const &flow_rate_param, RefrigerantProperties const &refrigerant, double const flow_rate_min, double const power_min)
std::variant< InflowTemperature, Power, BuildingPower, BuildingPowerHotWaterActiveCooling, BuildingPowerHotWaterPassiveCooling, BuildingPowerHotWater, BuildingPowerActiveCooling, BuildingPowerPassiveCooling, ActiveCooling > FlowAndTemperatureControl
PowerWithCOP createPowerWithCOPStruct(std::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > &parameters, std::map< std::string, std::unique_ptr< MathLib::PiecewiseLinearInterpolation > > const &curves)