- Index
- » Users
- » Koldo
- » Profile
Posts
Posts
Sorru archanahebbar
The only way I know to connect an OpenModelica simulation to do a co-simulation or a software/hardware in the loop is using sockets and including them through external functions inside your model.
In the past I tried to compile omc generated files adding personal patches but;
- I could not do it
- Probably I would not comply with license
Best regards
koldo
Hello archanahebbar
You have to do a simple communication between two programs using sockets.
The first I would do is to prepare and test two simple C /C++ programs, one as sender and other as receiver.
Then I would include the sender code in a simple Modelica model to try it.
You can find some details here:
http://blog.kempj.co.uk/2013/12/modelic … t-library/
Good luck
Koldo
Well, it has been very simple. Just download and install the RPM or DEB. It simply runs as in another desktop system... :-)
Bestregards
Koldo
Hello phallyka
If you want to access and modify Modelica simulation "on the fly" you can use a sockets connection.
There is a sample out there. I can help you to search it if it is interesting for you.
Best regards
Koldo
Hello archanahebbar
The simplest way (and maybe the only) to use your C code is using external functions:
http://book.xogeny.com/behavior/functions/external/
This means that Modelica model calls your functions, but your functions cannot call your Modelica model.
However you can launch your Modelica model .exe and connect to it through sockets (much easier than using CORBA interface).
Best regards
Koldo
MD wrote:
How to create black box model in modelica?
Sorry MD, could you give us more details?
Hello YacinOS
I do not think it is possible to get the algebraic solution of an ODE in Modelica.
However, if you do not have Matlab or Mathematica, you can try Maxima (I like wxMaxima), that is a full-featured open source CAS (Computer Algebra System).
Best regards
Koldo
Hello MrAndersDk
As you say you are new, maybe there is a problem around there.
Have you tried simply to multiply every element of the array with a "for"?
Best regards
Koldo
Hello YacinOS
You can do some things. For example:
- Set to save simulation results in a .csv file, and open it later to get the values
- Inside Modelica code, save the interesting results in a file
Best regards
Koldo
Hello all
I wanted to compile and run an OpenModelica model in a cluster running Red Hat. Until now I have compiled and run all models in Windows.
Could you give me some clues about how to do it? I have some experience compiling C++ source in Linux.
Best regards
Koldo
"Error: Derivative of expression
Differentiate.differentiateExpSolve failed ..." error message is got for almost all external functions called, even the simplest:
netpower = power*Performance(speed);
where while "power" and "speed" are obtained by solving differential equations, Performance() is a "pure" external function and "netpower" is just an output.
Do you now how to solve this?
Hello hu72005
If you know how to run your external C code from OpenModelica, you just need to create a .C file with a function like this:
#include <windows.h>
static HINSTANCE hinstLib = 0;
static double (* MyFunctionPointer)(double) = 0;
double MyFunction(double arg) {
if (hinstLib == 0)
hinstLib = LoadLibraryEx(TEXT("MyDLLFullFilePath"), NULL, LOAD_IGNORE_CODE_AUTHZ_LEVEL); // Loads the DLL
if (MyFunctionPointer == 0)
MyFunctionPointer = GetProcAddress(hinstLib, "MyFunctionName"); // Loads the function pointer
return (*MyFunctionPointer)(arg); // Calls it
}
This is in Windows. In Linux this is also possible to be done as easily calling dynamic libraries.
Best regards
Koldo
Hello hu72005
If you know how to run your external C code from OpenModelica, you just need to create a .C file with a function like this:
#include <windows.h>
static HINSTANCE hinstLib = 0;
static double (* MyFunctionPointer)(double) = 0;
double MyFunction(double arg) {
if (hinstLib == 0)
hinstLib = LoadLibraryEx(TEXT("MyDLLFullFilePath"), NULL, LOAD_IGNORE_CODE_AUTHZ_LEVEL); // Loads the DLL
if (MyFunctionPointer == 0)
MyFunctionPointer = GetProcAddress(hinstLib, "MyFunctionName"); // Loads the function pointer
return (*MyFunctionPointer)(arg); // Calls it
}
This is in Windows. In Linux this is also possible to be done as easily calling dynamic libraries.
Best regards
Koldo
hu72005@gmail.com wrote:
Thanks for your quick reply sjoelund.se , I am trying to use Visual c++ file I am able to access simple function from vc++ file but having trouble in calling COM dll methods.
Hello hu72005
As sjoelund.se has said, it is easier to work with MinGW. There is a copy of it bundled with OpenModelica. It is very easy to use it but you can ask if you have problems using it.
You say that you have problems calling DLLs. Does it mean that you have a DLL and you want to call it from OpenModelica?. That would be easy too. Please confirm if this is your problem.
Best regards
Koldo
Hello hu72005
Welcome to the Forum!
Please detail us the problems you have had.
Best regards
Koldo
Hello all
I have questions about the use of "derivative" annotation I wanted to ask you. Lets put a sample.
The equation is this:
Code:
z_level = LevelZ(time);
where LevelZ(time) is an external C function, and there are also LevelZ_der(time) and LevelZ_der2(time) that are the first and second derivative.
It the code is like this, it works well...
Code:
function LevelZ_der2
input Real t;
input Real dt;
input Real ddt;
output Real res;
external
res = LevelZ_der2(t);
annotation(Library="...", Include="...");
end LevelZ_der2;
function LevelZ_der
input Real t
input Real dt
output Real res;
external
res = LevelZ_der(t);
annotation(derivative=LevelZ_der2,
Library="...", Include="...");
end LevelZ_der;
function LevelZ
input Real t
output Real res;
external
res = LevelZ(t)
annotation(derivative=LevelZ_der,
derivative(order=2)=LevelZ_der2,
Library="...", Include="...");
end LevelZ;
... although these errors appear:
Code:
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der2.
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable ddt in function .LevelZ_der2.
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der.
Error: Derivative of expression
Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.
And if the code is like this, OpenModelica ignores the derivatives...
Code:
function LevelZ_der2
input Real t;
output Real res;
external
res = LevelZ_der2(t);
annotation(Library="...", Include="...");
end LevelZ_der2;
function LevelZ_der
input Real t
output Real res;
external
res = LevelZ_der(t);
annotation(derivative(zeroDerivative=t)=LevelZ_der2,
Library="...", Include="...");
end LevelZ_der;
function LevelZ
input Real t
output Real res;
external
res = LevelZ(t)
annotation(derivative(zeroDerivative=t)=LevelZ_der,
derivative(order=2)=LevelZ_der2,
Library="...", Include="...");
end LevelZ;
... and this error appear:
Code:
Error: Derivative of expression
Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.
What is the right way to do it?
Best regards
Koldo
Hello all
Does anybody know the reason of this warning?
Best regards
Koldo
Hello all
I have got the message:
"Error: Derivative of expression
Differentiate.differentiateExpSolve failed for $DER.v_In_H * A_h - der(v_In) * A_v
is non-existent."
The model compiles and runs succesfully.
Best regards
Koldo
You are right. I did not realized that the "Equations" column in "Equations Browser" contains a copy of the equation. Just widening it the equation appear. Thank you.
Hello Sjoelund.se
True. However when clicking the debug link the "Equations browser" is opened showing the line 51, but no code is highlighted. When clicking on other lines in the "Equations browser", their equation is highlighted in "Source browser".
I have compiled and run the code using omc directly and running the .exe. I have used checkModel(), instantiateModel() and dumpXMLDAE(). The .exe has been run with -w -lv=LOG_DEBUG,LOG_STATS options. I have not got more information.
checkModel() returns "Check of Wells completed successfully.Class Wells has 42 equation(s) and 42 variable(s).14 of these are trivial equation(s).", so it is more difficult to find nonlinear system 51 as there are only 42 equations.
Best regards
Koldo
PD. I have included you a "compact" one class version of the model. Here the equition number is 55.
class MyClass
Real mes__port_p(start = 100000.0, fixed = true);
Real mes__port_T(start = 300.0, fixed = true);
Real mes__port_G;
Real mes__port_H;
Real mes__vol;
parameter Real mes__sup = 0.0;
Real mes__rho;
parameter Real mes__vol_0 = 1500.0;
parameter Real mes__A = 480.0;
parameter Real mes__T = 10.0;
parameter Real mes__phaseShift = 0.0;
Real sys_one_p;
Real sys_one_T;
Real sys_one_G;
Real sys_one_H;
Real sys_two_p;
Real sys_two_T;
Real sys_two_G;
Real sys_two_H;
parameter Real sys_N = 8.0;
parameter Real sys_c = 0.55;
parameter Real sys_Rt = 1.25;
parameter Real sys_Rh = 0.75;
Real sys_rho;
Real sys_U;
Real sys_omega;
Real sys_AT;
Real sys_v1;
Real sys_alpha_e(start = 0.01);
Real sys_alpha_e_g;
Real sys_Cx;
Real sys_C_theta;
Real sys_Cl;
Real sys_Cd;
Real sys_phi(start = 0.01);
Real sys_Pm;
Real sys_Pf;
Real sys_eta_tt;
Real sys_eta_ts;
Real sys_deltaP;
Real sys_v2y;
Real sys_v2y_U;
Real sys_alpha2(start = 1.570796326794897);
Real sys_chi;
Real sys_chi_a;
Real sys_chi_pp;
Real sys_epsilon;
parameter Real sys_omega_0 = 209.4395102393195;
parameter Real sys_Rm = 0.5 * (sys_Rt + sys_Rh);
parameter Real sys_sigma = sys_N * sys_c / (sys_Rm * 6.283185307179586);
Real atm_port_p;
Real atm_port_T;
Real atm_port_G;
Real atm_port_H;
parameter Real atm_p_cte = 100000.0;
parameter Real atm_T_cte = 300.0;
equation
mes__vol = mes__vol_0 + mes__A * sin(6.283185307179586 * (time - mes__phaseShift) / mes__T);
mes__port_p = 287.0024853296514 * mes__rho * mes__port_T;
mes__vol * der(mes__rho) + mes__rho * der(mes__vol) + mes__port_G = 0.0;
mes__vol * der(mes__port_p) + 1.4 * mes__port_p * der(mes__vol) + 0.3999999999999999 * mes__port_H = 0.0;
sys_omega = sys_omega_0;
sys_one_G + sys_two_G = 0.0;
sys_one_H + sys_two_H = sys_Pf;
sys_deltaP / (sys_U ^ 2.0 * sys_rho) = sys_v2y_U + 0.5 * (sys_v2y_U ^ 2.0 + sys_chi * (sys_phi ^ 2.0 + (1.0 + sys_v2y_U) ^ 2.0));
sys_U = sys_omega * sys_Rm;
sys_AT = 3.141592653589793 * (sys_Rt ^ 2.0 - sys_Rh ^ 2.0);
sys_phi = sys_v1 / sys_U;
sys_alpha_e = atan2(4.0 * sys_v1, 4.0 * sys_U + sys_sigma * (sys_U ^ 2.0 + sys_v1 ^ 2.0) * sys_Cl * sin(sys_alpha_e) / sys_v1);
sys_Cx = sys_Cl * cos(sys_alpha_e) + sys_Cd * sin(sys_alpha_e);
sys_C_theta = sys_Cl * sin(sys_alpha_e) - sys_Cd * cos(sys_alpha_e);
sys_Pm / (sys_U ^ 3.0 * sys_rho * sys_AT) = 0.5 * sys_sigma * sys_C_theta * (1.0 + sys_phi ^ 2.0);
sys_Pf / (sys_U ^ 3.0 * sys_rho * sys_AT) = sys_phi * (sys_v2y_U + 0.5 * sys_chi * (sys_phi ^ 2.0 + (1.0 + sys_v2y_U) ^ 2.0));
if sys_Pm > 0.0 then
sys_eta_tt = sys_Pm / sys_Pf;
sys_eta_ts = 1.0 / (1.0 + 0.5 * (sys_chi * (sys_phi ^ 2.0 + (1.0 + sys_v2y_U) ^ 2.0) + sys_phi ^ 2.0 + sys_v2y_U ^ 2.0) / sys_v2y_U);
else
sys_eta_tt = 0.0;
sys_eta_ts = 0.0;
end if;
sys_v2y_U = sys_v2y / sys_U;
sys_v2y_U = 0.5 * sys_sigma * sys_C_theta * (1.0 + sys_phi ^ 2.0) / sys_phi;
sys_chi_a = (sys_sigma * sys_Cx * (1.0 + sys_phi ^ 2.0) -2.0 * sys_v2y_U - sys_v2y_U ^ 2.0) / (sys_phi ^ 2.0 + (1.0 + sys_v2y_U) ^ 2.0);
sys_epsilon = 57.29577951308232 * (sys_alpha_e - sys_alpha2);
sys_alpha2 = atan2(sys_phi, 1.0 + sys_v2y_U);
sys_chi_pp = 0.007669 + 3.532e-006 * sys_epsilon + 2.816e-006 * sys_epsilon ^ 2.0 -6.806e-009 * sys_epsilon ^ 3.0;
sys_chi = sys_chi_a + sys_chi_pp;
if noEvent(sys_one_p >= sys_two_p) then
sys_one_p = 287.0024853296514 * sys_rho * sys_one_T;
sys_deltaP = sys_one_p -0.5 * sys_rho * (sys_U * sys_phi) ^ 2.0 - sys_two_p;
sys_two_G = sys_phi * sys_rho * sys_U * sys_AT;
sys_one_H = 3.5 * sys_one_G * sys_one_p / sys_rho;
else
sys_two_p = 287.0024853296514 * sys_rho * sys_two_T;
sys_deltaP = sys_two_p -0.5 * sys_rho * (sys_U * sys_phi) ^ 2.0 - sys_one_p;
sys_one_G = sys_phi * sys_rho * sys_U * sys_AT;
sys_two_H = 3.5 * sys_two_G * sys_two_p / sys_rho;
end if;
if sys_alpha_e < 0.2099830057683906 then
sys_Cl = 6.283185307179586 * sys_alpha_e;
elseif sys_alpha_e < 0.4808936161475124 then
sys_Cl = sys_alpha_e * (6.283185307179586 -23.19283581542516 * (-0.2099830057683906 + sys_alpha_e));
else
sys_Cl = 0.0;
end if;
sys_Cd = 0.0058 + 0.24 * sys_alpha_e ^ 2.0;
sys_alpha_e_g = 57.29577951308232 * sys_alpha_e;
atm_port_p = atm_p_cte;
atm_port_T = atm_T_cte;
mes__port_H + sys_one_H = 0.0;
mes__port_G + sys_one_G = 0.0;
atm_port_H + sys_two_H = 0.0;
atm_port_G + sys_two_G = 0.0;
mes__port_T = sys_one_T;
mes__port_p = sys_one_p;
atm_port_T = sys_two_T;
atm_port_p = sys_two_p;
end MyClass;
Hello all
Sometimes I get messages like this:
Running model...
LOG_NLS | warning | Error solving nonlinear system 51 at time 5.76583
LOG_NLS | warning | nonlinear system 51 fails: at t=5.76583
The problem is, how to know what is the equation 51?
Best regards
Koldo
Hello all
I have got "Input warnings for function mapper2" warning with a model with external functions.
What is the meaning of the message?
Best regards
Koldo
Hello all
I have some components that work well in simple models, but when they are linked in a more complex model, this error appears:
"Error: Internal error ./Compiler/BackEnd/BackendDAETransform.mo: function findDiscreteEquation failed
Your model contains a mixed system involving algorithms or other complex-equations.
Sorry. Currently are supported only mixed system involving simple equations and boolean variables.
Try to break the loop by using the pre operator."
What does it mean?
Edit:
In addition, I have changed the system so that there are no Integer variables, but the result is the same.
I am using latest nightly build
Well, I think the question is relevant. However in my case I have found the root cause of the problem: a couple of tan() functions. Just replacing tan() with atan2(), the problem has been solved, because tan() introduces artificial discontinuities and multiple solutions. Certainly, after analising the case and reading this, tan() function is as dangerous as a bag of bombs :-)
Hello all
I have a model with variables that can have more than one solution. To try to avoid this, I have used the min and max when declaring the variable. However Modelica just informs that the min or max has been passed, but it does not try to avoid the unwanted solutions.
Do you know how to "force" the system to use the right solutions, or tricks to avoid ths?
Best regards
Koldo
Well. In fact instantiateModel() or dumpXMLDAE() do not require a previous call to buildModel().
Oh, found!
There is a lot of power in .mos file. Just adding some lines to .mos we can get it.
buildModel(MyModel);
writeFile("MyModel_instantiated.mo", instantiateModel(MyModel));
dumpXMLDAE(MyModel);
Best regards
Using omc, I would like to ask you how to get an output or dump of all instantiated equations.
The reason is for debugging. I have got the error "Too few equations, under-determined system". I would like to check thoroughly the final equations.
Using OMEdit is easy, just with option "Simulation/Instantiate model".
Running omc using +i=className, I do not get any output.
Best regards
No
Hello maxev5
The easiest way to do it is by changing the value of those parameters in the .xml file.
Best regards
Koldo
Hello Fnoel
FMU SDK includes a sample with a simple Euler solver. You can run your model in OpenModelica and choose "euler" solver to know if it is enough for you. It it does not work in OpenModelica you can see this post (https://www.openmodelica.org/index.php/ … c?id=1173)
Best regards
Koldo
Hello kinzzoku
You are welcome . If you converted those models to FMU I suppose you wanted to run them coupled to other model so I propose you these options:
- Run your OpenModelica FMU for model exchange from a home made improved solver: Absolutely not advised
- Run your OpenModelica FMU for model exchange from a solver: OpenModelica or others
- Run your OpenModelica model as a standalone exe with sockets communication to other processes or even models.
Best regards
Koldo
Hello kinzzoku
Forward Euler can solve some systems but many other require more powerful methods as rungekutta or dassl and it is also important to manage the events like zero crossing.
Have you tried your models directly inside OpenModelica using Euler and they work fine?
Best regards
Koldo
Hello kinzzoku
OpenModelica generates FMU for model exchange. Please describe the solver you use to run your FMU.
Best regards
Koldo
Hello peb
As far as I know the only way is using sockets. You can use the links in this post (https://www.openmodelica.org/index.php/ … c?id=1113) as a reference.
Best regards
Koldo
Well, it is also confirmed in the paper "A Generic FMU Interface for Modelica" by Wuzhu Chen, Michaela Huhn and Peter Fritzson presented in EOOLT 2011 conference. Authors say:
"The FMI function fmiCompletedIntegratorStep cannot be defined and called properly in Modelica, since Modelica language does not provide the functionalities, through which the status of a integration step can be queried and when an integrator step is finished can be detected."
You're welcome
Anyway a question still unsolved for the Modelica model is to know exactly the simulation steps.
Now the model do not know when a step has finished. That is a matter of the solver and remains hidden for the model. This makes more difficult to couple simulations.
Thank you sjoelund.se
I wonder if there is something similar to fmiEventUpdate(). This function appears in the automatically generated .mo file when doing FMI, and "is called after a time, state or step event occurred ... the function returns once a new consistent state has been found". This and other functions are located in SimulationRuntime/fmi/import/fmuWrapper.c.
Is there any trick that could fire a "when" under an algorithm section just before or after an iteration step has been successfully finished?
Hello!
How is it possible to do something once every solver iteration?
The expressions:
- when change(time)
- when time > pre(time)
are not permitted.
Best regards
Koldo
Hello pco38
You can do it using sockets. There is a sample here (http://www.modelica-forum.com/forums/lo … p/t17.html) that is also referenced here (http://kempproject.blogspot.com.es/2013 … art-1.html).
This sample shows communication between an OpenModelica simulation and other programs for co-simulation.
It is very simple. If you find any problem please post it.
Now OpenModelica supports CORBA for communication with simulations. However most of times OpenModelica users do not need the sophisticated CORBA interface. A very simple message exchange library as the one shown in example is just enough. It would be great if OpenModelica project would include something similar.
Best regards
Koldo
This is not urgent.
My OMC used a newer gcc version because of a PATH problem.
Changing the PATH to run the OpenModelica supplied MinGW, the warning disappears, so this warning could appear in the future. .
Edit: I have provoked an OMC error and this warning appears again, so OMC hides gcc warnings and only shows them if there is also a gcc error.
In summary, posted warning exists in MinGW version supplied with OMC.
Hello all
Yesterday I updated OpenModelica and now this warning appears when running omc. That file is automatically generated by omc:
Code:
MyModel_05evt.c: In function 'MyModel_zeroCrossingDescription':
MyModel_05evt.c:69: warning: assignment discards qualifiers from pointer target type
That function contains this:
Code:
const char *MyModel_zeroCrossingDescription(int i, int **out_EquationIndexes)
{
static const char *res[] = {"terminal() and time > 0.1"};
static const int occurEqs0[] = {1,193};
static const int *occurEqs[] = {occurEqs0};
*out_EquationIndexes = occurEqs[i]; // Warning points here
return res[i];
}
Best regards
Koldo
Hello Yahya
As far as I know Modelica does not include a standard way to implement PDEs.
However if your geometry is not complex you can assemble the equation system of the discretisation easily by hand.
There is an excellent example in the book "INTRODUCTION TO PHYSICAL MODELING WITH MODELICA" by Michael Tiller, page 120.
Best regards
Koldo
Great sjoelund.se!
It works even in Windows. Just put -port instead of -p in
Code:
$ ./ModelName -port 12345
Best regards
Koldo
Hello Cristian
As far as I know you cannot load directly a DLL into OpenModelica. However you can easily create a lib with some C functions using LoadLibrary() and GetProcAddress() to load the DLL and calling the DLL functions.
If you need more details we will be glad to answer you.
Best regards
Koldo
dersh wrote:
I am also seeing:
Translation 14:39:36 0:0-0:0 The initial conditions are not fully specified. Use +d=initialization for more information.
I am not sure, from the warning, where or how to us +d=initialization? Or how to set initial conditions so this warning going away. Can anyone offer any guidance?
Does this just mean that some of the variables in my model need start=0.0 (or whatever is an appropriate value?).
Thanks,
--Adam
Hello dersh
To get the later messages +d=initialization was used.
Probably some "start" or "fixed" conditions are necessary. However I do not know where.
Best regards
Koldo
Hello all
There are now some new warning messages including OMC parameter "+d=initialization" I would like to understand. Could you analise it?
Code:
Trying to fix over-determined initial system
========================================
Variables (0)
========================================
Equations (1, 1)
========================================
1/1 (1): 10.0 * v1 + 100.0 * v2 = 0.0
State Sets
========================================
no matching
record SimulationResult
...
end SimulationResult;
"Warning: Trying to fix over-determined initial system Variables 0 Equations 1... [not implemented yet!]
Warning: System is over-determined in Equations 1: 10.0 * v1 + 100.0 * v2 = 0.0;
Warning: Iteration variables with default zero start attribute in equation system:
$DER.v1:DUMMY_DER(fixed = false ) .MyModel, .Real type: Real
"
The model is:
Code:
model MyModel
constant Real rho = 1000;
constant Real g = 9.81;
constant Real S1 = 10;
constant Real S2 = 100;
constant Real h = 50;
Real m1(fixed = false);
Real m2(fixed = false);
Real x1(start = 5, fixed = true);
Real x2(fixed = false);
Real v1(start = 0, fixed = true);
Real v2(start = 0, fixed = true);
equation
m1 = rho*S1*(h + x1);
m2 = rho*S2*(h + x2);
S1*x1 + S2*x2 = 0;
v1 = der(x1);
v2 = der(x2);
v1^2/2 + (h + x1)*(g + der(v1)) = v2^2/2 + (h + x2)*(g + der(v2));
end MyModel;
Hello sjoelund.se
adeas31 indicates in ticket2131(https://trac.openmodelica.org/OpenModelica/ticket/2131) that problem has been solved in r16576(https://trac.openmodelica.org/OpenModel … eset/16576).
However the sample fails again .
Best regards
Koldo
Hello tgraeber
As far as I know it is possible through FMI standard. For example you can load a Simulink simulation from OpenModelica using ImportFMU or export an FMU from OpenModelica to Simulink.
You can find information about it in the Forum.
Best regards
Koldo
True sjoelund.se. It is an accepted defect in OpenModelica FMI support. Thank you.
So write that C/C++ library
I would like to do it . However it is a rather complex project, nothing to do with co-simulation.
If you want to have a rough idea, just open the model automatically created when an importFMU() is done.
Edited: In fact OpenModelica runtime libraries include all the necessary nuts and bolts. The best FMI library is just here . However OpenModelica license does not let to do it.
From this post (http://scicomp.stackexchange.com/questi … fmu-models). An OpenModelica model can open one FMU but not two. The .exe generated by OMC with this sample crash. However it runs in Dymola:
File TestFMU1.mo:
Code:
model TestFMU1
parameter Real p = 1.0;
connector TestOutputConnector
output Real value;
end TestOutputConnector;
TestOutputConnector c;
equation
c.value = p;
end TestFMU1;
File TestFMU2.mo:
Code:
model TestFMU2
Real result;
connector TestInputConnector
input Real value;
end TestInputConnector;
TestInputConnector c;
equation
result = c.value;
end TestFMU2;
Both of these are exported as FMUs and imported and combined as follows:
Code:
model TestConnection
TestFMU1_fmu OutputFMU;
TestFMU2_fmu InputFMU;
equation
connect(OutputFMU.c_value, InputFMU.c_value);
end TestConnection;
That is true although with nuances :
- OpenModelica translateModelFMU() cannot produce FMI for co-simulation, only for model exchange
- There are no C/C++ libraries that can simulate a FMI for model exchange. PyFMI from Modelon can do it, but is made in Python. FMIL from Modelon can only simulate FMI for co-simulation.
The paper "A Generic FMU Interface for Modelica" by Wuzhu Chen, Michaela Huhn and Peter Fritzson, published in the 4th International Workshop on Equation-Based Object-Oriented Modeling Languages and Tools. September, 2011, explains:
- how to load two samples of a FMU in OpenModelica: It does not work . It is like OpenModelica does not consider replaceable keyword generating an FMU.
This model hangs simulate():
Code:
model FMUMultipleInstance
BouncingBall_me_FMU model1, model2;
end FMUMultipleInstance;
model BouncingBall_me_FMU
...
- how to load an FMU and mix it with other equations: This works very well . For example:
Code:
model FMUMultipleInstance
BouncingBall_me_FMU model1;
Real myVar;
equation
der(myVar) = model1.h + 1;
end FMUMultipleInstance;
model BouncingBall_me_FMU
...
Hello all
An idea to load two FMU into a model was that both models would be partial and the linking equations (the equations that link the variables of both FMU models) would be in the master model.
This way it would be possible to do tight coupling of FMU for model exchange from a OM master model.
For example:
Code:
model Master
FMU_Model1_me_FMU model1; // Loaded from FMU_Model1_me_FMU.mo
FMU_Model2_me_FMU model2; // Loaded from FMU_Model2_me_FMU.mo
equation
model1.out = model2.in;
end Master;
However translateModelFMU():
- does not permit partial models
- does not permit models with less equations than unknowns
Best regards
Koldo
Hello all
I have tested successfully converting a model to FMU for model exchange, opening the FMU and running the simulation. It is very easy just from OMShell:
Code:
loadFile("BouncingBall.mo")
translateModelFMU(BouncingBall)
importFMU("BouncingBall.fmu")
loadFile("BouncingBall_me_FMU.mo")
simulate(BouncingBall_me_FMU, stopTime=3.0)
Do you know how to extend this sample by doing two FMUs, loading them, connecting the variables in a master model and running it all?
The automatically generated model "BouncingBall_me_FMU.mo" is not very easy to understand.
Best regards
Koldo
Other focus: Is it possible for an external program to force an .exe simulation generated by OMC to do a step by step simulation? (through sockets or CORBA)
If true, would it be possible that this external program could get/set values from/to the simulation?, and would it be possible to change the simulation step?
Hello sjoelund.se
We are trying to do co-simulation with Modelica and a powerful international university based GPL-3 CFD tool.
We are convincing the CFD tool developers to support FMU including the solver inside. Unfortunately our Modelica simulation is rather stiff: it only works with DASSL and it does not with euler or runge kutta.
I have the personal conviction to use OpenModelica. However we suffer a strong pressure to use a commercial Modelica environment. They promise to have lower project costs including year licenses and for now it seems that it is true: the budget of getting the year OpenModelica licenses and hacking OMC code base would be higher.
I would like to demonstrate that OpenModelica is the best option and I would love to have a joint open simulation, helping to extend the OpenModelica universe. All the results would be properly shown in a paper.
Could you advice me? What is your opinion?
Sorry sjoelund.se. It was a joke: I do know it is not possible to do that with the free (gratis) license.
Do you know if is there a sample like the M. Tiller one but using a real solver like SUNDIALS?
Thank you Adeel. I see.
sjoelund.se: Perhaps a way to do it would be to reverse engineer OpenModelica importFMU() function
sjoelund.se wrote:
If you want all the nice stuff in OpenModelica, don't use FMI Or wait a few (months? years?) before FMI for co-simulation is added and is stable.
... But can be done co-simulation with OpenModelica without FMI ?
AFAIK OpenModelica can export slave FMU for co-simulation. Is there a way (perhaps in beta) to do a good simulation mixing OpenModelica and other solvers with all the SUNDIALS stuff inside?
Hello sjoelund.se
That is a nice example from Michael Tiller. However I cannot see how it takes care of zero-crossing and things like that. I would prefer to use the OpenModelica solver technology instead of reinventing the wheel or doing reverse engineering of the same OpenModelica. This link could be interesting (http://www.claytex.com/exporting-models … her-tools/) .
I will read carefully this evening the FMU 2.0 for Co-Simulation...
Hello sjoelund.se
Following your links there are many other links. I have opened some of them but they do not seem to include any solver.
AFAIK the FMI interface for co-simulation supposes that the FMU includes the solver. Here (http://www.jmodelica.org/5337) it is said that OpenModelica does not support co-simulation FMUs.
I would like to integrate a OpenModelica model with a CFD to do co-simulation. For that I would need to include the solver with the OpenModelica FMU in any way. Is it possible to change the FMU compiling parameters in any way to include a kind of -lSUNDIALS in .DLL linking? Would it work?. Please see this comment about how it is done in Dymola (http://www.claytex.com/exporting-models … her-tools/)
Thank you very much
Koldo
Hello sjoelund.se
As I have understand you, a program to load a FMU generated with OpenModelica has to include the solver.
Is there a simple sample about how to do that?
Thank you very much
Koldo
Hello all
I would like to know your opinion about which of them is better for my needs. I have been using OpenModelica for many months successfully. However Dymola seems to promise:
- a faster simulation time (actually some of my models last for some days in being simulated)
- full co-simulation (now OpenModelica FMU does not use DASSL so it does not serve for the models I run)
What is your opinion?
Kind regards
Koldo
Hello sjoelund.se
Could you explain the scodeInstShortcut flag?
I have tried to find any doc about it unsuccessfully.
Best regards
Koldo
Hello sjoelund.se
If I could I would do it. However it would require to do deep changes inside OMC code.
It seems that it can be done only by core OpenModelica developers.
Best regards
Koldo
Hello sjoelund.se
Is there a way to define what solver to use or include in FMI?
Best regards
Koldo
Hello mariomar
G cannot be in that position and has to be declared in the beginning before the equation section.
In addition G cannot be a parameter as it is defined using R, that is a variable.
Now the easiest way is to let G to be a variable instead of a parameter, and to remove the =1/R in the initialization, as you have put the equation G = 1/R.
In addition you can put this equation only once instead of copying it to all if - elseif, iI mean:
Code:
equation
G=1/R;
if num == 0 then
L / (4 * (nodes - 1)) = L_1;
L_1 / (H * W * k_bar) = R;
elseif num == 1 then
L_1 = (3 * L) / (4 * (nodes - 1));
R = L_1 / (H * W * k_bar);
elseif num == 2 then
L_1 = L / (nodes - 1);
R = L_1 / (H * W * k_bar);
end if;
best regards
Koldo
Hello sjoelund.se
I have tried to use gcc-mingw optimizations (-O3) and now they work perfectly with the compiler supplied.
I will try to compile OMC. However now it is not so important
Best regards
Koldo
Koldo wrote:
I have obtained a FMU and tested it with the FMU Compliance Checker from https://www.fmi-standard.org/downloads.
Unfortunately although the standalone .EXE runs perfectly, the FMU fails with the message "FMU could not converge with in event update" error just in the 0.2 simulation second.
Other detail is that the .EXE is about 5Mb and the DLL is about 1Mb
Does perhaps the OMC FMI support is partial, or maybe I am doing anything wrong?
Best regards
Koldo
A detail to add is that the original model works using DASSL. However it fails using RUNGE-KUTTA or EULER.
Does FMI work with EULER by default?
Hello tonyng05
Please send us as many details as possible of the operating system you use and other details. In addition please include literally the errror messages you get.
In my opinion the easiest way to check OpenModelica is opening OpenModelica Notebook and running the examples. If you like one of them you can change it and see the results.
Please try all of this and tell us the results
Hello Lars
I get this error in Windows 7:
Assertion failed: NULL == "index out of bounds", file Iteration_step.c, line 341
Best regards
Koldo
Hello Sgasnier
Excuse me, could detail a little bit more what you need?
there isn't any variable which is linked to the time.
In fact "time" gets you the simulation time. Did you refer to this?
Best regards
Koldo
Hello sjoelund.se
Thank you for the advice.
I am trying to do it because in the model I use C libraries that have to be compiled without optimizations If I try to add any optimization to the minimum file with the simplest math operations, I get strange results.
However this happened to me some versions ago. I will try it again to see if the problem with the supplied compiler is solved.
Thank you!
Koldo
Hello all
I wanted to compile OMC in Windows and I had some questions:
- What are the required dependences?
- Are there a place with instructions?
- I wanted to compile it with MinGW 4.7. Is OpenModelica compatible with it?
Best regards
Koldo
I have obtained a FMU and tested it with the FMU Compliance Checker from https://www.fmi-standard.org/downloads.
Unfortunately although the standalone .EXE runs perfectly, the FMU fails with the message "FMU could not converge with in event update" error just in the 0.2 simulation second.
Other detail is that the .EXE is about 5Mb and the DLL is about 1Mb
Does perhaps the OMC FMI support is partial, or maybe I am doing anything wrong?
Best regards
Koldo
Hello
I have tried both cases with +d=bltdump,tearingdump,dumpindxdae,dumpInlineSolver,bltdump and the dumps are identical but the 0-0.001 numbers.
I imagine that perhaps the issue is inside DASSL.
Bet regards
Koldo
Hello all
Finally I got the problem. When modeling a variable section check valve, this code is very slow:
Code:
if noEvent(p_in > p_out) then
area = area0*(press_in - press_out)*press_factor;
else
area = 0;
end if;
And this is about 100 times faster:
Code:
if noEvent(p_in > p_out) then
area = area0*(press_in - press_out)*press_factor;
else
area = 0.001; // The only change
end if;
In fact the last is better because it is expected to have some leakage in the valve (^_^).
Do you know the reason of it?
Best regards
Koldo
Hello all
FMI option seems a great solution. However kermit_d says that it was a total failure. What happened?. Does anybody know where it is explained how to use the FMI DLL generated by OMC?
Best regards
Koldo
Hello all
I wanted to do a simulation of a heated and presurized air flow through some tanks (volume controls) and non return valves. I have implemented the model and it works well. However, it runs terribly slow. I have tried to include all the advices to improve the results, but the results are not better.
I have seen that it exists a library called Thermoflow that could fit. Does anybody knows it or another libraries to solve these kind of models?
Thank you very much in advance.
Koldo
Hello sjoelund.se
I have seen that nc listen TCP connection in Linux. In my case I am in Windows and the simulation duration is variable: the model decides when to stop.
Anyway sockets do not seem so difficult. I have collected a couple of samples and I will try them.
Best regards
Koldo
Hello sjoelund.se
I want the OpenModelica program to periodically send host program:
- the simulation time: To follow the simulation speed.
- some variables: SImulation time is not fixed and stops when some variables are stable
I will try to learn TCP sockets that seem to be the reliable way. It does not seem to be simple but it seems to be the only way.
Thank you
Koldo
Hello sjoelund.se
In my case there is a main GUI program that:
- Calls OMC to compile the .mos and .mo files
- Change some parameters in the XML
- and call the exe to get the results
However I would like to get some communication between the OMC compiled .exe and the main program, because the simulations sometimes take a long time.
What is the best way to do it? Is there a simple sample?
Best regards
Koldo
Hello Adrian
Thank you for your fast answer. PlanarMechanincs is better than I expected.
It runs just out of the box and is good for learning as an intermediate step between 1-D and 3-D.
It would be great if it could be released with OpenModelica library.
Best regards
Koldo
Hello all
I wanted to simulate a planar structure but I have failed to do it by hand from 1-D and from 3-D mechanical libraries.
Is there available a 2-D mechanical version?
I have seen information about a PlanarMultiBody library. However I have not seen their code.
Thank you
Koldo
- Index
- » Users
- » Koldo
- » Profile