CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   ¿Change boundary condition type? (https://www.cfd-online.com/Forums/fluent/38786-change-boundary-condition-type.html)

David November 30, 2005 09:30

¿Change boundary condition type?
 
Hello,

I trying to find a udf to change boundary condition type (from wall to outlet_vent).

I know that there is the possibility of using "Define>Dynamic Mesh>Events". Apart from the fact that "Events" do not change wall to vent, I need to do it with a UDF because of other reasons of the case.

I have found a UDF in Fluent´s web page: User-Defined Functions archive>UDF examples (the 2nd one), but the final part (where are the comands to change BC) is written in a programming language that I do not know. So I suppose that it is possible, however I have not found anything about in the UDF manual.

Could anyone help me,please?

Thank you very much, David

nasser December 1, 2005 03:20

Re: ¿Change boundary condition type?
 
Hi David I need this too.but I cant find anything about this Can you send that program me? I will study it and if I understand anything I will mail it to you If you find the answer plz guide me Thanks bye

David December 1, 2005 03:40

Re: ¿Change boundary condition type?
 
Hi nasser, how are you?

I will send you what I have found, but I need your e-mail adress in order to I may attach two word archives with the explanation of the UDF and the UDF source...

OK? Thanks for your interest. Maybe together we can achieve something

David December 1, 2005 11:56

Re: ¿Change boundary condition type?
 
Hellow, in order to share the information I found, here you have a copy+paste of the UDF information and the UDF source. The last part is what I do not understand(which programing language is it?) Thanks.

BRIEF DESCRIPTION: In time dependent runs, it is often desirable to change an inlet to a wall or an outlet to an inlet. Normally this needs some sort of journal file. The scheme file below defines a funtion (run-switched n-time-steps) that does standard timestepping but calls an on-demand udf before each timestep. The on-demand sets an array of switches (list of integers in scheme) that tells the (run-switched) function which actions to perform before the next timestep. These actions can be anything you'd put in a journal file, so changing BC types or values is possible. Currently I've only done an unsteady version, but such events could be done in a steady solver on an iteration-by-iteration basis. The first C file is the ON_DEMAND UDF. It does a simple cylinder valve port open close cycle. The next C & .h file are not needed in V6.2 but V6.1 doesnt have the RP_Set_List_of_Integer function. The final scheme is the main switch testing loop. The user need only change the (format) functions to change the operation due to each switch. Example case & data files (3d & 3d_parallel) are available on request. The (run-switched n-time-steps) must be run instead of the usual timestepping command. Interrupting is also not possible, so to stop the timestepping, a checkpointing file is used. create a file called "run-switched-stop.txt" with anything in it and if it is found in the current fluent directory, the timestepping will stop cleanly. #include "udf.h"

/* The RP_Set_List_of_Integer function does not in V6.1 but is in V6.2 */ /* Remove next line and list_of_integer.[ch] files for V6.2 */ #include "list_of_integer.h"

#define N_SWITCHES 4

#define UNKNOWN 0 #define LEAVE 0 #define CLOSED 1 #define OPENED 2

DEFINE_ON_DEMAND(set_switches) { #if !RP_NODE /* only does things on HOST or SERIAL */

static int states[N_SWITCHES] = {UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN};

real shifts[N_SWITCHES] = {0.0, 90.0, 270.0, 180.0};

int i, change, switches[N_SWITCHES]; real rpm = 6000.0; real time, period, phase, shift_phase;

period = 60.0/rpm; /* seconds */ time=CURRENT_TIME;

Message("\n-----------------------------------------------\n");

period = 60.0/rpm; /* seconds */

time= CURRENT_TIME + CURRENT_TIMESTEP; /* time at NEXT time step */ Message("Time is %f(s)\n",time);

phase=time/period; phase=360.0*(phase-floor(phase)); /* degrees */ Message("Phase is %f(degs)\n",phase);

for (i=0;i<N_SWITCHES;i++)

{

shift_phase = phase + shifts[i];

while(shift_phase >= 360.0) /* refix modulo after addition of shift */

shift_phase -= 360.0;

if(shift_phase< 80.0)

change=OPENED;

else

change=CLOSED;

if(states[i]==change)

switches[i]=LEAVE;

else

{

states[i]=change;

switches[i]=change;

}

}

RP_Set_List_of_Integer("udf-switches", switches, N_SWITCHES);

Message("-----------------------------------------------\n"); #endif /* !RP_NODE */ }

DEFINE_PROFILE(Mprof, ft, m) { face_t f;

begin_f_loop(f, ft)

{

F_PROFILE(f, ft, m) = 250;

} end_f_loop(f, ft) }

/* list_of_integer.c */ #include "cxserv.h"

static void rpsetvar(char *s, Pointer val) { Pointer p; stack *oldstk = Save_Stack(); extern Pointer sym_quote; Pointer sym_uienv; Pointer sym_rpsetvarlocal;

sym_uienv = intern("user-initial-environment"); sym_rpsetvarlocal = intern("rpsetvarlocal");

Push_Stack0(val); /* protect val from garbage collection */ /* (eval `(rpsetvarlocal ',s ',v) user-initial-environment) */ Push_Stack(p); p = cons(NIL,NIL); CAR(p) = cons(val,NIL); CAR(p) = cons(sym_quote,CAR(p)); p = cons(NIL,p); CAR(p) = cons(intern(s),NIL); CAR(p) = cons(sym_quote,CAR(p)); p = cons(sym_rpsetvarlocal,p); (void) eval(p, eval(sym_uienv,NIL)); Restore_Stack(oldstk); }

void RP_Set_List_of_Integer(char *s, int a[], int len) { int n; Pointer result = NIL; stack *oldstk;

if (len <= 0) err("RP_Set_List_of_Integer: zero length list", NIL);

oldstk = Save_Stack(); Push_Stack(result);

for (n=len-1; n>=0; n--)

{

result = cons(NIL,result);

CAR(result) = fixcons(a[n]);

}

rpsetvar(s,result); Restore_Stack(oldstk); }

/* list_of_integer.h */ void RP_Set_List_of_Integer(char *s, int a[], int len);

;; switch.scm

;; load this file into fluent so that (run-switched nts) is available

(if (not (rp-var-object 'udf-switches))

(rp-var-define 'udf-switches () 'list #f))

(define run-switched/stop-filename "run-switched-stop.txt")

(define (run-switched . t-steps) (if

(do ((i (car t-steps) (- i 1)))

((or (= i 0) (file-exists? run-switched/stop-filename)) (> i 0))

(let ((list)(len)(state))

(format "~%Time Steps Remaining ~d~%" i)

(%udf-on-demand "set_switches")

(set! list (%rpgetvar 'udf-switches))

(set! len (length (%rpgetvar 'udf-switches)))

(do ((j 1 (+ j 1))) ((> j len) j)

(set! state (car list))

(set! list (cdr list))

(if (= state 1)

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/mass_flow_inlet.~d wall~%" j)))

(if (= state 2)

(begin

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/ mass_flow_inlet.~d mass-flow-inlet~%" j))

(ti-menu-load-string

(format #f "/def/bc/mfi mass_flow_inlet.~d n y y \"udf\" \"Mprof\" n 330 n 0 y y y n 1 n 0 n 0~%" j))

))

)

(err-protect (physical-time-steps 1

(rpgetvar 'max-iterations-per-step)))))

(begin

(remove-file run-switched/stop-filename)

(format "~%(run-switched ~d) Stopped~%" (car t-steps)))

(format "~%(run-switched ~d) Completed~%" (car t-steps))))


Viatcheslav December 1, 2005 13:40

Re: ¿Change boundary condition type?
 
It is "scheme" programing language:

The scheme file below...

;; switch.scm

;; load this file into fluent so that (run-switched nts) is available

...


David December 2, 2005 04:50

Re: ¿Change boundary condition type?
 
Thanks Viatcheslav. Finally I found the programming language. However, I tried to "translate" it to "C" language programming and it is quite difficult for me. Could anyone help me with the following part? I need it for writing a UDF for changing BC type at a time. Thank you.

(if (= state 1)

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/mass_flow_inlet.~d wall~%" j))) (if (= state 2)

(begin

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/ mass_flow_inlet.~d mass-flow-inlet~%" j))

(ti-menu-load-string

(format #f "/def/bc/mfi mass_flow_inlet.~d n y y \"udf\" \"Mprof\" n 330 n 0 y y y n 1 n 0 n 0~%" j)) )) )


nasser December 3, 2005 02:30

Re: ¿Change boundary condition type?
 
Hi David Thanks My Email: nasser_rasooli@yahoo.com Best Regards

ustbdynamic March 14, 2013 22:19

hello

Who knows the meanings of these sentence:
(define (run-switched . t-steps)
(if
(do ((i (car t-steps) (- i 1))
...

Here the "t-steps" in the do loop ((do ((i (car t-steps) (- i 1))) is a variable, but it hasn't predefined and never give initial value. Then, how to run the procedure ?

thanks !








Quote:

Originally Posted by David
;126655
Hellow, in order to share the information I found, here you have a copy+paste of the UDF information and the UDF source. The last part is what I do not understand(which programing language is it?) Thanks.

BRIEF DESCRIPTION: In time dependent runs, it is often desirable to change an inlet to a wall or an outlet to an inlet. Normally this needs some sort of journal file. The scheme file below defines a funtion (run-switched n-time-steps) that does standard timestepping but calls an on-demand udf before each timestep. The on-demand sets an array of switches (list of integers in scheme) that tells the (run-switched) function which actions to perform before the next timestep. These actions can be anything you'd put in a journal file, so changing BC types or values is possible. Currently I've only done an unsteady version, but such events could be done in a steady solver on an iteration-by-iteration basis. The first C file is the ON_DEMAND UDF. It does a simple cylinder valve port open close cycle. The next C & .h file are not needed in V6.2 but V6.1 doesnt have the RP_Set_List_of_Integer function. The final scheme is the main switch testing loop. The user need only change the (format) functions to change the operation due to each switch. Example case & data files (3d & 3d_parallel) are available on request. The (run-switched n-time-steps) must be run instead of the usual timestepping command. Interrupting is also not possible, so to stop the timestepping, a checkpointing file is used. create a file called "run-switched-stop.txt" with anything in it and if it is found in the current fluent directory, the timestepping will stop cleanly. #include "udf.h"

/* The RP_Set_List_of_Integer function does not in V6.1 but is in V6.2 */ /* Remove next line and list_of_integer.[ch] files for V6.2 */ #include "list_of_integer.h"

#define N_SWITCHES 4

#define UNKNOWN 0 #define LEAVE 0 #define CLOSED 1 #define OPENED 2

DEFINE_ON_DEMAND(set_switches) { #if !RP_NODE /* only does things on HOST or SERIAL */

static int states[N_SWITCHES] = {UNKNOWN,UNKNOWN,UNKNOWN,UNKNOWN};

real shifts[N_SWITCHES] = {0.0, 90.0, 270.0, 180.0};

int i, change, switches[N_SWITCHES]; real rpm = 6000.0; real time, period, phase, shift_phase;

period = 60.0/rpm; /* seconds */ time=CURRENT_TIME;

Message("\n-----------------------------------------------\n");

period = 60.0/rpm; /* seconds */

time= CURRENT_TIME + CURRENT_TIMESTEP; /* time at NEXT time step */ Message("Time is %f(s)\n",time);

phase=time/period; phase=360.0*(phase-floor(phase)); /* degrees */ Message("Phase is %f(degs)\n",phase);

for (i=0;i<N_SWITCHES;i++)

{

shift_phase = phase + shifts[i];

while(shift_phase >= 360.0) /* refix modulo after addition of shift */

shift_phase -= 360.0;

if(shift_phase< 80.0)

change=OPENED;

else

change=CLOSED;

if(states[i]==change)

switches[i]=LEAVE;

else

{

states[i]=change;

switches[i]=change;

}

}

RP_Set_List_of_Integer("udf-switches", switches, N_SWITCHES);

Message("-----------------------------------------------\n"); #endif /* !RP_NODE */ }

DEFINE_PROFILE(Mprof, ft, m) { face_t f;

begin_f_loop(f, ft)

{

F_PROFILE(f, ft, m) = 250;

} end_f_loop(f, ft) }

/* list_of_integer.c */ #include "cxserv.h"

static void rpsetvar(char *s, Pointer val) { Pointer p; stack *oldstk = Save_Stack(); extern Pointer sym_quote; Pointer sym_uienv; Pointer sym_rpsetvarlocal;

sym_uienv = intern("user-initial-environment"); sym_rpsetvarlocal = intern("rpsetvarlocal");

Push_Stack0(val); /* protect val from garbage collection */ /* (eval `(rpsetvarlocal ',s ',v) user-initial-environment) */ Push_Stack(p); p = cons(NIL,NIL); CAR(p) = cons(val,NIL); CAR(p) = cons(sym_quote,CAR(p)); p = cons(NIL,p); CAR(p) = cons(intern(s),NIL); CAR(p) = cons(sym_quote,CAR(p)); p = cons(sym_rpsetvarlocal,p); (void) eval(p, eval(sym_uienv,NIL)); Restore_Stack(oldstk); }

void RP_Set_List_of_Integer(char *s, int a[], int len) { int n; Pointer result = NIL; stack *oldstk;

if (len <= 0) err("RP_Set_List_of_Integer: zero length list", NIL);

oldstk = Save_Stack(); Push_Stack(result);

for (n=len-1; n>=0; n--)

{

result = cons(NIL,result);

CAR(result) = fixcons(a[n]);

}

rpsetvar(s,result); Restore_Stack(oldstk); }

/* list_of_integer.h */ void RP_Set_List_of_Integer(char *s, int a[], int len);

;; switch.scm

;; load this file into fluent so that (run-switched nts) is available

(if (not (rp-var-object 'udf-switches))

(rp-var-define 'udf-switches () 'list #f))

(define run-switched/stop-filename "run-switched-stop.txt")

(define (run-switched . t-steps) (if

(do ((i (car t-steps) (- i 1)))

((or (= i 0) (file-exists? run-switched/stop-filename)) (> i 0))

(let ((list)(len)(state))

(format "~%Time Steps Remaining ~d~%" i)

(%udf-on-demand "set_switches")

(set! list (%rpgetvar 'udf-switches))

(set! len (length (%rpgetvar 'udf-switches)))

(do ((j 1 (+ j 1))) ((> j len) j)

(set! state (car list))

(set! list (cdr list))

(if (= state 1)

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/mass_flow_inlet.~d wall~%" j)))

(if (= state 2)

(begin

(ti-menu-load-string

(format #f "/def/bc/mz/zone-type/ mass_flow_inlet.~d mass-flow-inlet~%" j))

(ti-menu-load-string

(format #f "/def/bc/mfi mass_flow_inlet.~d n y y \"udf\" \"Mprof\" n 330 n 0 y y y n 1 n 0 n 0~%" j))

))

)

(err-protect (physical-time-steps 1

(rpgetvar 'max-iterations-per-step)))))

(begin

(remove-file run-switched/stop-filename)

(format "~%(run-switched ~d) Stopped~%" (car t-steps)))

(format "~%(run-switched ~d) Completed~%" (car t-steps))))


chengcheny April 17, 2013 12:35

Quote:

Originally Posted by David
;126589
Hello,

I trying to find a udf to change boundary condition type (from wall to outlet_vent).

I know that there is the possibility of using "Define>Dynamic Mesh>Events". Apart from the fact that "Events" do not change wall to vent, I need to do it with a UDF because of other reasons of the case.

I have found a UDF in Fluent´s web page: User-Defined Functions archive>UDF examples (the 2nd one), but the final part (where are the comands to change BC) is written in a programming language that I do not know. So I suppose that it is possible, however I have not found anything about in the UDF manual.

Could anyone help me,please?

Thank you very much, David

have your problem fixed? if it is ok now, can you help me? my Email:chengcheny@gmail.com
thank you very much


All times are GMT -4. The time now is 14:00.