29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425 | class GroundHeatExchanger: # TODO: Rename this. Just GHEDesignerManager? GHEDesigner?
def __init__(
self,
grout_conductivity: float,
grout_rho_cp: float,
soil_conductivity: float,
soil_rho_cp: float,
soil_undisturbed_temperature: float,
borehole_buried_depth: float,
borehole_radius: float,
pipe_arrangement_type: PipeType,
pipe_parameters: dict,
fluid_name: str = "Water",
fluid_concentration_percent: float = 0.0,
fluid_temperature: float = 20.0,
) -> None:
self.fluid = Fluid(fluid_name, fluid_temperature, fluid_concentration_percent)
self.grout = Grout(grout_conductivity, grout_rho_cp)
self.soil = Soil(soil_conductivity, soil_rho_cp, soil_undisturbed_temperature)
if pipe_arrangement_type == PipeType.SINGLEUTUBE:
params = ["conductivity", "rho_cp", "inner_diameter", "outer_diameter", "shank_spacing", "roughness"]
if not all(x in pipe_parameters for x in params):
raise ValueError(f"pipe_arrangement_type of {pipe_arrangement_type!s} requires these inputs: {params}")
pipe_parameters["num_pipes"] = 1
self.pipe = Pipe.init_single_u_tube(**pipe_parameters)
elif pipe_arrangement_type == PipeType.DOUBLEUTUBESERIES:
params = ["conductivity", "rho_cp", "inner_diameter", "outer_diameter", "shank_spacing", "roughness"]
if not all(x in pipe_parameters for x in params):
raise ValueError(f"pipe_arrangement_type of {pipe_arrangement_type!s} requires these inputs: {params}")
self.pipe = Pipe.init_double_u_tube_series(**pipe_parameters)
elif pipe_arrangement_type == PipeType.DOUBLEUTUBEPARALLEL:
params = ["conductivity", "rho_cp", "inner_diameter", "outer_diameter", "shank_spacing", "roughness"]
if not all(x in pipe_parameters for x in params):
raise ValueError(f"pipe_arrangement_type of {pipe_arrangement_type!s} requires these inputs: {params}")
self.pipe = Pipe.init_double_u_tube_parallel(**pipe_parameters)
else: # Assuming coaxial
params = [
"conductivity_inner",
"rho_cp",
"conductivity_outer",
"inner_pipe_d_in",
"inner_pipe_d_out",
"outer_pipe_d_in",
"outer_pipe_d_out",
]
if not all(x in pipe_parameters for x in params):
raise ValueError(f"pipe_arrangement_type of {PipeType.COAXIAL!s} requires these inputs: {params}")
pipe_parameters["conductivity"] = (
pipe_parameters["conductivity_inner"],
pipe_parameters["conductivity_outer"],
)
del pipe_parameters["conductivity_inner"]
del pipe_parameters["conductivity_outer"]
self.pipe = Pipe.init_coaxial(**pipe_parameters)
self.pygfunction_borehole = Borehole(100, borehole_buried_depth, borehole_radius, x=0.0, y=0.0)
@classmethod
def init_from_dictionary(cls, ghe_dict: dict, fluid_inputs: dict | None = None) -> "GroundHeatExchanger":
"""
Initialize a GroundHeatExchanger object from input dictionaries, performing validation and ultimately calling
the main object constructor.
:param ghe_dict: Dictionary of ground heat exchanger parameters, see the input schema specification for required
inputs in the ground_heat_exchanger schema field.
:param fluid_inputs: Optional dictionary of fluid input parameters, see the input schema fluid spec for details.
:return: GroundHeatExchanger object.
# TODO: Add validation back in to the input fields
"""
grout_parameters: dict = ghe_dict["grout"]
g_c: float = grout_parameters["conductivity"]
g_rho_cp: float = grout_parameters["rho_cp"]
soil_parameters: dict = ghe_dict["soil"]
s_k: float = soil_parameters["conductivity"]
s_rho_cp: float = soil_parameters["rho_cp"]
s_temp: float = soil_parameters["undisturbed_temp"]
borehole_parameters: dict = ghe_dict["borehole"]
buried_depth: float = borehole_parameters["buried_depth"]
diameter: float = borehole_parameters["diameter"]
radius: float = diameter / 2.0
fluid_dict = (
fluid_inputs if fluid_inputs else {"fluid_name": "Water", "concentration_percent": 0.0, "temperature": 20.0}
)
fluid_name = fluid_dict.get("fluid_name", "Water")
concentration_percent = fluid_dict.get("concentration_percent", 0.0)
temperature = fluid_dict.get("temperature", 20.0)
pipe_parameters: dict = ghe_dict["pipe"]
pipe_type: PipeType = PipeType(pipe_parameters["arrangement"].upper())
del pipe_parameters["arrangement"]
ghe: GroundHeatExchanger = cls(
g_c,
g_rho_cp,
s_k,
s_rho_cp,
s_temp,
buried_depth,
radius,
pipe_type,
pipe_parameters,
fluid_name,
concentration_percent,
temperature,
)
return ghe
def design_and_size_ghe(self, ghe_dict: dict, end_month: int, loads_override: list[float] | None = None):
ghe_loads = loads_override if loads_override else get_loads(ghe_dict["loads"])
if (end_month % MONTHS_IN_YEAR) > 0:
raise ValueError(f"end_month must be a multiple of {MONTHS_IN_YEAR}")
flow_type_str: str = ghe_dict["flow_type"]
flow_type = FlowConfigType(flow_type_str.upper())
flow_rate: float = ghe_dict["flow_rate"]
# grab some design conditions
design_parameters = ghe_dict["design"]
continue_if_design_unmet: bool = design_parameters.get("continue_if_design_unmet", False)
min_eft: float = design_parameters["min_eft"]
max_eft: float = design_parameters["max_eft"]
max_height: float = design_parameters["max_height"]
min_height: float = design_parameters["min_height"]
max_boreholes: int | None = design_parameters.get("max_boreholes")
# check_arg_bounds(min_eft, max_eft, "min_eft", "max_eft")
# set up the geometry constraints section
geom = ghe_dict["geometric_constraints"]
geometry_map = {geom.name: geom for geom in DesignGeomType}
geom_type = geometry_map.get(geom["method"].upper())
design: DesignBase
match geom_type:
case DesignGeomType.RECTANGLE:
# max_height: float, min_height: float, length: float, width: float, b_min: float, b_max: float
rect_geometry: GeometricConstraintsRectangle = GeometricConstraintsRectangle(
length=geom["length"],
width=geom["width"],
b_min=geom["b_min"],
b_max=geom["b_max"],
)
design = DesignRectangle(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
rect_geometry,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case DesignGeomType.NEARSQUARE:
near_sq_geometry: GeometricConstraintsNearSquare = GeometricConstraintsNearSquare(
b=geom["b"],
length=geom["length"],
)
design = DesignNearSquare(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
near_sq_geometry,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case DesignGeomType.BIRECTANGLE:
bi_rect_geometry: GeometricConstraintsBiRectangle = GeometricConstraintsBiRectangle(
length=geom["length"],
width=geom["width"],
b_min=geom["b_min"],
b_max_x=geom["b_max_x"],
b_max_y=geom["b_max_y"],
)
design = DesignBiRectangle(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
bi_rect_geometry,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case DesignGeomType.BIZONEDRECTANGLE:
bi_zoned_geometry: GeometricConstraintsBiZoned = GeometricConstraintsBiZoned(
length=geom["length"],
width=geom["width"],
b_min=geom["b_min"],
b_max_x=geom["b_max_x"],
b_max_y=geom["b_max_y"],
)
design = DesignBiZoned(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
bi_zoned_geometry,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case DesignGeomType.BIRECTANGLECONSTRAINED:
no_go_boundaries = geom.get("no_go_boundaries", None)
bi_rect_const_geometry: GeometricConstraintsBiRectangleConstrained = (
GeometricConstraintsBiRectangleConstrained(
b_min=geom["b_min"],
b_max_x=geom["b_max_x"],
b_max_y=geom["b_max_y"],
property_boundary=geom["property_boundary"],
no_go_boundaries=no_go_boundaries,
)
)
design = DesignBiRectangleConstrained(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
bi_rect_const_geometry,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case DesignGeomType.ROWWISE:
# use perimeter calculations if present
perimeter_spacing_ratio = geom.get("perimeter_spacing_ratio", None)
spacing_step = geom.get("spacing_step", 0)
no_go_boundaries = geom.get("no_go_boundaries", None)
geometry_row: GeometricConstraintsRowWise = GeometricConstraintsRowWise(
perimeter_spacing_ratio=perimeter_spacing_ratio,
max_spacing=geom["max_spacing"],
min_spacing=geom["min_spacing"],
spacing_step=spacing_step,
max_rotation=geom["max_rotation"] * DEG_TO_RAD,
min_rotation=geom["min_rotation"] * DEG_TO_RAD,
rotate_step=geom["rotate_step"],
property_boundary=geom["property_boundary"],
no_go_boundaries=no_go_boundaries,
)
design = DesignRowWise(
flow_rate,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
1,
end_month,
max_eft,
min_eft,
max_height,
min_height,
continue_if_design_unmet,
max_boreholes,
geometry_row,
ghe_loads,
flow_type=flow_type,
method=TimestepType.HYBRID,
)
case _:
raise ValueError(f'DesignGeomType "{geom_type}" not supported')
start_time = time()
search = design.find_design() # TODO: I wonder if it would simplify things to just return the GHE object
search_time = time() - start_time
found_ghe = cast(GHE, search.ghe)
found_ghe.compute_g_functions(min_height, max_height)
found_ghe.size(TimestepType.HYBRID, max_height, min_height, max_eft, min_eft)
return search, search_time, found_ghe
def get_g_function(self, ghe_dict: dict, boundary_condition="MIFT") -> tuple[ndarray, ndarray, ndarray]:
# TODO: Create a SingleUTube class or something in order to get the STS stitched up
pre_designed = ghe_dict["pre_designed"]
borehole_height: float = pre_designed["H"]
if pre_designed["arrangement"] == "MANUAL":
x_positions: Sequence[float] = pre_designed["x"]
y_positions: Sequence[float] = pre_designed["y"]
if len(x_positions) != len(y_positions):
raise RuntimeError("Borehole location coordinate mismatch, make sure length of x and y are equal")
locations = list(zip(x_positions, y_positions))
elif pre_designed["arrangement"] == "RECTANGLE":
num_bh_x = pre_designed["boreholes_in_x_dimension"]
num_bh_y = pre_designed["boreholes_in_y_dimension"]
spacing_x = pre_designed["spacing_in_x_dimension"]
spacing_y = pre_designed["spacing_in_y_dimension"]
locations = rectangle(num_bh_x, num_bh_y, spacing_x, spacing_y)
else:
raise RuntimeError("Invalid arrangement type for pre_designed borehole field")
nbh = len(locations)
flow_rate: float = ghe_dict["flow_rate"]
flow_type_str: str = str(ghe_dict["flow_type"]).upper()
if flow_type_str == FlowConfigType.BOREHOLE.name:
m_flow_borehole = flow_rate * self.fluid.rho / 1000 # conv lps to m3s to kgs
elif flow_type_str == FlowConfigType.SYSTEM.name:
m_flow_ghe = flow_rate * self.fluid.rho / 1000 # conv lps to m3s to kgs
m_flow_borehole = m_flow_ghe / nbh
else:
raise NotImplementedError(f"FlowConfigType {flow_type_str} not implemented.")
self.pygfunction_borehole.H = borehole_height
ts = borehole_height**2 / (9 * self.soil.alpha)
log_time_lts = eskilson_log_times()
time_values = exp(log_time_lts) * ts
g_lts = calculate_g_function(
m_flow_borehole,
self.pipe.type,
time_values,
locations,
self.pygfunction_borehole,
self.fluid,
self.pipe,
self.grout,
self.soil,
boundary_condition=boundary_condition,
)
single_u_bh = SingleUTube(
m_flow_borehole, self.fluid, self.pygfunction_borehole, self.pipe, self.grout, self.soil
)
log_time_sts, g_sts = single_u_bh.calc_sts_g_functions()
g_bhw = single_u_bh.g_bhw
g_interp = combine_sts_lts(
log_time_lts,
g_lts.tolist(),
log_time_sts.tolist(),
g_sts.tolist(),
)
g_bhw_interp = combine_sts_lts(
log_time_lts,
g_lts.tolist(),
log_time_sts.tolist(),
g_bhw.tolist(),
)
log_time_to_write = array(log_time_sts.tolist() + log_time_lts)
g_to_write = g_interp(log_time_to_write)
g_bhw_to_write = g_bhw_interp(log_time_to_write)
return log_time_to_write, g_to_write, g_bhw_to_write
|