Effacer les filtres
Effacer les filtres

Simscape: switch subsystem during simulation

4 vues (au cours des 30 derniers jours)
ds126
ds126 le 6 Juin 2024
Modifié(e) : Simar le 19 Juin 2024
Hello, I have a variant-subsystem that contains physical elements.
  • Variant 1 should be active for the first 25% of the simulation.
  • Variant 2 should be active for 50%.
  • The remaining 25% ​​of the simulation should be active again in variant 1.
How can I do that? Unfortunately, the Atomic subsystem doesn't work. I have set up the variant subsystem, but I find it very complicated to set this up correctly. I ask for help.
  1 commentaire
ds126
ds126 le 6 Juin 2024
Or is it possible to turn off the fuelcell block during simulation?

Connectez-vous pour commenter.

Réponses (1)

Simar
Simar le 10 Juin 2024
Modifié(e) : Simar le 19 Juin 2024
Hi @ds126,
Switching variants in Simscape based on simulation time, one can use variant subsystems controlled by variant control variables. This requires leveraging Simulink's MATLAB Function blocks orStateflow charts to adjust these variables during simulation.
It is crucial to recognize, that while control logic can be adapted, Simscape networks demand continuity and cannot modify their physical structure instantaneously during simulation. An alternative strategy involves simulating configuration switches by activating or deactivating specific model paths as follow:
1.Define Variant Control Variables: Define variant control variables in the MATLAB workspace or a data dictionary that correspond to the different states of system (e.g., VariantCondition1, VariantCondition2).
2.Configure Variant Subsystem: Set up variant subsystem with the variant choices controlled by these variables. Each variant will represent a different configuration of the physical system.
3.Control Logic for Switching: Use a MATLAB Function block or a Stateflow chart to implement logic based on the simulation time (simTime) that updates the variant control variables. This logic can check the percentage of the simulation time elapsed and update the variant control variables accordingly.
For example, in MATLAB Function block:
function variantSwitch(simTime, totalSimTime)
if simTime/totalSimTime <= 0.25 || simTime/totalSimTime > 0.75
VariantCondition1 = 1; % Activate Variant 1
VariantCondition2 = 0;
elseif simTime/totalSimTime > 0.25 && simTime/totalSimTime <= 0.75
VariantCondition1 = 0;
VariantCondition2 = 1; % Activate Variant 2
end
assignin('base','VariantCondition1',VariantCondition1);
assignin('base','VariantCondition2',VariantCondition2);
end
Note: This approach requires that simulation is set to stop and then restart at switching points, as direct runtime changes to physical network configurations are not supported within a continuous simulation step.
4. Simulating Disabling a Block: To simulate turning off a block like a fuel cell during simulation, consider using a controlled source (for electrical systems) or a controlled flow (for hydraulic systems) that can be set to effectively zero or bypassed based on the simulation condition. This does not remove the block from the simulation but can simulate its inactivity.
5. Simulation Settings: Ensure simulation settings, especially the solver settings, are compatible with the dynamic nature of the model. Solver settings might need to be adjusted to ensure stability and accuracy.
Important Considerations:
  • Simscape requires continuity in its equations and physical networks. Directly switching physical configurations mid-simulation can introduce discontinuities that are not physically realizable.
  • Implementing the control logic for variant switching outside the Simscape domain (e.g., using MATLAB Function blocks or Stateflow) and then mapping these controls onto Simscape elements is a common strategy.
  • Testing the model extensively to ensure that the switching logic works as intended and does not introduce numerical instability is crucial.
This approach allows for simulation of systems that change configuration over time, though with some limitations inherent to the simulation of physical systems.
Please refer to the following documentation links-
Hope it helps!
Best Regards
Simar
  1 commentaire
ds126
ds126 le 14 Juin 2024
Thanks a lot! That's helpful. I have one more short question. You said I have to stop and restart the simulation. Does that mean something like pressing pause, changing values, and then continuing – but automatically? Is there any tutorial for doing that?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Component-Based Modeling dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by