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

Problem with new users' exercises

Problem with new users' exercises

Hi,
I'm new italian openmodelica user.
I've bought Peter Fritzson principles of object-oriented modeling and simulation with modelica, that proposes some easy exercise, like HelloWorld.

The first question is:
where do I have to insert script? In OMEdit Text View or in OMShell?

So, when I insert this script:

class HelloWorld
   Real x(start=1);
parameter Real a = 1;
equation
   der(x)=-a*x;
end HelloWorld;

simulate(HelloWorld);

plot(x)


OMEdit gives back this error message:


Syntax    14:24:31        8:1-8:8    Parser error: Unexpected token near: simulate (IDENT)

I haven't any ideas, so please help me.

Regards,
Lorenzo

Re: Problem with new users' exercises

Hi Lorenzo,

The class HelloWorld is a model, while simulate and plot are scripting commands to the OMC compiler. When you're using OMEdit, create a new model and put in the code for the HelloWorld class in the text view. Then simply press the Simulate button in OMEdit (looks like an arrow) to simulate the model. OMEdit will then switch to the plot mode, and you can choose which variables to plot.

You can also use OMShell by loading the model from a file with loadFile or something similar, and then executing the commands. But OMEdit is much more user friendly, so use that instead unless you have some reason to use OMShell.

Regards,
Per

Re: Problem with new users' exercises

Hi Lorenzo,

If you want to use the commands then use OMShell. In OMShell first type in your model or load a model file,

Code:

class HelloWorld

   Real x(start=1);
parameter Real a = 1;
equation
   der(x)=-a*x;
end HelloWorld;

Then send the simulate command,

Code:

simulate(HelloWorld)

and then plot,

Code:

plot(x)

OMEdit allows users to use the GUI to performs these commands. You can create you model and then you can click on simulate button to simulate the model rather than typing the simulate command.

Adeel.

Re: Problem with new users' exercises

Hi Adeel
I tried but it's the result:

class HelloWorld
   Real x(start=1);
parameter Real a = 1;
equation
   der(x)=-a*x;
end HelloWorld;
{HelloWorld}

>> simulate(HelloWorld)
record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-006, method = 'dassl', fileNamePrefix = 'HelloWorld', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*', measureTime = false, cflags = ''",
    messages = "Simulation failed for model: HelloWorld
",
    timeFrontend = 0.0,
    timeBackend = 0.0,
    timeSimCode = 0.0,
    timeTemplates = 0.0,
    timeCompile = 0.0,
    timeSimulation = 0.0,
    timeTotal = 0.0
end SimulationResult;


Thank you very much for your help, Per too.

Lorenzo

Re: Problem with new users' exercises

Per,
Also I tried OMEdit but I don't go so far....

I write my model, play simulate but nothing happens.
If I push Plotting button, there isn't any graph or any variables to select.

Sorry, I've searched on web but I haven't found anything.

Re: Problem with new users' exercises

Hi,

What system do you have? Windows? Linux?
What OpenModelica version/revision you installed?

You could try to uninstall and install the latest nightly build from here:
http://build.openmodelica.org/omc/build … ly-builds/

Cheers,
Adrian Pop/

Re: Problem with new users' exercises

Hi Adrian

Windows SP3 on job desk with OpenModelica 1.8.0 (r10584)
at home MacPro 10.6.

What's the OM nightly version?

Regards,
Lorenzo

Re: Problem with new users' exercises

OpenModelica 1.8.1 (r11291)
http://build.openmodelica.org/omc/build … ly-builds/

Adeel.

Re: Problem with new users' exercises

Hi,

Nightly-builds are newer version of OpenModelica (not released yet officially).
You should try newer versions than 1.8.0 as this version can have some issues
with compilation of models depending of what you have installed on your system (like
some other MinGW compiler, etc).

Cheers,
Adrian Pop/

Re: Problem with new users' exercises

Do I uninstall older version before install nightly?

