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

¿Change boundary condition type?

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By David

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 30, 2005, 10:30
Default ¿Change boundary condition type?
  #1
David
Guest
 
Posts: n/a
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
  Reply With Quote

Old   December 1, 2005, 04:20
Default Re: ¿Change boundary condition type?
  #2
nasser
Guest
 
Posts: n/a
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
  Reply With Quote

Old   December 1, 2005, 04:40
Default Re: ¿Change boundary condition type?
  #3
David
Guest
 
Posts: n/a
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
  Reply With Quote

Old   December 1, 2005, 12:56
Default Re: ¿Change boundary condition type?
  #4
David
Guest
 
Posts: n/a
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))))

  Reply With Quote

Old   December 1, 2005, 14:40
Default Re: ¿Change boundary condition type?
  #5
Viatcheslav
Guest
 
Posts: n/a
It is "scheme" programing language:

The scheme file below...

;; switch.scm

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

...

  Reply With Quote

Old   December 2, 2005, 05:50
Default Re: ¿Change boundary condition type?
  #6
David
Guest
 
Posts: n/a
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)) )) )

  Reply With Quote

Old   December 3, 2005, 03:30
Default Re: ¿Change boundary condition type?
  #7
nasser
Guest
 
Posts: n/a
Hi David Thanks My Email: nasser_rasooli@yahoo.com Best Regards
  Reply With Quote

Old   March 14, 2013, 23:19
Default
  #8
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 40
Rep Power: 17
ustbdynamic is on a distinguished road
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))))
ustbdynamic is offline   Reply With Quote

Old   April 17, 2013, 13:35
Default
  #9
New Member
 
Join Date: Jun 2011
Posts: 2
Rep Power: 0
chengcheny is on a distinguished road
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
chengcheny 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
boundary conditions for simpleFoam calculation foam_noob OpenFOAM Running, Solving & CFD 8 July 1, 2015 09:07
Need help with boundary conditions: open to atmosphere Wolle OpenFOAM 2 April 11, 2011 08:32
Pressure instability with rhoSimpleFoam daniel_mills OpenFOAM Running, Solving & CFD 44 February 17, 2011 18:08
Boundary condition setting for non-premixed combustion using reactingFoam skyopener OpenFOAM 0 May 23, 2010 23:55
pipe flow with heat transfer Fabian OpenFOAM 2 December 12, 2009 05:53


All times are GMT -4. The time now is 19:37.