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
  • » adamLange
  • » Profile

Posts

Posts

Hello,

Today I released an open-source modelica-to-HDL interface generator: https://github.com/adamLange/hdlModelicaInterfaceGen

I've had success with the coupling method, explained here: https://hackaday.io/project/161284-coup … imulation/

The interface generator is still a work in progress.  I should be using the generator for the first time in about a day.  In a few days, there will be less bugs.

Adam

I clamped the range of the temperature in my external c code and retained the original function call signature.  It seems to work now.   

I'm using an external thermodynamic properties library, Cantera.  I have a whole bunch of external functions that are used to interface Cantera to Modelica.  The model is crashing because there's a negative temperature being supplied.  All of the temperatures that I can see in the output are well within the acceptable range, so I suspect a negative temperature is being passed as a result of a linear solver, non-linear solver, or a numerical jacobian evaluation.

Any ideas for how to track down the precise cause of the bad call?  I suppose I could try to figure out how to run the executable with gdb or something and get a backtrace.  Is that a good way?

I've been thinking about how I can code defensively so that negative temperatures don't get the the external library and cause it to throw and error and crash the simulation. 

This is what an example wrapper looks like now:

Code:

extern "C" void rho_TPY(void* obj,double T, double P, double* Y,

    double* rho)
{
  CanteraGas* cantera = reinterpret_cast<CanteraGas*>(obj);
  cantera->gas.setState_TPY(T,P,Y);
  *rho = cantera->gas.density(); //kg/kmol
  return;
}

I might try to add logic so that negative temperatures don't get sent to Cantera and add a error value the call signature.  Can modelica do anything with the error return variable in this proposed revision? 

Code:

extern "C" void rho_TPY(void* obj,double T, double P, double* Y,

    double* rho, int* error)
{
  CanteraGas* cantera = reinterpret_cast<CanteraGas*>(obj);
  if (*T >= T_min)
  {
      cantera->gas.setState_TPY(T,P,Y);
      *rho = cantera->gas.density(); //kg/kmol
      *error = 0;
  }
  else{*error=1;}
  return;
}

Thanks for your help

Adam

May-18-17 19:47:44
Possibility to start and stop simulation using radio button blocks

Hi Maria,

I was thinking of doing something like this by using an external function that connects to a gui over sockets.

There is an example here:
https://github.com/adamLange/modelicaSocketExample

In the example there is a python server, server.py.  An external modelica function connects to the server over a socket.  The python server is just taking to operands and returning the average value.  Following this same pattern you could add some widgets to the python server for whatever interaction it is that you need.

Another example that might be useful:
https://github.com/adamLange/podRunSim

Hope that helps,
Adam

--preOptModules+=introduceDerAlias didn't really make much difference.  Using this flag didn't allow the newtonXTol and FTol tolerances to be set lower like I was hoping it might.  Furthermore, the error doesn't seem to be effected very much by changing the nonlinear tolerance.

When the simulation is starting, there is usually a warning: Matrix singular!  The simulation completes despite the warning.  (with the ida solver, dassl fails partway through the solution) So maybe singular matrix warning is an indication that there is a very poorly conditioned matrix as a consequences of the system being modeled?

I also tried to switch the index reduction method.  The simulation will run to completion with dynamicStateSelection but dummyDerivatives fails with a translation error: Internal error BackendDAETransform.analyseStrongComponentBlock failed.

Here's a little update.  I reduced the tolerance of the nonlinear solver using the flags newtonXTol and newtonFTol until the simulation failed to converge.  Unfortunately this did not improve the solution noticeably.

I found this ticket:"Convergence issues on nonlinear equations involving der()" https://trac.openmodelica.org/OpenModelica/ticket/3111 Perhaps the issue cited in this ticket is preventing my model from converging when the newtonXTol and newtonFTol are low enough.  Does that sound like reasonable hypothesis?

It getting late here now but tomorrow when I resume I'm going to try these flags:

--preOptModules+=introduceDerAlias

This flag's depricated predecessor is mentioned in the ticket 3111 as a work-around solution.

--postOptModules+=addScaledVars_states

Does this sound like a reasonable plan of attack?  Any further suggestions?

Hi there,

