diff --git a/src/tespy/networks/network.py b/src/tespy/networks/network.py index 6ff268046..4cd8b40c3 100644 --- a/src/tespy/networks/network.py +++ b/src/tespy/networks/network.py @@ -1381,6 +1381,7 @@ def init_offdesign_params(self): ) logger.debug(msg) df = pd.read_csv(path, sep=';', decimal='.', index_col=0) + df.index = df.index.astype(str) # iter through all components of this type and set data _individual_design_paths = {} @@ -1400,6 +1401,9 @@ def init_offdesign_params(self): _individual_design_paths[path_c] = pd.read_csv( path_c, sep=';', decimal='.', index_col=0 ) + _individual_design_paths[path_c].index = ( + _individual_design_paths[path_c].index.astype(str) + ) data = _individual_design_paths[path_c].loc[comp.label] else: @@ -1480,14 +1484,14 @@ def init_conn_design_params(self, c, df): """ # match connection (source, source_id, target, target_id) on # connection objects of design file + df.index = df.index.astype(str) if c.label not in df.index: # no matches in the connections of the network and the design files msg = ( - 'Could not find connection %s in design case. ' - 'Please, make sure no connections have been modified or ' - 'components have been relabeled for your offdesign ' - 'calculation.' - ).format(c.label) + f"Could not find connection {c.label} in design case. Please " + "make sure no connections have been modified or components " + "havebeen relabeled for your offdesign calculation." + ) logger.exception(msg) raise hlp.TESPyNetworkError(msg) @@ -1514,9 +1518,10 @@ def init_conn_params_from_path(self, c, df): """ # match connection (source, source_id, target, target_id) on # connection objects of design file + df.index = df.index.astype(str) if c.label not in df.index: # no matches in the connections of the network and the design files - msg = ('Could not find connection %s in init path file.').format(c.label) + msg = f"Could not find connection {c.label} in init path file." logger.debug(msg) return diff --git a/tutorial/advanced/starting_values.py b/tutorial/advanced/starting_values.py index da8c53de9..ad13295ec 100644 --- a/tutorial/advanced/starting_values.py +++ b/tutorial/advanced/starting_values.py @@ -11,10 +11,7 @@ wf = "NH3" # network -nw = Network( - fluids=["water", wf], - T_unit="C", p_unit="bar", h_unit="kJ / kg", m_unit="kg / s" - ) +nw = Network(T_unit="C", p_unit="bar", h_unit="kJ / kg", m_unit="kg / s") # components cycle_closer = CycleCloser("Refrigerant Cycle Closer") @@ -50,10 +47,7 @@ c5 = Connection(int_heatex, "out1", valve, "in1", label="5") c6 = Connection(valve, "out1", cycle_closer, "in1", label="6") -nw.add_conns( - c0, c1, c2, c3, c4, - c5, c6 - ) +nw.add_conns(c0, c1, c2, c3, c4, c5, c6) # heat source c11 = Connection(heatsource_feedflow, "out1", heatsource_pump, "in1", label="11") @@ -78,15 +72,15 @@ T_cons_ff = 90 # consumer cycle -c23.set_attr(T=T_cons_ff, p=10, fluid={"water": 1, wf: 0}) +c23.set_attr(T=T_cons_ff, p=10, fluid={"water": 1}) c24.set_attr(T=T_cons_bf) # heat source cycle -c11.set_attr(T=T_hs_ff, p=1, fluid={"water": 1, wf: 0}) +c11.set_attr(T=T_hs_ff, p=1, fluid={"water": 1}) c13.set_attr(T=T_hs_bf, p=1) # evaporation to fully saturated gas -c1.set_attr(x=1, fluid={"water": 0, wf: 1}) +c1.set_attr(x=1, fluid={wf: 1}) # degree of overheating after internal heat exchanger (evaporation side) c2.set_attr(Td_bp=10) @@ -113,6 +107,7 @@ nw.solve("design") except ValueError as e: print(e) + nw._reset_topology_reduction_specifications() # %%[sec_4] import CoolProp.CoolProp as CP @@ -157,7 +152,6 @@ def generate_network_with_starting_values(wf): # network nw = Network( - fluids=["water", wf], T_unit="C", p_unit="bar", h_unit="kJ / kg", m_unit="kg / s", iterinfo=False ) @@ -196,10 +190,7 @@ def generate_network_with_starting_values(wf): c5 = Connection(int_heatex, "out1", valve, "in1", label="5") c6 = Connection(valve, "out1", cycle_closer, "in1", label="6") - nw.add_conns( - c0, c1, c2, c3, c4, - c5, c6 - ) + nw.add_conns(c0, c1, c2, c3, c4, c5, c6) # heat source c11 = Connection(heatsource_feedflow, "out1", heatsource_pump, "in1", label="11") @@ -223,15 +214,15 @@ def generate_network_with_starting_values(wf): T_cons_ff = 90 # consumer cycle - c23.set_attr(T=T_cons_ff, p=10, fluid={"water": 1, wf: 0}) + c23.set_attr(T=T_cons_ff, p=10, fluid={"water": 1}) c24.set_attr(T=T_cons_bf) # heat source cycle - c11.set_attr(T=T_hs_ff, p=1, fluid={"water": 1, wf: 0}) + c11.set_attr(T=T_hs_ff, p=1, fluid={"water": 1}) c13.set_attr(T=T_hs_bf, p=1) # evaporation to fully saturated gas - c1.set_attr(x=1, fluid={"water": 0, wf: 1}) + c1.set_attr(x=1, fluid={wf: 1}) # parametrization components # isentropic efficiency diff --git a/tutorial/advanced/stepwise.py b/tutorial/advanced/stepwise.py index ec64ea71b..d8ce42b89 100644 --- a/tutorial/advanced/stepwise.py +++ b/tutorial/advanced/stepwise.py @@ -42,8 +42,8 @@ # %%[sec_5] from CoolProp.CoolProp import PropsSI as PSI p_cond = PSI("P", "Q", 1, "T", 273.15 + 95, working_fluid) / 1e5 -c0.set_attr(T=170, p=p_cond, fluid={"water": 0, working_fluid: 1}) -c20.set_attr(T=60, p=2, fluid={"water": 1, working_fluid: 0}) +c0.set_attr(T=170, p=p_cond, fluid={working_fluid: 1}) +c20.set_attr(T=60, p=2, fluid={"water": 1}) c22.set_attr(T=90) # key design paramter @@ -96,7 +96,7 @@ c6.set_attr(h=h_sat) # evaporator system hot side -c17.set_attr(T=15, fluid={"water": 1, working_fluid: 0}) +c17.set_attr(T=15, fluid={"water": 1}) c19.set_attr(T=9, p=1.013) # %%[sec_11] nw.solve("design") @@ -140,7 +140,7 @@ ic.set_attr(pr1=0.99, pr2=0.98) hsp.set_attr(eta_s=0.75) # %%[sec_15] -c0.set_attr(p=p_cond, fluid={"water": 0, working_fluid: 1}) +c0.set_attr(p=p_cond, fluid={working_fluid: 1}) c6.set_attr(h=c5.h.val + 10) c8.set_attr(h=c5.h.val + 10) @@ -148,7 +148,7 @@ c7.set_attr(h=c5.h.val * 1.2) c9.set_attr(h=c5.h.val * 1.2) -c11.set_attr(p=1.013, T=15, fluid={"water": 1, working_fluid: 0}) +c11.set_attr(p=1.013, T=15, fluid={"water": 1}) c14.set_attr(T=30) # %% [sec_16] nw.solve("design") diff --git a/tutorial/basics/district_heating.py b/tutorial/basics/district_heating.py index 24d2f262e..c9c7212bb 100755 --- a/tutorial/basics/district_heating.py +++ b/tutorial/basics/district_heating.py @@ -6,8 +6,7 @@ ) from tespy.connections import Connection -fluid_list = ['INCOMP::Water'] -nw = Network(fluids=fluid_list) +nw = Network() nw.set_attr(T_unit='C', p_unit='bar', h_unit='kJ / kg') # central heating plant @@ -39,7 +38,7 @@ pipe_feed.set_attr(Q=-250, pr=0.98) pipe_return.set_attr(Q=-200, pr=0.98) -c1.set_attr(T=90, p=10, fluid={'Water': 1}) +c1.set_attr(T=90, p=10, fluid={'INCOMP::Water': 1}) c2.set_attr(p=13) c4.set_attr(T=65) diff --git a/tutorial/basics/heat_pump.py b/tutorial/basics/heat_pump.py index 771ed51d3..28951a126 100644 --- a/tutorial/basics/heat_pump.py +++ b/tutorial/basics/heat_pump.py @@ -2,7 +2,6 @@ from tespy.networks import Network # create a network object with R134a as fluid -fluid_list = ['R134a'] my_plant = Network() # %%[sec_2] # set the unitsystem for temperatures to °C and for pressure to bar diff --git a/tutorial/basics/rankine.py b/tutorial/basics/rankine.py index 0e9cb137c..f7d85fa22 100755 --- a/tutorial/basics/rankine.py +++ b/tutorial/basics/rankine.py @@ -2,8 +2,7 @@ from tespy.networks import Network # create a network object with R134a as fluid -fluid_list = ['water'] -my_plant = Network(fluids=fluid_list) +my_plant = Network() my_plant.set_attr(T_unit='C', p_unit='bar', h_unit='kJ / kg') # %%[sec_2] from tespy.components import ( diff --git a/tutorial/heat_pump_exergy/NH3.py b/tutorial/heat_pump_exergy/NH3.py index 1bb8bbdc5..92a4ba8c1 100644 --- a/tutorial/heat_pump_exergy/NH3.py +++ b/tutorial/heat_pump_exergy/NH3.py @@ -15,15 +15,13 @@ from tespy.tools.characteristics import load_default_char as ldc import numpy as np -# %% network pamb = 1.013 # ambient pressure Tamb = 2.8 # ambient temperature # mean geothermal temperature (mean value of ground feed and return flow) Tgeo = 9.5 -nw = Network(fluids=['water', 'NH3'], T_unit='C', p_unit='bar', - h_unit='kJ / kg', m_unit='kg / s') +nw = Network(T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components @@ -90,15 +88,15 @@ # %% connection parametrization # heat pump system -cc_cd.set_attr(fluid={'water': 0, 'NH3': 1}) +cc_cd.set_attr(fluid={'NH3': 1}) ev_cp.set_attr(Td_bp=3) # geothermal heat collector -gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1, 'NH3': 0}) +gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1}) ev_gh_out.set_attr(T=Tgeo - 1.5, p=1.5) # heating system -cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1, 'NH3': 0}) +cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1}) hs_ret_hsp.set_attr(T=35, p=2) # starting values @@ -114,9 +112,11 @@ # power bus char = CharLine(x=x, y=y) power = Bus('power input') -power.add_comps({'comp': cp, 'char': char, 'base': 'bus'}, - {'comp': ghp, 'char': char, 'base': 'bus'}, - {'comp': hsp, 'char': char, 'base': 'bus'}) +power.add_comps( + {'comp': cp, 'char': char, 'base': 'bus'}, + {'comp': ghp, 'char': char, 'base': 'bus'}, + {'comp': hsp, 'char': char, 'base': 'bus'} +) # consumer heat bus heat_cons = Bus('heating system') @@ -124,8 +124,7 @@ # geothermal heat bus heat_geo = Bus('geothermal heat') -heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, - {'comp': gh_out}) +heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, {'comp': gh_out}) nw.add_busses(power, heat_cons, heat_geo) diff --git a/tutorial/heat_pump_exergy/NH3_calculations.py b/tutorial/heat_pump_exergy/NH3_calculations.py index 95f452df1..a602ae0dc 100644 --- a/tutorial/heat_pump_exergy/NH3_calculations.py +++ b/tutorial/heat_pump_exergy/NH3_calculations.py @@ -119,9 +119,11 @@ # power bus char = CharLine(x=x, y=y) power = Bus('power input') -power.add_comps({'comp': cp, 'char': char, 'base': 'bus'}, - {'comp': ghp, 'char': char, 'base': 'bus'}, - {'comp': hsp, 'char': char, 'base': 'bus'}) +power.add_comps( + {'comp': cp, 'char': char, 'base': 'bus'}, + {'comp': ghp, 'char': char, 'base': 'bus'}, + {'comp': hsp, 'char': char, 'base': 'bus'} +) # consumer heat bus heat_cons = Bus('heating system') @@ -129,8 +131,7 @@ # geothermal heat bus heat_geo = Bus('geothermal heat') -heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, - {'comp': gh_out}) +heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, {'comp': gh_out}) nw.add_busses(power, heat_cons, heat_geo) @@ -178,9 +179,7 @@ # %% exergy analysis -ean = ExergyAnalysis(network=nw, - E_F=[power, heat_geo], - E_P=[heat_cons]) +ean = ExergyAnalysis(network=nw, E_F=[power, heat_geo], E_P=[heat_cons]) ean.analyse(pamb, Tamb) print("\n##### EXERGY ANALYSIS #####\n") ean.print_results() diff --git a/tutorial/heat_pump_exergy/R410A.py b/tutorial/heat_pump_exergy/R410A.py index fd59e3aca..c38a7f141 100644 --- a/tutorial/heat_pump_exergy/R410A.py +++ b/tutorial/heat_pump_exergy/R410A.py @@ -22,8 +22,7 @@ # mean geothermal temperature (mean value of ground feed and return flow) Tgeo = 9.5 -nw = Network(fluids=['water', 'R410A'], T_unit='C', p_unit='bar', - h_unit='kJ / kg', m_unit='kg / s') +nw = Network(T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components @@ -90,15 +89,15 @@ # %% connection parametrization # heat pump system -cc_cd.set_attr(fluid={'water': 0, 'R410A': 1}) +cc_cd.set_attr(fluid={'R410A': 1}) ev_cp.set_attr(Td_bp=3) # geothermal heat collector -gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1, 'R410A': 0}) +gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1}) ev_gh_out.set_attr(T=Tgeo - 1.5, p=1.5) # heating system -cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1, 'R410A': 0}) +cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1}) hs_ret_hsp.set_attr(T=35, p=2) # starting values @@ -114,9 +113,11 @@ # power bus char = CharLine(x=x, y=y) power = Bus('power input') -power.add_comps({'comp': cp, 'char': char, 'base': 'bus'}, - {'comp': ghp, 'char': char, 'base': 'bus'}, - {'comp': hsp, 'char': char, 'base': 'bus'}) +power.add_comps( + {'comp': cp, 'char': char, 'base': 'bus'}, + {'comp': ghp, 'char': char, 'base': 'bus'}, + {'comp': hsp, 'char': char, 'base': 'bus'} +) # consumer heat bus heat_cons = Bus('heating system') @@ -124,8 +125,7 @@ # geothermal heat bus heat_geo = Bus('geothermal heat') -heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, - {'comp': gh_out}) +heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, {'comp': gh_out}) nw.add_busses(power, heat_cons, heat_geo) diff --git a/tutorial/heat_pump_exergy/R410A_calculations.py b/tutorial/heat_pump_exergy/R410A_calculations.py index 39575354d..457a10472 100644 --- a/tutorial/heat_pump_exergy/R410A_calculations.py +++ b/tutorial/heat_pump_exergy/R410A_calculations.py @@ -27,8 +27,7 @@ # mean geothermal temperature (mean value of ground feed and return flow) Tgeo = 9.5 -nw = Network(fluids=['water', 'R410A'], T_unit='C', p_unit='bar', - h_unit='kJ / kg', m_unit='kg / s') +nw = Network(T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit='kg / s') # %% components @@ -95,15 +94,15 @@ # %% connection parametrization # heat pump system -cc_cd.set_attr(fluid={'water': 0, 'R410A': 1}) +cc_cd.set_attr(fluid={'R410A': 1}) ev_cp.set_attr(Td_bp=3) # geothermal heat collector -gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1, 'R410A': 0}) +gh_in_ghp.set_attr(T=Tgeo + 1.5, p=1.5, fluid={'water': 1}) ev_gh_out.set_attr(T=Tgeo - 1.5, p=1.5) # heating system -cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1, 'R410A': 0}) +cd_hs_feed.set_attr(T=40, p=2, fluid={'water': 1}) hs_ret_hsp.set_attr(T=35, p=2) # starting values @@ -119,9 +118,11 @@ # power bus char = CharLine(x=x, y=y) power = Bus('power input') -power.add_comps({'comp': cp, 'char': char, 'base': 'bus'}, - {'comp': ghp, 'char': char, 'base': 'bus'}, - {'comp': hsp, 'char': char, 'base': 'bus'}) +power.add_comps( + {'comp': cp, 'char': char, 'base': 'bus'}, + {'comp': ghp, 'char': char, 'base': 'bus'}, + {'comp': hsp, 'char': char, 'base': 'bus'} +) # consumer heat bus heat_cons = Bus('heating system') @@ -129,8 +130,7 @@ # geothermal heat bus heat_geo = Bus('geothermal heat') -heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, - {'comp': gh_out}) +heat_geo.add_comps({'comp': gh_in, 'base': 'bus'}, {'comp': gh_out}) nw.add_busses(power, heat_cons, heat_geo) @@ -178,9 +178,7 @@ # %% exergy analysis -ean = ExergyAnalysis(network=nw, - E_F=[power, heat_geo], - E_P=[heat_cons]) +ean = ExergyAnalysis(network=nw, E_F=[power, heat_geo], E_P=[heat_cons]) ean.analyse(pamb, Tamb) print("\n##### EXERGY ANALYSIS #####\n") ean.print_results() diff --git a/tutorial/heat_pump_exergy/plots.py b/tutorial/heat_pump_exergy/plots.py index b380d0287..7e4454ed5 100644 --- a/tutorial/heat_pump_exergy/plots.py +++ b/tutorial/heat_pump_exergy/plots.py @@ -6,8 +6,9 @@ # color range -colors = ['#00395b', '#74adc1', '#b54036', '#ec6707', - '#bfbfbf', '#999999', '#010101'] +colors = [ + '#00395b', '#74adc1', '#b54036', '#ec6707', '#bfbfbf', '#999999', '#010101' +] # %% figure 1: plot component exergy destruction