Skip to content

Commit bb8bf96

Browse files
Move relevant utils methods to powerplant.py
1 parent 99490d1 commit bb8bf96

File tree

1 file changed

+44
-6
lines changed

1 file changed

+44
-6
lines changed

src/fgem/powerplant.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,45 @@
77
import numpy as np
88
from scipy.spatial import cKDTree
99

10-
from .utils.utils import *
11-
1210
parent_path = Path(__file__).parent
1311

1412

13+
class _Utils:
14+
@staticmethod
15+
def heatcapacitywater(Twater):
16+
"""Computationally efficient correlation for water specific heat capacity based on the GEOPHIRES.
17+
18+
Args:
19+
Twater (Union[ndarray, float]): water temperature in deg C
20+
21+
Returns:
22+
Union[ndarray, float]: water specific heat capacity in J/kg-K
23+
"""
24+
25+
# Based on GEOPHIRES correlations (more stable XSTEAM)
26+
Twater = (Twater + 273.15) / 1000
27+
A = -203.6060
28+
B = 1523.290
29+
C = -3196.413
30+
D = 2474.455
31+
E = 3.855326
32+
cpwater = (A + B * Twater + C * Twater**2 + D * Twater**3 + E / (Twater**2)) / 18.02 * 1000
33+
return cpwater
34+
35+
@staticmethod
36+
def nonzero(x, thresh=1e-6):
37+
"""Ensure input is nonzero
38+
39+
Args:
40+
x (ndarray): input numbers
41+
thresh (float, optional): threshold below which numbers are set to zero. Defaults to 1E-6.
42+
43+
Returns:
44+
ndarray: nonzero version of input array
45+
"""
46+
return np.maximum(thresh, x)
47+
48+
1549
class CustomUnpickler(pickle.Unpickler):
1650

1751
def find_class(self, module, name):
@@ -140,9 +174,13 @@ def step(
140174
if m_tes_out > 0:
141175
m_wh_to_turbine = m_turbine - m_tes_out
142176
self.T_mix = (
143-
m_wh_to_turbine * heatcapacitywater(T_prd_wh) * T_prd_wh
144-
+ m_tes_out * heatcapacitywater(T_tes_out) * T_tes_out
145-
) / (m_wh_to_turbine * heatcapacitywater(T_prd_wh) + m_tes_out * heatcapacitywater(T_tes_out) + 1e-3)
177+
m_wh_to_turbine * _Utils.heatcapacitywater(T_prd_wh) * T_prd_wh
178+
+ m_tes_out * _Utils.heatcapacitywater(T_tes_out) * T_tes_out
179+
) / (
180+
m_wh_to_turbine * _Utils.heatcapacitywater(T_prd_wh)
181+
+ m_tes_out * _Utils.heatcapacitywater(T_tes_out)
182+
+ 1e-3
183+
)
146184
else:
147185
self.T_mix = T_prd_wh
148186

@@ -553,7 +591,7 @@ def __init__(self, Tres, Tamb, m_prd, num_prd=None, ppc=None, cf=1.0, k=2):
553591
self.T_inj = np.clip(model_output[1], a_min=self.Tamb_design, a_max=self.Tres_design) # deg C
554592

555593
if self.num_prd is None:
556-
m_g = ppc / nonzero(self.power_output_MWh_kg) / 3600 # kg/s
594+
m_g = ppc / _Utils.nonzero(self.power_output_MWh_kg) / 3600 # kg/s
557595
self.num_prd = np.ceil(m_g / m_prd).astype(int)
558596

559597
def compute_cplant(self, MaxProducedTemperature, min_cost=0):

0 commit comments

Comments
 (0)