This is a Python script that drives DWSIM headlessly using its .NET API.
It's set up to run parametric sweeps on two specific unit operations:
- Plug Flow Reactor (PFR): Simulating n-pentane isomerization across different reactor volumes and feed temperatures.
- Distillation Column: Separating a pentane mix across different reflux ratios and stage counts.
It systematically runs every combination of inputs, handles any solver failures gracefully, and drops all the data into a clean CSV file and a couple of plots.
You'll need a few things installed:
- Windows OS
- DWSIM installed locally
- Python 3.9 or 3.10
pip
First, clone or download this folder to your machine. Then open up a terminal inside the folder and set up a virtual environment:
python -m venv venvActivate it:
- Command Prompt:
venv\Scripts\activate.bat - PowerShell:
.\venv\Scripts\Activate.ps1
Then install the dependencies:
pip install -r requirements.txtBefore running anything, open run_screening.py and look at the top of the file. You'll see a DWSIM_PATH variable.
Update that path so it points exactly to where DWSIM is installed on your computer (for example, C:\Users\YourName\AppData\Local\DWSIM).
Make sure your virtual environment is still activated, then just run:
python run_screening.pyWhen it finishes, you'll see a new results.csv file pop up in your folder, along with a plots/ folder containing some graphs mapping out the sweep data.
The results.csv file contains 32 rows (16 combinations for the PFR and 16 for the Column).
Here's what the columns mean:
- case_id: A unique name for the run (like
PFR_V1.0_T350). - simulation_type: Either
PFRorCOL. - sweep_var: The parameters that were tweaked for that run.
- success:
Trueif the flowsheet converged,Falseif it crashed or couldn't solve. - error_message: If the run failed, the exact solver error is logged here.
- KPIs: Output properties like conversion rates, purities, and heat duties. If a case failed, these are just left blank.
- "DLL not found": The script can't find DWSIM. Double-check that your
DWSIM_PATHinrun_screening.pyis correct. - "pythonnet import error": This usually means you're using an unsupported Python version (try 3.9 or 3.10) or you forgot to pip install the requirements.
- "All cases failed": If every single simulation crashes, your DWSIM installation might be incomplete or missing a thermodynamics library. Try a fresh reinstall of DWSIM.