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   September 4, 2022, 05:37
Default
  #41
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Managed to get this scheme code going, no errors when compiled with Fluent, but when run got this error message after every time step! What could have gone wrong?

"
...
(Two_BC_type_Changes)
Error: eval: unbound variable
Error Object: two_bc_type_changes
"

(define (Two_BC_type_Changes)
(define time-sequence #(0 (30*8.333e-5) (310*8.333e-5))) ;begins opennings then close for compress and ignition finall opening with specific times
(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) (* 8.333e-5 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 8.333e-5 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) (30*8.333e-5))) ;suction open big timer
(begin
(ti-menu-load-string (format #f “define bou zone type 24 pressure-inlet”))) ;suction open big BC status
(and (> (rpgetvar ‘flow-time) 0.0) (< (rpgetvar ‘flow-time) (30*8.333e-5))) ;suction open timer
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.1e5 no 1 no 300 no yes”))) ;suction open big pressure on
(and (> (rpgetvar ‘flow-time) 0.0050) (< (rpgetvar ‘flow-time) (30*8.333e-5))) ;suction open small timer
(begin
(ti-menu-load-string (format #f “define bou zone type 23 pressure-inlet”))) ;suction open small BC status
(and (> (rpgetvar ‘flow-time) 0.0050) (< (rpgetvar ‘flow-time) (30*8.333e-5))) ;suction open small timer
(begin
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 23 yes no 1.1e5 no 1 no 300 no yes”))) ;suction open small pressure on
(and (> (rpgetvar ‘flow-time) (490*0.000104)) (<= (rpgetvar ‘flow-time) (720*8.333e-5))) ;outlet open big timer
(begin
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”))) ;outlet open big BC status
(and (> (rpgetvar ‘flow-time) (490*0.000104)) (<= (rpgetvar ‘flow-time) (720*8.333e-5))) ;outlet open small timer
(begin
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”))) ;outlet open big BC status
)
)
(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 4, 2022, 06:30
Default
  #42
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Latest scheme error when run with fluent.

At every time step I get this message.
Error: eval: unbound variable
Error: Object: flow-time
visitor is offline   Reply With Quote

Old   September 5, 2022, 02:56
Default
  #43
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Then I tried to simplify this and get rid of the flags and loops, by using the following scheme code, but keep getting this error??
---
Error: eval: unbound variable
Error Object: �flow-time
---

(define (change_BC_cond_only)
(cond (>=(rpgetvar ‘flow-time) 0)
(ti-menu-load-string “define/boundary-conditions/zone-type 24 pressure-inlet”))
(>=(rpgetvar ‘flow-time) 0)
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.2e5 no 1 no 360 no yes”))
(>=(rpgetvar ‘flow-time) 0.00312)
(ti-menu-load-string “define/boundary-conditions/zone-type 24 wall”))
(<=(rpgetvar ‘flow-time) 0.03224)
(ti-menu-load-string “define/boundary-conditions/zone-type 11 wall”))
(else (>=(rpgetvar ‘flow-time) 0.03224)
(ti-menu-load-string “define/boundary-conditions/zone-type 11 pressure-outlet”)))
)
visitor is offline   Reply With Quote

Old   September 6, 2022, 02:35
Default
  #44
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
problem is in brackets, as it was in other versions of code (above)
stick to scheme language syntax

example
Code:
(cond
   ((positive? -5) (error "doesn't get here"))
   ((zero? -5) (error "doesn't get here, either"))
   ((positive? 5) 'here))
answer
Code:
here
__________________
best regards


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

Old   September 6, 2022, 03:18
Default
  #45
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks Alex. I though it was the brackets, I will try this again. Meanwhile I run this code with one BC change relying on flag 1 and flag 2, rather than the complxity of the cond statement. The problem is the limitation of the two flags, it will be good if this can be modified with for example three or four flags (flag 1, flag 2, flag 3, flag 4..) The top part of the program loops over the flags. Still though no BC change was observed, but at least no errors.


(define (outlet_BC_type_Changes)
(define time-sequence #(0 0.05616)) ;begins opennings then close for compress and ignition finall opening with specific times
(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) (* 8.333e-5 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 8.333e-5 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 11 wall”))
(ti-menu-load-string (format #f “define bou zone type 12 wall”))
)
)
(if (= flag 2)
(begin
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”)) ;suction open big BC status
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”)) ;outlet open big BC status
)
)
)
visitor is offline   Reply With Quote