I'm trying to figure out what's going wrong here.  MX_u[1] should be constant in this plot:
http://i.imgur.com/ot7OCJn.png

I extracted some relevant equations from the <model>.json (bottom of this post)

Maybe scaling or non-linear solver tolerance is the problem?  Has anyone had a problem like this before?  Any hints for how to attack this problem?

The interesting part of the problem is that although equation index 272 states: der(thermoReactor1.MX_u[1]) = 0.0,
in the results der(thermoReactor1.MX_u[1]) is non-zero.

Code:

[{u'defines': [u'der(thermoReactor1.MX_u[1])'],

  u'eqIndex': 272,
  u'equation': [u'0.0'],
  u'section': u'regular',
  u'source': {u'info': {u'colEnd': 0,
    u'colStart': 0,
    u'file': u'',
    u'lineEnd': 0,
    u'lineStart': 0}},
  u'tag': u'assign',
  u'uses': []},
{u'defines': [u'thermoReactor1.MX_u[1]'],
  u'eqIndex': 294,
  u'equation': [u'thermoReactor1.M_u - (thermoReactor1.MX_u[2] + thermoReactor1.MX_u[3] + thermoReactor1.MX_u[4] + thermoReactor1.MX_u[5] + thermoReactor1.MX_u[6] + thermoReactor1.MX_u[7] + thermoReactor1.MX_u[8] + thermoReactor1.MX_u[9])'],
  u'parent': 321,
  u'section': u'regular',
  u'source': {u'info': {u'colEnd': 18,
    u'colStart': 3,
    u'file': u'/home/adam/projects/machine/models/Machine/ThermoReactorBase.mo',
    u'lineEnd': 99,
    u'lineStart': 99},
   u'instance': u'thermoReactor1',
   u'within': [u'Machine.ThermoReactor$thermoReactor1']},
  u'tag': u'assign',
  u'uses': [u'thermoReactor1.MX_u[9]',
   u'thermoReactor1.MX_u[8]',
   u'thermoReactor1.MX_u[7]',
   u'thermoReactor1.MX_u[6]',
   u'thermoReactor1.MX_u[5]',
   u'thermoReactor1.MX_u[4]',
   u'thermoReactor1.MX_u[3]',
   u'thermoReactor1.MX_u[2]',
   u'thermoReactor1.M_u']},
{u'defines': [u'thermoReactor1.ai.MX[1]'],
  u'eqIndex': 322,
  u'equation': [u'thermoReactor1.MX_u[1]'],
  u'section': u'regular',
  u'source': {u'info': {u'colEnd': 0,
    u'colStart': 0,
    u'file': u'',
    u'lineEnd': 0,
    u'lineStart': 0}},
  u'tag': u'assign',
  u'uses': [u'thermoReactor1.MX_u[1]']},
[],
[{u'defines': [u'thermoReactor1.MX_b[5]',
    u'thermoReactor1.MX_b[2]',
    u'thermoReactor1.MX_b[7]',
    u'thermoReactor1.MX_b[9]',
    u'thermoReactor1.MX_b[6]',
    u'thermoReactor1.MX_b[3]',
    u'thermoReactor1.MX_b[8]',
    u'thermoReactor1.MX_b[4]',
    u'thermoReactor1.MX_u[3]',
    u'thermoReactor1.MX_u[4]',
    u'thermoReactor1.MX_u[7]',
    u'thermoReactor1.MX_u[6]',
    u'thermoReactor1.MX_u[2]',
    u'thermoReactor1.MX_u[8]',
    u'thermoReactor1.MX_u[5]',
    u'thermoReactor1.MX_u[9]',
    u'thermoReactor1.M_b',
    u'thermoReactor1.M_u',
    u'thermoReactor1.V_b',
    u'thermoReactor1.T_b',
    u'thermoReactor1.p',
    u'thermoReactor1.T_u'],
   u'display': u'non-linear',
   u'eqIndex': 321,
   u'equation': [[285,286,287,288,289,290,291,292,293,294,295,296,297,298,299,300,301,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320],
    []],
   u'section': u'regular',
   u'tag': u'container'}]]

I'm going to try these:

