Search code examples
modelicadymola

How to generate n parameters/options in parameter-window?


I have the following code:

parameter Boolean Powerplant_on_Bus=true
    "Activate/Deactivate Conventional Energy Generation on Bus" annotation (
    Evaluate=true,
    HideResult=true,
    choices(__Dymola_checkBox=true),
    Dialog(group="Generation"));

  parameter Integer n[:]=
    "Number of Conventional Powerplants connected to the Bus"  annotation (
    Dialog(group="Generation", enable=Powerplant_on_Bus));

The result is this: Parameter Window

With the following code I want to generate an option for choosing a profile table for the Powerplant in the paramter window:

replaceable model Powerplant_Profile =
      IntegraNet.HighVoltage.Basics.Tables.ElectricGrid.GenericPowerDataTable   "Load-profile data table for Powerplant Generation" annotation (choicesAllMatching=false,Dialog(tab="Powerplant",enable=Powerplant_on_Bus));

The result looks like this: Parameter Window "Powerplant"

My goal is to generate n options for choosing a powerplant-profile. For example: When I have choosen 5 Powerplants in the first parameter window in the field "n" I want to have 5 fields for choosing a profile in the parameter window "powerplant".

Thanks you for help.


Solution

  • As far as I know dynamically changing the shown parameters directly in the parameter dialog is not possible currently in Dymola.

    As a workaround - although I'm not sure if this is exactly what you need - there is the following way to do something similar.

    package N_options
      package Data
        record Default "Default Record"
          parameter Real p1=1;
        end Default;
    
        record Data1 "Data set 1"
          extends Default(p1 = 2.3);
        end Data1;
    
        record Data2 "Data set 2"
          extends Default(p1 = 4.5);
        end Data2;
      end Data;
    
      record DataSelection
        parameter N_options.Data.Default data annotation (choicesAllMatching);
      end DataSelection;
    
      model MyModel
       parameter DataSelection vectorizedData[:];
      end MyModel;
    
      model MyExample
        MyModel myModel(vectorizedData={
          N_options.DataSelection(data=N_options.Data.Default()),
          N_options.DataSelection(data=N_options.Data.Data1()),
          N_options.DataSelection(data=N_options.Data.Data2())})
          annotation (Placement(transformation(extent={{-10,-10},{10,10}})));
      end MyExample;
    end N_options;
    

    This comes down to:

    • A package containing your data
    • An (intermediate) record where you can select which data you want to be able to choose
    • A model containing the data as a parameter
    • An example

    Double-clicking the myModel in the example gives you the following dialog in Dymola: Parameter Dialog

    Clicking the 'Edit' button then shows: Sub-Dialog for parameter editing

    In the second dialog you can select the number of data-sets you want to use and which one should be chosen.