R2024b: Can Simscape block callbacks trigger model update or initialization?

I am investigating the execution behavior of native Simscape blocks in MATLAB/Simulink R2024b (24.2).
For several library components, including Capacitor, Inductor, and Average-Value Voltage Source Converter (Three-Phase), static inspection of library metadata shows callback entries such as CopyFcn, LoadFcn, and Mask Initialization.
I have not executed these callbacks, and their downstream behavior has not been verified.
I would appreciate clarification on the following questions:
  1. Under what operations are CopyFcn, LoadFcn, and Mask Initialization executed? For example, copying a block, loading a library, opening a model, or changing block parameters?
  2. Can these callbacks directly or indirectly trigger Update Diagram, model compilation, Simscape physical network initialization, or numerical solver initialization?
  3. What is the technical distinction between mask initialization, model update/compilation, Simscape network initialization, and numerical solver initialization in R2024b?
  4. Is there an officially documented workflow for inspecting or replacing native Simscape blocks without triggering model update, compilation, or initialization?
I am particularly interested in the documented execution boundaries and supported workflows in R2024b.
References to official documentation or practical examples would be greatly appreciated.
Thank you.

1 Commento

Torsten
Torsten il 13 Nov 2026 alle 12:04
Modificato: Torsten il 13 Nov 2026 alle 12:33
If you want "human" advice or have further questions, contact support:
Answer from AI:
In MATLAB/Simulink R2024b (24.2), block lifecycle callbacks and mask initialization operate within well-defined execution boundaries that separate diagram editing/loading from model compilation and physical network initialization.
1. Execution Triggers for CopyFcn, LoadFcn, and Mask Initialization
According to the Simulink Block Callbacks and Mask Editor Overview documentation, these routines are triggered by specific structural and lifecycle events: [1, 2]
  • CopyFcn. Executes immediately after a block is copied into a model or library. This occurs during interactive copy-paste, dragging a block from the Library Browser, or programmatic copying via add_block and replace_block. Note that it is suppressed for commented-out blocks or inactive variant choices. [1]
  • LoadFcn. Executes after a model or library containing the block is loaded into memory (via open_system or load_system), or when a previously commented block is uncommented. In native Simscape libraries, LoadFcn and CopyFcn are typically used for internal library link management, backward-compatibility forwarding, or registering block-specific UI listeners. [1]
  • Mask Initialization (MaskInitialization). Executes whenever Simulink needs to evaluate the mask workspace or redraw the block's dynamic icon. Specifically, it runs when:
  • You click Apply or OK in the block parameter dialog box (changing block parameters).
  • You programmatically modify a mask parameter via set_param.
  • You edit and save the mask code itself.
  • You trigger an Update Diagram (Ctrl+D), start a simulation, or initiate code generation. [1, 2]
2. Can These Callbacks Trigger Model Compilation or Simscape Initialization?
By design and official specification, no. Under standard MathWorks architecture, native Simscape block callbacks (CopyFcn, LoadFcn, and MaskInitialization) do not trigger Update Diagram, model compilation, Simscape physical network initialization, or numerical solver initialization:
  • Execution Boundary. CopyFcn and LoadFcn execute strictly during the edit/load phase. MaskInitialization executes either on-demand during parameter edits or as a pre-compilation step during an Update Diagram.
  • Documented Restrictions. MathWorks enforces strict rules for Mask Initialization Code prohibiting commands that alter model-level simulation states or force compilation loops during initialization.
  • Native Simscape Usage. In native components (such as Capacitor, Inductor, and Average-Value Voltage Source Converter), MaskInitialization is used locally to validate parameter dimensions, compute derived mask workspace variables, and configure underlying Simscape component parameters or icon graphics. It does not invoke set_param(bdroot, 'SimulationCommand', 'update') or sim. [1, 2, 3]
3. Technical Distinction Between Initialization and Compilation Stages
In R2024b, moving from an edited block diagram to a running simulation follows a strict sequential pipeline detailed in How Simscape Simulation Works: [1]
Stage Scope & Trigger Technical Operations Performed
1. Mask Block-level ( Evaluates mask parameters in the block's isolated mask
Initialization Parameter edit or workspace, runs MaskInitialization code, updates
start of Update block icons, and pushes values to underlying child
Diagram) blocks.
2. Model Model-level
Update & (Update Diagram / Executes InitFcn callbacks (Model InitFcn →Block
Compilation Ctrl+D) InitFcn → MaskInitialization). Propagates signal
dimensions, sample times, and data types across
Simulink lines, and flattens the diagram hierarchy.
3. Simscape Physical Network- Identifies topologically connected physical networks tied
Network level (During to each Solver Configuration block. Extracts the
Initialization Compiling & underlying Simscape language equations, performs
Running phases of index reduction (DAE structural analysis), applies
Update/Sim) variable targets/priorities, and solves for consistent initial
conditions at .
4. Numerical Engine-level Initializes the chosen ODE/DAE numerical integrator
Solver (Immediately prior to (e.g., ode15s, ode23t, or Simscape local solver),
Initialization time-stepping at ) allocates state vectors, computes initial state derivatives,
and configures step-size controllers.
4. Supported Workflow for Inspecting or Replacing Blocks Without Compilation
You can inspect metadata, query parameters, and replace native Simscape blocks programmatically without triggering diagram compilation or physical network initialization:
  • Load Without UI Rendering (load_system).Use load_system instead of open_system to load the target model and required Simscape libraries into memory in the background. Note that LoadFcn still executes upon loading, which is required for Simulink to resolve library links properly, but no compilation occurs. [1, 2]
matlab
load_system('my_model');
load_system('fl_lib'); % Foundation Library (Capacitor, Inductor)
load_system('ee_lib'); % Simscape Electrical (Converters)
  • Static Metadata & Parameter Inspection (get_param / Simulink.Mask).Inspect block callbacks, mask parameters, and underlying Simscape source links directly using get_param or the Simulink.Mask.get API. Neither API triggers MaskInitialization or model update.
matlab
blk = 'my_model/Capacitor';
callbacks = struct( ...
'LoadFcn', get_param(blk, 'LoadFcn'), ...
'CopyFcn', get_param(blk, 'CopyFcn'), ...
'MaskInit', get_param(blk, 'MaskInitialization'));
maskObj = Simulink.Mask.get(blk);
  • Programmatic Block Replacement (replace_block).Use the documented replace_block workflow to swap blocks while preserving port connectivity.
matlab
% Replaces matching blocks without compiling the model
replace_block('my_model', 'Name', 'Capacitor', 'fl_lib/Electrical/Electrical Elements/Capacitor', 'noprompt');
  • What runs: CopyFcn and MaskInitialization of the newly inserted block will execute once to establish the block's initial mask state.
  • What does NOT run: Update Diagram, Simulink compilation, Simscape DAE construction, and solver initialization do not execute unless you explicitly call set_param('my_model', 'SimulationCommand', 'update') or sim('my_model'). [1]
  • Handling Commented Blocks (Optional Isolation).If you are staging complex multi-block replacements and want to suppress CopyFcn and MaskInitialization until all edits are complete, set 'Commented', 'on' on the target subsystem or blocks before modifying them, then set 'Commented', 'off' once wiring is finished. [1]

Accedi per commentare.

Risposte (0)

Categorie

Prodotti

Release

R2024b

Richiesto:

亮
il 13 Nov 2026 alle 10:42

Modificato:

il 13 Nov 2026 alle 12:33

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by