-newtonFTol=value or -newtonFTol value
    Tolerance respecting residuals for updating solution vector in Newton solver. Solution is accepted if the (scaled) 2-norm of the residuals is smaller than the tolerance newtonFTol and the (scaled) newton correction (delta_x) is smaller than the tolerance newtonXTol. The value is a Double with default value 1e-12.

-newtonXTol=value or -newtonXTol value
    Tolerance respecting newton correction (delta_x) for updating solution vector in Newton solver. Solution is accepted if the (scaled) 2-norm of the residuals is smaller than the tolerance newtonFTol and the (scaled) newton correction (delta_x) is smaller than the tolerance newtonXTol. The value is a Double with default value 1e-12.

Hello,

Is there a separate tolerance that can be set for the non-linear solver?  I'm getting some bad results.  I suspect the problem is related to the tolerance of a non-linear solver.

Is this right?:
  - there are different tolerances for the integration step and for the non-linear solver. 
  - there is a default tolerance applied to the non-linear solver.
  - an appropriate simulation flag must be passed to override the non-linear solver tolerance.

Adam

I'm wondering how I can squeeze a little more performance out of OpenModelica...  I have a model with a run time that is just a little too long to be practical.  To this point I've been using DASSL.  Is looking inside DASSL a good place to start looking for performance gains?  What is going on inside of DASSL?  Is there anywhere linear algebra routines are being called that could be made parallel?

Best regards,
Adam

I'm using an external, c++ library to calculate properties of a medium.  Construction of the c++ object is expensive, so I am trying to do it only once.  In order to use the Fluid library components I think what I need is a way store a instance of the external object in the medium package.  Packages can't store instances of ExternalObjects though, can they?

Hello,

I'm defining a new medium for use in with the fluids components in the standard library.  I followed the guidelines in the build in documentation in the Medium package.  Now I'm trying to run this test:

Code:


within gri30;

model Test_gri30
   extends Modelica.Media.Examples.Tests.Components.PartialTestModel(
            redeclare package Medium = gri30);
end Test_gri30;

When I run Test_gri30, I get this error:

Code:


[1] 08:52:33 Error
OMC unable to load `./Modelica_specificEnthalpy_pTX_15.so': ./Modelica_specificEnthalpy_pTX_15.so: undefined symbol: omc_Modelica_Media_Examples_Tests_Components_FluidPort__a$shortPipe$port__a_Medium_setState__pTX.

...

[16] 08:52:33 Error
OMC unable to load `./gri30_Test__gri30_Medium_specificEnthalpy__pTX.so': ./gri30_Test__gri30_Medium_specificEnthalpy__pTX.so: undefined symbol: omc_gri30_Test__gri30_Medium_setState__pTX.


[17] 08:52:33 Translation Error
Error occurred while flattening model gri30.Test_gri30

Any hints?

Thank you,

Adam Lange

I can dedicate 60 hours in the next two weeks to help with anything on this system.  Please let me know if you make any progress on the licensing and release.

Is there any way I can help with the development of the TLM co-simulation framework?

Hello,

I'm interested in learning to use the TLM co-simulation features of Open Modelica.  I have a model which has become quite complex and is taking a long time to run.  I'm hoping I can break it into pieces and run them in parallel with TLM co-simulation.

I'm looking for a good foot-hold to get started.  So far I've found this:
  https://openmodelica.org/doc/OpenModeli … ation.html

Is everything I need to get started included here: https://github.com/OpenModelica/OpenModelica? or are there other dependencies?

Thanks!
Adam

I got it to work.  I'm not exactly sure what the problem was, but it seems to be working now.

I know that for -override the syntax is something like this:

Code:


-override=startTime=0,stopTime=30,stepSize=0.0003,tolerance=1e-06,solver=dassl,outputFormat=mat,variableFilter=.* 

What is the format of the file passed to -overrideFile?  xml?  or just a file with the same contents that you would pass to -override?

Hello.  I'm having quite a hard time overriding the the path for the combiTable1Ds1 in my model.  Does combiTable1Ds1.fileName need to be specified at compile time or something?

Hello.

I'm trying to run the executable that was created after I ran my model from within OMEdit and I am changing the values in model_init.xml to run with different variable values.  It also seems that the executable needs model_info.json.  What is model_info.json for?  Do I need to do anything with it for this to work right?

Thanks.
Adam

