Greeting foot people.

I was creating a external function to create a normal distributed
source signal, but i found myself in a little problem, look at this:

f.c:
#include <stdlib.h>

double f(void)
{
    return random();
}

f.h:
double f(void);

f.mo:
function f
    output Real y;
    external
        annotation(Library="/tmp/f.o", Include="#include \"/tmp/f.h\"");
end f;


class A
    Real x;
initial equation
    x = 20;
equation
    der(x) = -x;
end A;


class B
    Real x;
    Real y;
initial equation
    x = 20;
equation
    der(x) = -x;
    y = 0;
end B;

class C
    Real x(fixed=false);
    Real y;
initial equation
    x = 20;
equation
    der(x) = -x;
    y = 0;
end C;

class D
    Real x(fixed=false);
    Real y;
initial equation
    x = 20;
equation
    der(x) = -x;
    y = f();
end D;

class E
    Real y;
equation
    y = f();
end E;

class F
    Real x;
    Real y;
initial equation
    x = 20;
equation
    der(x) = -x;
    y = f();
end F;

well, copy this to /tmp and in a OMShell-terminal:
[EMAIL PROTECTED]:/tmp$ OMShell-terminal
Open Source Modelica Terminal Shell
Copyright 1997-2007, PELAB, Linkoping University

To get help on using Mosh and OpenModelica, type "help()" and press enter
Started server using:/usr/share/omc-omshell/bin/omc +d=interactive >
/tmp/error.log 2>&1 &
 res = 0
>>> loadModel(Modelica)
true
>>> loadFile("/tmp/f.mo")
true
>>> system("gcc -c -o /tmp/f.o /tmp/f.c")
0
>>> simulate(A,timeStop=10)
record
    resultFile = "A_res.plt"
end record
>>> plot(x)
true
>>> simulate(B,timeStop=10)
record
    resultFile = "B_res.plt"
end record
>>> plot({x,y})
true
>>> simulate(C,timeStop=10)
record
    resultFile = "C_res.plt"
end record
>>> plot({x,y})
true
>>> simulate(D,timeStop=10)
record
    resultFile = "D_res.plt"
end record
>>> plot({x,y})
true
>>> simulate(E,timeStop=10)
record
    resultFile = "E_res.plt"
end record
>>> plot(y)
true
>>> simulate(F,timeStop=10)
record
    resultFile = "F_res.plt"
end record
>>> plot({x,y})
true


Well, the class A only has a variable and decrease from 20 to 0,
that's ok. The class B has two variables, one should decrease from 20
to 0 and the other one should be constant on 0, but both of them are
0s. At the class C, i declare the x variable with fixed=false, and
that work great. At class D, i declard that y is the returned value
form f, which return a random number, but the simulation stop silently
without error, but without data. At class E, i had deleted the x
variable, and then the simulation work great and y has random values,
and in class F  i declared again the variable, but without fixed and
the simulation works but x is not initialized at 20, so, it is a
constant 0.

I don't know if i just missing something here, what i need is work
with the random generator, and initializa other variables with
"initial equation".

What can i do to deal whit this?

PD: If you need some hands to type some lines of code of OpenModelica,
just say, i will be happy to help with it.

-- 
Jorge Eduardo Cardona
[EMAIL PROTECTED]
jorgeecardona.blogspot.com
------------------------------------------------
Linux registered user  #391186
Registered machine    #291871
------------------------------------------------

Reply via email to