Skip to main content
Ctrl+K
Rizer documentation (v0.1.dev1+ga30adafce) - Home Rizer documentation (v0.1.dev1+ga30adafce) - Home
  • Examples
  • Using Rizer from Simulink
  • API Reference
  • Bibliography
  • GitHub
  • Examples
  • Using Rizer from Simulink
  • API Reference
  • Bibliography
  • GitHub

Section Navigation

  • Using Rizer from Simulink / Simscape

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 its cantera.conf): MATLAB loads its own, incompatible hdf5.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#

  1. Build the C++ extension, from a shell where the rizer-env environment is active. This builds rizer_plasma_load.dll too:

    ./build_plasma1d.ps1
    
  2. 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.yaml and my_bundle/reactor.yaml. The last argument, np.inf, keeps the plasma volume constant. Ready-made bundles are in simulink/ref/bundle_ch4_rl/ and simulink/ref/bundle_ch4_nrp/.

  3. 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’s vcvars64.bat from rizer.config.psd1, the same file build_plasma1d.ps1 uses. It writes the folder dist/rizer_simulink/ and dist/rizer_simulink_<version>.zip. If Cantera was built in another environment than rizer-env (e.g. a pixi environment), set CanteraDepsLibBin in rizer.config.psd1.

    Or skip steps 1 and 3 and download a prebuilt package. The .github/workflows/simulink-dist.yml workflow builds rizer_simulink_<version>.zip (with a .sha256), uploads it as the rizer-simulink-dist artifact of every pull request that touches rizer/cantera_ext/, simulink/ or CMakeLists.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).

  4. 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')
    
  5. 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, ode15s or ode23t.

    Besides its terminals, the block outputs Tg and Te [K], the current i [A], the resistance R [Ohm], the electron number density n_e [m^-3] and the plasma channel diameter d [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.

previous

Plot transport data vs. temperature for a plasma of methane.

next

rizer

On this page
  • Prerequisites
  • Steps
  • Checking the installation
  • Further reading

© Copyright 2025, Copyright (C) Spark Cleantech SAS (SIREN 909736068).

Created using Sphinx 9.2.0.

Built with the PyData Sphinx Theme 0.24.0.