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 22, 2022, 08:34
Default
  #21
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks Alex. Z 👍
visitor is offline   Reply With Quote

Old   August 22, 2022, 08:58
Default
  #22
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
I originally wanted valve wall movement using UDF, but didn't work because of parse errors. Then tried UDF to switch boundary flow in x y z directions between 0 and 1, to stop/allow flow, didn't work.

Thanks, this seems to work, using scheme.
visitor is offline   Reply With Quote

Old   August 22, 2022, 14:22
Default
  #23
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Also Alex, I am trying this now, controlling to BCs, in one file code.

(define (outlet_BC_type_Change)
(define time-sequence #(0.0 0.0374))
(define type-sequence #(1 2))
(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 7 wall”)))
(if (= flag 2)
(ti-menu-load-string (format #f “define bou zone type 7 pressure-outlet”))
))
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure outlet”))
)
(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”)
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1.1e5 no 1 no 400 no yes”))
))
(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 23, 2022, 03:03
Default
  #24
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
as you defining flag and bctype variable twice in your code, it could lead to problem
Code:
(define flag 0)
(define bctype 0)
you may change the names to avoid it
__________________
best regards


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

Old   August 23, 2022, 04:19
Default
  #25
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Alright, so I could the first part as it is, but the second part will be changed through out; -

(define flag_second 0)
(define bctype_second 0)


Thanks, but it did look ok when run, maybe because the two different parts are pulled under different calculation activities.
visitor is offline   Reply With Quote

Old   August 23, 2022, 09:08
Default
  #26
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Dear Alex.

Worked alright with yesterday's 22.08.2022, 13:22 posting, but now when I made the following changes in the second part, I got this error message
"Error: eval: unbound variable
Error Object: flag"

Changes made in the second part to distinguish flag & bctype, from what is shown in the first part. In second part now showing:
"
(define flag_second 0)
(define bctype_second 0)
"

I think I should leave it as it was before, because when defining commands, command-1 and command-2, the two parts are executed separately.


(define (outlet_BC_type_Change)
(define time-sequence #(0.0 0.0374))
(define type-sequence #(1 2))
(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 7 wall”)))
(if (= flag 2)
(ti-menu-load-string (format #f “define bou zone type 7 pressure-outlet”))
))
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure outlet”))
)
(define (inlet_BC_type_Change)
(define time-sequence #(0 0.0052))
(define type-sequence #(2 1))
(define flag_second 0)
(define bctype_second 0)
(define time (rpgetvar ‘flow-time))
(define dt (rpgetvar ‘physical-time-step))
(set! flag_second 0)
(set! bctype_second 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_second 1)
(set! bctype_second (vector-ref type-sequence i))
)))
(if (= 1 bctype_second)
(if (= flag_second 1)
(set! flag_second 2)))
(if (= flag_second 1)
(ti-menu-load-string (format #f “define bou zone type 6 wall”)))
(if (= flag_second 2)
(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 1.1e5 no 1 no 400 no yes”))
))
(newline)
(if (= flag_second 1) (display “Exhaust BC now wall”))
(if (= flag_second 2) (Display “Exhaust BC now pressure inlet”))
)
visitor is offline   Reply With Quote

Old   August 23, 2022, 13:13
Default
  #27
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Moving a way from Scheme, but on the same subject, just tried this UDF for moving a valve wall, got this error again!!
"
line 2: parse error.
"

Now what could be wrong with this, just ran through an interpreter.

#include “udf.h”
DEFINE_CG_MOTION(oscillate_valve,dt,vel,omega,time ,dtime )
{
Thread*t;
face_t f;
t=DT_THREAD(dt);
begin_f_loop(f,t)
{
if(time>=0.03744 && time<=0.0383)
vel[1]=5.0;
if (time<0.03744 && time>0.0383)
vel[1]=-5.0;
else
vel[1]=0.0;
}
end_f_loop(f,t)
}
visitor is offline   Reply With Quote

Old   August 23, 2022, 14:00
Default
  #28
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Now tried another way to move valve wall in 3D, got this error message:
"
line 9: structure reference not implemented
"
What the code should do, is move the valve with positive and negative velocities in the given time conditions, and therefore controlling distance movement.

#include "udf.h"
#include "threads.h"

