Clear Filters
Clear Filters

How to switch a variant model on the basis of the ssimulation solver in use?

3 views (last 30 days)
I have two protected models one for RK4 and one for Euler.
I would like to create a variant system which selects the correct one on the basis of the solver selected in the simulation pane.
How can I do that?
The model is a referenced one run in accelerator mode and I would like it to be recompiled only if the solver is changed between two simulations.

Answers (1)

Lokesh
Lokesh on 23 Oct 2023
Hi Andrea,
I understand that you want to switch a variant model based on the solver selected in the simulation pane.
You can use the get_param(gcs, 'Solver') command to retrieve the solver selected in the simulation pane. Please refer to the following steps to switch a variant model based on the solver:
  • Create a variant subsystem and include the protected models for both the RK4 and Euler solvers.
  • Select the variant subsystem and access the "Block Parameters" dialog.
  • In the "Variant Choices" section, choose the "RK4" model and set the "Variant control expression" field to (get_param(gcs, 'Solver')=="ode4"). This expression will check if the solver selected in the simulation pane is set to "ode4" (Runge-Kutta). Similarly, set the condition for "Euler" model.
  • Save and close the variant subsystem.
When you run the simulation, the variant subsystem will select the appropriate model.
Please refer to the following MATLAB documentation links to know more aboutget_param” function and variant subsystems:
I hope you find this helpful.
Best Regards,
Lokesh

Categories

Find more on Component-Based Modeling in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!