import entropyk
from collections import defaultdict

system = entropyk.System()
refrigerant = "R410A"
water = "Water"

comp = system.add_component(entropyk.Compressor(fluid=refrigerant))
hot = system.add_component(entropyk.Pipe(fluid=refrigerant))
cond = system.add_component(entropyk.Condenser(fluid=refrigerant, ua=4500.0, water_temp=30.0, water_flow=2.0))
liq = system.add_component(entropyk.Pipe(fluid=refrigerant))
spl = system.add_component(entropyk.FlowSplitter(n_outlets=2))
eva_a = system.add_component(entropyk.ExpansionValve(fluid=refrigerant, opening=0.5))
evap_a = system.add_component(entropyk.Evaporator(ua=2000.0, fluid=refrigerant, water_temp=12.0, water_flow=1.0))
eva_b = system.add_component(entropyk.ExpansionValve(fluid=refrigerant, opening=0.5))
evap_b = system.add_component(entropyk.Evaporator(ua=2000.0, fluid=refrigerant, water_temp=15.0, water_flow=1.0))
mrg = system.add_component(entropyk.FlowMerger(n_inlets=2))
suc = system.add_component(entropyk.Pipe(fluid=refrigerant))

w_src = system.add_component(entropyk.FlowSource(fluid=water, pressure_pa=100000.0, temperature_k=300.0))
w_pmp = system.add_component(entropyk.Pump(pressure_rise_pa=50000.0, efficiency=0.6))
w_pip = system.add_component(entropyk.Pipe(fluid=water))
w_snk = system.add_component(entropyk.FlowSink())

a_src = system.add_component(entropyk.FlowSource(fluid="Air", pressure_pa=100000.0, temperature_k=300.0))
a_fan = system.add_component(entropyk.Fan(pressure_rise_pa=200.0, efficiency=0.5))
a_snk = system.add_component(entropyk.FlowSink())

system.add_edge(comp, hot)
system.add_edge(hot, cond)
system.add_edge(cond, liq)
system.add_edge(liq, spl)
system.add_edge(spl, eva_a)
system.add_edge(spl, eva_b)
system.add_edge(eva_a, evap_a)
system.add_edge(eva_b, evap_b)
system.add_edge(evap_a, mrg)
system.add_edge(evap_b, mrg)
system.add_edge(mrg, suc)
system.add_edge(suc, comp)

system.add_edge(w_src, w_pmp)
system.add_edge(w_pmp, w_pip)
system.add_edge(w_pip, w_snk)

system.add_edge(a_src, a_fan)
system.add_edge(a_fan, a_snk)

system.finalize()
print(f"Edges: {system.edge_count} -> expected vars: {system.state_vector_len}")
