Automation API¶
Overview¶
The Wet Cooling Tower can be fully controlled headlessly via the DWSIM Automation API, enabling batch simulations, parametric studies, and automated testing without the DWSIM GUI.
Setup (Python with pythonnet)¶
import clr
import sys
import os
# Path to DWSIM installation
dwsim_path = r'C:\Users\<username>\AppData\Local\DWSIM'
sys.path.append(dwsim_path)
# Load DWSIM assemblies
clr.AddReference(os.path.join(dwsim_path, 'DWSIM.Automation.dll'))
clr.AddReference(os.path.join(dwsim_path, 'DWSIM.Interfaces.dll'))
from DWSIM.Automation import Automation3
Requirements
- Python 3.8+ with
pythonnet3.0+:pip install pythonnet - A saved DWSIM flowsheet (
.dwxmz) with the Cooling Tower already placed
Loading and Running a Flowsheet¶
# Create automation instance
auto = Automation3()
# Load flowsheet
sim = auto.LoadFlowsheet(r'path\to\CoolingTower.dwxmz')
# Find objects by tag
ct = None
inlet = None
for name, obj in sim.SimulationObjects.items():
tag = obj.GraphicObject.Tag
if tag == 'CT-1':
ct = obj
elif tag == '1':
inlet = obj
# Set inlet stream properties
inlet.SetPropertyValue('PROP_MS_0', 313.15) # Temperature (K)
inlet.SetPropertyValue('PROP_MS_1', 101325.0) # Pressure (Pa)
inlet.SetPropertyValue('PROP_MS_2', 1.0) # Mass flow (kg/s)
# Set cooling tower parameters
ct.SetPropertyValue('Calculation Method', 1) # 1 = Merkel
ct.SetPropertyValue('Calculation Mode', 1) # 1 = Design
ct.SetPropertyValue('Air Dry-Bulb Temperature', 298.15)
ct.SetPropertyValue('Air Wet-Bulb Temperature', 293.15)
ct.SetPropertyValue('Atmospheric Pressure', 101325.0)
ct.SetPropertyValue('L/G Ratio', 1.0)
ct.SetPropertyValue('Desired Outlet Temperature', 303.15)
ct.SetPropertyValue('Air Pressure Drop', 200.0)
ct.SetPropertyValue('Fan Efficiency', 0.75)
# Run calculation
auto.CalculateFlowsheet2(sim)
# Read results
kavl = float(ct.GetPropertyValue('Calculated KaV/L'))
tw_out = float(ct.GetPropertyValue('Water Outlet Temperature'))
q_rejected = float(ct.GetPropertyValue('Heat Rejected'))
print(f'KaV/L = {kavl:.4f}')
print(f'Tw,out = {tw_out - 273.15:.2f} C')
print(f'Q = {q_rejected/1000:.2f} kW')
Property Names for Get/Set¶
Inlet Stream (Material Stream)¶
| Property | Code | Units |
|---|---|---|
| Temperature | PROP_MS_0 |
K |
| Pressure | PROP_MS_1 |
Pa |
| Mass Flow | PROP_MS_2 |
kg/s |
Cooling Tower Properties¶
Use the exact property names from the Parameters Reference.
ct.SetPropertyValue('Calculation Method', 1) # 0=Poppe, 1=Merkel
ct.SetPropertyValue('Calculation Mode', 1) # 0=Rating, 1=Design
ct.SetPropertyValue('Air Dry-Bulb Temperature', 298.15)
ct.SetPropertyValue('Air Wet-Bulb Temperature', 293.15)
ct.SetPropertyValue('Atmospheric Pressure', 101325.0)
ct.SetPropertyValue('L/G Ratio', 1.2)
ct.SetPropertyValue('KaV/L (Merkel Number)', 1.5)
ct.SetPropertyValue('Desired Outlet Temperature', 303.15)
kavl = float(ct.GetPropertyValue('Calculated KaV/L'))
tw_out = float(ct.GetPropertyValue('Water Outlet Temperature'))
q = float(ct.GetPropertyValue('Heat Rejected'))
evap = float(ct.GetPropertyValue('Evaporation Rate'))
t_air_out = float(ct.GetPropertyValue('Air Outlet Temperature'))
w_out = float(ct.GetPropertyValue('Air Outlet Humidity Ratio'))
Parametric Study Example¶
import numpy as np
results = []
for lg in np.arange(0.5, 2.5, 0.1):
sim = auto.LoadFlowsheet(r'path\to\CoolingTower.dwxmz')
# ... find ct and inlet objects ...
ct.SetPropertyValue('L/G Ratio', lg)
ct.SetPropertyValue('Calculation Mode', 1) # Design
ct.SetPropertyValue('Desired Outlet Temperature', 303.15)
auto.CalculateFlowsheet2(sim)
kavl = float(ct.GetPropertyValue('Calculated KaV/L'))
results.append((lg, kavl))
print(f'L/G = {lg:.1f} -> KaV/L = {kavl:.4f}')
Batch Efficiency
For large parametric studies, reload the flowsheet for each case to ensure a clean state. The DWSIM Automation API is fast enough for hundreds of cases in minutes.