DEFINE_ADJUST(Valve_adjust,domain)
{
/*NOTE; wall ID is 36*/
Thread *thread = Lookup_Thread(domain, 36);
real current_time = RP_Get_Real("flow-time");
if (current_time>= 0.0374 && current_time<=0.0383)
THREAD_VAR(thread).wall.translate_mag = 5;
Else if (current_time> 0.0383 && current_time<=0.03882)
THREAD_VAR(thread).wall.translate_mag = -5;
Else
THREAD_VAR(thread).wall.translate_mag = 0;
}
visitor is offline   Reply With Quote

Old   August 24, 2022, 01:09
Default
  #29
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by visitor View Post
Moving a way from Scheme, but on the same subject, just tried this UDF for moving a valve wall, got this error again!!
"
line 2: parse error.
"

Now what could be wrong with this, just ran through an interpreter.

#include “udf.h”
DEFINE_CG_MOTION(oscillate_valve,dt,vel,omega,time ,dtime )
{
Thread*t;
face_t f;
t=DT_THREAD(dt);
begin_f_loop(f,t)
{
if(time>=0.03744 && time<=0.0383)
vel[1]=5.0;
if (time<0.03744 && time>0.0383)
vel[1]=-5.0;
else
vel[1]=0.0;
}
end_f_loop(f,t)
}
compile code
__________________
best regards


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

Old   August 24, 2022, 01:38
Default
  #30
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
I did try to compile, these are the errors.

24 Aug moving wall define cg.c(2,1): warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
DEFINE_CG_MOTION(oscillate_valve,dt,vel,omega,time ,dtime )
^
24 Aug moving wall define cg.c(4,1): error: use of undeclared identifier 'Thread'
Thread*t;
^
24 Aug moving wall define cg.c(4,8): error: use of undeclared identifier 't'
Thread*t;
^
24 Aug moving wall define cg.c(5,1): error: use of undeclared identifier 'face_t'
face_t f;
^
24 Aug moving wall define cg.c(6,1): error: use of undeclared identifier 't'
t=DT_THREAD(dt);
^
24 Aug moving wall define cg.c(7,14): error: use of undeclared identifier 'f'
begin_f_loop(f,t)
^
24 Aug moving wall define cg.c(7,16): error: use of undeclared identifier 't'
begin_f_loop(f,t)
^
1 warning and 7 errors generated.
scons: *** [24 Aug moving wall define cg.obj] Error 1
scons: building terminated because of errors.

Done.

latest version timings changed.

#include “udf.h”
DEFINE_CG_MOTION(oscillate_valve,dt,vel,omega,time ,dtime )
{
Thread*t;
face_t f;
t=DT_THREAD(dt);
begin_f_loop(f,t)
{
if(time>=0.000104 && time<=0.000624)
vel[1]=5.0;
if (time>0.000624 && time<=0.001144)
vel[1]=-5.0;
else
vel[1]=0.0;
}
end_f_loop(f,t)
}
visitor is offline   Reply With Quote

Old   August 24, 2022, 08:41
Default
  #31
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
I don't understand why Fluent hasn't made this easy. This should be menu driven or allow an expression to move a boundary wall in 2/3D, just a suggestion for Fluent.
visitor is offline   Reply With Quote

Old   August 25, 2022, 05:13
Default
  #32
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
After trying out various UDFs which because of code errors non worked, I am now looking for a scheme code example. Just to explore if scheme can move 2/3D walls embedded in a mesh.
visitor is offline   Reply With Quote

Old   August 26, 2022, 15:16
Default
  #33
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
This for you Alex if you can help out, you are the scheme expert.

Made some changes and got this error message;
"
Error: eval: unbound variable
Error Object: flag
"
this the scheme code.

