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
  • Index
  • » Users
  • » philgun
  • » Profile

Posts

Posts

Hi An,

I have re-installed OM 1.18 from scratch following the guidelines posted on

https://openmodelica.org/download/download-linux

However I still got the same problem, OMSimulator can not be found in my machine. I checked my path and it was pointing to .local/bin and other possible locations that store an executable.

Where usually OMSimulator is installed in on a linux machine?  Should I open a ticket now?

Cheers,
Phil

Hi,

I recently installed OM 1.18 stable version on my Linux (Ubuntu 16.04) machine. For some unknown reasons, OMSimulator was not installed while it's supposed to be, based on OM GitHub. When I run OMSimulator command on my terminal it showed:

Code:

OMSimulator: command not found

With that being said, I tried to install OMSimulator following the guidelines on https://github.com/OpenModelica/OMSimulator

I clone the repo and fetch the sub-modules:

Code:

git submodule update --init

then I proceeded by installing libxml2-dev and configuring the 3rd-party dependencies:

Code:

make config-3rdParty

When configuring the 3rd party, I got an error:

Code:


lua.c:82:31: fatal error: readline/readline.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'lua.o' failed
make[4]: *** [lua.o] Error 1

I have two big questions:

1. Why OMSimulator was not installed in the first place when I finished installing OpenModelica?
2. How to deal with the fatal error when configuring the 3rd party?

Thanks a lot and any help will be very much appreciated.

Cheers,
Phil

Hi Ann,

Thanks for your reply. Apparently, when I followed your suggestion to run the Model.ssp using OMSimulator directly, I got this error:

Code:

OMSimulator: command not found

It is a bit strange since I follow the installation straight from the OpenModelica website. I started with OM 1.14.2 then running a software update

Code:

sudo apt upgrade

to upgrade my OM to 1.18.0~23-g2c8def3. In OM GitHub, it is written that OMSimulator is part of OpenModelica.

Do I need to uninstall the OM that I have and re-install it again from scratch?

Cheers,
P

Hi An,

Sorry to take quite a long time to get back to you. I managed to update my OM to the latest stable version:

Code:

OpenModelica 1.18.0~23-g2c8def3

Then, I proceed by following the tutorial in:

Code:

 https://github.com/OpenModelica/OMTeaching

combined by following:

Code:

 https://openmodelica.org/doc/OMSimulator/master/html/OMEdit.html 

I managed to export system1 and system2 from DualMassOscillator model as FMUs (CS & ME). I then followed the tutorial to use SSP, added both FMUs as sub-models, and finally connected the I/Os. The system looked exactly similar to the one shown in the OMEdit tutorial.

However, when I hit the 'simulate' button in OMEdit, I got the following error:

Code:


/usr/bin/../bin/OMSimulatorPython3 /usr/bin/../share/OMSimulator/scripts/OMSimulatorServer.py --model=/tmp/OpenModelica_philgun/OMEdit//Model.ssp --endpoint-pub=tcp://127.0.0.1:46325 --logLevel=0 --option "--suppressPath=true"
No such file or directorySimulation process finished successfully.

I already double-checked the directory where my Model.ssp was located, the address for --model args was correct. Do you know what might cause this error?

Thanks a lot.
Cheers,
P



Hi An,

Thanks for the answers. I will consider to re-install my OM to v1.17.

The reason why I keep using v1.14 is that all the component models in the system were written using OM < 1.14, and it works perfectly on 1.14.

I do not know what complication that it will bring when I change to v.1.17.

My colleague, who is using v 1.17, could not compile the system model which worked perfectly in 1.14. Here is the snapshot of her error:

Code:


[/var/lib/jenkins2/ws/LINUX_BUILDS/tmp.build/openmodelica-1.17.0/OMCompiler/Compiler/NFFrontEnd/NFUnit.mo:883:7-883:68:writable] Error: Internal error function lexer failed

Do you know what the errors mean?

Your thought will be very much appreciated! Thank you so much.

Cheers

Hi,

I am trying to exploit OpenModelica FMI TLM Co-simulation feature. I am running on OMC 1.14.2. I am quite new in Modelica FMI feature, if my question is very basic, I apologise.

/*EDITED*/
I successfully exported Modelica.Mechanics.Rotational.Examples.Utilities.DirectInertia as an FMU.

