UDE to solve buffer #505
-
Hi, def option_1_mode5_test(q_owd, q_tud, t_supply, t_return_tud, t_return_owd, q_condenser, t_buffer, iterinfo=False):
demand_owd = q_owd*-1e6
demand_tud = q_tud*-1e6
q_condenser = q_condenser*-1e6
dap_si = Sink('Sink')
dap_so = Source('Source')
me_bypass = Merge('Merge Bypass')
me_owd = Merge('Merge OWD')
va_bypass = Valve('Valve Bypass')
sp_tud = Splitter('Splitter TUD')
sp_tud_1 = Splitter('Splitter TUD 1')
va_tud = Valve('Valve TUD')
cc = CycleCloser('CC')
pu_tud = Pump('Pump before TUD')
pu_ev = Pump('Pump before Evaporator')
he_dap = HeatExchanger('DAP')
tud = SimpleHeatExchanger('TUD')
owd = SimpleHeatExchanger('OWD')
buffer = SimpleHeatExchanger('Buffer')
sp_buffer = Splitter('Splitter Buffer')
me_buffer = Merge('Merge Buffer')
va_buffer = Valve('Valve Buffer')
# Heat Pump
cd = Condenser('Condenser')
va_hp = Valve('Expansion Valve')
cp = Compressor('Compressor')
ev = HeatExchanger('Evaporator')
cc_hp = CycleCloser('CC Heat Pump')
c0 = Connection(dap_so, 'out1', he_dap, 'in1', label='0')
c1 = Connection(he_dap, 'out1', dap_si, 'in1', label='1')
c5 = Connection(he_dap, 'out2', me_bypass, 'in1', label='5')
c7 = Connection(me_bypass, 'out1', cd, 'in2', label='7')
c8 = Connection(cd, 'out2', cc, 'in1', label='8')
c9 = Connection(cc, 'out1', pu_tud, 'in1', label='9')
c10= Connection(pu_tud, 'out1', sp_buffer, 'in1', label='10')
c12 = Connection(sp_buffer, 'out1', sp_tud, 'in1', label='12')
c13 = Connection(sp_tud, 'out1', owd, 'in1', label='13')
c14 = Connection(owd, 'out1', me_owd, 'in1', label='14')
c15 = Connection(va_bypass, 'out1', me_owd, 'in2', label='15')
c16 = Connection(sp_tud_1, 'out1', va_bypass, 'in1', label='16')
c17 = Connection(sp_tud_1, 'out2', me_buffer, 'in1', label='17')
c18 = Connection(me_buffer, 'out1', me_bypass, 'in2', label='18')
c19 = Connection(me_owd, 'out1', pu_ev, 'in1', label='19')
c20 = Connection(pu_ev, 'out1', ev, 'in1', label='20')
c21 = Connection(ev, 'out1', he_dap, 'in2', label='21')
c22 = Connection(sp_buffer, 'out2', va_buffer, 'in1', label='22')
c23 = Connection(va_buffer, 'out1', buffer, 'in1', label='23')
c24 = Connection(buffer, 'out1', me_buffer, 'in2', label='24')
c25 = Connection(sp_tud, 'out2', va_tud, 'in1', label='25')
c26 = Connection(va_tud, 'out1', tud, 'in1', label='26')
c27 = Connection(tud, 'out1', sp_tud_1, 'in1', label='27')
# HP
c30 = Connection(cc_hp, 'out1', cp, 'in1', label='30')
c31 = Connection(cp, 'out1', cd, 'in1', label='31')
c32 = Connection(cd, 'out1', va_hp, 'in1', label='32')
c33 = Connection(va_hp, 'out1', ev, 'in2', label='33')
c34 = Connection(ev, 'out2', cc_hp, 'in1', label='34')
nw = Network(T_unit='C', p_unit='bar', h_unit='kJ / kg', m_unit = 'kg / s')
nw.add_conns(c0, c1, c5, c7, c8, c9, c10, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c30, c31, c32, c33, c34)
he_dap.set_attr(pr1=0.98, pr2=0.98)
tud.set_attr(pr=0.98, Q = demand_tud)
owd.set_attr(pr=0.98, Q = demand_owd)
buffer.set_attr(pr=0.98)
pu_ev.set_attr(eta_s=0.75)
pu_tud.set_attr(eta_s=0.75)
# Heat Pump
cd.set_attr(pr1=0.98, pr2=0.98, Q = q_condenser)
ev.set_attr(pr1=0.98, pr2=0.98)
cp.set_attr(eta_s=0.85)
c0.set_attr(fluid={'water': 1}, T=76.5, p=1, v=375/3600)
c5.set_attr(fluid={'water': 1}, T=74.5)
c7.set_attr(p=1)
c19.set_attr(p=1)
c8.set_attr(T=t_supply+1)
c20.set_attr(v=375/3600)
c27.set_attr(T = t_return_tud+1)
c14.set_attr(T = t_return_owd+1)
# Buffer
#c24.set_attr(T=t_buffer)
# Heat Pump
# condensation point
p_cond = CP.PropsSI("P", "Q", 0, "T", t_supply + 5 + 273.15, 'NH3') * 1e-5
c32.set_attr(p=p_cond)
# evaporation point
p_eva = CP.PropsSI("P", "Q", 1, "T", 16 + 273.15, 'NH3') * 1e-5
c34.set_attr(p=p_eva, x=1, fluid={'NH3':1})
nw.set_attr(iterinfo=iterinfo)
def solve_buffer(ude):
t_tank_initial = ude.params['t_tank_initial']
volume_tank = ude.params['volume_tank']
equation = ude.conns[0].calc_T() + (t_tank_initial - ude.conns[0].calc_T()) * np.exp((ude.conns[0].v.val_SI()*3600)/volume_tank) - ude.conns[1].calc_T()
return equation
def solve_buffer_deriv(ude):
c23 = ude.conns[0]
c24 = ude.conns[1]
if c23.m.is_var:
ude.jacobian[c23.m.J_col] = ude.numeric_deriv('m', c23)
if c23.p.is_var:
ude.jacobian[c23.p.J_col] = ude.numeric_deriv('p', c23)
if c23.h.is_var:
ude.jacobian[c23.h.J_col] = ude.numeric_deriv('h', c23)
if c24.p.is_var:
ude.jacobian[c24.p.J_col] = ude.numeric_deriv('p', c24)
if c24.h.is_var:
ude.jacobian[c24.h.J_col] = ude.numeric_deriv('h', c24)
ude = UserDefinedEquation('ude numerical', solve_buffer, solve_buffer_deriv, [c23, c24], params={'volume_tank': 1200, 't_tank_initial': t_buffer})
nw.add_ude(ude)
nw.set_attr(m_range=[.1, 100])
nw.solve('design')
return nw
q_owd = 9.37
q_tud = 6.07
t_supply = 85
t_return_owd = 46
q_condenser = 10
t_buffer = 80.64
res5 = option_1_mode5_test(q_owd, q_tud, t_supply, t_return_tud, t_return_owd, q_condenser, t_buffer)
res5.print_results() |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi and thanks for reaching out! Can you post a minimal working example where you want to replace some condition with the ude (an example, where the simulation works without the ude inserted and tell me which condition should be replaced by the ude). That would help a lot trouble shooting the issue. Thanks a lot, have a nice weekend Francesco |
Beta Was this translation helpful? Give feedback.
Hi Paula,
thank you, that is very helpful. Simple issue actually:
calc_T
(all thecalc_...
methods ofConnections
actually) will provide you SI values... So you are mixing °C with K here, which is why, the solver cannot find a solution (see the warning message on the remaining residual value). Go with something like this: