|
[Sponsors] |
August 7, 2022, 17:20 |
Expression conditional statement in Fluent
|
#1 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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. |
|
August 11, 2022, 06:01 |
|
#2 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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.
|
|
August 12, 2022, 17:46 |
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 |
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. |
|
August 13, 2022, 12:41 |
|
#4 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
Or an expression which can introduce a virtual wall in a pipe? For an example, effectively stopping flow in pipe.
|
|
August 15, 2022, 20:31 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
August 16, 2022, 13:06 |
|
#6 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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. |
|
August 16, 2022, 14:57 |
|
#7 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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; } |
|
August 17, 2022, 15:13 |
|
#8 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 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) } |
|
August 18, 2022, 08:08 |
|
#9 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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; } |
|
August 18, 2022, 16:25 |
|
#10 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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; { |
|
August 18, 2022, 19:28 |
|
#11 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
manual:
Quote:
__________________
best regards ****************************** press LIKE if this message was helpful |
||
August 19, 2022, 00:28 |
|
#12 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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!
|
|
August 19, 2022, 02:14 |
|
#13 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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; { |
|
August 20, 2022, 07:22 |
|
#14 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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. |
|
August 20, 2022, 12:57 |
|
#15 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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; } |
|
August 21, 2022, 01:10 |
|
#16 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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”)) ) |
|
August 22, 2022, 02:16 |
|
#17 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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”)) )) Quote:
__________________
best regards ****************************** press LIKE if this message was helpful |
||
August 22, 2022, 02:56 |
|
#18 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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 ”)) )) |
|
August 22, 2022, 04:10 |
|
#19 |
Senior Member
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13 |
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 |
|
August 22, 2022, 06:22 |
|
#20 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
put 2e5 instead of 1000 and 400 instead of 300
transcription of options is described in previous answer
__________________
best regards ****************************** press LIKE if this message was helpful |
|
|
|
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 |