- Index
- » Users
- » foadsf
- » Profile

Page Start Prev 1 Next End

As I reported on this Tweet, Martin Sjölund replied to my question the Discord group, saying that the noEvent should be used for the conditions of the if-statement. I tested it for both OpenModelica and JModelica both working fine now.

model test_1

//parameters

Real firstVar;

Real secondVar;

Real thirdVar;

algorithm

firstVar := 1.0 * sin(time);

secondVar := abs(firstVar);

if noEvent(firstVar < secondVar) then

thirdVar := 1;

else

thirdVar := -1;

end if;

annotation(

experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-08, Interval = 0.02),

__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "euler"));

end test_1;

but anyways it seems like bad behavior to me and I would consider changing this if I were the developer of these projects. At least show the user some warning.

P.S. I kind of knew from past that adding noEvent is a good idea but I was kinda misguided by this answer suggesting that removing noEvent is OK.

I tried the if-statement in the equations section, the same problem:

model test_1

//parameters

Real firstVar;

Real secondVar;

Real thirdVar;

algorithm

firstVar := 1.0 * sin(time);

secondVar := abs(firstVar);

equation

if (firstVar < secondVar) then

thirdVar = 1;

else

thirdVar = -1;

end if;

annotation(

experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-08, Interval = 0.02),

__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));

end test_1;

I just reported this bug for JModelica here in the PyFMI GitHub repository, but then I realized that OpenModelica also has then the same issue. Consider this simple code:

//test_1.mo

model test_1

//parameters

Real firstVar;

Real secondVar;

Real thirdVar;

algorithm

firstVar := 1.0 * sin(time);

secondVar := abs(firstVar);

if (firstVar < secondVar) then

thirdVar := 1;

else

thirdVar := -1;

end if;

annotation(

experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-08, Interval = 0.02),

__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));

end test_1;

**click on the image to see the complete picture**

which doesn't make sense. The "thirdVar" should return to -1 right after firstVar drops below secondVar.

## sjoelund.se wrote:

Does## Code:

if (abs(relVel) < eps)solve it?

came to say exactly how I solved this, but you were faster ? thanks a lot

I changed the code to :

package friction1D

final constant Real eps=1.e-15 "Biggest number such that 1.0 + eps = 1.0";

function coulombFriction

input Real relVel;

input Real shearForce;

input Real normalForce;

input Real statfricco;

input Real kinfricco;

input Real inertia;

input Real relAcc;

output Real fricForce;

algorithm

//if (relVel < eps) and (abs(shearForce - inertia * relAcc) < statfricco * normalForce) then

//fricForce := shearForce - inertia * relAcc;

if (relVel < eps) and (abs(shearForce) < statfricco * normalForce) then

fricForce := shearForce;

else

fricForce := kinfricco * normalForce * sign(relVel);

end if;

end coulombFriction;

model fricexample_1

//parameters

parameter Real kco = 0.3;

parameter Real sco = 0.4;

parameter Real nfo = 1.0;

parameter Real mass = 1.0;

Real sfo;

Real ffo;

Real x;

Real v;

initial equation

x = 0;

v = 0;

algorithm

sfo := 0.7 * sin(time);

ffo := coulombFriction(relVel = v, shearForce = sfo, normalForce = nfo, statfricco = sco, kinfricco = kco, inertia = mass, relAcc = der(v));

equation

v = der(x);

mass * der(v) = sfo - ffo;

annotation(

experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-8, Interval = 0.02),

__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));

end fricexample_1;

end friction1D;

and now the first issue is solved:

and it makes sense at point 1, but then from point 2 to 3 where ffo simply should be -0.3 it is following the sfo!

Following this and this questions, I'm trying to simulation the below model in OpenModelica:

package friction1D

function coulombFriction

input Real relVel;

input Real shearForce;

input Real normalForce;

input Real statfricco;

input Real kinfricco;

input Real inertia;

input Real relAcc;

output Real fricForce;

algorithm

if (relVel == 0) and (abs(shearForce - inertia * relAcc) < statfricco * normalForce) then

fricForce := shearForce - inertia * relAcc;

else

fricForce := kinfricco * normalForce * sign(relVel);

end if;

end coulombFriction;

model fricexample_1

//parameters

parameter Real kco = 0.3;

parameter Real sco = 0.4;

parameter Real nfo = 1.0;

parameter Real mass = 1.0;

Real sfo;

Real ffo;

Real x;

Real v;

initial equation

x = 0;

v = 0;

algorithm

sfo := 0.7 * sin(time);

ffo := coulombFriction(relVel = v, shearForce = sfo, normalForce = nfo, statfricco = sco, kinfricco = kco, inertia = mass, relAcc = der(v));

equation

v = der(x);

mass * der(v) = sfo - ffo;

annotation(

experiment(StartTime = 0, StopTime = 10, Tolerance = 1e-8, Interval = 0.02),

__OpenModelica_simulationFlags(lv = "LOG_STATS", outputFormat = "mat", s = "dassl"));

end fricexample_1;

end friction1D;

apart from the warning:

Translation Warning

Iteration variables with default zero start attribute in torn nonlinear equation system:

$DER.v:VARIABLE() type: Real

The results don't make sense.

I expect the ffo to rise till 0.4 and then fall to 0.3 at point 1, but it shows weird behavior, which I can't explain at points 2 and 3. I would appreciate it if you could help me understand what is happening here and why I'm not getting the behavior I expect?

P.S. I post this question here on Modelica language Discord group and well as here on Reddit.

## Xwang wrote:

Moreover what is the difference between openmodelica and jmodelica?

