- Index
- » Programming
- » Modelica Language
- » How to set value from one model to...
How to set value from one model to another
How to set value from one model to another
model A
Integer aValue1(start=1);
Integer aValue2(start=2);
equation
aValue1 = 2;
aValue2 = aValue1 + 10;
end A;
model B
Integer bValue1(start=1);
Integer bValue2(start=2);
A a;
equation
bValue1 = bValue2 + 1;
a.aValue1 = bValue1;
end B;
I want to set the value calculated in model B (bValue1) to model A(a.aValue1). I cannot do it during instantiation
as i have to calculate the value and then set the value.
Thanks !
Re: How to set value from one model to another
Code:
loadString("model A
Integer aValue1(start=1);
Integer aValue2(start=2);
equation
aValue1 = 2;
aValue2 = aValue1 + 10;
end A;
model B
Integer bValue1(start=1);
Integer bValue2(start=2);
A a;
equation
bValue1 = bValue2 + 1;
a.aValue1 = bValue1;
end B;
");getErrorString();
simulate(A);
v:=val(aValue1,1.0 /* endTime */);
simulate(B, simflags = "-override bValue1=" + String(v));
plot(bValue1);
Or something like that
- sjoelund.se
- 1700 Posts
Re: How to set value from one model to another
you can't run it in OMEdit.
In OMEdit once you have simulated the model then you can change the values in the variables browser and re-simulate it.
Note that you need atleast revision 18123.
Adeel.
- adeas
- 454 Posts
Re: How to set value from one model to another
Simulate the model and switch to modeling view.
One the right side you will see the "variables browser". It has the value column which allows you to modify the variables/parameters which are changeable.
Change the value and then right click the parent item of the list and choose re-simulate.
BTW why don't you use a function?
Adeel.
- adeas
- 454 Posts
Re: How to set value from one model to another
Code:
model A
Integer aValue1(start=1);
Integer aValue2(start=2);
equation
aValue1 = B(2);
aValue2 = aValue1 + 10;
end A;
function B
input Integer bValue1;
output Integer bValue2;
algorithm
bValue2 := bValue1 + 1;
end B;
Adeel.
- adeas
- 454 Posts
Re: How to set value from one model to another
Hi Adeel,
I could only see the 'variable browser" in plotting view not in modeling view . I could not edit the value column.
model A
Integer aValue1(start=1);
Integer aValue2(start=2);
equation
aValue1 = B(2);
aValue2 = aValue1 + 10;
end A;
In this model,variables(aValue1,aValue2) are changeable i guess but i could not modify them in "value column".
About using function, can we call chains of functions from a model. For eg, i have function A calling B , B calls C and C calls D. I do not know what are the good and bad things if i model in such a way. One might think why do i have chains of functions instead of one block of function but then individually A, B,C, D can be used somewhere else.
- Index
- » Programming
- » Modelica Language
- » How to set value from one model to...