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

Logical Operators

Logical Operators

Hello everyone,
I'm trying to implement a logical loop. It's pretty easy but not sure what I'm doing wrongly

equation
   if noEvent(extraPointSurface_1=8) then
     Extra1=true;
   else
     Extra1=false;
   end if;

   if noEvent(extraPointSurface_2=8) then
     Extra2=true;
   else
     Extra2=false;
   end if;

   ExtraPointsCondition=Extra1*Extra2;


I would use the logical operator OR but I got errors. By the way with this very easy code I got this error message

Unknown named argument 'extraPointSurface_1' for function noEvent in (model RCR_OS.Chassis.Bottoming.Contact.N17_GroundContact_withLateral).

In call noEvent(extraPointSurface_1=8)

The function is declared as:
function noEvent
end noEvent;

Errors found in: if (noEvent()) then
// No equations
end if;

Modelica Text: line 156

Unknown named argument 'extraPointSurface_2' for function noEvent in (model RCR_OS.Chassis.Bottoming.Contact.N17_GroundContact_withLateral).

In call noEvent(extraPointSurface_2=8)

The function is declared as:
function noEvent
end noEvent;

Errors found in: if (noEvent()) then
// No equations
end if;

Modelica Text: line 162

The model contained invalid expressions.

Check aborted.

Anyone can help?
Thank you in advance

Re: Logical Operators

This is the complete code

model x
  Boolean Extra1;
  Boolean Extra2;
  Boolean ExtraPointsCondition;
  Real extraPointSurface_1;
  Real extraPointSurface_2;
equation
if noEvent(extraPointSurface_1=8) then
     Extra1=true;
   else
     Extra1=false;
   end if;

   if noEvent(extraPointSurface_2=8) then
     Extra2=true;
   else
     Extra2=false;
   end if;

   ExtraPointsCondition=Extra1*Extra2;
end x;

Re: Logical Operators

This is an equation  (extraPointSurface_1=8) or a binding, not a relation!
It should be  (extraPointSurface_1==8)

Re: Logical Operators

I'll try, thank you.

What is the right sintax if I want to put both the logical conditions all together:

if noEvent(extrapointSurface_1==8) or noEvent(extraPointSurface==8)

May it work?

Thanks a lot

Re: Logical Operators

Should work, but you can put it inside: if noEvent(extrapointSurface_1==8 or extraPointSurface_2==8).
Note however that is not good to test Real for equality. You should test for an interval with an epsilon, see:
https://github.com/modelica/Modelica-Co … ce/Util.mo

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