Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Filtering variables in simulation

Filtering variables in simulation

When I click on simulate in OMEdit, there is an option to add a variable filter.

I assumed that this meant you could insert the names of the variables that you want to output to the output file.
So I added several names separated by commas.

But all I get in the output file is the time variable.

How do I use the filter correctly?

Re: Filtering variables in simulation

It's a regular expression (full match). The default is ".*"

Re: Filtering variables in simulation

Right, so if I want to see 2 variables: 'A_LengthBRD.distance' and 'A_LengthBLD.distance' what do I enter.

I can get just one by entering:

A_LengthBRD.distance

but if I try:

A_LengthBRD.distance, A_LengthBLD.distance

I get none

If I try:

"A_LengthBRD.distance", "A_LengthBLD.distance"

It doesn't even run.

and if I try:

A_*

I also get nothing.

Please forgive me for my ignorance of things that are not in the manual. I am new to this.

Re: Filtering variables in simulation

regex is common to very many applications (for example searching for text in most text editors): http://en.wikipedia.org/wiki/Regular_expression

The pipe (|) is the or operator

Re: Filtering variables in simulation

Ok, Thanks.

I feel the need to summarise my understanding for any other fools like me, and anyone who can enlighten me further


If you want to filter variables in OMEdit you need to use Regex, a summary of which can be found here:
http://en.wikipedia.org/wiki/Regular_expression

For example:
If I have only 2 variables that I want to see, then I can enter

A_LengthA.distance|A_LengthB.distance

This will force the output file to only log the 2 distances named above, A_LengthA.distance and A_LengthB.distance

Entering only A_LengthA will not give all the variables associated with A_LengthA
Entering A_LengthA.* will keep all the variables associated with A_LengthA, along with a few other random variables it decides start with "A_LengthA", but which actually dont.
For example: "motor.frame_a.w_a" and "A_FloorDamperBL.frame_a.r_0". Most of the variables that don't contain "A_LengthA" are rejected however.

Re: Filtering variables in simulation

If you use the mat4 format, aliases of the filtered variables might still appear in the result-file. They don't take up any extra space anyway.

Re: Filtering variables in simulation

I want to use csv format so that I can easily export the relevant data into my 3rd party software. I can't import a database of 5600 variables for 10000 time-steps, so I want to filter out the stuff I don't need.

I thought that there might be an easier and more precise way of doing it, like
"Export all variables containing string: 'A_'"


What is an 'alias' and why does it appear when it doesn't appear to follow the rule that I set using regex?

Re: Filtering variables in simulation

Alias variables appear because you have code like "a = b", usually from making connections. The mat format uses them to compress output files.

Code:

loadString("model M

  Real x = time;
  Real y = x;
end M;");getErrorString();
buildModel(M);getErrorString();
system("./M -override outputFormat=csv");
system("./M -override outputFormat=mat");
readSimulationResultVars("M_res.mat");
readSimulationResultVars("M_res.csv");

system("./M -override outputFormat=csv,variableFilter=x");
system("./M -override outputFormat=mat,variableFilter=x");
readSimulationResultVars("M_res.mat");
readSimulationResultVars("M_res.csv");

system("./M -override outputFormat=csv,variableFilter=y");
system("./M -override outputFormat=mat,variableFilter=y");
readSimulationResultVars("M_res.mat");
readSimulationResultVars("M_res.csv");

Above, you can see that filtering on x will cause x and the main variable y is output. If y is requested, only y is output. For csv-files you get at most twice as many variables as you intended to filter.

Re: Filtering variables in simulation

Right, thanks

Re: Filtering variables in simulation

Adding a paranthesis worked for me in OMEDIT / Simulation Setup / Output / Variable Filter (optional)


  (variable1|variable2|variable3)

I selected for mat format

hope it helps someone

Edited by: sathishmswamy - Jun-22-21 09:23:35
There are 0 guests and 0 other users also viewing this topic
You are here: