FIX A VARIATION RANGE FOR A VARIABLE

Numerical methods and mathematical models of Elmer
Post Reply
Andrea_P
Posts: 176
Joined: 22 Mar 2021, 18:39
Antispam: Yes
Location: POLYTHECNIC UNIVERSITY OF TURIN

FIX A VARIATION RANGE FOR A VARIABLE

Post by Andrea_P »

Hi,
I want to fix a limit for my variable coordinate 1, in my case from 0 to 0.05. I proved with a while loop but it does not work not giving an error mex. This is part of my code. Thanks in advance.

Code: Select all

Initial Condition 1

  Pressure = 0.0 
  Surface = Variable Coordinate 1
     Real MATC "-tx+0.05" ! preaviously 0.0575originaly 0.2
  Velocity 1 = 0
  Velocity 2 = Variable Coordinate 1
      Real MATC "while (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up;"
End

-Andrea
POLYTECHNIC UNIVERSITY OF TURIN-DIMEAS
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: FIX A VARIATION RANGE FOR A VARIABLE

Post by kevinarden »

I believe it is if else

Velocity 2 = Variable Coordinate 1
Real MATC "if (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up; else (0)"

although the manual says while is available
https://www.nic.funet.fi/pub/sci/physic ... Manual.pdf

while( expr ) expr;

so perhaps you need the while not part at the end?
Velocity 2 = Variable Coordinate 1
Real MATC "while (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up; 0"
Andrea_P
Posts: 176
Joined: 22 Mar 2021, 18:39
Antispam: Yes
Location: POLYTHECNIC UNIVERSITY OF TURIN

Re: FIX A VARIATION RANGE FOR A VARIABLE

Post by Andrea_P »

kevinarden wrote: 26 May 2021, 19:09 I believe it is if else

Velocity 2 = Variable Coordinate 1
Real MATC "if (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up; else (0)"

although the manual says while is available
https://www.nic.funet.fi/pub/sci/physic ... Manual.pdf

while( expr ) expr;

so perhaps you need the while not part at the end?
Velocity 2 = Variable Coordinate 1
Real MATC "while (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up; 0"
Hi,
I have proved with if condition, I had already read the "while section" but it didn't work as you have written.
Regards,
Andrea
POLYTECHNIC UNIVERSITY OF TURIN-DIMEAS
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: FIX A VARIATION RANGE FOR A VARIABLE

Post by kevinarden »

Perhaps

while( expr ) expr;
while( expr )
expr;
...
expr;

means

While (this is true) do this;
While (this is true) do this;
While (this is true) do this;
etc.

Velocity 2 = Variable Coordinate 1
Real MATC "while (tx <= 0.05) -0.5*g*tx^2/nuPlus + g*h*tx/nuPlus -Up; while(tx > 0.05) 0;"
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: FIX A VARIATION RANGE FOR A VARIABLE

Post by raback »

Hi

Yes, "while" would be cycling until not true anymore. Even though the expression depends on "coordinate 1" there is no implicit internal logic that would have this cycle over the coordinates. It is just evaluated at the node once and for all. "max" might be a more useful operator in this context.

-Peter
Andrea_P
Posts: 176
Joined: 22 Mar 2021, 18:39
Antispam: Yes
Location: POLYTHECNIC UNIVERSITY OF TURIN

Re: FIX A VARIATION RANGE FOR A VARIABLE

Post by Andrea_P »

raback wrote: 26 May 2021, 21:27 Hi

Yes, "while" would be cycling until not true anymore. Even though the expression depends on "coordinate 1" there is no implicit internal logic that would have this cycle over the coordinates. It is just evaluated at the node once and for all. "max" might be a more useful operator in this context.

-Peter
Hi Peter,
In my case the domain of Coordinate 1 is 0-0.1.
-Andrea
POLYTECHNIC UNIVERSITY OF TURIN-DIMEAS
Post Reply