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

UDF for time integral field function

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By AlexanderZ
  • 1 Post By paolofug87

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 10, 2017, 01:55
Default UDF for time integral field function
  #1
New Member
 
Paolo
Join Date: Jan 2017
Posts: 19
Rep Power: 9
paolofug87 is on a distinguished road
Hi all,
I would like to create an udf for calculating the time integral of a variable (i.e. CO concentration) and allocating it in a UDM. Nothing special, just multiply the new value for dt and adding the one calculated in the previous step.
I know how to write udf but this time it seems that I need to declare a global variable and I don't now where I have to hook it in the model.

Thank you in advance

Paolo

P.s. is there any precaution to use this udf in parallel computing?
paolofug87 is offline   Reply With Quote

Old   October 10, 2017, 11:26
Default
  #2
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,674
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
Why can't you use the built-in data sampling for time statistics option? You should have the option of selecting species.

If you cannot select it, I think it is much easier to define a custom field function, set it equal to the [CO] and then sample this custom variable again using the data sampling option.

Quote:
Originally Posted by paolofug87 View Post
I know how to write udf but this time it seems that I need to declare a global variable and I don't now where I have to hook it in the model.
I don't know how to decipher that to understand what your problem is.
LuckyTran is offline   Reply With Quote

Old   October 10, 2017, 12:59
Default
  #3
New Member
 
Paolo
Join Date: Jan 2017
Posts: 19
Rep Power: 9
paolofug87 is on a distinguished road
Sorry for my English, I wish to have a field variable that is the cumulative of the co concentration in time for each cell. The aim is to show contour of FED (fractional effective dose) in all the domain.
I figured out that I have probably to set two udm, one for storing the [CO] in the previous time step (let's say udm0) and one for the last time step (udm1) and then sum udm0+udm1 each time step updating the first one (udm0=udm1). My problem is to write the udf that does this task and where to hook it (probably in the udf hook panel in one of the options).

Thank you
paolofug87 is offline   Reply With Quote

Old   October 10, 2017, 13:01
Default
  #4
New Member
 
Paolo
Join Date: Jan 2017
Posts: 19
Rep Power: 9
paolofug87 is on a distinguished road
Furthermore I wish to run the simulation in parallel, I know that loops over cells require some precaution
paolofug87 is offline   Reply With Quote

Old   October 10, 2017, 20:40
Default
  #5
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,674
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
This doesn't require a UDF afaik. Just turn on data sampling for time-statistics.
LuckyTran is offline   Reply With Quote

Old   October 10, 2017, 21:58
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by paolofug87 View Post
Hi all,
I would like to create an udf for calculating the time integral of a variable (i.e. CO concentration) and allocating it in a UDM. Nothing special, just multiply the new value for dt and adding the one calculated in the previous step.
I know how to write udf but this time it seems that I need to declare a global variable and I don't now where I have to hook it in the model.

Thank you in advance

Paolo

P.s. is there any precaution to use this udf in parallel computing?

Hello

For UDF use ANSYS Fluent Customization Manual

For your case you may use this code for single cell as a basis, modify it
Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
Thread *t;
/* Integrate dissipation. */
real integral=0.;
real dtime;
real temperature;
cell_t c;
d = Get_Domain(1); /* mixture domain if multiphase */
dtime = CURRENT_TIMESTEP;	 		/* get time step value */
thread_loop_c (t,d)
{
/* Loop over all cells */
	begin_c_loop(c,t)
	{
		/* Calculate volume of JR */
		temperature = C_T(c,t); 			/* get temperature*/
		integral += temperature*dtime;		/* calculate integral */
		C_UDMI(c,t,0) = integral;			/* write to UDM */
	}
	end_c_loop (c,t)
}
Message("Temperature time integral: %f\n", integral);
}
Save this as a .c file. Compile.
Then load in fluent. Hook DEFINE_EXECUTE_AT_END function (User-Defined -> function hooks)
Add UMD ( User-Defined -> Memory -> Set memory locations 1)

Best reagards
amandahan likes this.
AlexanderZ is offline   Reply With Quote

Old   October 15, 2017, 05:57
Default
  #7
New Member
 
Paolo
Join Date: Jan 2017
Posts: 19
Rep Power: 9
paolofug87 is on a distinguished road
Thank you very much!
I was able to do my task modifiyng the code like here below.
Obviously is only an example, in my code I'll use the CO concentration instead of temperature.
Now I just need to change the UDM name, for the parallel computing it seems that I don't need any change (looking at results).

Thank you again, hope this post could help someone else.

Cheers

Paolo

Quote:
#include "udf.h"
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
Thread *t;
/* Integrate dissipation. */
real integral=0.;
real dtime;
real temperature;
cell_t c;
d = Get_Domain(1); /* mixture domain if multiphase */
dtime = CURRENT_TIMESTEP; /* get time step value */
thread_loop_c (t,d)
{
/* Loop over all cells */
begin_c_loop(c,t)
{
/* Calculate volume of JR */
temperature = C_T(c,t)*dtime; /* get temperature*/
C_UDMI(c,t,0) = C_UDMI(c,t,0) + temperature; /* write to UDM */

}
end_c_loop (c,t)
}
Message("Temperature time integral: %f\n", integral);
Message("Temperature time integral: %f\n", dtime);
}
amandahan likes this.
paolofug87 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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 17:22
Running UDF with Supercomputer roi247 FLUENT 4 October 15, 2015 13:41
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
ParaView for OF-1.6-ext Chrisi1984 OpenFOAM Installation 0 December 31, 2010 06:42


All times are GMT -4. The time now is 05:31.