feat(python): implement python bindings for all components and solvers
This commit is contained in:
45
bindings/python/test!entropyk.py
Normal file
45
bindings/python/test!entropyk.py
Normal file
@@ -0,0 +1,45 @@
|
||||
import entropyk
|
||||
|
||||
# === Types physiques ===
|
||||
p = entropyk.Pressure(bar=10.0)
|
||||
print(p) # Pressure(1000000.0 Pa)
|
||||
print(p.to_bar()) # 10.0
|
||||
print(float(p)) # 1000000.0 (en Pascals)
|
||||
|
||||
t = entropyk.Temperature(celsius=25.0)
|
||||
print(t.to_celsius()) # 25.0
|
||||
print(t.to_kelvin()) # 298.15
|
||||
|
||||
h = entropyk.Enthalpy(kj_per_kg=400.0)
|
||||
m = entropyk.MassFlow(kg_per_s=0.5)
|
||||
|
||||
# === Composants ===
|
||||
cond = entropyk.Condenser(ua=10000.0) # UA = 10 kW/K
|
||||
evap = entropyk.Evaporator(ua=8000.0) # UA = 8 kW/K
|
||||
comp = entropyk.Compressor(efficiency=0.85)
|
||||
valve = entropyk.ExpansionValve(fluid="R134a")
|
||||
pipe = entropyk.Pipe(length=5.0, diameter=0.025)
|
||||
|
||||
# === Système ===
|
||||
system = entropyk.System()
|
||||
c_idx = system.add_component(comp)
|
||||
d_idx = system.add_component(cond)
|
||||
v_idx = system.add_component(valve)
|
||||
e_idx = system.add_component(evap)
|
||||
|
||||
system.add_edge(c_idx, d_idx) # compresseur → condenseur
|
||||
system.add_edge(d_idx, v_idx) # condenseur → détendeur
|
||||
system.add_edge(v_idx, e_idx) # détendeur → évaporateur
|
||||
system.add_edge(e_idx, c_idx) # évaporateur → compresseur
|
||||
|
||||
system.finalize()
|
||||
|
||||
# === Solveur ===
|
||||
config = entropyk.NewtonConfig(max_iterations=100, tolerance=1e-6)
|
||||
# result = config.solve(system) # résoudre le système
|
||||
|
||||
# === Exceptions ===
|
||||
try:
|
||||
entropyk.Pressure(bar=-1.0) # ValueError
|
||||
except ValueError as e:
|
||||
print(f"Erreur: {e}")
|
||||
Reference in New Issue
Block a user