Using Bloc from DWSIM#
DWSIM can call Bloc directly from its embedded IronPython scripting environment (Simulation → Object Editor → Scripts), letting a DWSIM flowsheet stream compositions/conditions into a Bloc reactor model and read the results back into a DWSIM material stream.
Environment#
DWSIM users should build the environment from environment-dwsim.yml, not the
main environment.yml — it excludes the private packages (spy, schem)
that aren’t needed to run Bloc reactor models standalone:
conda env update --file environment-dwsim.yml --name bloc
conda activate bloc
bloc.io.dwsim compatibility shim#
DWSIM’s IronPython (Python.NET) environment does not handle Python’s print
the same way CPython does, and mixed bytes/string output from Cantera/NumPy
objects can raise or produce garbled output. Import
bloc.io.dwsim at the very top of a DWSIM script to patch
builtins.print with a DWSIM-safe version before doing anything else:
import bloc.io.dwsim # fixes Python.NET print/output issues
from bloc.testing.testing_utils import defaults, default_simulation
config = defaults()
sim = default_simulation(**config)
Set the DWSIM_SILENT environment variable to "true" before the import to
suppress all print output instead of sanitizing it (useful once a script is
verified and running unattended inside a flowsheet).
Example script#
sandbox/dwsim_script/dwsim_bloc_script.py is a worked example: it reads
temperature, pressure and composition off a DWSIM input material stream
(ims1), maps them onto a Bloc STONE scenario via ctwrap, runs the
simulation, and writes the reactor outlet state back onto a DWSIM output
stream (oms1). ims1/oms1 are provided by DWSIM’s script runner itself —
they are not Bloc objects and do not need to be imported.