How to do a parameter sweep in activate?

NilsWaap
NilsWaap New Altair Community Member
edited October 2020 in Community Q&A

Hello community,

how can I do a parameter sweep in activate?

 

I want to simulate a controller with different parameters for the gain.

Afterwards I want to overlay the different system responses in a plot.

 

I defined a vector with different values for the controller gain 'KR' and use it in a 'MatrixGain'-block.

KR = [1 .1 .06 .01 .02];

I hoped that could work but it doesnt. Another approch could be to do it by doing multiple simulations with different parameters.

 

best regards

 

Nils

Answers

  • robertavarela
    robertavarela New Altair Community Member
    edited July 2019

    Nils,

     

    If you open a Water Tank tutorial model (attached) to give it a try, you will see that the constant is assigned to a certain variable x:

    image.png.f333f9b3aa2a31a426c25b003b5e49c4.png

     

    Which is declared in your Diagram Home as a static variable:

    image.png.89adadb8f58c3bc5563db78e7d6b9f32.png

     

    Instead of having a single value, you can sweep multiple values of x by simply doing a loop like this:

    image.png.94abe26def169a4b68cd2512d66920b0.png

     

    Your response under Scope block will show the results for all x values:

    image.png.930e1739db6896b11b5305acba7dea3a.png

     

    Regards,

     

    Roberta

    Unable to find an attachment - read this blog

  • NilsWaap
    NilsWaap New Altair Community Member
    edited July 2019

    Thank you Roberta!

     

    I modified your 'watert.scm' example as you showed me and it works fine!

    If I use the watertank model from the 'turtorial_models' folder the modification does not work.

    image.png.2503584e405d1179491292270ef2d6b8.png

    I made sure that both models are exactly the same. But for some reason there is a problem with the dimensions.

    I exchanged the superblocks with the superblock from your model and then it worked fine!

     

    The same problem shows up for my controller model.

     

    best regards

     

    Nils

  • robertavarela
    robertavarela New Altair Community Member
    edited July 2019

    Nils,

     

    The difference is the activation of Use subplots parameter in the Scope block, as per the screenshot below:

    image.png.bb59ba02d3e4704f0054434d5d2c8545.png

     

    This parameter was turned off in the tutorial model, whereas it was on in the file I shared. If you turn it on, you will see that it will work and generate a plot like this for i = 1:8:

    image.png.f5803d894f72ea709395f302e1d95652.png

     

    If Use subplots is on, we will have one plot per input. Otherwise each input is considered to be a curve (scalar inputs) in the single plot.

     

    Regards,

     

    Roberta

     

  • NilsWaap
    NilsWaap New Altair Community Member
    edited July 2019

    Thanks Roberta,

    the watertank example works fine :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />

     

    A parameter sweep still does not work in my 'controller-vehicle'-model.

     

    Are there any other parameters I need to change for my model?

     

    I am also using 'Signal Out'-blocks and 'to mat'--blocks. Furthermore I use look-up-tables. Could any of these blocks be a problem for a parameter sweep?

    image.png.971f5aed7734373f3f46a19e1bbce9a6.png

     

    Regards

     

    Nils

     

    Unable to find an attachment - read this blog

  • NilsWaap
    NilsWaap New Altair Community Member
    edited August 2019

    Solution:

    Up to now the Look-Up-Tables don't support to do a sweep by running a single simulation.

    Instead of doing a single simulation with a parameter vector, we have to do multiple simulations.

     

    By using the code below we can change the KR value with the use of the __counter__ variable. (Counts number of simulations performed)

     

    if __counter__<=length(KR_test)
        KR = KR_test(__counter__)
    else
        return
    end

     

    If you want to use signal out for different signals, you must name the variables differently, for example:

    ['simout_fahrer',num2str(__counter__)]

     

    And a end-block is needed that restarts the simulation at the event.

    image.png.8aedfe038b6f5b640c9a772004054873.png

     

    Regards

    Nils

    Unable to find an attachment - read this blog

  • robertavarela
    robertavarela New Altair Community Member
    edited October 2020

    Nils,

     

    Another user in the forum (Livio) has a suggestion of using Compose as a master and Activate as a slave in order to run Activate in batch to perform parameter sweep.

     

    This post:

    https://community.altair.com/community?id=community_question&sys_id=bd96c07a1b2bd0908017dc61ec4bcb13

    May help you to achieve your goal!

     

    Regards,

     

    Roberta

  • Livio Mariano_20459
    Livio Mariano_20459
    Altair Employee
    edited November 2019

    Let me add another approach that I've just learned.

     

    There are many options to perform it but I’ve found this method very simple, flexible and self-explanatory.

     

    Summary:

    In the example, watertank.oml is the master file.

    It:

    • changes the input parameters (controller gains)
    • runs (repeatedly) the file Watertank_parm.scm (slave)
    • collects results doing post-processing (plot) at the end.

     

    I’ve created a quick video to summarize how to run the demo.

    Present working directory must be where you save the files (the video shows how to select the pwd).

    Otherwise use an absolute path in the oml file.

     

    Liv

     

    Unable to find an attachment - read this blog