Skip to content

Commit

Permalink
Merge pull request #20 from jfreissmann/feature_tespy_bump
Browse files Browse the repository at this point in the history
Feature tespy bump
  • Loading branch information
jfreissmann authored Jun 19, 2024
2 parents 7b3b045 + 69efaaa commit 25be330
Show file tree
Hide file tree
Showing 29 changed files with 317 additions and 451 deletions.
11 changes: 0 additions & 11 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
python_requires='>=3.9',
install_requires=[
'tespy==0.6.3',
'tespy>=0.7.0',
'streamlit>=1.32.0',
'numpy>=1.24.0',
'pandas>=1.5.3',
Expand Down
15 changes: 2 additions & 13 deletions src/heatpumps/models/HeatPumpBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,12 @@ def __init__(self, params):
self.si = self.params['fluids']['si']
self.so = self.params['fluids']['so']

if self.si == self.so:
self.fluid_vec_wf = {self.wf: 1, self.si:0}
self.fluid_vec_si = {self.wf: 0, self.si: 1}
self.fluid_vec_so = {self.wf: 0, self.si: 1}
else:
self.fluid_vec_wf = {self.wf: 1, self.si: 0, self.so: 0}
self.fluid_vec_si = {self.wf: 0, self.si: 1, self.so: 0}
self.fluid_vec_so = {self.wf: 0, self.si: 0, self.so: 1}

self.comps = dict()
self.conns = dict()
self.buses = dict()

self.nw = Network(
fluids=[fluid for fluid in self.fluid_vec_wf],
T_unit='C', p_unit='bar', h_unit='kJ / kg',
m_unit='kg / s'
T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s'
)

self.cop = np.nan
Expand Down Expand Up @@ -80,7 +69,7 @@ def _solve_model(self, **kwargs):
if 'print_results' in kwargs:
if kwargs['print_results']:
self.nw.print_results()
if self.nw.res[-1] < 1e-3:
if self.nw.residual[-1] < 1e-3:
self.solved_design = True
self.nw.save(self.design_path)

Expand Down
57 changes: 12 additions & 45 deletions src/heatpumps/models/HeatPumpCascade.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from CoolProp.CoolProp import PropsSI as PSI
from tespy.components import (Compressor, Condenser, CycleCloser,
HeatExchanger, HeatExchangerSimple, Pump, Sink,
HeatExchanger, Pump, SimpleHeatExchanger, Sink,
Source, Valve)
from tespy.connections import Bus, Connection
from tespy.networks import Network
Expand All @@ -31,45 +31,12 @@ def __init__(self, params):
self.si = self.params['fluids']['si']
self.so = self.params['fluids']['so']

if self.wf1 == self.wf2:
if self.si == self.so:
self.fluid_vec_wf1 = {self.wf1: 1, self.si: 0}
self.fluid_vec_wf2 = {self.wf1: 1, self.si: 0}
self.fluid_vec_si = {self.wf1: 0, self.si: 1}
self.fluid_vec_so = {self.wf1: 0, self.si: 1}
else:
self.fluid_vec_wf1 = {self.wf1: 1, self.si: 0, self.so: 0}
self.fluid_vec_wf2 = {self.wf1: 1, self.si: 0, self.so: 0}
self.fluid_vec_si = {self.wf1: 0, self.si: 1, self.so: 0}
self.fluid_vec_so = {self.wf1: 0, self.si: 0, self.so: 1}
else:
if self.si == self.so:
self.fluid_vec_wf1 = {self.wf1: 1, self.wf2: 0, self.si: 0}
self.fluid_vec_wf2 = {self.wf1: 0, self.wf2: 1, self.si: 0}
self.fluid_vec_si = {self.wf1: 0, self.wf2: 0, self.si: 1}
self.fluid_vec_so = {self.wf1: 0, self.wf2: 0, self.si: 1}
else:
self.fluid_vec_wf1 = {
self.wf1: 1, self.wf2: 0, self.si: 0, self.so: 0
}
self.fluid_vec_wf2 = {
self.wf1: 0, self.wf2: 1, self.si: 0, self.so: 0
}
self.fluid_vec_si = {
self.wf1: 0, self.wf2: 0, self.si: 1, self.so: 0
}
self.fluid_vec_so = {
self.wf1: 0, self.wf2: 0, self.si: 0, self.so: 1
}

self.comps = dict()
self.conns = dict()
self.buses = dict()

self.nw = Network(
fluids=[fluid for fluid in self.fluid_vec_wf1],
T_unit='C', p_unit='bar', h_unit='kJ / kg',
m_unit='kg / s'
T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s'
)

self.cop = np.nan
Expand All @@ -96,7 +63,7 @@ def generate_components(self):
# Heat sink
self.comps['cons_cc'] = CycleCloser('Consumer Cycle Closer')
self.comps['cons_pump'] = Pump('Consumer Recirculation Pump')
self.comps['cons'] = HeatExchangerSimple('Consumer')
self.comps['cons'] = SimpleHeatExchanger('Consumer')

# Main cycle
self.comps['cond'] = Condenser('Condenser')
Expand Down Expand Up @@ -238,21 +205,21 @@ def init_simulation(self, **kwargs):

# Main cycle
self.conns['A3'].set_attr(x=self.params['A3']['x'], p=p_evap2)
self.conns['A0'].set_attr(p=p_cond2, fluid=self.fluid_vec_wf2)
self.conns['A0'].set_attr(p=p_cond2, fluid={self.wf2: 1})
self.conns['D3'].set_attr(x=self.params['D3']['x'], p=p_evap1)
self.conns['D0'].set_attr(p=p_cond1, fluid=self.fluid_vec_wf1)
self.conns['D0'].set_attr(p=p_cond1, fluid={self.wf1: 1})
# Heat source
self.conns['B1'].set_attr(
T=self.params['B1']['T'], p=self.params['B1']['p'],
fluid=self.fluid_vec_so
fluid={self.so: 1}
)
self.conns['B2'].set_attr(T=self.params['B2']['T'])
self.conns['B3'].set_attr(p=self.params['B1']['p'])

# Heat sink
self.conns['C3'].set_attr(
T=self.params['C3']['T'], p=self.params['C3']['p'],
fluid=self.fluid_vec_si
fluid={self.si: 1}
)
self.conns['C0'].set_attr(T=self.params['C0']['T'])

Expand Down Expand Up @@ -409,9 +376,9 @@ def offdesign_simulation(self, log_simulations=False):
'%H:%M:%S'
)
log_entry = (
f'{timestamp};{(self.nw.res[-1] < 1e-3)};'
f'{timestamp};{(self.nw.residual[-1] < 1e-3)};'
+ f'{T_hs_ff:.2f};{T_cons_ff:.2f};{pl:.1f};'
+ f'{self.nw.res[-1]:.2e}\n'
+ f'{self.nw.residual[-1]:.2e}\n'
)
if not os.path.exists(logpath):
with open(logpath, 'w', encoding='utf-8') as file:
Expand All @@ -424,7 +391,7 @@ def offdesign_simulation(self, log_simulations=False):
with open(logpath, 'a', encoding='utf-8') as file:
file.write(log_entry)

