|
[Sponsors] |
June 25, 2012, 07:06 |
How to write a UDF
|
#1 |
New Member
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14 |
Dear all,
I need to write a UDF for pressure inlet boundary condition where i knew 10 data points of time vs pressure. Can someone help me in detailing the procedure to write such a UDF. Thanks in advance |
|
June 26, 2012, 13:08 |
|
#2 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Assuming you want to interpolate the pressure linearly between the discrete values, something like this might do the trick
Code:
#include "udf.h" DEFINE_PROFILE(pressure_profile,t,i) { real tn[10]; real pn[10]; face_t f; int n; real time=RP_Get_Real("flow-time"); tn[1]=2; tn[2]=3; //...and so on, here you may enter your data points pn[1]=4; pn[2]=7; //...and so on begin_f_loop(f,t) { for(n=10;n>0;n=n-1) { if(tn[n]<time) { F_PROFILE(f,t,i)=pn[n]+(time-tn[n])/(tn[n+1]-tn[n])*(pn[n+1]-pn[n]); } } } end_f_loop(f,t) } |
|
June 26, 2012, 21:33 |
|
#3 |
New Member
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14 |
Thanks Alexander,
will try your suggestion and post whether it worked for me or not. Thanks for your timely support Balaji |
|
June 27, 2012, 01:25 |
|
#4 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Sorry I just found a little mistake:
Code:
#include "udf.h" DEFINE_PROFILE(pressure_profile,t,i) { real tn[10]; real pn[10]; face_t f; int n; real time=RP_Get_Real("flow-time"); tn[1]=2; tn[2]=3; //...and so on, here you may enter your data points pn[1]=4; pn[2]=7; //...and so on begin_f_loop(f,t) { n=1; while(tn[n]<=time) { F_PROFILE(f,t,i)=pn[n]+(time-tn[n])/(tn[n+1]-tn[n])*(pn[n+1]-pn[n]); n++; } } end_f_loop(f,t) } |
|
June 27, 2012, 09:00 |
|
#5 |
New Member
Balaji
Join Date: Jun 2011
Posts: 9
Rep Power: 14 |
Thanks Alexander
I have solved the problem using your help. Thanks Saeed For your help anyways i have solved the problem |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
HOW to write udf for motion of piston and displacer? | mani.rajendiran | Fluent UDF and Scheme Programming | 0 | March 13, 2012 00:22 |
Fluent write UDF for calculating My, Mz and Fz | davesmith_01 | FLUENT | 1 | November 20, 2011 21:20 |
how write UDF | lnjxhl | FLUENT | 3 | March 3, 2010 08:32 |
how to write a 3D linear temperature of UDF | venus | FLUENT | 1 | October 28, 2008 02:46 |
UDF to read and write data | Mcgregor | FLUENT | 4 | June 9, 2003 13:21 |