Thanks,
Lorenzo

Re: Problem with new users' exercises

Yes. Is not possible to have 2 versions at the same time.

Cheers,
Adrian Pop/

Re: Problem with new users' exercises

Good Job!!!!

It works!!!!!

Thank you very much!

Lorenzo

Re: Problem with new users' exercises

So, I have the same problem with Mac.
At home I'll try nightly version.

Re: Problem with new users' exercises

Hi

I'm at home with my MacBook Pro, Mac OS X V. 10.6.8 and OM 1.6.0.
I've tried to simulate Hello World in OMShell and it doesn't work.

I post the result


class HelloWorld
   Real x(start=1);
parameter Real a = 1;
equation
   der(x)=-a*x;
end HelloWorld;
{HelloWorld}

>> simulate(HelloWorld)
record SimulationResult
    resultFile = "",
    simulationOptions = "startTime = 0.0, stopTime = 1.0, numberOfIntervals = 500, tolerance = 1e-06, method = 'dassl', fileNamePrefix = 'HelloWorld', storeInTemp = false, noClean = false, options = '', outputFormat = 'mat', variableFilter = '.*'",
    messages = "Simulation failed for model: HelloWorld
Error: Error building simulator. Buildlog: /opt/openmodelica/share/omc/scripts/Compile: line 2: make: command not found

Error: Error building simulator. Buildlog: command g++ not found. Check $OPENMODELICAHOME
Error: Error building simulator. Buildlog: command \"/opt/openmodelica/share/omc/scripts/Compile\" not found. Check $OPENMODELICAHOME
",
    timeFrontend = 0.0,
    timeBackend = 0.0,
    timeSimCode = 0.0,
    timeTemplates = 0.0,
    timeCompile = 0.0,
    timeSimulation = 0.0,
    timeTotal = 0.0
end SimulationResult;

Changed OS, new nightmare.
Please, help me....

Re: Problem with new users' exercises

First of all OM 1.6.0 is very old and I'd strongly recommend a newer one. Secondly, you should simply need to install XCode to get the gcc and g++ commands available.

Re: Problem with new users' exercises

Hi,
I installed XCode 3.2 for OS X Snow Leopard.
I tried to simulate this model:

model MassaForza "Massa spinta da una forza costante"
  parameter Real m = 2 "Massa del blocco";
  parameter Real f = 6 "Forza applicata";
  Real s "Posizione del blocco";
  Real v "Velocità del bloco";

equation
  v = der(s);
  m * der(v) = f;
end MassaForza;

Then I simulated, so plotting, but selecting variables nothing happens, it doesn't appear any graphs.

So I ri-pushed simulate and OMEdit gives it:

---- Error 2 : 19:42:42 ----
Unable to simulate the Model 'MassaForza'
Following Error has occurred.