It is a matter of personal preference but IMHO JModelica has easier Python bindings. I have written a very short introduction here. Feel free to leave comments over there, on Twitter or on Modelica Language Discord group.

Jun-07-19 09:51:04

Dsicord chatroom for Modelica Language, OpenModelica, JModelica, Dymola, scicos/xcos...

Category:
Programming

Forum:
Modelica Language

Hello everyone,

Following this post where I listed some of the available Modelica related forums and groups, I decided to create a Discord chatroom as well:

https://discordapp.com/invite/bp2yeYU

I would like to invite you all to join and help the community to be better in touch and share knowledge and experience. You can use the chatroom in your browser or install the mobile and desktop Discord apps and get real-time notifications when there are new discussions.

P.S. Please install the discord app on you desktop or mobile phone here: https://discordapp.com/download

Jun-06-19 11:00:22

Topic:
Understanding error message.

Need help in understanding an error message

Category:
Usage and Applications

I reported a similar error here .

Jun-05-19 21:01:50

When I try to simulate a model with a bearingfriction block I get the message that the equations...

Category:
Usage and Applications

I've got the same error as I have reported here.

Nov-14-17 08:59:33

Warning: maximal number of iteration reached but no root found Error solving nonlinear system

Category:
Programming

Forum:
Modelica Language

I am trying to simulate a system of of ADEs with discrete conditions. but I get the error below:

Warning: maximal number of iteration reached but no root found Error solving nonlinear system

I have explained the problem with details in this SO post. I would appreciate if you could help me know why this problem happens and how I can solve it.

https://scicomp.stackexchange.com/quest … nt-results

I would appreciate if you could help me with this.

This code does not work for me. I tried in OpenModelica and got the error:

Translation Error

Internal error Transformation Module PFPlusExt index Reduction Method Pantelides failed!

and in Mathematica SystemModeler I got the error:

Building "TestPde" as experiment "TestPde 1" started at 18:27:12

Error: Error: Variable T[2] is not present in any equation.

Build finished at 18:27:12 (took 00:00).

I would appreciate if you could help me know what is the problem and how I can fix it?

Aug-04-17 16:19:20

Topic:
describing domain PDE

describing domain PDE in Peter Fritzson way

Category:
Usage and Applications

I am trying the same thing. maybe you can share your code? I tried this and got some errors.

Aug-04-17 16:15:28

Topic:
PDE in Modelica?

What is the status of PDElib?

Category:
Programming

Forum:
Modelica Language

this is the theses you are referring to

-PDEInModelica.pdf

-PDEInModelica.pdf

. though it might help the next person

I made this GitHub repository to collect all the materials i could find the internet regarding solving partial differential equations in Modelica. please join me to push this matter a little bit forward:

https://github.com/Foadsf/ModelicaPDE

Jul-24-17 23:24:30

OpenModelica: Translation Warning In component in relation on Real numbers is only allowed inside...

Category:
Programming

Forum:
Modelica Language

Thanks for the reply. here some questions:

1. the function you linked to seems to offer a way to compare two real numbers and if they are within a threshold they can be considered as equal. here is what I do not understand:

1.1. the diff < absTol part is clear but what is the diff <= max(abs(b), abs(a)) * relTol does and why should we have it?

1.2. can you give an example of how I should use this function and how to call it?

2. why my simulation is so slow? does it have anything with the waring and will using your solutions help accelerating?

3. Is this warning the same reason I can't run my code in Wolfram SystemModeler? please see this post in their forum.

4. int function what is the := operand called and what does it do?

I would appreciate if you could help me with these questions.

Jul-24-17 21:45:37

OpenModelica: Translation Warning In component in relation on Real numbers is only allowed inside...

Category:
Programming

Forum:
Modelica Language

I have posted related questions in StackOverFlow and Wolfram SystemMdeler forum but nobody has answered me yet. The issue is That I want to run this code but I get the warning below:

Translation Warning [multibody_Coulomb_static_friction: 43:3-47:9]: In component , in relation V1 == V2, == on Real numbers is only allowed inside functions.

I would appreciate if you could help me know why this is happening and how I can solve this

same question in stackoverflow

I'm trying to create a model where one Modelica variable is a triangular wave of another variable. First I tried the floor() function as below:

model test1

final constant Real pi=2*Modelica.Math.asin(1.0);

parameter Real b = 1;

parameter Real a = 1;

Real x,p,u;

equation

if sign(sin(x*pi/b))>=0 then

p=a*(x-b*floor(x/b));

else

p=a*(b-(x-b*floor(x/b)));

end if;

x=time;

u = floor(x/b);

end test1

(x=time; is arbitrary so the model compiles)

but the result is weird, as you can see below

zoom in:

somehow 0.005 seconds before the next step floor function behaves unexpectedly and becomes a linear function ending by the next value.

then I tried the ceil() function. everything seemed right till I realised the same problem happens with ceil() function at other values (e.g. x=13)

I would appreciate if you could:

1. help me understand why this "glitch" happens and if it is intentional by design or a bug?

2. how I can fix this?

3. are there any alternatives to create a triangular wave function?

P.S. I am using this "wave function" to model the interaction between two jagged bodies

how did you exactly stored the pre(y) into t0?

I am also trying to use pre() function to model collision but I have the error below:

Translation Error

[/build/openmodelica-xkbOOS/openmodelica-1.11.0/OMCompiler/Compiler/SimCode/SimCodeUtil.mo: 552:5-552:146]: Internal error function createSimCode failed [Transformation from optimised DAE to simulation code structure fail

Page Start Prev 1 Next End

- Index
- » Users
- » foadsf
- » Profile