As per https://build.openmodelica.org/Document … fFMUs.html , it is said that this model can be used to test import/export FMU feature in Modelica.

The FMU is then imported back to OpenModelica using the toolbar function "import FMU". Then, I drag and drop the FMU into a new composite model "CompositeModel1". However, when I try to fetch the interface data, the fetching process did not progress at all, even after waiting for 30 minutes. The only message in the "output window" is:

Code:


/usr/bin/../OMTLMSimulator/bin/tlmmanager -r /tmp/OpenModelica_philgun/OMEdit/Modelica.Mechanics.Rotational.Examples.Utilities.DirectInertia/CompositeModel1.xml

Is there anything wrong with my OpenModelica? I reckon, since the model that I use is coming from Modelica standard example, it should not contain any error. I am hitting a dead end and could not find any solution available online. Any help will be very appreciated! Thanks!

Cheers,
Phil

Apr-21-21 14:58:21
Question about how der() operator calculates the derivative
Category: Programming

Oh I see, so since dassl needs the derivative of a function to create polynomials for der(y), it makes the simulation slow. The surrogate model that I am trying to use is a neural-network, which does not have derivative w.r.t time, while the example from modelica by example website, the function definition is a polynomial which, can be  derived w.r.t time. So is it always the case that dassl wants the derivative of a function call to be able to calculate the derivative of a state?

Regarding inlining, what is the limit of complexity of a function that is still able to be inlined? Is an external C function inline-able? What will be your suggestion to overcome this slow-simulation speed problem? Should I use polynomial-based surrogate model instead of neural-net?


Thanks for your prompt response!

Cheers

Apr-21-21 14:11:52
Question about how der() operator calculates the derivative
Category: Programming

Hi Sjoelund,

Thanks for your prompt response. You're right that I have neither derivative nor inline annotation in the function definition. I was struggling to understand how (numerically) to implement these two annotations in the problem context that I am having.

If it is not too troubling you, would you mind giving me any pointer to where I should read more about the implementation of those annotations, or probably where a minimal example can be found? I read the Modelica specification handbook, but I don't get how the "derivative" and "inline" annotation can be used in my problem.

From what I understood, derivative annotation is useful to guide the solver to read another function that computes the derivative of the function being annotated. Given the fact that the function call (surrogate model/SM) is used to predict the der(y), how can I use the derivative annotation in the SM definition, since SM it self is used to calculate the derivative of y w.r.t. to time (dydt) and SM function call does not have any derivative?

The same about the inline function, how to implement it in the context that I am having?

Thanks a lot for your time

Cheers,




Apr-21-21 13:07:41
Question about how der() operator calculates the derivative
Category: Programming

Thanks for replying to my question.

So if using DASSL, the value of der(y) reported by Modelica is the only way to grab the derivative value, is it not?

Actually, I have some other questions, which related to der() operator and how the DASSL solver solves the problem. I am trying to replace a physics of a model with a surrogate model SM which is constructed/trained to predict der(x) given time (dtype=double) outside Modelica and is called via an external C-function.

Minimal example:

Real x(start=0);

equation

//real equation: der(x) = 3 * time^2 + 2 * time + 3;


/*Surrogate Call*/
der(x) = SM(time);

What I found is that the solver takes twice the amount of time-stepping (and slow as well) when using the surrogate model compared to the real function. Do you know the reason behind this? Do you think this approach (replacing the derivative with a surrogate model) is feasible to be implemented in Modelica with DASSL solver?

Thanks a lot.

Apr-21-21 11:44:11
Question about how der() operator calculates the derivative
Category: Programming

Hi,

I am trying to understand how Modelica solver calculates the value of 'der(X)' where X is a variable. Minimal example:


Real X1(start=1);
Real X2(start=0);
Real X3(start=0);

equation
der(y1) = -0.04*y1 + 1e4*y2 * y3;
der(y2) = 0.04 * y1 - 1e4 * y2 * y3 - 3e7 * y2 ^ 2;
der(y3) = 3e7 * y2 ^ 2;


When I print out the results after simulating it with -noEquidistantGrid flag and manually calculate the dy/dt :

dydt = (y_next-y)/dt

where dt, y_next and y are delta time, y at t+Δt and y at t (calculated manually after printed out the result), the value does not match with the reported der(y) from the Modelica simulation result.

