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

Monitoring UDF?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pavankonchada

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 12, 2018, 14:06
Default Monitoring UDF?
  #1
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Hi everyone

One of the CFD-ONLINE users helped me to write a C++ code for a monitoring user-defined function. The code consists of two functions, the first one is to store value in UDMI during the transient simulation and the other function is to write data that were stored in the first one to a (.txt) file for time and temperature.

We expected the file to be like, see below (A). But what happened is that the time data has not been recorded at all and the faces counting was seperate from the temperature value see below (B) a sample of the written data.

I have checked the ANSYS UDF manual but I couldn't find any example on writing files using DEFINE_EXECUTE_AT_END macro to identify the mistake and why I'm not getting what I expect. The other thing is that the file's size became super big I couldn't open it even in excel. Do you have any experience with this regards? Any help is much appreciated and sorry for the long post

A)
time face000 face001 face002 ...
0.1 300.0 301.0 302.0 ...
0.2 300.2 300.8 301.5 ...

B)
time face000 face001 face002 face003 face004 face005 face006 face007 face008 face009 face010 face011 face012 face013 face014 face015 face016 face017 face018 face019 face020 face021 face022 face023 face024 face025 face026 face027 face028 face029 face030 face031 face032 face033 face034 face035 .....
..... 0.00000e+00 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02 2.93000e+02


The code is
#include "udf.h"
#define ID 8

/* Solution a: store value in UDMI */
/* Both the face thread and their adjacent cells */
/* of the UDMI are set for proper visulazation in FLUENT */
DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
face_t f;
real temp, tmax, tmin;
real value;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
begin_f_loop(f,t)
{
temp = F_T(f,t);
value = (temp - tmin) / (tmax-tmin);
F_UDMI(f,t,0) = value;
F_UDMI(F_C0(f, t), t->t0, 0) = value;
}
end_f_loop(f,t);
#endif
}

/* Solution b: write data to file */
FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
face_t f;
real temp, tmax, tmin;
real value;
real time;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
int cnt;
char header[16];
if (!fptemp)
{
fptemp = fopen("temp-vs-time.txt", "w");
fprintf(fptemp, "%16s", "time");
for (cnt = 0; cnt < t->nelements; ++cnt)
{
sprintf(header, "face%03d", cnt);
fprintf(fptemp, "%16s", header);
}
fprintf(fptemp, "\n");
}
time = CURRENT_TIME;
fprintf(fptemp, "%16.5e", time);

begin_f_loop(f,t)
{
temp = F_T(f,t);
value = (temp - tmin) / (tmax-tmin);
fprintf(fptemp, "%16.5e", value);
}
end_f_loop(f,t);

fprintf(fptemp, "\n");
fflush(fptemp);
#endif
}
Oula is offline   Reply With Quote

Old   December 13, 2018, 00:00
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your code
Code:
#include "udf.h"
#define ID 8

/* Solution a: store value in UDMI */
/* Both the face thread and their adjacent cells */
/* of the UDMI are set for proper visulazation in FLUENT */
DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
face_t f;
real temp, tmax, tmin;
real value;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
begin_f_loop(f,t)
{
temp = F_T(f,t);
value = (temp - tmin) / (tmax-tmin);
F_UDMI(f,t,0) = value;
F_UDMI(F_C0(f, t), t->t0, 0) = value;
}
end_f_loop(f,t);
#endif
}
ID 8, check this ID value -> in Fluent gui go to boundary conditions and manualy click one by one all your boundaries, find ID = 8 for your model, is this surface is what you want?

F_UDMI(f,t,0) = value;
F_UDMI(F_C0(f, t), t->t0, 0) = value;

you rewrite first UDMI value with the second.
you may use
Code:
F_UDMI(f,t,0) = value;
F_UDMI(F_C0(f, t), t->t0, 1) = value;
if you think you need them both, in that case you will have 2 udms, was 1.
Code:
#if !RP_HOST
#endif
which version of fluent do you use, if less than 19.0 you may delete it, this macro is for parallel computation, you don't need it for single core.

tmax
tmin
ARE NOT DEFINED!

best regards
AlexanderZ is offline   Reply With Quote

Old   December 13, 2018, 00:10
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your code
Code:
/* Solution b: write data to file */
FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
face_t f;
real temp, tmax, tmin;
real value;
real time;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
int cnt;
char header[16];
if (!fptemp)
{
fptemp = fopen("temp-vs-time.txt", "w");
fprintf(fptemp, "%16s", "time");
for (cnt = 0; cnt < t->nelements; ++cnt)
{
sprintf(header, "face%03d", cnt);
fprintf(fptemp, "%16s", header);
}
fprintf(fptemp, "\n");
}
time = CURRENT_TIME;
fprintf(fptemp, "%16.5e", time);

