Help - Search - Members - Calendar
Full Version: assign different values to a vectorial component's parameter
Modelica Forum > Modelica > Modelica
David
Dear community,

a little Modelica-programmers question:

I work on a model for a stratified storage for hot water. It exists of n "layers" of water which are instantiated by creating a vector-component layer[n] of the type Layer

CODE
Layer layer[n]


and are connected within the equation area by a for-loop.

CODE
for i in 1 : n-1 loop
connect(layer[i].out, layer[i+1].in);
end for;


The layers have a parameter for their start-temperature. Until now I commit the same start-temperature to all layers by

CODE
Layer layer[n](each T_0=T_0);


But in real life each layer starts with it's own temperature so I would like to commit different start-temperatures to different layers.

Do you have any idea how to do this?

Thank you!
david.
wagner
Hello David,

you could write a Modelica script that assigns the parameter to the different layers before simulation is started.

Regards

Florian
David
Hello Florian,

thank you. But I am sorry, I don't know how to do this. Could you please give me a little hint?
Thank you.

Regards,
david.
Carsten
What's about creating a parameter array of start values, which you might fill by upper and lower storage temperature
.
QUELLTEXT
parameter SI.Temperature T_01 = 300;
parameter SI.Temperature T_0n = 280;
parameter SI.Temperature T_0Array[n] = {T_01 + (T_0n-T_01)/(n-1)*i for i in 1:n};


and then you can modify your start values in the component by:
QUELLTEXT

Layer layer[n](T_0=T_0Array);


its that what you want (you even can edit the array by hand)?

regards
Carsten

wagner
Hello David,

attached to this post you'll find a simple model and a script that assigns some parameters before simulation.

To use the script load your model and before running the simulation start the script. In the script the parameters are assigned. Then start the simulation in the ordinary way.

In Dymola you can start the script by calling @Scriptname.mos in the command window on the simulation screen. I don't know how it works in other simulation environments.

In the sample script the parameter values are calculated in a for loop. It's also possible to load the parameter values from a file.

All Modelice IDE's have a pool of functions that can be used in Modelica sripts. In Dymola you get the list of available functions by calling listfunctions() in the command window. In a Modelica script you can use all ordinary Modelica functions (also user defined ones) and the functions of the Script function pool.

Play a little bit around with Modelica scripts. It's a really powerful feature which is rarely known by many Modelica users.

Regards

Florian
David
Good morning Florian,

I think you saved the same model-file two times accidentally. There is no script file to be found (by me). I am curious what's in there ; )

Thank you,
david.
David
Hello Carsten,

thanks for your help: it works! Unbelievable simple.
I tried so much combinations in the assigning line but not this very reasonable one.
Thanks a lot.

Regards
david.
wagner
Hello David,

I replaced the wrong file with the correct Modelica script. Sorry for the mistake.

Florian
David
Hi Florian,

thank you very much! I am happy to know this feature now.
david.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.