Old   September 6, 2022, 03:48
Default
  #46
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Just wrote this and got this error message, brackets!
Error: eof inside list
Error Object: ()

(define (Two_BC_type_Changes)
(define time-sequence #(0 0.00312 0.05616))
(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) (* 8.333e-5 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 8.333e-5 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 6 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
)
)
(if (= flag 2)
(cond
((> (rpgetvar ‘flow-time) 0.0) (ti-menu-load-string (format #f “define bou zone type 24 pressure-inlet”))
((> (rpgetvar ‘flow-time) 0.0) (ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.1e5 no 1 no 300 no yes”))
((> (rpgetvar ‘flow-time) 0.0) (ti-menu-load-string (format #f “define bou zone type 23 pressure-inlet”))
((> (rpgetvar ‘flow-time) 0.0) (ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 23 yes no 1.1e5 no 1 no 300 no yes”))
((> (rpgetvar ‘flow-time) 0.05616) (ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”))
((> (rpgetvar ‘flow-time) 0.05616) (ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”))
)
)
)

Last edited by visitor; September 6, 2022 at 06:37.
visitor is offline   Reply With Quote

Old   September 6, 2022, 19:23
Default
  #47
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
I recommend you to use notepad++, its quite comfortable, it will help you to check your brackets
__________________
best regards


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

Old   September 7, 2022, 01:50
Default
  #48
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks Alex. I will look at this tool, but looking at the first 22 lines of scheme code, what should change to make the code work with a third or even fourth flag. Right now it just works for two flags, flag 1 and flag 2. Thanks again
visitor is offline   Reply With Quote

Old   September 7, 2022, 07:45
Default
  #49
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
Thanks Alex, downloaded Notepad++, yes it is helpful, had an extra bracket at the end.! Still if there is a way in increasing flags from 2 to 3 or even 4, it will be neater I think, no need for 'if' 'and' 'cond' ...
visitor is offline   Reply With Quote

Old   September 7, 2022, 15:16
Default
  #50
Senior Member
 
AH
Join Date: Apr 2014
Posts: 282
Rep Power: 13
visitor is on a distinguished road
This is what I am aiming for now to simplify the code and just change BCs based on flag 1, flag 2 and flag 3. I have not run this yet, though did check this with notepad++, and no bracket errors showed, still doesn't seem right.


(define (Two_BC_type_Changes)
(define time-sequence #(0 0.00312 0.05616))
(define type-sequence #(2 1 3))
(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) (* 8.333e-5 dt)))
(if (<= time (+ (vector-ref time-sequence i) (* 8.333e-5 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 6 wall”))
(ti-menu-load-string (format #f “define bou zone type 11 wall”))
)
)
(if (= flag 2)
(cond
(ti-menu-load-string (format #f “define bou zone type 24 pressure-inlet”)
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 24 yes no 1.1e5 no 1 no 300 no yes”)
(ti-menu-load-string (format #f “define bou zone type 23 pressure-inlet”)
(ti-menu-load-string (format #f “define boundary-conditions pressure-inlet 23 yes no 1.1e5 no 1 no 300 no yes”)
)
)
(if (= flag 3)
(cond
(ti-menu-load-string (format #f “define bou zone type 11 pressure-outlet”)
(ti-menu-load-string (format #f “define bou zone type 12 pressure-outlet”)
)
)
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 00:19.