|
[Sponsors] |
December 12, 2018, 14:06 |
Monitoring UDF?
|
#1 |
Member
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11 |
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 } |
|
December 13, 2018, 00:00 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 } 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; Code:
#if !RP_HOST #endif tmax tmin ARE NOT DEFINED! best regards |
|
December 13, 2018, 00:10 |
|
#3 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 } Code:
#if !RP_HOST #endif Code:
time = CURRENT_TIME; fprintf(fptemp, "%16.5e", time); 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 } best regards |
|
December 13, 2018, 14:33 |
|
#4 |
Member
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11 |
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 |
|
December 13, 2018, 21:42 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
December 14, 2018, 01:43 |
Getting different answer when intializing through udf
|
#6 |
New Member
pavan
Join Date: Sep 2014
Posts: 5
Rep Power: 12 |
Hi alexander
When I am trying to interpret 6th degree polynomial I am getting different answer when normally calculating with calculator |
|
December 14, 2018, 07:01 |
|
#7 |
Member
Oula
Join Date: Apr 2015
Location: United Kingdom
Posts: 81
Rep Power: 11 |
||
December 14, 2018, 10:20 |
Regarding intialization problem
|
#8 |
New Member
pavan
Join Date: Sep 2014
Posts: 5
Rep Power: 12 |
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) |
|
|
|
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 |