Using Rizer from Simulink / Simscape#
Rizer’s plasma reactor (PlasmaReactor0D: two temperatures, finite-rate
chemistry) is available as a two-terminal load for Simscape Electrical, the
MATLAB/Simulink library of electrical components. The block behaves like a
resistor whose resistance depends on the plasma’s own temperature and
composition; Simulink’s solver integrates the plasma and your circuit
together.
No Python runs inside MATLAB. The reactor is compiled into a Windows DLL
(rizer_plasma_load.dll) with plain C functions, and a Simulink block written
in C (an S-function, compiled by MATLAB into a MEX file) calls it.
Prerequisites#
Windows. The MATLAB side (DLL packaging and loading) is Windows only.
This package built with its C++ extension, against a Cantera 4.0 source build, as described in
rizer/cantera_ext/INSTALL.md. Cantera must be built without HDF5 (hdf_support = 'n'in itscantera.conf): MATLAB loads its own, incompatiblehdf5.dll, and an HDF5-enabled Cantera then fails to load inside MATLAB.MATLAB with Simulink and Simscape Electrical, R2026a or R2026b, and a C compiler configured for
mex(Visual Studio 2022).
Steps#
Build the C++ extension, from a shell where the
rizer-envenvironment is active. This buildsrizer_plasma_load.dlltoo:./build_plasma1d.ps1
Write a bundle: a folder holding everything the block needs (the mechanism and the reactor’s parameters and initial state). Example: CH4 at 1000 K and 1 atm, electron density 1e19 m^-3, in a 2 mm long, 250 um radius channel:
import cantera as ct import numpy as np import rizer.kinetics.extensible_rate # registers the mechanism's custom rates import rizer.misc.units as u from rizer.misc.utils import get_path_to_data from rizer.simulink.bundle import write_bundle from rizer.transport.loaders import ( get_default_collision_frequency_model, get_momentum_transfer_collision_frequencies_list, ) mech = str(get_path_to_data("mechanisms") / "Goutier2025" / "CH4_to_C2H2.yaml") plasma = ct.Solution(mech, "plasma", transport_model=None) x_e = 1e19 / (ct.one_atm / (u.k_b * 1000.0)) # electron mole fraction [-] plasma.Te = 1000.0 plasma.TPX = 1000.0, ct.one_atm, {"CH4": 1 - 2 * x_e, "e-": x_e, "CH4+": x_e} mtcf = get_momentum_transfer_collision_frequencies_list( plasma.species_names, get_default_collision_frequency_model() ) gap, radius = 2e-3, 250e-6 # m V0 = gap * np.pi * radius**2 # m^3 mass = V0 * plasma.density # kg y0 = np.concatenate([[plasma.T, plasma.Te, V0], plasma.Y]) # [Tg, Te, V, Y...] write_bundle("my_bundle", plasma, mtcf, y0, mass, gap, ct.one_atm, np.inf)
This creates
my_bundle/mechanism.yamlandmy_bundle/reactor.yaml. The last argument,np.inf, keeps the plasma volume constant. Ready-made bundles are insimulink/ref/bundle_ch4_rl/andsimulink/ref/bundle_ch4_nrp/.Package a folder MATLAB users can use without Python:
make simulink-package
This runs
simulink/package_dist.ps1, which reads the Cantera clone, the conda environment and Visual Studio’svcvars64.batfromrizer.config.psd1, the same filebuild_plasma1d.ps1uses. It writes the folderdist/rizer_simulink/anddist/rizer_simulink_<version>.zip. If Cantera was built in another environment thanrizer-env(e.g. a pixi environment), setCanteraDepsLibBininrizer.config.psd1.Or skip steps 1 and 3 and download a prebuilt package. The
.github/workflows/simulink-dist.ymlworkflow buildsrizer_simulink_<version>.zip(with a.sha256), uploads it as therizer-simulink-distartifact of every pull request that touchesrizer/cantera_ext/,simulink/orCMakeLists.txt, and attaches it to the GitHub Release of every tag. It ships without the two MEX files, so the next step compiles them (needs a C compiler:mex -setup C).In MATLAB, from the packaged folder:
run('rizer_simulink_setup.m') % loads cantera_shared.dll, builds the MEX files rizer_build_library % builds the block library rizer_lib.slx open_system('rizer_lib')
Drag the Plasma Load Complete block into your Simscape Electrical model and connect its two electrical terminals. In its dialog, set “Bundle reactor.yaml path” to your bundle’s
reactor.yaml, in single quotes (the field is evaluated as MATLAB code), for example'C:\work\my_bundle\reactor.yaml'. Use a variable-step solver,ode15sorode23t.Besides its terminals, the block outputs
TgandTe[K], the currenti[A], the resistanceR[Ohm], the electron number densityn_e[m^-3] and the plasma channel diameterd[m] as Simulink signals (ports 1 to 6).
Checking the installation#
From the repository, with MATLAB on PATH:
make simulink-package # again after rebuilding the C++ extension
make simulink-test
This runs the MATLAB tests in simulink/test/: an arc-only RL circuit and a
pulse generator with a transmission line, both compared against Rizer’s own
Python results, plus checks of the solver behaviour the block relies on and
of repeated setup calls.
Further reading#
simulink/ARCHITECTURE.md
explains how the block works: its parts, the bundle format, how to add
another reactor model, solver settings, measured performance and known
limitations.