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

simulate without buildModel

simulate without buildModel

Hello.  I'm running an OpenModelica simulation from Python, much along the lines of `Python interoperability' in the `OpenModelica Users Guide'.  In particular, following the `second option', after having built the binary executable, I tinker with the parameters in *_init.txt and rerun using

   os.popen ('./CalledbyPython').read ()

What I wonder though is how to do this using the `third option' (`to use the Corba interface for invoking the compiler and then just use the scripting interface to send commands to the compiler via this interface').  I have this working, but in order to run a simulation after having modified the parameters (via Corba, using setComponentModifierValue, etc.), I can only find the `simulate' command which seems to involve (a) recompiling the Modelica model from .mo to .c, (b) compiling the .c program to an executable, and (c) running the executable.  I know I can do (a) and (b) with buildModel (either in OMshell or via Corba), but how do I do (c) without (a) and (b)?

In my case, I want to run the same model dozens or hundreds of times with different values in the _init.txt file, but no structural changes to the model, so recompilation should not be required; indeed it's not as I can do this via the OS shell.  The question is, can this also be done via the OMShell/Corba?

Re: simulate without buildModel

You can call system("./MyFile") via CORBA to run an external command.

Re: simulate without buildModel

Hey, that's easy. Thank you very much for the prompt response!

Re: simulate without buildModel

Oh, but if I want to modify parameters between simulations, such as those appearing in the MyModel_init.txt, the OMShell/CORBA way is to use e.g. setComponentModifierValue, but these modifications won't be made known to the precompiled simulator binary MyModel; if I simply follow the calls to setComponentModifierValue by a call

    system("./MyModel")

it will just read the old MyModel_init.txt and my modifications will have been in vain.  Is that right?

What I want to do is compile once and then run many times with slightly different parameters.  I can do this via tinkering with MyModel_init.txt, but I wonder if it is possible via OMShell/CORBA.

Re: simulate without buildModel

Well, you can modify the _init.txt using shell-scripting.

For example:

sed -i 's/.*a_a.x_x/2.5 \/\/ a_a.x_x/' B_init.txt

Note that newer versions of OpenModelica has changed format of the init-file to xml. Adding a scripting command to change parameters directly in CORBA/OMShell is on my TODO-list current/wink

Re: simulate without buildModel

O.K. then.

I guess there's not much point using CORBA system to edit init.txt and then CORBA system to run the old executable.

Thanks for the tip about sed.  It's a nice program.  I've been using awk for the same purpose.  Ultimately though I'll be doing it in Python, which shouldn't be very difficult.

Thanks too for the notice about the switch to XML for init.txt.  I won't bother writing an init.txt pyparser then.

I guess my immediate plan then will be to update my OpenModelica to get the init.xml behaviour, set up init.xml reading, modifying, and writing in Python, and then call the simulator with os.popen (or rather subprocess.check_call since os.popen is deprecated).

Thank you again for the prompt and clear responses.

There are 0 guests and 0 other users also viewing this topic