Issues with offdesign calculation #701
-
|
Hi, i'm trying to build a simulation of sorts of a real heat pump that's part of a lab at my uni. I built a small website as a GUI for the simulation and connected it to this tespy model running in the background. In the GUI Users have the ability to change;
The tespy model should then calculate the system parameters with the specified parameters. # PARAMETER LIST
working_fluid = "R410A" # Kaeltemittel
high_pressure = 2480000 # pa
low_pressure = 1040000 # pa
high_temp = 273.15 + 56.3
t_cond = PropsSI("T", "Q", 1, "P", high_pressure, working_fluid) # verdampfungstemperatur Hochdurck
t_evap = PropsSI("T", "Q", 1, "P", low_pressure, working_fluid) # verdampfungstemperatur Niederdurck
print("t_cond: " + str(t_cond))
print("t_evap: " + str(t_evap))
compressor_power = 880 # Leistungsaufnahme Verdichter [W]
isentropen_koeffizient = 0.7 # isentropische effizienz Verdichter
design_heat_output = 5070 # design Leistung der Wärmequelle
design_heat_input = 4158 # Leistung des Verdampfers (inkl superheater)
condenser_pressure_ratio = 0.98
evaporator_pressure_ratio = 0.98
superheater_pressure_ratio = 0.99
superheat = 4.8 # K
compressor_entry_enthalpy = PropsSI("H", "P", low_pressure, "T", t_evap + superheat, working_fluid)
compressor_output_enthalpy = PropsSI("H", "P", high_pressure, "T", high_temp, working_fluid)
print("compressor_entry_enthalpy: " + str(compressor_entry_enthalpy))
print("compressor_output_enthalpy: " + str(compressor_output_enthalpy))
# falls notwendig:
superheater_entry_enthalpy = PropsSI("H", "P", low_pressure / superheater_pressure_ratio, "T", t_evap, working_fluid)
# # --- HEATING SYSTEM PARAMETERS ---
wq_massflow_data = 23 # kg/min
ww_massflow_data = 16.1 # kg/min
wq_massflow = wq_massflow_data / 60 # kg/s
ww_massflow = ww_massflow_data / 60 # kg/s
ww_inflow_temp = 273.15 + 35.5
water_pressure = 200000 # pa
condenser_wq_pressure_ratio = 0.99
superheater_wq_pressure_ratio = 0.99
# Heatpipe compensation
t_eingang = 273.15 + 14.2 # K
t_ausgang = 273.15 + 11.7 # K
h1 = PropsSI("H", "P", water_pressure, "T", t_eingang, "water")
h2 = PropsSI("H", "P", water_pressure * superheater_wq_pressure_ratio, "T", t_ausgang, "water")
dh = h2 - h1 # Enthalpieverlust der Wärmequelle
Q = wq_massflow * dh # von der Wärmequelle übertragene Wärme
Q_ges = -design_heat_input # gesamte Leistung der Wärmeaufnahme
dh_ges = Q_ges / wq_massflow # Enthalpieverlust der Wärmequelle wenn gesamte Leistung von Wärmequelle kommen würde
h1_virt = h2 - dh_ges
t_compensated = PropsSI("T", "P", water_pressure, "H", h1_virt, "water" ) # theoretische Einganstemperatur der Wärmequelle
wq_inflow_temp = t_compensated
class Heatpump():
def __init__(self):
# --- HEATPUMP PARAMETERS ---
self.working_fluid = working_fluid
self.compressor_power = compressor_power
self.isentropen_koeffizient = isentropen_koeffizient
self.design_heat_output = design_heat_output
self.condensation_temp = t_cond
self.evaporation_temp = t_evap
self.low_pressure = low_pressure / 100000
self.condenser_pressure_ratio = condenser_pressure_ratio
self.superheat = superheat
self.compressor_out_enth = compressor_output_enthalpy / 1000
self.high_pressure = high_pressure / 100000
# --- HEATING SYSTEM PARAMETERS ---
self.wq_massflow = wq_massflow # Massenstrom Wärmequelle (kg/s)
self.wq_inflow_temp = t_compensated # Wärmequelle Rücklauftemperatur (K)
self.ww_massflow = ww_massflow # Massenstrom Warmwasser (kg/s)
self.ww_inflow_temp = ww_inflow_temp # Warmwasser Rücklauftemperatur (K)
self.condenser_w_pressure_ratio = condenser_wq_pressure_ratio
self.superheater_w_pressure_ratio = superheater_wq_pressure_ratio
self.superheater_pressure_ratio = superheater_pressure_ratio
self.evaporator_pressure_ratio = evaporator_pressure_ratio
# --- Network ---
self.heatpump = Network()
self.heatpump.set_attr(T_unit='K', p_unit='bar', h_unit='kJ / kg', iterinfo=True)
# Components
# --- Heatpump ---
self.cc = com.CycleCloser('cycle_closer')
self.evaporator = com.HeatExchanger('evaporator')
self.condenser = com.HeatExchanger('condenser')
self.expansionvalve = com.Valve('expansionValve')
self.compressor = com.Compressor('compressor')
self.superheater = com.HeatExchanger('superheater')
# --- Sources ---
self.tank_in_ww = com.Sink('tank_in_ww')
self.tank_out_ww = com.Source('tank_out_ww')
self.tank_in_wq = com.Sink('tank_in_wq')
self.tank_out_wq = com.Source('tank_out_wq')
# Connections
# --- Heatpump ---
self.conn0 = Connection(self.cc, 'out1', self.compressor, 'in1')
self.conn1 = Connection(self.compressor, 'out1', self.condenser, 'in1')
self.conn2 = Connection(self.condenser, 'out1', self.expansionvalve, 'in1')
self.conn3 = Connection(self.expansionvalve, 'out1', self.evaporator, 'in2')
self.conn4 = Connection(self.evaporator, 'out2', self.superheater, 'in2')
self.conn5 = Connection(self.superheater, 'out2', self.cc, 'in1')
# --- Water system ---
self.ww1 = Connection(self.tank_out_ww, 'out1', self.condenser, 'in2')
self.ww2 = Connection(self.condenser, 'out2', self.tank_in_ww, 'in1')
self.wq1 = Connection(self.tank_out_wq, 'out1', self.superheater, 'in1')
self.wq2 = Connection(self.superheater, 'out1', self.evaporator, 'in1')
self.wq3 = Connection(self.evaporator, 'out1', self.tank_in_wq, 'in1')
# --- Add Connections and parametise ---
self.conn_list = [self.conn0, self.conn1, self.conn2, self.conn3, self.conn4, self.conn5]
self.parametise()
self.heatpump.add_conns(self.conn0, self.conn1, self.conn2, self.conn3, self.conn4, self.conn5, self.ww1, self.ww2, self.wq1, self.wq2, self.wq3)
def parametise(self):
# --- PARAMETRISATION ---
# COMPONENTS
self.compressor.set_attr(eta_s=self.isentropen_koeffizient, P=self.compressor_power)
self.compressor.set_attr(design=['P', 'eta_s'], offdesign=['P', 'eta_s'])
self.condenser.set_attr(Q=-self.design_heat_output, pr1=self.condenser_pressure_ratio, pr2=self.condenser_w_pressure_ratio)
self.condenser.set_attr(design=['Q', 'pr1', 'pr2'], offdesign=['kA_char', 'zeta1', 'zeta2'])
self.superheater.set_attr(pr1=self.superheater_w_pressure_ratio, pr2=self.superheater_pressure_ratio)
self.superheater.set_attr(design=['pr1', 'pr2'], offdesign=['kA_char', 'zeta1', 'zeta2'])
self.evaporator.set_attr(pr1=self.superheater_w_pressure_ratio, pr2=self.evaporator_pressure_ratio)
self.evaporator.set_attr(design=['pr1', 'pr2'], offdesign=['kA_char', 'zeta1', 'zeta2'])
# CONNECTIONS
self.conn1.set_attr(p=self.high_pressure)
self.conn3.set_attr(p=self.low_pressure)
self.conn3.set_attr(design=['p'])
self.conn4.set_attr(x=1, fluid={working_fluid: 1})
self.conn5.set_attr(T=self.evaporation_temp + self.superheat)
self.conn5.set_attr(design=['T'])
self.ww1.set_attr(T=self.ww_inflow_temp, p=2, m=self.ww_massflow, fluid={'ethanol': 1})
self.wq1.set_attr(T=self.wq_inflow_temp, p=2, m=self.wq_massflow, fluid={'ethanol': 1})
def parametise_offdesign(self):
compressor_power = 600
compressor_efficiency = 0.77
p_conn1 = 0.02756776456653455*compressor_power + 1.2160357159127209 # lineare Regression von Betriesdaten
h_comp_out = 0.05909297981868707*compressor_power + 6.368557241127974
#print(f"p_conn1: {p_conn1}")
self.conn1.set_attr(p=p_conn1, m0=0.2, h0=h_comp_out)
#self.conn3.set_attr(p0=self.low_pressure)
self.compressor.set_attr(P=compressor_power, eta_s=compressor_efficiency)
def solve(self, design):
if design:
self.reset()
self.heatpump.solve(mode='design', init_path="design_state.json")
self.heatpump.save('design_state.json')
self.heatpump.print_results()
else:
print("solving in offdesign mode!")
self.parametise_offdesign()
self.heatpump.solve(mode="offdesign", design_path='design_state.json')
self.heatpump.print_results()Currently i cannot get rid of this error; 2025-07-03 15:48:54,838 - INFO - network - Network initialised.
2025-07-03 15:48:54,838 - INFO - network - Starting solver.
2025-07-03 15:48:54,838 - DEBUG - network - Number of connection equations: 1.
2025-07-03 15:48:54,838 - DEBUG - network - Number of bus equations: 0.
2025-07-03 15:48:54,838 - DEBUG - network - Number of component equations: 14.
2025-07-03 15:48:54,838 - DEBUG - network - Number of user defined equations: 0.
2025-07-03 15:48:54,838 - DEBUG - network - Total number of variables: 15.
2025-07-03 15:48:54,838 - PROGRESS - network - iter | residual | progress | massflow | pressure | enthalpy | fluid | component
2025-07-03 15:48:54,838 - PROGRESS - network - -------+------------+------------+------------+------------+------------+------------+------------
2025-07-03 15:48:54,862 - DEBUG - connection - Enthalpy out of fluid property range at connection condenser:out2_tank_in_ww:in1, adjusting value to -428612.9244121148 J / kg.
2025-07-03 15:48:54,862 - DEBUG - connection - Enthalpy out of fluid property range at connection cycle_closer:out1_compressor:in1, adjusting value to 98453.49662698088 J / kg.
2025-07-03 15:48:54,862 - DEBUG - connection - Enthalpy out of fluid property range at connection evaporator:out1_tank_in_wq:in1, adjusting value to 2277662.21673056 J / kg.
2025-07-03 15:48:54,862 - DEBUG - connection - Enthalpy out of fluid property range at connection evaporator:out2_superheater:in2, adjusting value to 106336.91227700001 J / kg.
2025-07-03 15:48:54,862 - DEBUG - connection - Pressure out of fluid property range at connection expansionValve:out1_evaporator:in2, adjusting value to 50000000.0 Pa.
2025-07-03 15:48:54,863 - DEBUG - connection - Enthalpy out of fluid property range at connection superheater:out1_evaporator:in1, adjusting value to -428612.9244121148 J / kg.
2025-07-03 15:48:54,863 - PROGRESS - network - 1 | 2.14e+10 | 0 % | 1.05e+00 | 9.97e+08 | 6.25e+06 | 0.00e+00 | 0.00e+00
2025-07-03 15:48:54,863 - ERROR - network - Simulation crashed due to an unexpected error:
unable to solve 1phase PY flash with Tmin=199.999, Tmax=300.775 due to error: HSU_P_flash_singlephase_Brent could not find a solution because Smolar [40.7017 J/mol/K] is below the minimum value of 40.8066662174 J/mol/K
Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
thank you for reaching out! I will have a look on this once I find the time for it and then come back to you. Very cool project by the way, I would like to learn more about it :). Let me know if you are interested in an exchange on the topic! Best Francesco |
Beta Was this translation helpful? Give feedback.
Quick update here:
Since there are measurement values, which can be utilized to create regressions/relationships between the different model parameters, it is not necessary to use offdesign mode for this specific case. The compressor power can be calculated using a
UserDefinedEquationas function of the condensation pressure (and potentially pressure ratio of condensation to evaporation pressure if there are measurement values at variable evaporation temeprature levels). The condensation and evaporation pressure values can be controlled through assumed (and later also through regression functions) temperature differences to the heat source and heat sink fluid respectively. For this, it is…