Co-simulate with Simulink
Co-simulation lets you run a gas network and a control, electrical, or thermal model in Simulink as part of the same job. NexusFlow solves the gas network. Simulink solves the part that interacts with it. They exchange values at the configured interval in simulation time. The Communication Interface in the workbench specifies which signals to exchange. The NexusFlow Bridge desktop app starts Simulink on its computer and passes the signals between the two.
Availability. The Communication Interface is currently available only in the Gas Network Simulation Workbench.
Systems you can co-simulate
Decide what Simulink will calculate, what it needs from the gas network, and how its results will affect that network. The following are three ways to set up the exchange.
| Application | What NexusFlow sends to Simulink | Returned value and its use |
|---|---|---|
| Valve control | Pressure measured in the gas network | The controller calculates a target opening. An actuator sends the command to the valve |
| Compressor station electrical simulation | Centrifugal compressor shaft power as the motor's mechanical load | A motor and drive model calculates electrical demand and returns a speed setpoint subject to power supply constraints. An actuator sends it to the compressor in speed control mode |
| Cooling loop thermal simulation | The actual heat duty of a heat exchanger in a non-isothermal gas network | The cooling loop calculates its supply water temperature. The heat exchanger uses external temperature and overall heat transfer coefficient mode, and an actuator updates its external fluid temperature |
The electrical and thermal networks are solved inside their respective Simulink models. The two tools exchange boundary values as ordinary Simulink signals. Each channel carries one finite real number per exchange. Use a separate channel for each value and agree on units, sign conventions, and initial values. For example, the heat exchanger reports heat absorbed by the gas as positive. Convert the sign as needed for the cooling loop. Communication Interface reference
If the electrical or thermal model uses Simscape, use sensors or controlled sources to read values and apply inputs, with PS-Simulink Converter and Simulink-PS Converter blocks to connect to ordinary signal ports. Bridge requires the model to run in Normal mode with a fixed-step solver. The communication interval must be a whole multiple of the Simulink base step. MathWorks: Connect Simscape to Simulink signals
Integrator example
For a first connection, use a constant, an integrator, and an oscilloscope to verify the round trip. The workbench sends u = 2. Simulink integrates it from zero, and the workbench oscilloscope receives the result y. The simulation runs for 3 seconds with an exchange every 0.5 seconds. The final reading should be 6.
Before you start
- Install and pair NexusFlow Bridge. Confirm it is online under Personal Center → Bridge Management. Use the same account in the workbench.
- Make sure MATLAB and Simulink are licensed on the computer running Bridge. For first-time setup, install a C compiler supported by your MATLAB release and select it by running
mex -setup cin MATLAB. MathWorks compiler setup
1. Set the signals to send and receive in the workbench
Download the integrator example ZIP and import it into a blank tab in the Gas Network Simulation Workbench with New/Open → Local File. The example includes the channels and simulation settings. Select the Communication Interface on the canvas and check the two channels.
| Channel table | Channel name | Bound port | Unit | Initial value |
|---|---|---|---|---|
| Input Channels | u | Output signal port of the Constant Input | Blank | 0 |
| Output Channels | y | Input signal port of the Oscilloscope | Blank | 0 |
Input and output are named from Simulink's perspective. The constant's output is Simulink's input u, and the integral is Simulink's output y. The Bound Port setting connects the three workbench components, so you can leave them unwired on the canvas. Keep the oscilloscope input available for y.

Build the example from a blank model
- Add a Constant Input from Controllers, name it
Send u, and set Constant Value to2. - Add an Oscilloscope and a Communication Interface from Signals and Communication. Name the oscilloscope
Receive y. - Select the Communication Interface and add one row to each channel table using the values above. Hover over an option in the port selector to see the full sheet, component, and port names.
Right-click the Communication Interface on the canvas and choose Export Compute Interface. Save the exported JSON file on the computer running Bridge. It lists the signals to exchange, and Bridge uses it to generate the corresponding Simulink ports. You can leave Target Bridge and Compute Configuration unselected for now.

