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.


DWSIM 10#

DWSIM 10 is a full rewrite onto .NET 10 with a cross-platform Avalonia UI (Windows/Linux/macOS, x64/arm64), replacing the old Windows-only Windows Forms build. The scripting subsystem this integration depends on is unchanged: flowsheet scripts still run through the same two interpreters, IronPython or Python.NET, from the Script Manager. Everything below — the environment-dwsim.yml environment and the bloc.io.dwsim print shim — applies to DWSIM 10 as-is.

DWSIM 10 also adds DWSIM.MCPServer, a Model Context Protocol server exposing the flowsheet, streams, unit operations, thermodynamics and solver as MCP tools over stdio or HTTP/SSE, so an MCP-capable agent can build and solve a flowsheet directly instead of going through a pasted script. That’s a separate, agent-facing integration surface, not a replacement for the script-based one documented here — Bloc doesn’t use it yet.


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.