Skip to content

Commit d309db0

Browse files
fix trapz/slice integration in AC & HP surface plants (unit tests still pending)
1 parent d6df485 commit d309db0

File tree

2 files changed

+41
-39
lines changed

2 files changed

+41
-39
lines changed

src/geophires_x/SurfacePlantDistrictHeating.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,37 +215,37 @@ def Calculate(self, model: Model) -> None:
215215
self.HeatkWhExtracted.value = np.zeros(self.plant_lifetime.value)
216216
self.PumpingkWh.value = np.zeros(self.plant_lifetime.value)
217217

218+
def _integrate_slice(series, _i, util_factor):
219+
return SurfacePlant.integrate_time_series_slice(
220+
series, _i, model.economics.timestepsperyear.value, util_factor
221+
)
222+
223+
218224
for i in range(0, self.plant_lifetime.value):
219-
if self.plant_type.value == PlantType.DISTRICT_HEATING: # for district heating, we have a util_factor_array
220-
# FIXME TODO WIP adjust dx for slice size
221-
self.HeatkWhExtracted.value[i] = np.trapz(self.HeatExtracted.value[
222-
(0 + i * model.economics.timestepsperyear.value):((
223-
i + 1) * model.economics.timestepsperyear.value) + 1],
224-
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * \
225-
self.util_factor_array.value[i]
226-
self.PumpingkWh.value[i] = np.trapz(model.wellbores.PumpingPower.value[
227-
(0 + i * model.economics.timestepsperyear.value):((
228-
i + 1) * model.economics.timestepsperyear.value) + 1],
229-
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * \
230-
self.util_factor_array.value[i]
225+
if self.plant_type.value == PlantType.DISTRICT_HEATING:
226+
self.HeatkWhExtracted.value[i] = _integrate_slice(
227+
self.HeatExtracted.value,
228+
i,
229+
self.util_factor_array.value[i]
230+
)
231+
232+
self.PumpingkWh.value[i] = _integrate_slice(
233+
model.wellbores.PumpingPower.value,
234+
i,
235+
# for district heating, we have a util_factor_array
236+
self.util_factor_array.value[i]
237+
)
231238
else:
232-
# FIXME TODO WIP adjust dx for slice size
233-
self.HeatkWhExtracted.value[i] = np.trapz(self.HeatExtracted.value[
234-
(0 + i * model.economics.timestepsperyear.value):((
235-
i + 1) * model.economics.timestepsperyear.value) + 1],
236-
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
237-
self.PumpingkWh.value[i] = np.trapz(model.wellbores.PumpingPower.value[
238-
(0 + i * model.economics.timestepsperyear.value):((
239-
i + 1) * model.economics.timestepsperyear.value) + 1],
240-
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
239+
self.HeatkWhExtracted.value[i] = _integrate_slice(self.HeatExtracted.value, i, self.utilization_factor.value)
240+
self.PumpingkWh.value[i] = _integrate_slice(model.wellbores.PumpingPower.value, i, self.utilization_factor.value)
241241

242242
self.HeatkWhProduced.value = np.zeros(self.plant_lifetime.value)
243243
for i in range(0, self.plant_lifetime.value):
244-
self.HeatkWhProduced.value[i] = np.trapz(self.HeatProduced.value[
245-
(0 + i * model.economics.timestepsperyear.value):((
246-
i + 1) * model.economics.timestepsperyear.value) + 1],
247-
dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * \
248-
self.util_factor_array.value[i]
244+
self.HeatkWhProduced.value[i] = _integrate_slice(
245+
self.HeatProduced.value,
246+
i,
247+
self.util_factor_array.value[i]
248+
)
249249

250250
# calculate reservoir heat content
251251
self.RemainingReservoirHeatContent.value = SurfacePlant.remaining_reservoir_heat_content(

src/geophires_x/SurfacePlantHeatPump.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def __init__(self, model: Model):
1919
:return: None
2020
"""
2121

22-
model.logger.info("Init " + str(__class__) + ": " + inspect.currentframe().f_code.co_name)
22+
model.logger.info(f'Init {str(__class__)}: {inspect.currentframe().f_code.co_name}')
2323
super().__init__(model) # Initialize all the parameters in the superclass
2424

2525
# Set up all the Parameters that will be predefined by this class using the different types of parameter classes.
@@ -65,7 +65,7 @@ def __init__(self, model: Model):
6565
CurrentUnits=EnergyFrequencyUnit.KWhPERYEAR
6666
)
6767

68-
model.logger.info("Complete " + str(__class__) + ": " + inspect.currentframe().f_code.co_name)
68+
model.logger.info(f'Complete {str(__class__)}: {inspect.currentframe().f_code.co_name}')
6969

7070
def __str__(self):
7171
return "SurfacePlantHeatPump"
@@ -78,12 +78,12 @@ def read_parameters(self, model:Model) -> None:
7878
:param model: The container class of the application, giving access to everything else, including the logger
7979
:return: None
8080
"""
81-
model.logger.info("Init " + str(__class__) + ": " + inspect.currentframe().f_code.co_name)
81+
model.logger.info(f'Init {str(__class__)}: {inspect.currentframe().f_code.co_name}')
8282
super().read_parameters(model) # Read in all the parameters from the superclass
8383

8484
# Since there are no parameters unique to this class, we don't need to read any in here.
8585

86-
model.logger.info("complete "+ str(__class__) + ": " + inspect.currentframe().f_code.co_name)
86+
model.logger.info(f'complete {str(__class__)}: {inspect.currentframe().f_code.co_name}')
8787

8888
def Calculate(self, model: Model) -> None:
8989
"""
@@ -93,7 +93,7 @@ def Calculate(self, model: Model) -> None:
9393
:type model: :class:`~geophires_x.Model.Model`
9494
:return: Nothing, but it does make calculations and set values in the model
9595
"""
96-
model.logger.info("Init " + str(__class__) + ": " + inspect.currentframe().f_code.co_name)
96+
model.logger.info(f'Init {str(__class__)}: {inspect.currentframe().f_code.co_name}')
9797

9898
# This is where all the calculations are made using all the values that have been set.
9999
# If you subclass this class, you can choose to run these calculations before (or after) your calculations,
@@ -115,24 +115,26 @@ def Calculate(self, model: Model) -> None:
115115
self.HeatkWhExtracted.value = np.zeros(self.plant_lifetime.value)
116116
self.PumpingkWh.value = np.zeros(self.plant_lifetime.value)
117117

118+
def _integrate_slice(series, _i):
119+
return SurfacePlant.integrate_time_series_slice(
120+
series, _i, model.economics.timestepsperyear.value, self.utilization_factor.value
121+
)
122+
118123
for i in range(0, self.plant_lifetime.value):
119-
# FIXME TODO WIP adjust dx for slice size
120-
self.HeatkWhExtracted.value[i] = np.trapz(self.HeatExtracted.value[(0 + i * model.economics.timestepsperyear.value):((i + 1) * model.economics.timestepsperyear.value) + 1],dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
121-
self.PumpingkWh.value[i] = np.trapz(model.wellbores.PumpingPower.value[(0 + i * model.economics.timestepsperyear.value):((i + 1) * model.economics.timestepsperyear.value) + 1],dx=1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
124+
self.HeatkWhExtracted.value[i] = _integrate_slice(self.HeatExtracted.value, i)
125+
self.PumpingkWh.value[i] = _integrate_slice(model.wellbores.PumpingPower.value, i)
122126

123127
self.HeatkWhProduced.value = np.zeros(self.plant_lifetime.value)
124128
for i in range(0, self.plant_lifetime.value):
125-
# FIXME TODO WIP adjust dx for slice size
126-
self.HeatkWhProduced.value[i] = np.trapz(self.HeatProduced.value[(0+i*model.economics.timestepsperyear.value):((i+1)*model.economics.timestepsperyear.value)+1],dx = 1./model.economics.timestepsperyear.value*365.*24.)*1000.*self.utilization_factor.value
129+
self.HeatkWhProduced.value[i] = _integrate_slice(self.HeatProduced.value, i)
127130

128131
self.heat_pump_electricity_kwh_used.value = np.zeros(self.plant_lifetime.value)
129132
for i in range(0, self.plant_lifetime.value):
130-
# FIXME TODO WIP adjust dx for slice size
131-
self.heat_pump_electricity_kwh_used.value[i] = np.trapz(self.heat_pump_electricity_used.value[(0 + i * model.economics.timestepsperyear.value):((i + 1) * model.economics.timestepsperyear.value) + 1], dx =1. / model.economics.timestepsperyear.value * 365. * 24.) * 1000. * self.utilization_factor.value
133+
self.heat_pump_electricity_kwh_used.value[i] = _integrate_slice(self.heat_pump_electricity_used.value, i)
132134

133135
# calculate reservoir heat content
134136
self.RemainingReservoirHeatContent.value = SurfacePlant.remaining_reservoir_heat_content(
135137
self, model.reserv.InitialReservoirHeatContent.value, self.HeatkWhExtracted.value)
136138

137139
self._calculate_derived_outputs(model)
138-
model.logger.info(f"complete {str(__class__)}: {inspect.currentframe().f_code.co_name}")
140+
model.logger.info(f'complete {str(__class__)}: {inspect.currentframe().f_code.co_name}')

0 commit comments

Comments
 (0)