Anybody knows how does Modelica calculates the derivative of y w.r.t time? Or how to calculate the dydt manually from the Modelica result file?

Thanks a lot!

Apr-07-21 01:23:38
Calling an external function in C from modelica
Category: Programming

Hi Ardpo,

Thanks for getting back to me about this issue. I found a workaround by using the algorithm section instead of calling the external C function in the equation. Which I am not entirely sure how it affects the performance and accuracy of the model.

I was using the new frontend (the "Enable new frontend use in the OMC API" is ticked under the tools tab) I believe and compiled it in the OMEdit, my compiler is OMC version 1.14.2.

How should we proceed with this bug reporting?

Thanks a lot!

Cheers,PG

Apr-01-21 05:08:09
Calling an external function in C from modelica
Category: Programming

Hello,

I am trying to call an external function in C that returns an array (size of 2, double) of the derivative of the system's state (der(enthalpy_fluid) and der(enthalpy_solid)). I had some success in calling an external function in C that returns an array (without involving any "der" function), by using an implicit call, as shown below:

function foo
    input Real raw_input[:];
    input Real params;
    output Real out[outputsize];
    external "C" run_surrogate_multi_output(
            raw_input,
            params,
            out
    )
     
    annotation(IncludeDirectory="modelica://SolarTherm/Resources/Include",
              Include="#include \"tf.c\"",
              Library = "tensorflow");
  end foo;

I followed the same logic (literally using the same function), and calling my function like this in the equation:

equation

     {out[1,1], out[1,2]} = foo(
                X_in[1,1:inputdim],
                params
     );
     der(h_fluid[1]) = out[1,1];
     der(h_solid[1]) = out[1,2];

however, I got an error in compilation, and the message was:

SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:40: warning: implicit declaration of function 'der' is invalid in C99 [-Wimplicit-function-declaration]
    tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
                                       ^
SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:72: warning: expression result unused [-Wunused-value]
    tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
                                                                       ^~
SolarTherm.Systems.Publications.Thermocline.Constant_Charging.Time_Controlled.Part2_MgO_6h_10h_8h_NeuralNetTank_02nls.c:8100:44: error: use of undeclared identifier 'thermocline_Tank'
    tmp7 = (*real_array_element_addr1(&der(thermocline_Tank.Tank_A.h_p[89,1]), 1, ((modelica_integer) 1))) - ((*real_array_element_addr1(&thermocline_Tank.Tank_A.out[89,2,1], 1, ((modelica_integer) 1))));
fatal error: too many errors emitted, stopping now [-ferror-limit=]



I read online and I suspected that no function name "der" is declared in the code, but how can this happen since "der" function is "native" to Modelica? Does anybody have any idea of how to tackle this problem?

Thanks a lot and have a great day!

Cheers,
Philipe

Hi guys,

Thanks for your reply. I do appreciate it. I managed to overcome the problem. The solution is in

https://stackoverflow.com/questions/626 … al-library

Thanks a lot!

Hi Modelica Gurus around the earth,

I am trying to linking my C code that calls external library, namely GLPK (GNU Linear Programming Kit) with my Modelica model.

The C code works just fine, I have tested it in a stand alone condition.

gcc standalonecode.c -lglpk -o standalonecode

When I plugged in the external C function with my Modelica models, I started to get this error:

Code:


/usr/bin/../lib/x86_64-linux-gnu/omc/libModelicaExternalC.a(ModelicaInternal.o): In function `ModelicaInternal_temporaryFileName':
(.text+0x571): warning: the use of `tmpnam' is dangerous, better use `mkstemp'
/usr/bin/../lib/x86_64-linux-gnu/omc/libModelicaMatIO.a(ModelicaMatIO.o): In function `Mat_VarDelete':
(.text+0x1e14): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
examples.SimpleSystemOptimalDispatch_functions.o: In function `st_linprog':
examples.SimpleSystemOptimalDispatch_functions.c:(.text+0x8b1): undefined reference to `glp_create_prob'
examples.SimpleSystemOptimalDispatch_functions.c:(.text+0x8c1): undefined reference to `glp_set_obj_dir'
....
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I believe that it comes from the linking process. Do you guys know how to solve this linking problem? Thanks!

Cheers,
Phil

  • Index
  • » Users
  • » philgun
  • » Profile
You are here: