Model Operations - Nouman090/ThermoSim GitHub Wiki
Creating a Model
from ThermoSim import ThermodynamicModel
Model = ThermodynamicModel()
Model.set_dead_state(T0=298.15, P0=101325)
Dead State
The dead state defines the reference environment for exergy calculations.
# Default: 25°C, 1 atm
Model.set_dead_state()
# Custom: 20°C, 1 bar
Model.set_dead_state(T0=293.15, P0=1e5)
Adding State Points
Model.add_point(fluid, StatePointName, Mass_flowrate=None, **properties)
Model.add_point('water', '1', P=8e6, T=753.15, Mass_flowrate=1)
Model.add_point('water', '2', P=0.008e6)
Model.add_point('water', '3', P=0.008e6, Q=0)
Iterative Solver
For cycles with interdependent components:
Model.Solve(max_iter=10, verbose=True)
| Parameter | Type | Default | Description |
|---|---|---|---|
max_iter |
int | 10 | Maximum iterations |
verbose |
bool | False | Print progress |
Returns True if converged, False otherwise.
Model Summary
Model.ModelSummary()
Prints energy analysis (work, heat, efficiency) and exergy analysis.
Access results after calling:
Model.ModelSummary()
print(f"Net Power: {Model.Net_power/1e3:.2f} kW")
print(f"Efficiency: {Model.Efficiency:.2f} %")
print(f"Heat Input: {Model.Q_in/1e3:.2f} kW")
print(f"Heat Output: {Model.Q_out/1e3:.2f} kW")
print(f"Total Ex_D: {Model.Total_Ex_d/1e3:.2f} kW")
print(f"Power Out: {Model.Power_Out/1e3:.2f} kW")
print(f"Power In: {Model.Power_In/1e3:.2f} kW")
Print State Points
# Default columns
Model.Point_print()
# Custom columns
Model.Point_print(header=['StatePointName', 'fluid', 'P', 'T', 'H', 'S', 'Q',
'Mass_flowrate', 'ex', 'Ex'])
Print Components
Model.Component_print()
Print Everything
print(Model)
Save Model
Save all state points and component definitions to a JSON file:
Model.save_model('my_rankine_cycle.json')
Load Model
Restore state points from a previously saved file:
Model2 = ThermodynamicModel()
Model2.load_model('my_rankine_cycle.json')
# State points are restored
print(Model2.Point['1'])
# Components must be re-created from your script
# (Component logic is not serialised)
Accessing Individual Points and Components
# Access a state point
pt = Model.Point['1']
print(pt.T, pt.P, pt.H)
# Access a component
turb = Model.Component['Turbine']
print(turb.work, turb.Ex_D)
# List all point names
print(list(Model.Point.keys()))
# List all component names
print(list(Model.Component.keys()))