88 lines
3.8 KiB
Python
88 lines
3.8 KiB
Python
"""
|
|
Cycle frigorifique simple R134a - 4 composants
|
|
Compresseur → Condenseur → Détendeur → Évaporateur → (retour)
|
|
|
|
Équations des composants mock (python_components.rs) :
|
|
Compresseur : r[0] = p_disc - (p_suc + 1 MPa) r[1] = h_disc - (h_suc + power/m_dot)
|
|
Condenseur : r[0] = p_out - p_in r[1] = h_out - (h_in - 225 kJ/kg)
|
|
Détendeur : r[0] = p_out - (p_in - 1 MPa) r[1] = h_out - h_in
|
|
Évaporateur : r[0] = p_out - p_in r[1] = h_out - (h_in + 150 kJ/kg)
|
|
|
|
État initial cohérent : P_HP - P_LP = 1 MPa → tous les résidus de pression valent 0 au départ.
|
|
"""
|
|
import entropyk
|
|
import time
|
|
|
|
def main():
|
|
system = entropyk.System()
|
|
print("Construction du système simple (R134a)...")
|
|
|
|
fluid = "R134a"
|
|
|
|
comp = system.add_component(entropyk.Compressor(
|
|
m1=0.85, m2=2.5, m3=500.0, m4=1500.0, m5=-2.5, m6=1.8,
|
|
m7=600.0, m8=1600.0, m9=-3.0, m10=2.0,
|
|
speed_rpm=3600.0, displacement=0.00008, efficiency=0.88, fluid=fluid
|
|
))
|
|
cond = system.add_component(entropyk.Condenser(
|
|
ua=5000.0, fluid=fluid, water_temp=30.0, water_flow=2.0
|
|
))
|
|
valve = system.add_component(entropyk.ExpansionValve(
|
|
fluid=fluid, opening=0.5 # target_dp = 2e6*(1-0.5) = 1 MPa
|
|
))
|
|
evap = system.add_component(entropyk.Evaporator(
|
|
ua=3000.0, fluid=fluid, water_temp=10.0, water_flow=2.0
|
|
))
|
|
|
|
system.add_edge(comp, cond) # edge 0 : comp → cond
|
|
system.add_edge(cond, valve) # edge 1 : cond → valve
|
|
system.add_edge(valve, evap) # edge 2 : valve → evap
|
|
system.add_edge(evap, comp) # edge 3 : evap → comp
|
|
|
|
system.finalize()
|
|
print(f"Propriétés: {system.node_count} composants, {system.edge_count} connexions, "
|
|
f"{system.state_vector_len} variables d'état.")
|
|
|
|
# ─── État initial cohérent avec les équations mock ───────────────────────
|
|
# Valve et Comp utilisent tous les deux target_dp = 1 MPa
|
|
# → P_HP - P_LP = 1 MPa ⇒ résidus de pression = 0 dès le départ
|
|
# Enthalpies choisies proches de l'équilibre attendu :
|
|
# Cond : h_in - 225 kJ/kg = h_out_cond (225 000 J/kg)
|
|
# Evap : h_in + 150 kJ/kg = h_out_evap (150 000 J/kg)
|
|
# Comp : h_in + w_sp ≈ h_in + 75 kJ/kg (AHRI 540)
|
|
P_LP = 350_000.0 # Pa — basse pression (R134a ~1.5°C sat)
|
|
P_HP = 1_350_000.0 # Pa — haute pression = P_LP + 1 MPa ✓
|
|
initial_state = [
|
|
P_HP, 485_000.0, # edge0 comp→cond : vapeur surchauffée HP (≈h_suc + 75 kJ/kg)
|
|
P_HP, 260_000.0, # edge1 cond→valve : liquide HP (≈485-225)
|
|
P_LP, 260_000.0, # edge2 valve→evap : biphasique BP (isenthalpique)
|
|
P_LP, 410_000.0, # edge3 evap→comp : vapeur surchauffée BP (≈260+150)
|
|
]
|
|
|
|
config = entropyk.NewtonConfig(
|
|
max_iterations=150,
|
|
tolerance=1e-4,
|
|
line_search=True,
|
|
use_numerical_jacobian=True,
|
|
initial_state=initial_state
|
|
)
|
|
|
|
print("Lancement du Newton Solver...")
|
|
t0 = time.time()
|
|
try:
|
|
res = config.solve(system)
|
|
elapsed = time.time() - t0
|
|
print(f"\n✅ Convergé en {res.iterations} itérations ({elapsed*1000:.1f} ms)")
|
|
sv = res.state_vector
|
|
print(f"\nÉtat final du cycle R134a :")
|
|
print(f" comp → cond : P={sv[0]/1e5:.2f} bar, h={sv[1]/1e3:.1f} kJ/kg")
|
|
print(f" cond → valve : P={sv[2]/1e5:.2f} bar, h={sv[3]/1e3:.1f} kJ/kg")
|
|
print(f" valve → evap : P={sv[4]/1e5:.2f} bar, h={sv[5]/1e3:.1f} kJ/kg")
|
|
print(f" evap → comp : P={sv[6]/1e5:.2f} bar, h={sv[7]/1e3:.1f} kJ/kg")
|
|
except Exception as e:
|
|
elapsed = time.time() - t0
|
|
print(f"\n❌ Échec après {elapsed*1000:.1f} ms : {e}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|