(define (outlet_BC_type_Change)
(define time-sequence #(0.0 0.0374))
(define type-sequence #(1 2))
(define flag 0)
(define bctype 0)
(define time (rpgetvar ‘flow-time))
(define dt (rpgetvar ‘physical-time-step))
(set! flag 0)
(set! bctype 0)
(do ((1 0 (+ 1 1)))
((= 1 (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 7 wall”)))
(if (= flag 2)
(ti-menu-load-string (format #f “define bou zone type 7 pressure-outlet”))
))
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure outlet”))
)
visitor is offline   Reply With Quote

Old   August 27, 2022, 08:21
Default
  #34
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Now I have tried something a bit different, controlling to BC with an if condition, but got this error .
"
Error: eval: unbound variable
Error Object: also
"
What I did in lines 22 and 23 I have started two 'ti' for wall 6 and 11.
At line 27 started an if condition statement which;
*sets wall 6 as a pressure-inlet "true condition" if flow-time is less than 0.0052 seconds, and
*a "false condition" which sets wall 11 as pressure-inlet, this means this change in BC can occur after 0.0052 seconds.

Lines 31 and 33 define BCs for wall 6 and 11.

What could be the error?? Please and 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”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
)
(if (= flag 2)
(
if (< (rpgetvar ‘flow-time) 0.0052) (ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”) (ti-menu-load-string (format #f “define bou zone type 11 pressure-inlet”)
)
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1.1e5 no 1 no 400 no yes”))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 11 yes no 1.1e5 no 1 no 400 no yes”))
))
(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 29, 2022, 04:00
Default
  #35
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
each if statement can have only one tru and one false condition
try this code
Code:
(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)
(begin
(ti-menu-load-string (format #f “define bou zone type 6 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
)
)
(if (= flag 2)
(if (< (rpgetvar ‘flow-time) 0.0052) 
(begin
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”)) 
(ti-menu-load-string (format #f “define bou zone type 11 pressure-inlet”))
)
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1.1e5 no 1 no 400 no yes”))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 11 yes no 1.1e5 no 1 no 400 no yes”))
))()
)
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure inlet”))
)
visitor likes this.
__________________
best regards


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

Old   August 29, 2022, 05:58
Default
  #36
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks but maybe I did not explain properly, BC 6 and 11 need to change BC type at different times within the 0.0052 seconds time. Example BC 6 changes BC type at 0.0050 seconds, and BC 11 changes type at 0.0052 seconds.

So starting from line 26, how about this? Flag 2 is split up into two if conditions, the rest should follow. THANKS.

(if (= flag 2)
(if (< (rpgetvar ‘flow-time) 0.005)
(
begin
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”))
)
(if (= flag 2)
(if (< (rpgetvar ‘flow-time) 0.0052)
(
begin
(ti-menu-load-string (format #f “define bou zone type 11 pressure-inlet”))
)
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1.1e5 no 1 no 400 no yes”))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 11 yes no 1.1e5 no 1 no 400 no yes”))
))()
)
visitor is offline   Reply With Quote

Old   August 29, 2022, 10:38
Default
  #37
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
How about this Alex, from line 26 onwards, I have split up flag 2 with two time based if condition statements, less than 0.0050 & less than 0.0052 seconds. After 0.0052 seconds, flag 1 will prevail and switch both BC to walls. I am a bit concerned about the use of brackets, maybe I got mixed up after line 26 and towards the end.