if pl == self.pl_range[-1] and self.nw.res[-1] < 1e-3:
if pl == self.pl_range[-1] and self.nw.residual[-1] < 1e-3:
self.nw.save(os.path.abspath(os.path.join(
os.path.dirname(__file__), 'stable',
f'{self.subdirname}_init'
Expand All @@ -439,7 +406,7 @@ def offdesign_simulation(self, log_simulations=False):
if inranges:
empty_or_worse = (
pd.isnull(results_offdesign.loc[idx, 'Q'])
or (self.nw.res[-1]
or (self.nw.residual[-1]
< results_offdesign.loc[idx, 'residual']
)
)
Expand All @@ -464,7 +431,7 @@ def offdesign_simulation(self, log_simulations=False):
/ results_offdesign.loc[idx, 'P']
)
results_offdesign.loc[idx, 'residual'] = (
self.nw.res[-1]
self.nw.residual[-1]
)

if self.params['offdesign']['save_results']:
Expand Down
57 changes: 12 additions & 45 deletions src/heatpumps/models/HeatPumpCascade2IHX.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pandas as pd
from CoolProp.CoolProp import PropsSI as PSI
from tespy.components import (Compressor, Condenser, CycleCloser,
HeatExchanger, HeatExchangerSimple, Pump, Sink,
HeatExchanger, Pump, SimpleHeatExchanger, Sink,
Source, Valve)
from tespy.connections import Bus, Connection, Ref
from tespy.networks import Network
Expand All @@ -31,45 +31,12 @@ def __init__(self, params):
self.si = self.params['fluids']['si']
self.so = self.params['fluids']['so']

if self.wf1 == self.wf2:
if self.si == self.so:
self.fluid_vec_wf1 = {self.wf1: 1, self.si: 0}
self.fluid_vec_wf2 = {self.wf1: 1, self.si: 0}
self.fluid_vec_si = {self.wf1: 0, self.si: 1}
self.fluid_vec_so = {self.wf1: 0, self.si: 1}
else:
self.fluid_vec_wf1 = {self.wf1: 1, self.si: 0, self.so: 0}
self.fluid_vec_wf2 = {self.wf1: 1, self.si: 0, self.so: 0}
self.fluid_vec_si = {self.wf1: 0, self.si: 1, self.so: 0}
self.fluid_vec_so = {self.wf1: 0, self.si: 0, self.so: 1}
else:
if self.si == self.so:
self.fluid_vec_wf1 = {self.wf1: 1, self.wf2: 0, self.si: 0}
self.fluid_vec_wf2 = {self.wf1: 0, self.wf2: 1, self.si: 0}
self.fluid_vec_si = {self.wf1: 0, self.wf2: 0, self.si: 1}
self.fluid_vec_so = {self.wf1: 0, self.wf2: 0, self.si: 1}
else:
self.fluid_vec_wf1 = {
self.wf1: 1, self.wf2: 0, self.si: 0, self.so: 0
}
self.fluid_vec_wf2 = {
self.wf1: 0, self.wf2: 1, self.si: 0, self.so: 0
}
self.fluid_vec_si = {
self.wf1: 0, self.wf2: 0, self.si: 1, self.so: 0
}
self.fluid_vec_so = {
self.wf1: 0, self.wf2: 0, self.si: 0, self.so: 1
}

self.comps = dict()
self.conns = dict()
self.buses = dict()

self.nw = Network(
fluids=[fluid for fluid in self.fluid_vec_wf1],
T_unit='C', p_unit='bar', h_unit='kJ / kg',
m_unit='kg / s'
T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s'
)

self.cop = np.nan
Expand All @@ -96,7 +63,7 @@ def generate_components(self):
# Heat sink
self.comps['cons_cc'] = CycleCloser('Consumer Cycle Closer')
self.comps['cons_pump'] = Pump('Consumer Recirculation Pump')
self.comps['cons'] = HeatExchangerSimple('Consumer')
self.comps['cons'] = SimpleHeatExchanger('Consumer')

# Main cycle
self.comps['cond'] = Condenser('Condenser')
Expand Down Expand Up @@ -272,23 +239,23 @@ def init_simulation(self, **kwargs):

# Main cycle
self.conns['A4'].set_attr(x=self.params['A4']['x'], p=p_evap2)
self.conns['A0'].set_attr(p=p_cond2, fluid=self.fluid_vec_wf2)
self.conns['A0'].set_attr(p=p_cond2, fluid={self.wf2: 1})
self.conns['A5'].set_attr(h=h_superheat2)
self.conns['D4'].set_attr(x=self.params['D4']['x'], p=p_evap1)
self.conns['D0'].set_attr(p=p_cond1, fluid=self.fluid_vec_wf1)
self.conns['D0'].set_attr(p=p_cond1, fluid={self.wf1: 1})
self.conns['D5'].set_attr(h=h_superheat1)
# Heat source
self.conns['B1'].set_attr(
T=self.params['B1']['T'], p=self.params['B1']['p'],
fluid=self.fluid_vec_so
fluid={self.so: 1}
)
self.conns['B2'].set_attr(T=self.params['B2']['T'])
self.conns['B3'].set_attr(p=self.params['B1']['p'])

# Heat sink
self.conns['C3'].set_attr(
T=self.params['C3']['T'], p=self.params['C3']['p'],
fluid=self.fluid_vec_si
fluid={self.si: 1}
)
self.conns['C0'].set_attr(T=self.params['C0']['T'])

Expand Down Expand Up @@ -463,9 +430,9 @@ def offdesign_simulation(self, log_simulations=False):
'%H:%M:%S'
)
log_entry = (
f'{timestamp};{(self.nw.res[-1] < 1e-3)};'
f'{timestamp};{(self.nw.residual[-1] < 1e-3)};'
+ f'{T_hs_ff:.2f};{T_cons_ff:.2f};{pl:.1f};'
+ f'{self.nw.res[-1]:.2e}\n'
+ f'{self.nw.residual[-1]:.2e}\n'
)
if not os.path.exists(logpath):
with open(logpath, 'w', encoding='utf-8') as file:
Expand All @@ -478,7 +445,7 @@ def offdesign_simulation(self, log_simulations=False):
with open(logpath, 'a', encoding='utf-8') as file:
file.write(log_entry)

if pl == self.pl_range[-1] and self.nw.res[-1] < 1e-3:
if pl == self.pl_range[-1] and self.nw.residual[-1] < 1e-3:
self.nw.save(os.path.abspath(os.path.join(
os.path.dirname(__file__), 'stable',
f'{self.subdirname}_init'
Expand All @@ -493,7 +460,7 @@ def offdesign_simulation(self, log_simulations=False):
if inranges:
empty_or_worse = (
pd.isnull(results_offdesign.loc[idx, 'Q'])
or (self.nw.res[-1]
or (self.nw.residual[-1]
< results_offdesign.loc[idx, 'residual']
)
)
Expand All @@ -518,7 +485,7 @@ def offdesign_simulation(self, log_simulations=False):
/ results_offdesign.loc[idx, 'P']
)
results_offdesign.loc[idx, 'residual'] = (
self.nw.res[-1]
self.nw.residual[-1]
)

if self.params['offdesign']['save_results']:
Expand Down
Loading

0 comments on commit 25be330

Please sign in to comment.