|
[Sponsors] |
UDF to record FLUENT Solver variables... |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 29, 2010, 07:09 |
UDF to record FLUENT Solver variables...
|
#1 |
Member
Join Date: Jan 2010
Posts: 54
Rep Power: 16 |
dear friends,
Fluent provides macros to access solution variables like velocity etc. These macros are used in writing UDF to access any variable of interest. I am doing LES, and i want to capture the fluctuations in velocity. If i write a UDF to access the velocity variable provided in these macros, i can observe the fluctuating component of velocity which will offcourse be not observed once the same UDF is linked to URANS case. Is that right? Correct me if i am wrong. Plz anyone help me in writing the UDF or give me if someone has done some similar work, i dont know how to write the UDF! Waiting patiently for your quick reply |
|
January 30, 2010, 14:00 |
|
#2 |
Senior Member
Join Date: Nov 2009
Posts: 411
Rep Power: 20 |
Maybe this will help you:
http://www.cfd-online.com/Forums/flu...ome-nodes.html it is actually a Scheme macro and not a UDF, but you can use this in Fluent if you want to save some data at every time step. I suspect you want to record the velocity fluctuations in some particular region and not on your entire mesh (if you have a 3d problem and try to save these at every point at each time step you will end up with some GB of data). Do |
|
January 31, 2010, 06:46 |
|
#3 |
Member
Join Date: Jan 2010
Posts: 54
Rep Power: 16 |
Hey Do thanks for ur input,
Yeah exactly this is the problem, i want to capture velocity fluctuations at a single cell or face or node, not the entire domain or the entire zone (mesh is 10 mill so hard disk is gonna start crying haha). I saw ur link, i havent looked into scheme programming before so ill do check it out as well. But i have heard that for my particular problem, i have to write UDF. Nobody mentioned scheme macro, but surely ill see them as well. I have been studying UDF for the past couple of days, i can use the DEFINE_EXECUTE_AT_END macro which executes the UDF at the end of each time step. Now i am facing 2 problems in the UDF, 1. How to tell Fluent to pick up say x property at y cell? I have used UDF's which do this, but they either do it for the entire domain or the entire zone. I couldnt find any which does the operation on a single cell... 2. After that i want the UDF to write that value to say data.out or data.txt file on the hard disk? I have used UDF's that print the data onto ur Fluent screen after every time step, but i dont want that... Can u help... |
|
January 31, 2010, 14:02 |
|
#4 |
Senior Member
Join Date: Nov 2009
Posts: 411
Rep Power: 20 |
"2. After that i want the UDF to write that value to say data.out or data.txt file on the hard disk? I have used UDF's that print the data onto ur Fluent screen after every time step, but i dont want that..."
Open a file and use fprintf instead of Message or printf ... This should be basic for any C programmer (this will write an integer to data.txt): FILE *fp; fp=fopen("data.txt","w"); fprintf(fp,"%d\n",int_test); .............. You should probably move the part that opens the file in a EXECUTE_ON_DEMAND and the part that actually writes in EXECUTE_AT_END, and keep *fp as a global variable in your UDF. Do |
|
February 1, 2010, 12:30 |
|
#5 |
Member
Join Date: Jan 2010
Posts: 54
Rep Power: 16 |
Thankyou so much,
Ill check it out and give u the input, hope i dont have to ask any more questions |
|
February 1, 2010, 14:37 |
Monitors
|
#6 |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
||
February 2, 2010, 13:54 |
|
#7 |
Member
Join Date: Jan 2010
Posts: 54
Rep Power: 16 |
Hey Dragos,
If u read my original post, i want to do this to show the difference of how the NS equations are solved for LES and URANS. In URANS equations, although we do take the time derivative, but its the time derivative of mean velocity "u bar". But in LES, time derivative of actual velocity is taken which includes the fluctuating part as well. So i want to access this velocity variable "u" solved in the equations. for URANS it will show no fluctuations, for LES it will show fluctuations.Since Fluent calculates all values at the centroid of each cell, i want to record this value at a single cell at each time step. No such option is available in the monitors. Also i have heard from everybody that u have to write a UDF to accomplish this task. Now i dont exactly know that the approach which i am taking, which i described above, is correct because my theoretical knowledge about the background equations which Fluent solves is not so good. Plz tell me if im wrong??? Thanks |
|
February 4, 2010, 07:06 |
|
#8 |
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20 |
I still think that you may use monitors for this, but if you want udf's...here it comes an example:
Code:
#include "udf.h" DEFINE_ON_DEMAND(bubu) { real pos[ND_ND] = {1,2,3};/*the position of the monitoring point*/ static cell_t c0 = -1;/*index of the cell containing the monitoring point*/ cell_t c; static Thread *t0 = NULL;/*thread of the cell containing the monitoring point*/ Thread *t; real x[ND_ND], d2 = 1.0e9, d20 = 1.0e9; FILE *pf; Domain *d = Get_Domain(1); /*find once the thread and index of the cell containing the monitoring point*/ if(NULL == t0) thread_loop_c(t,d) { begin_c_loop(c,t) { C_CENTROID(x,c,t); NV_V(x,-=,pos); d2 = NV_MAG2(x); if(d2 < d20) { d20 = d2; t0 = t; c0 = c; } } end_c_loop(c,t) } if(NULL == (pf = fopen("Ux.txt","a"))) Error("Could not open file!\n"); fprintf(pf,"%e\t%e\n",CURRENT_TIME, C_U(c0,t0)); fclose(pf); } |
|
February 9, 2010, 07:39 |
|
#9 |
Senior Member
|
As stated by dmoroian, the most obvious way to do this is by defining a monitor point (unless you don't want the velocity in a whole region). There is no difference in the turbulence model you are going to use, you just need to monitor the velocity in a specified point...and of course you have to write the result in a file, instead of printing it on the console
|
|
February 19, 2010, 13:25 |
|
#10 |
Member
Join Date: Jan 2010
Posts: 54
Rep Power: 16 |
Thanks for ur guidance,
I have used point monitors and it seems its working well as i wanted. So far so good |
|
September 23, 2019, 15:34 |
|
#11 | |
New Member
Athalia
Join Date: Sep 2019
Posts: 2
Rep Power: 0 |
Quote:
Hello @dmoroian, it's been over 9 years! But I hope you could answer two questions about your code. 1. I believe in Code:
C_CENTROID(x,c,t); NV_V(x,-=,pos); d2 = NV_MAG2(x); if(d2 < d20) { d20 = d2; t0 = t; c0 = c; } 2. I want to use your code to print out the UDF output in a particular cell. How can I adapt the following line it your code? If there isn't a macro defined for the value, I want to store (like C_U(c0, t0) ), how can I store if to a text data? Code:
DEFINE_EXCHANGE_PROPERTY(drag, cell, mix_thread, s_col, f_col) { /*calculate drag coefficient drag_coeff*/ return drag_coeff; } DEFINE_ON_DEMAND(bubu) { /*[...] */ fprintf(pf, "%e\t%e\n", CURRENT_TIME, C_U(c0, t0)); /*[...] */ } |
||
September 24, 2019, 01:07 |
|
#12 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
||
Tags |
les, macros, udf, velocity fluctuations |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF in Fluent | Andrew | Fluent UDF and Scheme Programming | 5 | March 7, 2016 04:38 |
Using Fluent with a UDF frm a remote m/c | aarti | FLUENT | 2 | September 11, 2008 20:53 |
compiling my UDF | Seyed Farid Hosseinizadeh | FLUENT | 22 | February 14, 2006 11:19 |
UDF problem caused by various version of Fluent | Yurong | FLUENT | 3 | January 15, 2006 11:57 |
UDF variables F1, y / problem with UDF | Fabian | FLUENT | 6 | June 2, 2003 11:22 |