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

Skipping build process

Skipping build process

Hey everybody,

I am using the ModelicaSystem from OMPython to build and run the model, and to set parameters, flags, load inputs etc.
The model is rather large so the build process takes some time and since, most of the time the structural parameters remain unchanged, is not really necessary.
I am therefore looking for a way to store a built model and to import it (pickling does not work).

I thought I might be able to just reuse existing exe-files. The constructor does not offer this possibility though:

Code:


class ModelicaSystem(object):
    def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, commandLineOptions=None):  # 1
        """
        "constructor"
        It initializes to load file and build a model, generating object, exe, xml, mat, and json files. etc. It can be called :
            •without any arguments: In this case it neither loads a file nor build a model. This is useful when a FMU needed to convert to Modelica model
            •with two arguments as file name with ".mo" extension and the model name respectively
            •with three arguments, the first and second are file name and model name respectively and the third arguments is Modelica standard library to load a model, which is common in such models where the model is based on the standard library.

Any help would be highly appreciated.

Edited by: TULU - May-06-22 10:32:57

Re: Skipping build process

You can call the generatd simulation executable directly and just overwrite values / parameters or change other simulation options.

Assuming you have a model named `A` you have A.exe (on Windows) in your working directory. You can find simulation flags in the User's Guide: https://openmodelica.org/doc/OpenModeli … flags.html

I guess `-override=value` or `-overrideFile=value` is what you are looking for.

If you want to stick to the scripting API (callable from OMPython) you can use `buildModel(A)` to build the model once and then call the executable via subprocess package in Python.

Re: Skipping build process

Thank you for your answer!

I am already re-simulating with different parameters and different inputs without building the model again but I cannot store the built model.

Such a stored model would bring some benefits.
The two most important for me are:
- After I restart my computer I do not need to build again
- Calling numerous instances of the stored model and let them run in parallel

Edited by: TULU - May-06-22 11:13:39

Re: Skipping build process

Check your working directory. The executable is (usually) not removed, so restarting the computer shouldn't matter. But I'm not super sure about what OMPython is removing after finishing simulating.

The other way would be to export an FMU and use a FMU simulation tool. See https://fmi-standard.org/

Re: Skipping build process

The exe remains there but I do not know how to call it without building the model again.
How would this be done?

I tried with FMUs but they are much slower...

Re: Skipping build process

TULU wrote:


The exe remains there but I do not know how to call it without building the model again.
How would this be done?

I tried with FMUs but they are much slower...

In Linux, you just call the executable. For Windows... You're better off running it through WSL than trying to figure out how to modify the PATH (although I guess someone will tell you how)

Re: Skipping build process

Thank you!
I could try using Linux.

I thought this would also work with Windows using the windows console
See this forum post:
how to utilize the exe file that is compiled when i simulate a model?

However, I struggle with getting it to run. Before executing I need to load quite some parameters from a JSON file. Not sure how to do this in the Windows console.

Edited by: TULU - May-06-22 14:16:53

Re: Skipping build process

Just in case somebody else will struggle with a this:
It works now on my Windows PC.

Before executing the model I set the parameters that need to be set in
myModel_init.xml
Setting the parameters like this is not as user-friendly as using OMPythons setParameters() but still...

Then I run (cmd):
myModel.exe -csvInput=a_path/input.csv

All the files need are:
myModel.exe, myModel_init.xml and myModel_info.json


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