-----
(define (Two_BC_type_Changes)
(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)
(begin
(ti-menu-load-string (format #f “define bou zone type 6 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
)
)
(if (= flag 2)
(if (< (rpgetvar ‘flow-time) 0.0050)
(
begin
(ti-menu-load-string (format #f “define bou zone type 6 pressure-inlet”))
)
(if (< (rpgetvar ‘flow-time) 0.0050)
(
begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 6 yes no 1.1e5 no 1 no 400 no yes”)
)
(if (> (rpgetvar ‘flow-time) 0.0050)
(
begin
(ti-menu-load-string (format #f “define bou zone type 11 pressure-inlet”))
)
(if (> (rpgetvar ‘flow-time) 0.0050)
(
begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 11 yes no 1.1e5 no 1 no 400 no yes”))
)
)
(newline)
(if (= flag 1) (display “Exhaust BC now wall”))
(if (= flag 2) (Display “Exhaust BC now pressure inlet”))
)

Last edited by visitor; August 29, 2022 at 15:52.
visitor is offline   Reply With Quote

Old   September 2, 2022, 15:37
Default
  #38
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Dear Alex another question for you, hope you can help out. Thanks.

What about if I want the 'if' condition to have this time limits; > 0.005 && <= 0.00572.

Is the line below acceptable in scheme?
(if (> (rpgetvar 'flow-time) 0.005 && <=(rpgetvar 'flow-time) 0.00572)

Maybe I should get rid of the 'if' condition, instead use this?
(and (> (rpgetvar 'flow-time) 0.005) (<=(rpgetvar 'flow-time) 0.00572))
visitor is offline   Reply With Quote

Old   September 3, 2022, 02:24
Default
  #39
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Latest run with errors, it sounds I got brackets missed somewhere.
What this code does now; keeps walls closed when flag 1, but with flag 2 opens walls under specific time spans using the "cond" & "and" conditions rather than "if" conditions.

"
Error: eof inside list
Error Object: ()
"

(define (Two_BC_type_Changes)
(define time-sequence #(0 0.00572 0.03276))
(define type-sequence #(2 1 2))
(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)
(begin
(ti-menu-load-string (format #f “define bou zone type 24 wall”))
(ti-menu-load-string (format #f “define bou zone type 23 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
(ti-menu-load-string (format #f “define bou zone type 12 wall”))
)
)
(if (= flag 2)
(cond
[(and (> (rpgetvar ‘flow-time) 0.0) (< (rpgetvar ‘flow-time) 0.0050))
(begin
(ti-menu-load-string (format #f “define bou zone type 24 pressure-inlet”)))]
[(and (> (rpgetvar ‘flow-time) 0.0) (< (rpgetvar ‘flow-time) 0.0050))
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.1e5 no 1 no 300 no yes”)))]
[(and (> (rpgetvar ‘flow-time) 0.0050) (< (rpgetvar ‘flow-time) 0.0057))
(begin
(ti-menu-load-string (format #f “define bou zone type 23 pressure-inlet”)))]
[(and (> (rpgetvar ‘flow-time) 0.0050) (< (rpgetvar ‘flow-time) 0.0057))
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 23 yes no 1.1e5 no 1 no 300 no yes”)))]
[(and (> (rpgetvar ‘flow-time) 0.03276) (<= (rpgetvar ‘flow-time) 0.05616))
(begin
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”)))]
[((> (rpgetvar ‘flow-time) 0.03346)
(begin
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”)))]
)
(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   September 3, 2022, 14:36
Default
  #40
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Why this error in flag 1, "too many arguments"? How can this be rectified? I was more concerned about flag 2, because of the newly introduced 'cond' statement!
Should flag 1 be segrageated into four parts, eg.;
((= flag 1) (ti-menu-load-string (format #f “define bou zone type 24 wall”)))
((= flag 1) (ti-menu-load-string (format #f “define bou zone type 23 wall”)))
((= flag 1) (ti-menu-load-string (format #f “define bou zone type 11 wall”)))
((= flag 1) (ti-menu-load-string (format #f “define bou zone type 12 wall”)))

Or maybe there is a better way? I am still concerned with brackets, I hope it's OK. THANKS in advance!
-------
Error: if syntax: Too many arguments
Error Object: ((= flag 1) (ti-menu-load-string (format #f �define bou zone type 24 wall�)) (ti-menu-load-string (format #f �define bou zone type 23 wall�)) (ti-menu-load-string (format #f �define bou zone type 11 wall�)) (ti-menu-load-string (format #f �define bou zone type 12 wall�)))
=====

(define (changeboundary)
(define time-sequence #(0 (390*0.000104) (670*0.000104))
(define type-sequence #(2 1 2))
(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.5 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 0.5 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 24 wall”))
(ti-menu-load-string (format #f “define bou zone type 23 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
(ti-menu-load-string (format #f “define bou zone type 12 wall”)))
(if (= flag 2)
Cond (> (rpgetvar ‘flow-time) (200*0.000104))
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”))
(> (rpgetvar ‘flow-time) (200*0.000104))
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”))
(> (rpgetvar ‘flow-time) (165*0.000104))
(ti-menu-load-string (format #f “define bou zone type 24 pressure-inlet”))
(> (rpgetvar ‘flow-time) (165*0.000104))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.1e5 no 1 no 400 no yes”))
(> (rpgetvar ‘flow-time) (165*0.000104))
(ti-menu-load-string (format #f “define bou zone type 23 pressure-inlet”))
(> (rpgetvar ‘flow-time) (165*0.000104))
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 23 yes no 1.1e5 no 1 no 400 no yes”))
(> (rpgetvar ‘flow-time) (200*0.000104))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
(> (rpgetvar ‘flow-time) (200*0.000104))
(ti-menu-load-string (format #f “define bou zone type 12 wall”))
(> (rpgetvar ‘flow-time) (390*0.000104))
(ti-menu-load-string (format #f “define bou zone type 23 wall”))
(> (rpgetvar ‘flow-time) (390*0.000107))
(ti-menu-load-string (format #f “define bou zone type 24 wall”))
(> (rpgetvar ‘flow-time) (670*0.000104))
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”)))
(else
(> (rpgetvar ‘flow-time) (673*0.000104))
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”)))
)
(newline)
(if (= flag 1) (display “Boundaries set as walls”))
(if (= flag 2) (Display “Boundaries open/close depending on timings”))
)
visitor 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 15:38.