CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Expression conditional statement in Fluent (https://www.cfd-online.com/Forums/fluent-udf/244418-expression-conditional-statement-fluent.html)

visitor August 7, 2022 17:20

Expression conditional statement in Fluent
 
I have used this in CFD before and it works, but not in Fluent. Please correct what is wrong, error message 'invalid expression"

IF(<expr>,<vector>,<vector>)0 [m/s] "this is given by Fluent"

IF(atstep=>1,1[m/s],0[m/s]) "that's what I would write in CFX"

The condition is; if accumulated time step (atstep) is equal or greater than 1 second, than velocity is 1 m/s, else it's 0 m/s. Please show correct expression, thanks.

visitor August 11, 2022 06:01

Solved, what is used in CFX "atstep", is "flow-time" in Fluent. It's menu driven, just select parameters from what is given in the menu/s.

visitor August 12, 2022 17:46

A conditional expression which changes a boundary condition from a wall to an outlet.
 
Is there a way in changing a boundary condition type from a wall to an outlet.?

Example a pipe opening needs to be a wall (capped), and then after e.g. 1 second becomes a pressure outlet boundary condition.

Anyone, please. Thanks.

visitor August 13, 2022 12:41

Or an expression which can introduce a virtual wall in a pipe? For an example, effectively stopping flow in pipe.

AlexanderZ August 15, 2022 20:31

you need TUI command to do that
it could be done automatically through journal file or "execute command" tab in "calculation activities"

visitor August 16, 2022 13:06

Thanks Alexander, I don't know what you mean, maybe you can give an example.

What I have tried recently to open a valve in a cylinder outlet, is use the expression:

IF(3.79e-2[s]>{flow-time}>=3.73e-2[s],-8[m/s],0[m/s])

In dynamic mesh together with piston wall movement ,and cylinder wall. I have tried to assigned valve_walls (exhaust valve), as a rigid body, but when tried to change boundary condition for the valve_wall to a moving wall, with the expression inserted in the velocity field, it didn't work.

Everything else is fine the piston movement and deforming walls, but cant get the valve wall in 3D, to move down the y axis for about 5 mm, after flow-time 3.73e-2 s. That's all I need, thanks in advance if you/anyone can help out.

visitor August 16, 2022 14:57

Tried this to move valve wall, just for experiment, moving velocity on y direction with vely, didn't work. Used interpreter and got error " ... valve.c.6436.3.c: line 2: parse error." Cant see what is wrong.

#include “udf.h”
static real vely = 0.0;
DEFINE_CG_MOTION(exhaust_valve,dt,vel,omega,time,d time)
{
NV_S(vel,=, 0.0);
NV_S(omega, =, 0.0);
Vely= 0.05*sin(3.142*time/5);
Vel[0]=vely;
}

visitor August 17, 2022 15:13

Tried this UDF, run on interpreter, but valve walls didn't move. This should have moved the valve walls at 5 m/s between the conditional times, along the y-axis selected on the wall boundary condition menu.


#include "udf.h"
DEFINE_PROFILE(moving_wall_exhaustValve, thread, i)
{

face_t f;

begin_f_loop(f, thread)

{
if(CURRENT_TIME >= 0.0374 && CURRENT_TIME <= 0.0383)
F_PROFILE(f,thread,i) = -5;
else if(CURRENT_TIME < 0.0374 && CURRENT_TIME > 0.0383)
F_PROFILE(f,thread,i) = 0;
}

end_f_loop(f, thread)

}

visitor August 18, 2022 08:08

Now tried this program, but got a "line 2: parse error." Not so good in programming, hope someone can help.

#include “udf.h”
DEFINE_CG_MOTION(valve_wall, dt, cg_vel, cg_omega, time, dtime)
{
/*below are conditions for the 'valve_wall' to move*/
Real vel;
if(CURRENT_TIME >= 0.03744 && CURRENT_TIME <= 0.0383)
vel=5;
vel=0;
cg_vel[0]=0.0;
cg_vel[1]=vel;
cg_vel[2]=0.0;

cg_omega[0]=0.0;
cg_omega[1]=0.0;
cg_omega[2]=0.0;

else if(CURRENT_TIME < 0.03744 && CURRENT_TIME >0.0383)
vel=0;
cg_vel[0]=0.0;
cg_vel[1]=vel;
cg_vel[2]=0.0;

cg_omega[0]=0.0;
cg_omega[1]=0.0;
cg_omega[2]=0.0;
}

visitor August 18, 2022 16:25

Latest attempt, this is a nice short easy to follow, but got the same message from the interpreter "line 2: parse error.". What is wrong with this anyone? Thanks.
ex_valve is a 3D wall which needs to move according to the given conditional statement.

#include “udf.h”
real vely =0.0;
DEFINE_CG_MOTION(ex_valve,dt,vel,omega,time,dtime)
{
NV_S(vel=0.0);
NV_S(omega=0.0);
if (time>= 0.0374 && time<=0.0383)
vely=5;
else
vely=0.0;
vel[1]=vely;
{

AlexanderZ August 18, 2022 19:28

manual:
Quote:

Note that UDFs that are defined using DEFINE_CG_MOTION can ONLY be executed as compiled UDFs.
I recommend you to compile your code always

visitor August 19, 2022 00:28

I did think about compiler v interpreter issues, but why would a fluent interpreter show this message? Can't see myself what is the parse error in line 2!

visitor August 19, 2022 02:14

1 Attachment(s)
Tried compiler but got errors see attached file.

UDF code below:
#include “udf.h”
real vely =0.0;
DEFINE_CG_MOTION(ex_valve,dt,vel,omega,time,dtime)
{
NV_S(vel=0.0);
NV_S(omega=0.0);
if (time>= 0.0374 && time<=0.0383)
vely=5;
else
vely=0.0;
vel[1]=vely;
{

visitor August 20, 2022 07:22

If I can make a suggestion for Ansys Fluent, it might be an idea to add this as part of the expressions user menu, and avoid such programming issues.

Example moving a 2/3D wall:
Once this option is selected within the boundary layer wall menu, then the code will interact with the chosen expression and perform.

visitor August 20, 2022 12:57

Tried this today, and got the following errors, code shown below:
#include <93>udf.h<94>
^
valva wall moving define cg.c(2,1): warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
DEFINE_CG_MOTION(ex_valve_wall, dt, cg_vel, cg_omega, time, dtime)
^
valva wall moving define cg.c(4,1): error: use of undeclared identifier 'Real'
Real vel;
^
valva wall moving define cg.c(6,1): error: use of undeclared identifier 'vel'
vel=5;
^
valva wall moving define cg.c(7,1): error: use of undeclared identifier 'vel'
vel=0;
^
valva wall moving define cg.c(8,7): error: subscripted value is not an array, pointer, or vector
cg_vel[0]=0.0;
~~~~~~^~
valva wall moving define cg.c(9,7): error: subscripted value is not an array, pointer, or vector
cg_vel[1]=vel;
~~~~~~^~
valva wall moving define cg.c(9,11): error: use of undeclared identifier 'vel'
cg_vel[1]=vel;
^
valva wall moving define cg.c(10,7): error: subscripted value is not an array, pointer, or vector
cg_vel[2]=0.0;
~~~~~~^~
valva wall moving define cg.c(12,9): error: subscripted value is not an array, pointer, or vector
cg_omega[0]=0.0;
~~~~~~~~^~
valva wall moving define cg.c(13,9): error: subscripted value is not an array, pointer, or vector
cg_omega[1]=0.0;
~~~~~~~~^~
valva wall moving define cg.c(14,9): error: subscripted value is not an array, pointer, or vector
cg_omega[2]=0.0;
~~~~~~~~^~
valva wall moving define cg.c(16,1): error: expected expression
else if(time < 0.03744 && time >0.0383)
^
valva wall moving define cg.c(18,7): error: subscripted value is not an array, pointer, or vector
cg_vel[0]=0.0;
~~~~~~^~
valva wall moving define cg.c(19,7): error: subscripted value is not an array, pointer, or vector
cg_vel[1]=vel;
~~~~~~^~
valva wall moving define cg.c(19,11): error: use of undeclared identifier 'vel'
cg_vel[1]=vel;
^
valva wall moving define cg.c(20,7): error: subscripted value is not an array, pointer, or vector
cg_vel[2]=0.0;
~~~~~~^~
valva wall moving define cg.c(22,9): error: subscripted value is not an array, pointer, or vector
cg_omega[0]=0.0;
~~~~~~~~^~
valva wall moving define cg.c(23,9): error: subscripted value is not an array, pointer, or vector
cg_omega[1]=0.0;
~~~~~~~~^~
valva wall moving define cg.c(24,9): error: subscripted value is not an array, pointer, or vector
cg_omega[2]=0.0;
~~~~~~~~^~
1 warning and 19 errors generated.
scons: *** [valva wall moving define cg.obj] Error 1
scons: building terminated because of errors.

Done.

code below should move walls based on gven time conditions at a velocity vel=5 and along the y axis::

#include “udf.h”
DEFINE_CG_MOTION(ex_valve_wall, dt, cg_vel, cg_omega, time, dtime)
{
Real vel;
if(time >= 0.03744 && time <= 0.0383)
vel=5;
vel=0;
cg_vel[0]=0.0;
cg_vel[1]=vel;
cg_vel[2]=0.0;

cg_omega[0]=0.0;
cg_omega[1]=0.0;
cg_omega[2]=0.0;

else if(time < 0.03744 && time >0.0383)
vel=0;
cg_vel[0]=0.0;
cg_vel[1]=vel;
cg_vel[2]=0.0;

cg_omega[0]=0.0;
cg_omega[1]=0.0;
cg_omega[2]=0.0;
}

visitor August 21, 2022 01:10

Some how with a help from the internet, managed to put this scheme code together, changing wall boundary type from wall to pressure inlet. At time 0 seconds it's type 2 a pressure inlet, and at time 0.0052 seconds it's type 1 a wall. Just couldn't find away to assign a pressure value when the boundary condition (BC 6) is a acting as a pressure inlet. Maybe I would have to write a separate UDF with a define profile and apply a pressure value at the stated time of 0 seconds. Any help from scheme experts, thanks?


(define (inlet_BC_type_Change)
(define time-sequence #(0 0.0052))
(define type-sequence #(2 1))
(define flag 0)
(define bctype 0)
(define time (rpgetvar ‘flow-time))
(define dt (rpgetvar ‘physical-time-step))
(set! flag 0)
(set! bctype 0)
(do ((i 0 (+ i 1)))
((= i (vector-length time-sequence)))
(if (>= time (- (vector-ref time-sequence i) (* 0.000104 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 0.000104 dt)))
(set! flag 1)
(set! bctype (vector-ref type-sequence i))
)))
(if (= 1 bctype)
(if (= flag 1)
(set! flag 2)))
(if (= flag 1)
(ti-menu-load-string (format #f “define bou zone type 6 wall”)))
(if (= flag 2)
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”)))
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure inlet”))
)

AlexanderZ August 22, 2022 02:16

boundary conditions are controlled by TUI commands inside (ti-menu-load-string (format #f “ ... ”))
for your case you need to modify last if condition
Code:

(if (= flag 2)
(begin
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1000 no 1 no 300 no yes”))
))

where
Quote:

zone id/name [6] 6
Reference Frame: Absolute [yes]
Use Profile for Gauge Total Pressure? [no]
Gauge Total Pressure (in [Pa]) [0] 1000
Use Profile for Supersonic/Initial Gauge Pressure? [no]
Supersonic/Initial Gauge Pressure (in [Pa]) [0] 1
Use Profile for Total Temperature? [no]
Total Temperature (in [K]) [300] 300
Direction Specification Method: Direction Vector [no]
Direction Specification Method: Normal to Boundary [yes]
you can find these comands by typing define -> boundary-cond and so on in console of fluent

visitor August 22, 2022 02:56

Thanks for your reply, but I new to scheme programming. Could you please type and modify this last 'if' condition?

Could I add this line after last 'if' condition, and set the pressure gauge to 5e5 Pa?
(ti-menu-load-string (format #f “Gauge Total Pressure 2e5 ”))
))

visitor August 22, 2022 04:10

Alexander, do you mean type it as shown below?

(if (= flag 2)
(begin
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1000 no 1 no 300 no yes”))
))

How can the pressure be set at 2e5 Pa and temperature to 400 K? I didn't understand the;

... yes no 1000 no 1 no 300 no yes”))
))

Thanks

AlexanderZ August 22, 2022 06:22

put 2e5 instead of 1000 and 400 instead of 300

transcription of options is described in previous answer


All times are GMT -4. The time now is 18:16.