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

Posts

Posts

Oct-07-15 16:36:27
I'm looking for developers interested in helping me finish a pure python modelica compiler.
Category: Developer

I just finished a hello world ipython notebook example using pymola:

Features:
1. Analytical jacobians with sympy
2. Scipy python ode solver

https://github.com/jgoppert/pymola/blob … mple.ipynb

Sep-28-15 12:57:46
I'm looking for developers interested in helping me finish a pure python modelica compiler.
Category: Developer

I've been working with openmodelica for awhile and always have found it difficult to extend the compiler for my needs. Recently ANTLR released a python runtime. I was able to easily combine the AST created with antlr and the jinja templates engine to create a compiler from modelica to a python based simulation for simple examples. I'm looking for anyone with interest in helping me out.

https://github.com/jgoppert/pymola

Jinja template to render AST into python simulation:
https://github.com/jgoppert/pymola/blob … ympy.jinja


ANTLR 4 Modelica Grammar:
https://github.com/jgoppert/pymola/blob … odelica.g4

Recently the svn revision of the stable version was bumped from 12318 to 12630. The new revision fails to linearize my aircraft model even after some cleanup of obvious changes (unless I'm missing something). I also tested release/ nightly and neither work. Can stable be restored to previous version or the linearization issues fixed?

Model: (see) https://github.com/arktools/openfdm

Script

Code:


// options
setCommandLineOptions({
"+showErrorMessages",
"+preOptModules=inlineArrayEqn,partitionIndependentBlocks",
"+postOptModules=inlineArrayEqn,constantLinearSystem,removeSimpleEquations,generateSymbolicLinearization",
//"+a",
//"+noSimplify",
"+d=linearization,gendebugsymbols"
});

// this line required the project path to be appended to OPENMODELICALIBRARY
loadModel(Modelica);
loadModel(OpenFDM);
loadModel(test);
getErrorString();


// it is necessary to extract the model form all packages so the "." is not mis-read
system("rm -f linear_AerosondeModel.mo AerosondeModel.*");
loadString("
model AerosondeModel
  extends OpenFDM.Aircraft.Aerosonde.Aircraft;
end AerosondeModel;
");

// get linear model
simulate(AerosondeModel,
    stopTime=0.001,
    numberOfIntervals=1,
    measureTime=true);
//getErrorString();
system("./AerosondeModel -l 0 > log.out");
readFile("log.out");
loadFile("linear_AerosondeModel.mo");
//getErrorString();
list(linear_AerosondeModel);
//getErrorString();

// simulate non-linear model
simulate(AerosondeModel,
    stopTime=1000,
    numberOfIntervals=100000,
    measureTime=true);

plotParametric(p.r_r[1],p.agl);
system("chromium-browser $PWD/AerosondeModel_prof.html &");
//getErrorString();

Output

Code:


{"Error: Internal error BackendDAEOptimize.generateSymbolicJacobian failed", "TRANSLATION", "Error", "63"}
{"Error: Internal error BackendDAEOptimize.createJacobian failed", "TRANSLATION", "Error", "63"}
{"Error: Internal error Generation of LinearModel Matrices failed. Function: BackendDAEOpimize.createLinearModelMatrixes", "TRANSLATION", "Error", "63"}
{"Error: Internal error Optimisation Module generateSymbolicLinearization failed.", "TRANSLATION", "Error", "63"}
Warning If equations not handled propper in findZeroCrossings2
...
{"Error: Internal error createOdeSystem failed for {133:149}", "TRANSLATION", "Error", "63"}
...
{"Error: Internal error ./Compiler/BackEnd/SimCode.mo: function createSimCode failed [Transformation from optimised DAE to simulation code structure failed]", "TRANSLATION", "Error", "63"}
record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 0.001, numberOfIntervals = 1, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'AerosondeModel', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = true, cflags = '', simflags = ''",
    messages = "Simulation failed for model: AerosondeModel
Error: Internal error BackendDAEOptimize.generateSymbolicJacobian failed
Error: Internal error BackendDAEOptimize.createJacobian failed
Error: Internal error Generation of LinearModel Matrices failed. Function: BackendDAEOpimize.createLinearModelMatrixes
Error: Internal error Optimisation Module generateSymbolicLinearization failed.
Error: Internal error createOdeSystem failed for {133:149}
Error: Internal error createEquationsForSystem1 failed
Error: Internal error createOdeSystem failed for {135:154}
Error: Internal error createEquationsForSystem1 failed
Error: Internal error createOdeSystem failed for {136:155}
Error: Internal error createEquationsForSystem1 failed
Error: Internal error createOdeSystem failed for {137:156}
Error: Internal error createEquationsForSystem1 failed
Error: Internal error ./Compiler/BackEnd/SimCode.mo: function createSimCode failed [Transformation from optimised DAE to simulation code structure failed]
",
    timeFrontend = 0.0,
    timeBackend = 0.0,
    timeSimCode = 0.0,
    timeTemplates = 0.0,
    timeCompile = 0.0,
    timeSimulation = 0.0,
    timeTotal = 0.0
end SimulationResult;

Aug-09-12 09:23:38
Is there a way around this compile error in the linearsystems library.

I'm trying to find a discrete PID controller that is usable with openmodelica. I found the one in the linearsystems library, but there is a compile issue. Is there an easy way around this error, or do you know of another discrete PID library available?

/usr/lib/omlibrary/Modelica_LinearSystems2 2.0/DiscreteStateSpace.mo:112:3-405:20:readonly] Error: Class operators are allowed in OPERATOR RECORD only. Error on:'constructor' not found in scope 'constructor'.

Is there an easy way to decrease the allowed simplex cost during initialization? I am trimming an aircraft in steady level flight, but the tolerance is too lax.

Aug-05-12 08:55:19
Category: Developer

I have added various improvements to OMPython. The improvements are helpful for automatic testing/analysis using OMPython as demonstrated in the OpenFDM project.


    * I moved the main shell interface into OMShell, which makes it more friendly to use.
    * I added error checking to the execute command. The execute command can handle multiple line statements with error handling on each.
    * The run_script command just calls runScript. I do a regex to look for fail or error on the string that is returned. I tried to do individual script line parsing, but it was too much work for now.


Hope this is helpful to someone else.

https://github.com/arktools/openfdm/tre … n/OMPython

We have our aircraft library based off of MultiBody finally up and running (still a lot left to do): https://github.com/arktools/openfdm.git
Now I'm trying to push the limits for multiple aircraft simulation.

I have a hyper-threaded quad-core i7 processor and am simulating 8 aircraft:
https://github.com/arktools/openfdm/blo … impleEx.mo

However, when i simulate 1 aircraft it takes 3 seconds, and for 8 aircraft it scales linearly to 24 seconds. Is there an option that I am missing? Does it not work with the rungekutta solver? The other solvers were failing for me on the aircraft model. Linearization does work, even for this large model with my changes to the MultiBody library described in other posts.

Code:


// options
setCommandLineOptions({
"+numProcs=8",
//"+showErrorMessages",
"+preOptModules=inlineArrayEqn,partitionIndependentBlocks",
"+postOptModules=inlineArrayEqn,constantLinearSystem,removeSimpleEquations,generateSymbolicLinearization",
//"+a",
//"+noSimplify",
"+d=linearization,gendebugsymbols"
});

// this line required the project path to be appended to OPENMODELICALIBRARY
loadModel(Modelica);
loadModel(MultiBodyOmc);
loadModel(OpenFDM);
getErrorString();

// it is necessary to extract the model form all packages so the "." is not mis-read
system("rm *DatcomSimpleEx*");
loadString("
model DatcomSimpleEx
  extends OpenFDM.Aerodynamics.Examples.DatcomSimpleEx;
end DatcomSimpleEx;
");

// get linear model
simulate(DatcomSimpleEx,
    numberOfIntervals=1,
    stopTime=0.001,
    measureTime=false,
    method="rungekutta");
//getErrorString();
system("./DatcomSimpleEx -l 0 > log.out");
readFile("log.out");
loadFile("linear_DatcomSimpleEx.mo");
//getErrorString();
list(linear_DatcomSimpleEx);
//getErrorString();

// simulate non-linear model
simulate(DatcomSimpleEx,
    stopTime=1000,
    numberOfIntervals=100000, // atleast 100 Hz
    measureTime=false,
    method="rungekutta");
plotParametric(body.airframe.r_0[1],
    body.aerodynamics.env.agl);
//system("chromium-browser $PWD/DatcomSimpleEx_prof.html &");
//getErrorString();

I was able to get multibody to linearize correctly by making one small change:

I replaced:

Code:

    

    annotation (derivative(noDerivative=R) = Internal.resolve2_der,
        __Dymola_InlineAfterIndexReduction=true);

with:

Code:

    

    annotation(Inline=true);
    annotation (derivative(noDerivative=R) = Internal.resolve2_der,
        __Dymola_InlineAfterIndexReduction=true);

Note that putting:

Code:

    

     annotation (Inline=true,derivative(noDerivative=R) = Internal.resolve2_der,
        __Dymola_InlineAfterIndexReduction=true);

Also does not work for some reason.

For now, I'm getting around this error by using my own kinematics with a multibody frame connector. It seems to be due to the array-equation case not being handled yet. Stable did linearize my own kinematics block.

Attempting to linearize a MultiBody example on stable:

model Body
  import Modelica.Mechanics.MultiBody.Parts.Body;
  import Modelica.Mechanics.MultiBody.World;
  inner World world;
  Body body;
end Body;

Yields these errors:

Error: Internal error BackendDAEOptimize.derive failed: ARRAY_EQUATION-case
Error: Internal error BackendDAEOptimize.derive failed
Error: Internal error BackendDAEOptimize.deriveAll failed
Error: Internal error BackendDAEOptimize.derive failed: ARRAY_EQUATION-case
Error: Internal error BackendDAEOptimize.derive failed
Error: Internal error BackendDAEOptimize.deriveAll failed
Error: Internal error BackendDAEOptimize.generateSymbolicJacobian failed
Error: Internal error BackendDAEOptimize.createJacobian failed
Error: Internal error Generation of LinearModel Matrices failed. Function: BackendDAEOpimize.createLinearModelMatrixes
Error: Internal error Optimisation Module generateSymbolicLinearization failed.
Error: Internal error array equations currently only supported on form v = functioncall(...)
Error: Internal error createOdeSystem failed for Array 0 {16, 17, 18}
Error: Internal error createEquations failed
Error: Internal error createOdeSystem failed for {29:19}
Error: Internal error createEquations failed
Error: Internal error createOdeSystem failed for {7:26}
Error: Internal error createEquations failed
Error: Internal error createOdeSystem failed for {30:20}

In stable, combitables have the jacobian computed correctly, but the linearization is not correct:
The equation used is:

der(x) = A*x + B*u;
y = C*x +  D*u;

where: A=df/dx, B=df/du, C = dh/dx, D = dh/du

The above equation only works for u0=0, x0=0, dx0=0, and y0=0. (The typical conditions for equilibrium).
For this to work in general these equations should be used instead:

der(x) = A*(x-x0) + B*(u-u0) + dx0;
y = C*(x-x0) +  D*(u-u0) + y0;

Also, for blocks with no states, there is an error due to incorrect syntax with the dummy x variable added:
Real x_P$dummy = x[1];

This seems to be a general problem with linearization for the nightly build. It can't even linearize without a combitable, I'm switching to stable to test the combitable support.

I'm working on tracking down the error with combi tables with the nightly openmodelica:

Here is the test model:

model Linearization
  import Modelica.Blocks.Tables.CombiTable1Ds;
  CombiTable1Ds testTable(table={{0,0},{1,1}},columns={2});
  Real x1(start=1);
  Real x2(start=2);
  parameter Real a=6,b=2,c=4;
  input Real u = 0;
  output Real y;
  Real tVal;
equation
  connect(testTable.y[1],tVal);
  connect(testTable.u,u);
  der(x1) = x1*(a-b*x1-x2);
  der(x2) = x2*(c-x1-x2) + tVal;
  y = x1 * u + x2 * u;
end Linearization;

here is the backtrace:

(gdb) run -l 0
Starting program: /tmp/jgoppert/Linearization -l 0
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
Linearization will performed at point of time: 0

Program received signal SIGSEGV, Segmentation fault.
0x0804df87 in eqFunction_11 (data=0xbffff000, discreteCall=0 '\000') at Linearization.c:599
599      $Py$pDERAdummyVarA = (($Px1$pDERAx1 * $Pu) + ($Px2$pDERAx2 * $Pu));
(gdb) backtrace
#0  0x0804df87 in eqFunction_11 (data=0xbffff000, discreteCall=0 '\000')
    at Linearization.c:599
#1  0x0804e1cf in functionJacA_column (data=0xbffff000) at Linearization.c:619
#2  0x0804e4a6 in functionJacA_dense (data=0xbffff000, jac=0x80ddb18) at Linearization.c:652
#3  0x0805e8e7 in linearize(DATA*) ()
#4  0x0805d171 in startNonInteractiveSimulation(int, char**, DATA*) ()
#5  0x0805d9c3 in _main_SimulationRuntime ()
#6  0x08050cc2 in main (argc=3, argv=0xbffff214) at Linearization.c:1263

The nightly openmodelica package  just returns 0 when linearizing a model with a MultiBody.Body for A/B/C/D, and stable/ release return errors. Are there plans to support this. I would be willing to help fix it if someone can point me in the right direction. I'm trying to linearize an aircraft based on the MultiBody library and using Modelica.Blocks.CombiTables so I need all of this to be working with the linearization. An option to do a simple finite difference Jacobian approximation would also be useful until the symbolic jacobian is fully working. I would also be willing to help write this but again need some direction as where the code should be added.

Jul-10-12 07:36:01
MDT Auto-completion/ browsing for other libraries

Well wasn't too hard to get a new directory added, would  be nice if the user could add libraries manually though. Any idea how I could tie this into a menu of some sort where you could add library names.

svn diff OMCProxy.java
Index: OMCProxy.java
===================================================================
--- OMCProxy.java    (revision 1569)
+++ OMCProxy.java    (working copy)
@@ -1100,10 +1100,12 @@
        if (!systemLibraryLoaded) {
            if (standardLibraryPackages == null) {
                standardLibraryPackages = new ArrayList<String>();
                standardLibraryPackages.add("Modelica");
+                standardLibraryPackages.add("Modelica_LinearSystems2");
            }

            sendExpression("loadModel(Modelica)", true);
+            sendExpression("loadModel(Modelica_LinearSystems2)", true);

            systemLibraryLoaded = true;
        }

Jul-10-12 05:42:46
MDT Auto-completion/ browsing for other libraries

Thanks, I got it building. I'll see what I can do to improve/ debug the auto-complete.

Jul-09-12 23:37:25
MDT Auto-completion/ browsing for other libraries

Thanks Adrian,

I did attempt to add it on eclipse-indigo, but it won't let you add a new library to the project where msl is as far as I can tell. On eclipse-juno it lets you add things but it doesn't seem to work correctly. (running ubuntu 12.04)

Also the autocomplete wasn't working for packages that I was working on/ or for imported projects. The only things that work for me are auto-completing for the standard library, auto-completing within the same file, and words within a file with alt-/

I also attempted to download and build your eclipse-plugin but was having some trouble. There are many dependencies, do you have some guidance on this so I can help contribute.

-James

Jul-09-12 23:30:48
The non-linear solver fails with a modelica standard library ex.

The non-linear solver fails with a modelica standard library example "Free Body" when angles_start = 0*{0.174532925199433,0.174532925199433,0.174532925199433} is given as an initial condition instead of : angles_start = {0.174532925199433,0.174532925199433,0.174532925199433}

Code:
model FreeBody
  extends Modelica.Icons.Example;
  //inner ModelicaServices.Modelica3D.Controller m3d_control;
  inner Modelica.Mechanics.MultiBody.World world;
  parameter Boolean animation = true "= true, if animation shall be enabled";
  Modelica.Mechanics.MultiBody.Parts.BodyShape body_cg(m = 1, I_11 = 1, I_22 = 1, I_33 = 1, r = {0.4,0,0}, r_CM = {0.2,0,0}, width = 0.05, r_0(start = {0.2,-0.5,0.1}, fixed = true), v_0(fixed = true), angles_fixed = true, w_0_fixed = true,
angles_start = 0*{0.174532925199433,0.174532925199433,0.174532925199433}, shapeType = "cone");
end FreeBody;

Script:
loadModel(Modelica);
loadFile("FreeBody.mo");
simulate(FreeBody);
plot(body_cg.frame_a.r_0[2])

Script Output: omc test.mos
true
true
record SimulationResult
    resultFile = "/hsl/homes/jgoppert/Desktop/FreeBody_res.mat",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'FreeBody', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
    messages = "warning | Error solving nonlinear system SES_ALGORITHM 0 at time 1.7656e-07
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 1.23592e-06
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 2.6484e-06
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 5.47335e-06
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 1.11233e-05
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 2.24231e-05
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 4.50227e-05
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 9.0222e-05
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 0.000180621
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 0.000361418
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 0.000723012
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 0.0014462
warning | Error solving nonlinear system SES_ALGORITHM 0 at time 0.00289258
info    | model terminate | Simulation terminated at time 0.002
",
    timeFrontend = 0.973176914,
    timeBackend = 1.830438558,
    timeSimCode = 0.232440043,
    timeTemplates = 0.37542255100000005,
    timeCompile = 1.307932783,
    timeSimulation = 0.10955988300000001,
    timeTotal = 4.829020529
end SimulationResult;
true

Jul-08-12 14:17:00
MDT Auto-completion/ browsing for other libraries

It would be nice if there was auto-completion/ browsing for other libraries in addition to the Modelica standard library. Is there any way to configure the MDT eclipse plugin to do this?

I am porting some tools for aerospace modelling from scicoslab to modelica. I would really like to have the capability of real-time openmodelica for hardware in the loop simulations. I have seen that there is an interactive branch, would this help toward this goal? If so, what is the status on that branch being merged with the trunk? Let me know if I can help with any of this.

Jul-01-12 21:05:09
debian package links to newer kinsol library (not in squeeze)

Thanks for the quick response! I jumped ship and upgraded our network to ubuntu 12.04 so we are more on the same page with your development.

Jun-29-12 00:26:03
debian package links to newer kinsol library (not in squeeze)

Temporary hack:

Add to /etc/apt/sources.list:
deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free

Install newer versions of sundials packages:
sudo apt-get install -t wheezy libsundials-serial-dev

Comment  out wheezy packages in your sources.list to keep other packages stable after install:
#deb http://ftp.us.debian.org/debian/ wheezy main contrib non-free

Jun-28-12 23:56:11
debian package links to newer kinsol library (not in squeeze)

simulate( HelloWorld, startTime=0, stopTime=4 )

record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 4.0, numberOfIntervals = 500, tolerance = 0.000001, method = 'dassl', fileNamePrefix = 'HelloWorld', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = '', simflags = ''",
    messages = "Simulation failed for model: HelloWorld
Error: Error building simulator. Buildlog: gcc   -falign-functions -march=native -mfpmath=sse   -I\"/usr/include/omc\" -I.    -c -o HelloWorld.o HelloWorld.c
gcc   -falign-functions -march=native -mfpmath=sse   -I\"/usr/include/omc\" -I.    -c -o HelloWorld_records.o HelloWorld_records.c
g++ -I. -o HelloWorld HelloWorld.o HelloWorld_records.o -I\"/usr/include/omc\" -I.        -falign-functions -march=native -mfpmath=sse   -L\"/usr/lib/omc\" -lSimulationRuntimeC   -ldl -linteractive  -lexpat -lrt -lsundials_kinsol -lsundials_nvecserial -llapack -lpthread -Wl,-Bstatic -lf2c -Wl,-Bdynamic
/usr/lib/omc/libSimulationRuntimeC.a(kinsol_initialization.o): In function `kinsol_initialization':
(.text+0x347): undefined reference to `KINSetUserData'
/usr/lib/omc/libSimulationRuntimeC.a(kinsol_initialization.o): In function `kinsol_initialization':
(.text+0x3a3): undefined reference to `KINInit'
/usr/lib/omc/libSimulationRuntimeC.a(kinsol_initialization.o): In function `kinsol_initialization':
(.text+0x43e): undefined reference to `KINDlsGetNumJacEvals'
/usr/lib/omc/libSimulationRuntimeC.a(kinsol_initialization.o): In function `kinsol_initialization':
(.text+0x450): undefined reference to `KINDlsGetNumFuncEvals'
collect2: ld returned 1 exit status
make: *** [omc_main_target] Error 1

",
    timeFrontend = 0.0,
    timeBackend = 0.0,
    timeSimCode = 0.0,
    timeTemplates = 0.0,
    timeCompile = 0.0,
    timeSimulation = 0.0,
    timeTotal = 0.0
end SimulationResult;

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