OGS
BHECommon.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
19
20#pragma once
21
22#include <algorithm>
23#include <vector>
24
25#include "BaseLib/Error.h"
26#include "BoreholeGeometry.h"
28#include "GroutParameters.h"
30
31namespace ProcessLib
32{
33namespace HeatTransportBHE
34{
35namespace BHE
36{
40inline double checkedGroutArea(double const borehole_area_fraction,
41 double const pipe_outside_area,
42 int const section_index)
43{
44 double const grout_area = borehole_area_fraction - pipe_outside_area;
45 if (grout_area <= 0)
46 {
48 "Non-positive grout cross-sectional area at section {:d}. "
49 "Borehole diameter is too small for the pipe dimensions.",
50 section_index);
51 }
52 return grout_area;
53}
54
56{
57public:
58 BHECommon(BoreholeGeometry const& borehole_geometry_,
59 RefrigerantProperties const& refrigerant_,
60 GroutParameters const& grout_,
61 FlowAndTemperatureControl const& flowAndTemperatureControl_,
62 bool const use_python_bcs_)
63 : borehole_geometry(borehole_geometry_),
64 refrigerant(refrigerant_),
65 grout(grout_),
66 flowAndTemperatureControl(flowAndTemperatureControl_),
67 use_python_bcs(use_python_bcs_)
68 {
69 }
70
75 bool const use_python_bcs;
76 constexpr bool isPowerBC() const
77 {
78 return std::visit([](auto const& ftc) { return ftc.is_power_bc; },
80 }
81
84 {
85 return borehole_geometry.sections.getNumberOfSections();
86 }
87
89 std::vector<double> const& getSectionBoundaries() const
90 {
91 return borehole_geometry.sections.section_boundaries;
92 }
93
95 double thermalResistanceAtSection(int const unknown_index,
96 int const section_index) const
97 {
98 auto const& thermal_resistances =
99 getThermalResistancesAtSection(section_index);
100 if (unknown_index < 0 ||
101 unknown_index >= static_cast<int>(thermal_resistances.size()))
102 {
103 OGS_FATAL("Invalid unknown index {:d} for section {:d}.",
104 unknown_index, section_index);
105 }
106 return thermal_resistances[unknown_index];
107 }
108
109protected:
116 template <typename Fn>
117 void recomputeSectionalResistances(Fn&& calcForSection)
118 {
119 int const n = getNumberOfSections();
122 for (int i = 0; i < n; ++i)
123 {
124 _sectional_thermal_resistances.push_back(calcForSection(i));
125 }
126 }
127
129 std::vector<double> _flow_velocities;
130
133 double getClampedFlowVelocity(int const section_index) const
134 {
135 return _flow_velocities.empty()
136 ? 0.0
137 : _flow_velocities[std::min(
138 section_index,
139 static_cast<int>(_flow_velocities.size()) - 1)];
140 }
141
144 std::vector<std::vector<double>> _sectional_thermal_resistances;
145
147 std::vector<double> const& getThermalResistancesAtSection(
148 int const section_index) const
149 {
150 if (section_index < 0 ||
151 section_index >=
152 static_cast<int>(_sectional_thermal_resistances.size()))
153 {
154 OGS_FATAL("Invalid section index: {:d}", section_index);
155 }
156 return _sectional_thermal_resistances[section_index];
157 }
158};
159} // end of namespace BHE
160} // end of namespace HeatTransportBHE
161} // end of namespace ProcessLib
#define OGS_FATAL(...)
Definition Error.h:19
double thermalResistanceAtSection(int const unknown_index, int const section_index) const
Get thermal resistance for a specific section and unknown.
Definition BHECommon.h:95
RefrigerantProperties const refrigerant
Definition BHECommon.h:72
void recomputeSectionalResistances(Fn &&calcForSection)
Recompute _sectional_thermal_resistances for all sections.
Definition BHECommon.h:117
std::vector< double > const & getSectionBoundaries() const
Get section boundaries (cumulative distance from wellhead).
Definition BHECommon.h:89
int getNumberOfSections() const
Get number of sections in the borehole geometry.
Definition BHECommon.h:83
BHECommon(BoreholeGeometry const &borehole_geometry_, RefrigerantProperties const &refrigerant_, GroutParameters const &grout_, FlowAndTemperatureControl const &flowAndTemperatureControl_, bool const use_python_bcs_)
Definition BHECommon.h:58
std::vector< std::vector< double > > _sectional_thermal_resistances
Definition BHECommon.h:144
FlowAndTemperatureControl const flowAndTemperatureControl
Definition BHECommon.h:74
std::vector< double > const & getThermalResistancesAtSection(int const section_index) const
Get the thermal resistance vector for a given section.
Definition BHECommon.h:147
double getClampedFlowVelocity(int const section_index) const
Get velocity for a section, clamping to last section if index exceeds the number of velocity entries....
Definition BHECommon.h:133
double checkedGroutArea(double const borehole_area_fraction, double const pipe_outside_area, int const section_index)
Definition BHECommon.h:40
std::variant< InflowTemperature, Power, BuildingPower, BuildingPowerHotWaterActiveCooling, BuildingPowerHotWaterPassiveCooling, BuildingPowerHotWater, BuildingPowerActiveCooling, BuildingPowerPassiveCooling, ActiveCooling > FlowAndTemperatureControl