2. Add the interface to the Simulink model in Bridge
-
In Simulink, create a blank model and save it as
bridge_integrator.slx. Open Modeling → Model Settings → Solver. Set Type to Fixed-step and Solver to ode4 (Runge-Kutta). Expand Solver details, set Fixed-step size (fundamental sample time) to0.1seconds, and save the model. MathWorks fixed-step solvers
Simulink solver settings with Fixed-step, ode4, and the 0.1-second fundamental sample time marked -
In the Bridge desktop app, open Compute Configurations → New Compute Configuration. Name it
Simulink integrator exampleand set Launch Mode to Simulink Model. Select the local MATLAB executable,bridge_integrator.slx, and the communication interface manifest you just exported. Set the base step to0.1seconds. If your project has dependencies, provide the project directory and any additional dependency directories. -
In Bridge, use Check Environment and Compile Interface Self-test to check licensing and compilation on first use. Select Generate Simulink Interface Subsystem and save the copy as
bridge_integrator_linked.slx. Bridge adds NexusFlow Interface to the copy and sets Model File to the copy's path. -
In Simulink, open the copy. Add an Integrator from the Continuous library and set its initial condition to
0. Wire the NexusFlow Interface outputu_out1to the integrator input. Wire the integrator output to the NexusFlow Interface inputy_in1. Save the copy.
Simulink wiring from u_out1 to the integrator input and from the integrator output back to y_in1 -
In Bridge, confirm that Model File points to the wired copy and Communication Interface Manifest points to the exported JSON. Click Save and Sync to Platform.
3. Select the configuration and run from the workbench
- Select the Communication Interface. Set Target Bridge to your paired device and Compute Configuration to
Simulink integrator example. - Click a blank area of the canvas and check the global parameters below. If you imported the example, use its simulation settings.
| Parameter | Example value |
|---|---|
| Simulation type | Transient simulation |
| Calculation start and end times | 3 seconds apart |
| Minimum and maximum time steps | 0.1 and 0.5 seconds, respectively |
| Development and Debugging → Kernel Execution Mode | Platform Image, so the platform kernel runs the main model |
| Development and Debugging → Communication Interval | 0.5 seconds |
| Development and Debugging → Communication Wait Timeout | 100 seconds to allow for first-time loading |
Simulink advances 0.1 seconds per step and exchanges signals with the main kernel every five steps. When changing these settings, use a communication interval that is a whole multiple of the Simulink base step and a simulation duration that is a whole multiple of the communication interval. Global simulation parameters
Save the model, open Logs, and select Validate Simulation Model. Once validation passes, click Start Calculation. Bridge starts MATLAB, and the platform kernel and Simulink begin exchanging signals at the start of the simulation.
4. Check the values on the oscilloscope
Open the run from Tasks on the left and confirm that it succeeded. Select the oscilloscope that receives y and open Signal → Signal Trend Chart. Measure time from the start of the calculation and check the values below. Floating-point values may be rounded slightly.
| Elapsed simulation time (seconds) | 0 | 0.5 | 1 | 1.5 | 2 | 2.5 | 3 |
|---|---|---|---|---|---|---|---|
Oscilloscope value y | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
Change the constant from 2 to 3, save, and run again. At three seconds the oscilloscope should read 9. With your own model, send a gas network measurement to Simulink and use an oscilloscope to check the magnitude and timing of the returned signal. Then connect outputs that affect the gas network to actuators.
Troubleshooting
| Symptom | What to check |
|---|---|
| The compute configuration is missing in the workbench | Save the Simulink configuration in Bridge. Confirm Bridge is online and paired with your account, then reopen the configuration selector |
| Configuration revision or interface digest mismatch | If you changed execution settings in Bridge, reselect the configuration in the workbench. If you added or removed channels or changed their names, units, or initial values, export the manifest again, regenerate the interface, and save its wiring. You can reuse the manifest when switching to another valid port of the same direction |
| No port is available, or validation reports multiple drivers | Use an enabled control output as the source and an enabled control input as the target. Check that the target signal has a single source |
| Startup or advancement times out | Check the platform task log and Tasks and Logs in Bridge for licensing, dependencies, step size, and simulation duration. If a disconnect ends the task, reconnect Bridge before starting another run |
| MATLAB reports an existing interface | Each model uses one session interface. Generate a fresh copy from the original model and wire the new copy |