Skip to content

Automation API

Overview

The MSHX unit operation can be fully controlled through the DWSIM Automation API, enabling headless simulation without the GUI. This is useful for:

  • Batch calculations — running many cases programmatically
  • Optimization — embedding MSHX in optimization loops
  • Validation — automated testing against reference solutions
  • Integration — connecting DWSIM to external tools (Python, MATLAB, Excel)

Setup

Python with pythonnet

import clr
import sys

# Add DWSIM path
dwsim_path = r"C:\Users\<username>\AppData\Local\DWSIM"
sys.path.append(dwsim_path)

# Load DWSIM assemblies
clr.AddReference("DWSIM.Automation")
clr.AddReference("DWSIM.Interfaces")
clr.AddReference("DWSIM.Thermodynamics")
clr.AddReference("DWSIM.UnitOperations")
clr.AddReference("DWSIM.UnitOperations.MultiStreamHeatExchanger")

from DWSIM.Automation import Automation3

Example: 2-Stream UA Calculation

# Initialize DWSIM
auto = Automation3()
flowsheet = auto.LoadFlowsheet(r"path\to\flowsheet.dwxmz")

# Get the MSHX object
mshx = flowsheet.GetFlowsheetSimulationObject("MSHX-1")

# Configure calculation mode
mshx.SetPropertyValue("Calculation Mode", 2)   # 2 = UA mode
mshx.SetPropertyValue("Flow Direction", 0)      # 0 = Counterflow
mshx.SetPropertyValue("UA", 1000.0)             # W/K

# Configure inlet streams
stream1 = flowsheet.GetFlowsheetSimulationObject("HOT-IN")
stream1.SetPropertyValue("Temperature", 363.15)  # 90°C in K
stream1.SetPropertyValue("Pressure", 1013250)     # 10 atm in Pa
stream1.SetPropertyValue("Mass Flow", 1.0)         # kg/s

stream2 = flowsheet.GetFlowsheetSimulationObject("COLD-IN")
stream2.SetPropertyValue("Temperature", 293.15)  # 20°C in K
stream2.SetPropertyValue("Pressure", 1013250)
stream2.SetPropertyValue("Mass Flow", 1.0)

# Run simulation
errors = flowsheet.SolveFlowsheet()
if errors:
    print(f"Errors: {errors}")

# Read results
Q = mshx.GetPropertyValue("Heat Duty")              # W
mita = mshx.GetPropertyValue("MITA (Calculated)")   # K
ua = mshx.GetPropertyValue("UA (Calculated)")        # W/K
lmtd = mshx.GetPropertyValue("LMTD")                # K
eff = mshx.GetPropertyValue("Thermal Efficiency")    # fraction

print(f"Heat Duty:  {Q:.1f} W")
print(f"MITA:       {mita:.2f} K")
print(f"UA:         {ua:.1f} W/K")
print(f"LMTD:       {lmtd:.2f} K")
print(f"Efficiency: {eff:.4f}")

Example: Parametric Study

import json

results = []

for ua_val in [500, 1000, 2000, 5000, 10000]:
    mshx.SetPropertyValue("UA", float(ua_val))
    flowsheet.SolveFlowsheet()

    results.append({
        "UA_spec": ua_val,
        "Q_W": mshx.GetPropertyValue("Heat Duty"),
        "MITA_K": mshx.GetPropertyValue("MITA (Calculated)"),
        "LMTD_K": mshx.GetPropertyValue("LMTD"),
        "Efficiency": mshx.GetPropertyValue("Thermal Efficiency")
    })

# Export to JSON
with open("parametric_results.json", "w") as f:
    json.dump(results, f, indent=2)

Example: Pressure Drop Sweep

for dp in [0, 10000, 50000, 100000]:  # Pa
    mshx.SetPropertyValue("Pressure Drop 1", float(dp))
    mshx.SetPropertyValue("Pressure Drop 2", float(dp))
    flowsheet.SolveFlowsheet()

    Q = mshx.GetPropertyValue("Heat Duty")
    print(f"DP = {dp/1000:.0f} kPa → Q = {Q:.1f} W")

Available Properties

All properties listed in the Parameters Reference are accessible via GetPropertyValue, SetPropertyValue, and GetPropertyUnit.

Discovering Properties

Use GetProperties(PropertyType.ALL) to list all available property names at runtime.