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

temperature store and monitoring UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 7, 2021, 03:53
Smile temperature store and monitoring UDF
  #1
New Member
 
jangsujin
Join Date: Jul 2021
Posts: 1
Rep Power: 0
indsujin is on a distinguished road
Hello

Currently, I'm try UDF to use mesh morpher & optimizer functionality in ansys fluent.

It is also a problem to apply UDF to mmo, but I would like to ask for help because the previous steps are blocked.

I've been referring to C++, UDF Tutorial, CFD Forum for a long time, and I don't see the answer. Please let me know.

Thank you in advance.


What I want to do with mmo is 'Optimization according to surface temperature'.

The key is to get the temperature for each time step and apply it to the system, and to design optimization using mesh morpher&optimizer function based on the temperature received.

Therefore, it is important to get the temperature per time step and store it in the system, and to implement this feature, we are first planning the following UDF code:

1. Use the UDMI function to store the temperature of each time step on the system.
2. Store face information (wafer surface) - temperature (temperature information matched at each face point) of each time step as a .txt file

In fact, only number 1 is needed to apply to mmo, but number 2 is also being used to see if the function is working properly.

My code is like this.

============================================
#include "udf.h"
#include "math.h"
#include "mem.h"

#define ID 3
real tem;
real value;

DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
face_t f;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
begin_f_loop(f, t)
{
tem = F_T(f, t);
value = tem;
F_UDMI(f, t, 0) = value;
F_UDMI(F_C0(f, t), t->t0, 0) = value;
}
end_f_loop(f, t);
#endif
}


FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if !RP_HOST
face_t f;
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)
{
tem = F_T(f, t);
value = tem;
fprintf(fptemp, "%16.5e", value);
}
end_f_loop(f, t);

fprintf(fptemp, "\n");
fflush(fptemp);
#endif
}
=============================================


The number 2 I want is as follows.

========================================
(information)
Time step size : 0.05
Number of time step : 100 (total flow time : 6 sec)
Number of mesh :
Number of partition : 16
========================================
print :

Current flow time : 0.00 sec
face001 face002 face003 face003 … … faceNNNN(para
3.20e+02(matching at face) 3.20e+2 … … 3.20e+02

Current flow time : 0.05 sec
face001 face002 face003 face003 … … faceNNNN(para
3.195e+02 3.187e+02 … … 3.196e+02

Current flow time : 0.10 sec
face001 face002 face003 face003 … … faceNNNN(para
3.193e+02 3.185e+02 … … 3.192e+02
..
.
.
Current flow time : 6.00 sec
face001 face002 face003 face003 … … faceNNNN(para
2.783e+02 2.781e+02 … … 2.782e+02
=========================================

However, the output is currently like this.

==========================================
face000 face001 face002 face003 face004
...
...
face1136 face1137 face1138
0.00000e+00

face1140 face1141 face1142 face1143 face1144
..
..
face2160 face2161 face2162
0.00000e+00
===========================================

Could you tell me how to fix the code in order to implement number 1 and 2 properly?
i appreciate your help.
have a good day.
thank you.

The data I referred to.
Monitoring UDF?
indsujin is offline   Reply With Quote

Old   July 9, 2021, 04:08
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
try this code
Code:
#include "udf.h"
#include "math.h"
#include "mem.h"

#define ID 3
real tem;
real value;

DEFINE_EXECUTE_AT_END(wall_temp)
{
#if !RP_HOST
face_t f;
Domain *domain = Get_Domain(ROOT_DOMAIN_ID);
Thread *t = Lookup_Thread(domain, ID);
begin_f_loop(f, t)
{
tem = F_T(f, t);
value = tem;
F_UDMI(f, t, 0) = value;
C_UDMI(F_C0(f, t), t->t0, 0) = value;
}
end_f_loop(f, t);
#endif
}


FILE* fptemp = NULL;
DEFINE_EXECUTE_AT_END(write_temp_to_file)
{
#if RP_HOST
face_t f;
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)
{
tem = F_T(f, t);
value = tem;
fprintf(fptemp, "%16.5e", value);
}
end_f_loop(f, t);

fprintf(fptemp, "\n");
fflush(fptemp);
#endif
}
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
mesh morpher&oprimizer, mmo, monitor, stored data, udf


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 store UDF output for arbitrary/particular cell athalia FLUENT 1 September 24, 2019 05:02
Monitoring UDF? Oula Fluent UDF and Scheme Programming 7 December 14, 2018 09:20
monitoring variables Veera Siemens 1 February 12, 2001 17:19


All times are GMT -4. The time now is 08:03.