CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Expression conditional statement in Fluent

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 7, 2022, 17:20
Default Expression conditional statement in Fluent
  #1
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 11, 2022, 06:01
Default
  #2
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 12, 2022, 17:46
Default A conditional expression which changes a boundary condition from a wall to an outlet.
  #3
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 13, 2022, 12:41
Default
  #4
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Or an expression which can introduce a virtual wall in a pipe? For an example, effectively stopping flow in pipe.
visitor is offline   Reply With Quote

Old   August 15, 2022, 20:31
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you need TUI command to do that
it could be done automatically through journal file or "execute command" tab in "calculation activities"
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 16, 2022, 13:06
Default
  #6
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 16, 2022, 14:57
Default
  #7
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 17, 2022, 15:13
Default
  #8
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 18, 2022, 08:08
Default
  #9
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 18, 2022, 16:25
Default
  #10
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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;
{
visitor is offline   Reply With Quote

Old   August 18, 2022, 19:28
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 19, 2022, 00:28
Default
  #12
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 19, 2022, 02:14
Default
  #13
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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;
{
Attached Files
File Type: pdf compiler errors.pdf (103.2 KB, 4 views)
visitor is offline   Reply With Quote

Old   August 20, 2022, 07:22
Default
  #14
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 20, 2022, 12:57
Default
  #15
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 21, 2022, 01:10
Default
  #16
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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”))
)
visitor is offline   Reply With Quote

Old   August 22, 2022, 02:16
Default
  #17
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 22, 2022, 02:56
Default
  #18
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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 is offline   Reply With Quote

Old   August 22, 2022, 04:10
Default
  #19
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
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
visitor is offline   Reply With Quote

Old   August 22, 2022, 06:22
Default
  #20
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
put 2e5 instead of 1000 and 400 instead of 300

transcription of options is described in previous answer
visitor likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF switching with a conditional statement visitor FLUENT 15 July 5, 2019 12:28
Ansys Fluent 17.0 Expression u_k FLUENT 8 May 13, 2019 06:15
Surface tension force expression at the wall in fluent IndrajitW FLUENT 0 April 15, 2013 08:37
Conditional statement over the entire mesh xisto OpenFOAM Programming & Development 6 November 24, 2010 12:13
CFX Expression Statement Ivan CFX 3 June 5, 2006 11:42


All times are GMT -4. The time now is 22:33.