Main Content

Use Best Practices While Modeling and Simulating Faults

During model compilation and simulation, some fault modeling practices can cause errors in models that otherwise run without issue. Additionally, changing the properties of the signals can cause simulation errors if the signal has faults. Resolve some of these common issues by deploying these best practices.

Save Faults and Conditionals

When you create the first fault, fault model, or conditional associated with a model, Simulink® Fault Analyzer™ automatically saves the information to the fault information file. If you update properties or create additional faults, fault behaviors, or conditionals, you must save the model to save the fault information. If you attempt to close the model without saving after making changes to these artifacts, Simulink displays a dialog box that allows you to save the fault model and fault information file before closing.

Log Signals from Faults

If you log a signal from a block output that also has a fault, the log returns the data from the signal before the fault. The icon order indicates the order of evaluation. For example, the signal log in this model retrieves the output of the Sine Wave block without the fault behavior.

A model with a logged signal that has a fault. The log and the fault are on the output port of a Sine Wave block. The log icon is to the left of the fault badge on the signal.

To log the value of a signal after a fault, log the signal value going in to the Fault Outport block in the fault behavior, or log the data from the output port of another block that is downstream from the fault.

Add Faults to Buses

You cannot simulate faults on virtual buses. For more information on virtual blocks, see Nonvirtual and Virtual Blocks. However, you can add and simulate faults on nonvirtual buses.

For example, this model uses a Bus Creator block that outputs a virtual bus.

This example shows a model with virtual buses. You cannot add faults to the Bus Creator block output ports of this model.

Adding faults to either of the virtual buses causes an error during model compilation.

By contrast, this model has a fault on a nonvirtual bus. For more information on creating nonvirtual buses, see Create Nonvirtual Buses. You can simulate this model.

This example shows a model with nonvirtual buses. The Bus Creator block uses

Avoid changing nonvirtual signals to virtual signals when modeling with faults. If you add faults to a nonvirtual bus and change the faulted signal to virtual, the model generates an error during compilation.

Faults added to buses affect each bus element. To fault individual signals, use a Bus Selector block to split the signal from the Fault Inport block, apply behaviors to the bus elements, and then recombine them with a Bus Creator block. For example, this fault behavior applies offsets to each bus element before recombining them.

An example fault behavior. The bus has three elements, which are separated, and each one is offset, before it is recombined into a bus. The output bus must be nonvirtual.

To ensure the output signal and input signal are compatible, assign the signal created by the Bus Creator block to the same bus sent to the fault.

If you do not apply faults to the individual bus elements, the blocks that you use in the fault behavior must support buses. See Bus-Capable Blocks. In this situation, you can only use the stuck-at-ground fault behavior in the default fault library, mwfaultlib. For more information on creating custom behaviors, see Create Predefined and Custom Fault Behaviors.

If you use an incompatible signal data type or an alias of an incompatible data type, a simulation error occurs.

Limitations on Fault Injection

To avoid possible simulation errors and discrepancies, follow these guidelines when simulating models that contain faults:

  • You can only use fast restart for models that have faults on Simscape™ blocks.

  • You can only use accelerator or rapid accelerator mode in models that have faults on Simscape blocks.

  • Virtual blocks support faults only on their input and output ports.

  • Atomic subsystems support faults only on their ports that correspond to Inport and Outport blocks.

  • You cannot add faults to duplicate Inport blocks.

  • If you add a fault to a continuous signal, the signal must enter a block with a discrete sample time. For more information on sample time, see What Is Sample Time?

  • You cannot simulate faults on variable-size signals.

  • You cannot simulate faults on signals with constant sample times.

  • You cannot simulate faults on signals at the top level of export-function models or models that execute concurrently. However, you can simulate faults on signals in referenced models or atomic subsystems in these models.

  • The blocks that you use in Fault Subsystem blocks must have inherited or constant sample times.

  • Fault evaluates the state of the conditional before the conditional evaluates. As a result, faults only trigger in the time step that follows from the time step where the conditional status changes.

Related Topics