Yep, that was it:

In a component I tried to call the external function with the "c" call signature and this generated the error failed to elaborate expression:

Code:

equation

  getEddyBrakeData(con,v,h,f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean);
  ...

I changed the modelica code to this and now there's no problem!:

Code:

equation

  (f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean) = getEddyBrakeData(con,v,h);
  ...

I think I found the answer in the Modelica specification version 3.3 revision 1 section 12.9.5.2:

12.9.5.2 Arbitrary Placement of Output Parameters, No External Function Value
[In the following example, the external function call is given explicitly which allows passing the arguments in a
different order than in the Modelica version.

Code:


function foo
input Real x;
input Integer y;
output Real
u1;
output Integer u2;
external "C" myfoo(x, u1, y, u2);
end foo;

This corresponds to the following C-prototype:

Code:


void myfoo(double, double *, int, int *);

Example call in Modelica:

Code:

(z1,i2) = foo(2.4, 3);

Translated call in C:

Code:

myfoo(2.4, &z1, 3, &i2);

]

There are only three inputs.  f_drag, f_lift, H_y_max, H_y_mean, q_max, q_mean are all outputs.

Code:


function getEddyBrakeData
    input EddyBrakeConnection con;
    input Real v;
    input Real h;
    output Real f_drag;
    output Real f_lift;
    output Real H_y_max;
    output Real H_y_mean;
    output Real q_max;
    output Real q_mean;
    external "C" getEddyBrakeData(con,v,h,f_drag,f_lift,H_y_max,H_y_mean,q_max,q_mean) annotation(
        Library="eddybrakeclient",
        LibraryDirectory="modelica://PodRunSim/ExternalLibraries");
  end getEddyBrakeData;

The c function is defined as follows:

Code:

int getEddyBrakeData(void* object,

  double v,double h,
  double* f_drag,double* f_lift,
  double* H_y_max,double* H_y_mean,
  double* q_max,double* q_mean)

The outputs are written to wherever the pointer point.

Would it be better if return the outputs as an array?

Hello,

I've got a model that giving me a Translation Error.  I can't tell too much about the problem from the error message:

[1] 16:49:53 Translation Error
[PodRunSim.Components: 23:5-23:74]: Failed to elaborate expression: .PodRunSim.Utilities.getEddyBrakeData(con, v, h, f_drag, f_lift, H_y_max, H_y_mean, q_max, q_mean).

[2] 16:49:53 Translation Error
Error occurred while flattening model PodRunSim.Examples.HelloPodRunSim

The model is HelloPodRunSim in the dev branch of this repo: https://github.com/adamLange/podRunSim

What might be causing this error?

Adam

Here's the example in case you'd like to check it out:

https://github.com/adamLange/modelicaSocketExample

Thank you sjoelund.se and swaroop.katta!

I read the chapter in the modelica specification about external classes.  For an example case I'm making a python server that returns the mean of two numbers and a model that calls the server to get the average.  I've got everything roughly implemented.  The communication is handled with a unix socket.  I'm still working out a few bugs and then need to get rid of some of the hardcoded paths (seeing how arguments are passed for the serial example will help with this...). Its going pretty well overall.

Adam


Hello everyone,

I'm planning making a server application that will communicate with a client that is an external function.  The communication will be sockets or shared memory.  If possible I'd like to make the client stateful so the connection doesn't have to be re-made each time the external function is called.  Is there a some way to do this or should I just try making the connection on every external function evaluation?

Adam

Hello,

I am investigating the feasibility this project.  I would like to couple Open Modelica and the Moose Multiphysics Framework.  Moose solves systems of non-linear PDE's on finite elements using libmesh and petsc.  There is a interface in Moose where you can add scalar equations to the system of equations being solved in the Moose problem.  My idea is to create a solver for Open Modelica which uses Moose as a backend.  That way, the system of equations including the modelica model and the PDE on N-D finite elements can solved in one system of non-linear equations.

I'm starting to look around in Open Modelica source code to see how the system of equations is assembled and passed to the solver.  I've started here: OpenModelica/OMCompiler/SimulationRuntime/c

Are there any places in particular where you would recommend looking?  Is there any documentation relevant to this problem that you would recommend reading?

Adam

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