begin_f_loop(f,t)
{
temp = F_T(f,t);
value = (temp - tmin) / (tmax-tmin);
fprintf(fptemp, "%16.5e", value);
}
end_f_loop(f,t);

fprintf(fptemp, "\n");
fflush(fptemp);
#endif
}
first of all delete
Code:
#if !RP_HOST #endif
tmax, tmin are not defined
Code:
time = CURRENT_TIME;
fprintf(fptemp, "%16.5e", time);
printing time works well, but it write only ONCE, you may put it inside the loop to the the time in each face

so you may get something like this, NOT TESTED
Code:
FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
face_t f;
real temp, tmax, tmin;
real value;
real time;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
int cnt;
char header[16];
time = CURRENT_TIME;
if (!fptemp)
{
	fptemp = fopen("temp-vs-time.txt", "w");
	fprintf(fptemp, "%16s", "time");
		for (cnt = 0; cnt < t->nelements; ++cnt)
		{
			sprintf(header, "face%03d", cnt);
			fprintf(fptemp, "%16s", header);
		}
	fprintf(fptemp, "\n");
	
	begin_f_loop(f,t)
	{
	fprintf(fptemp, "%16.5e ", time);
	}
	end_f_loop(f,t);
	
	fprintf(fptemp, "\n");
	
	begin_f_loop(f,t)
	{
		temp = F_T(f,t);
		value = (temp - tmin) / (tmax-tmin);
		fprintf(fptemp, "%16.5e ", value);
	}
	end_f_loop(f,t);

fprintf(fptemp, "\n");
}
fflush(fptemp);
#endif
}
you should define tmin tmax as well

best regards
AlexanderZ is offline   Reply With Quote

Old   December 13, 2018, 14:33
Default
  #4
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Many thanks Alexander. It is just the face counting that I'm not sure about. I wish if there is any way to stop the counting and give the average. What do you think is this possible?

Best Regards
Oula is offline   Reply With Quote

Old   December 13, 2018, 21:42
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
check 2.2.9. DEFINE_ON_DEMAND in Ansys Fluent Customization manual.
There you may find example, how to calculate average temperature, you may you it as a basis
number may be different, depending on version.

best regards
AlexanderZ is offline   Reply With Quote

Old   December 14, 2018, 01:43
Default Getting different answer when intializing through udf
  #6
New Member
 
pavan
Join Date: Sep 2014
Posts: 5
Rep Power: 12
pavankonchada is on a distinguished road
Hi alexander
When I am trying to interpret 6th degree polynomial I am getting different answer when normally calculating with calculator
Oula likes this.
pavankonchada is offline   Reply With Quote

Old   December 14, 2018, 07:01
Default
  #7
Member
 
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11
Oula is on a distinguished road
Quote:
Originally Posted by pavankonchada View Post
Hi alexander
When I am trying to interpret 6th degree polynomial I am getting different answer when normally calculating with calculator
Hi pavan, could you explain more? is it the polynomial equation is to fit a curve of original data?

Regards
Oula is offline   Reply With Quote

Old   December 14, 2018, 10:20
Default Regarding intialization problem
  #8
New Member
 
pavan
Join Date: Sep 2014
Posts: 5
Rep Power: 12
pavankonchada is on a distinguished road
I am trying to write udf for variable dynamic viscosity for PCM as shown below
DEFINE_PROPERTY(PCM_Dynamicviscosity,cell,thread)
{
real tempe2,mu,bt;
tempe2 = C_T(cell,thread);
bt=(6722811.795)-(67319.37*tempe2)+(224.7*tempe2*tempe2)-(0.25*tempe2*tempe2*tempe2);
printf("bt=%f \n",bt);
if (tempe2 < 298.6)
mu=180000;
if ((tempe2 >= 298.6) && (tempe2 <= 300.6))
mu=0.001798(1+((100000(1-bt)*(1-bt))/((bt*bt*bt)+0.001)));
else
{
mu=0.001798;
}
return mu;
}
the value of bt is 0.011 and hence mu value is 175632.39
but the value I am getting for bt when initializing is 1.5 and dynamic viscosity is coming wrong
Problem is
0.25*tempe2*tempe2*tempe2=6655940.5 (fluent value)
0.25*tempe2*tempe2*tempe2=6655941.9189(Actual value)
pavankonchada 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
How to set the BC on a wall that is under monitoring using UDF? Oula FLUENT 3 November 19, 2018 05:46
UDF for monitoring velocity difference in each cell?? gaza Fluent UDF and Scheme Programming 0 January 21, 2016 10:52
parse error while interpreting udf Kristin Fluent UDF and Scheme Programming 3 March 15, 2012 07:43
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
I need UDF help. S.Whitney FLUENT 0 October 15, 2007 12:29


All times are GMT -4. The time now is 17:10.