- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » To check the instantaneous value of a...
To check the instantaneous value of a variable
To check the instantaneous value of a variable
Hello
I wish to check the instantaneous value of a variable at a particular time instant. I am currently unable to do so. I am new to the modeling environment, so please excuse me if the question seems rather silly.
I am attaching a sample code below. Its a function x which varies as the square of time. I wish to find the value of x (at say time = 0.4 sec) and store it in another variable (say y) which would be constant. I would like to know the procedure and the syntax to obtain the desired value of y. For example in the following case the value of y should be 0.08.
Code:
model test
Real x;
equation
der(x) = time;
end test;
Thank You for your assistance.
Re: To check the instantaneous value of a variable
Code:
loadString("model test
Real x;
equation
der(x) = time;
end test; ");getErrorString();
simulate(test);getErrorString();
y:=val(x, 0.4);getErrorString();
// Create new model with y
loadString("model M
constant Real y = " + String(y) + "
end M;");getErrorString();
list(M);getErrorString();
Code:
$ omc a.mos
true
""
record SimulationResult
resultFile = "/home/martin/tmp/test_res.mat",
simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'test', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
messages = "",
timeFrontend = 0.009196981,
timeBackend = 0.004855915000000001,
timeSimCode = 0.001735353,
timeTemplates = 0.001114121,
timeCompile = 0.15997102200000002,
timeSimulation = 0.008438043000000001,
timeTotal = 0.185361157
end SimulationResult;
""
0.08000000008381952
""
true
""
"model M
constant Real y = 0.08;
end M;
"
""
- sjoelund.se
- 1700 Posts
Re: To check the instantaneous value of a variable
That worked out pretty well. I entered your code in OMShell and it worked just as you had said. Thanks!
I tried to introduce the code into OMedit as the value which I need is to be used further but to no avail. I am getting confused as I don't know where to enter the code. Is there a way of doing so ?
Thanks a lot !
Pratyush
Re: To check the instantaneous value of a variable
OMEdit has no way of doing this. Sorry.
- sjoelund.se
- 1700 Posts
Re: To check the instantaneous value of a variable
Oh I see. Anyways are you aware of any other method in which we can store the value of a variable in the middle of a simulation ?
I am actually making a library in OMEdit and one the components needs to have the intermediate values of a variable for further use.
Thanks Again!
Re: To check the instantaneous value of a variable
Write it to a text-file during simulation or read the result-file after OMEdit simulates a model. You could even write your own external C code to read the result-file during initialization.
- sjoelund.se
- 1700 Posts
- Index
- » Usage and Applications
- » OpenModelica Usage and Applications
- » To check the instantaneous value of a...