Simulation failed for model: MassaForza
ERROR: system(OPENMODELICAHOME=\"$OPENMODELICAHOME\" /opt/openmodelica/share/omc/scripts/Compile MassaForza ) failed: Interrupted system call
Error: Error building simulator. Buildlog: \"perl\" /opt/openmodelica/share/omc/scripts/convert_lines.pl MassaForza.cpp MassaForza.conv.cpp.tmp
g++ -I. -o MassaForza MassaForza.conv.cpp MassaForza_functions.cpp -L\"/Users/lorenzotrombetta/Desktop/Modelica\"   -lsim -linteractive -I\"/opt/openmodelica/include/omc\" -msse2 -mfpmath=sse  -L/opt/openmodelica/lib -arch x86_64 -lsendData -lQtNetwork -lQtCore -lQtGui -lpthread -L\"/opt/openmodelica/lib/omc\" -lc_runtime -lf2c MassaForza_records.c

Error: Error building simulator. Buildlog: command g++ not found. Check $OPENMODELICAHOME
Error: Error building simulator. Buildlog: command \"/opt/openmodelica/share/omc/scripts/Compile\" not found. Check $OPENMODELICAHOME

Any suggests,
Lorenzo

Re: Problem with new users' exercises

Code:

sakura:~ martin$ ls -l /usr/bin/{g,}cc

lrwxr-xr-x  1 root  wheel  12 Feb 10 07:54 /usr/bin/cc -> llvm-gcc-4.2
lrwxr-xr-x  1 root  wheel  12 Feb 10 07:54 /usr/bin/gcc -> llvm-gcc-4.2

That's so odd. My XCode 4.2 installed gcc and g++ just fine. What is your output of

Code:

ls -l /usr/bin/{gcc,cc,g++,c++,clang,clang++}

Re: Problem with new users' exercises

lorenzotrombetta$ ls -l /usr/bin/{gcc,cc,g++,c++,clang,clang++}

ls: /usr/bin/clang: No such file or directory
ls: /usr/bin/clang++: No such file or directory
lrwxr-xr-x  1 root  wheel  7  8 Mar 19:26 /usr/bin/c++ -> c++-4.2
lrwxr-xr-x  1 root  wheel  7  8 Mar 19:26 /usr/bin/cc -> gcc-4.2
lrwxr-xr-x  1 root  wheel  7  8 Mar 19:26 /usr/bin/g++ -> g++-4.2
lrwxr-xr-x  1 root  wheel  7  8 Mar 19:26 /usr/bin/gcc -> gcc-4.2

Re: Problem with new users' exercises

But that means the command "g++" should be available and OSX should quit crying.

Try ls -lH /usr/bin/g++ to be sure the chain of symlinks point somewhere real. And try "g++ --version" from command-line to see if the file is executable.

Re: Problem with new users' exercises

lorenzotrombetta$ ls -lH /usr/bin/g++
lrwxr-xr-x  1 root  wheel  7  8 Mar 19:26 /usr/bin/g++ -> g++-4.2


lorenzotrombetta$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

So, what's the matter?

Re: Problem with new users' exercises

Maybe login/logout helps? Can also try the following:

Code:


echo "checkSettings()" > ~/tmp.mos
/opt/openmodelica/bin/omc ~/tmp.mos
rm ~/tmp.mos

Re: Problem with new users' exercises

I tried but OMEdit gives me same error.

I'm sad, becaus I don't want to use Windows....

What is login/logout?

Re: Problem with new users' exercises

Shift-Command-Q - Log out

Re: Problem with new users' exercises

same problem....

trying new exercise from Fritzon book, "pendulum":


Simulation failed for model: pendulum
ERROR: system(OPENMODELICAHOME=\"$OPENMODELICAHOME\" /opt/openmodelica/share/omc/scripts/Compile pendulum ) failed: Interrupted system call
Error: Error building simulator. Buildlog: \"perl\" /opt/openmodelica/share/omc/scripts/convert_lines.pl pendulum.cpp pendulum.conv.cpp.tmp
g++ -I. -o pendulum pendulum.conv.cpp pendulum_functions.cpp -L\"/Users/lorenzotrombetta/Desktop/Modelica\"   -lsim -linteractive -I\"/opt/openmodelica/include/omc\" -msse2 -mfpmath=sse  -L/opt/openmodelica/lib -arch x86_64 -lsendData -lQtNetwork -lQtCore -lQtGui -lpthread -L\"/opt/openmodelica/lib/omc\" -lc_runtime -lf2c pendulum_records.c

Error: Error building simulator. Buildlog: command g++ not found. Check $OPENMODELICAHOME
Error: Error building simulator. Buildlog: command \"/opt/openmodelica/share/omc/scripts/Compile\" not found. Check $OPENMODELICAHOME

Re: Problem with new users' exercises

I've tried in OMShell pendulum's exercise.
Simulation ok, but when I write plot(vx), OMShell give "true" but nothing happens.

There are 0 guests and 0 other users also viewing this topic
You are here: