# how can use the cell temperature of each cell from zone 1 in zone 2 with UDF?

 Register Blogs Members List Search Today's Posts Mark Forums Read November 14, 2021, 07:11 how can use the cell temperature of each cell from zone 1 in zone 2 with UDF? #1 New Member   wcs Join Date: Mar 2021 Posts: 8 Rep Power: 3 I want to use the cell temperature of zone 1 in the source term of zone 2. In the code i calculated the temperature of each cell in zone 1 and return it us function, but the problem is :in the fluent,zone 2 copy from zone1,and it's thread ID is 12, so in the UDF i use if(THREAD_ID(aux_t) == 12) to loop cell value,but it can't loop .The problem I am currently experiencing is that zone2 is copied from zone1, so the loop function cannot be run if(THREAD_ID(aux_t) == 12) { begin_c_loop(aux_c,aux_t) { C_CENTROID(aux_x,aux_c,aux_t); Message( "in thread=%g \n",1.0); a_x=aux_x; a_y=aux_x; a_z=aux_x; Message( "a_x=%g a_y=%g C_T(aux_c,aux_t)=%g THREAD_ID=%d\n",a_x,a_y,C_T(aux_c,aux_t),THREAD_ID (aux_t)); if(a_x==x && a_y==y && a_z==z ) { aux_tem=C_T(aux_c,aux_t); } } end_c_loop(aux_c,aux_t) } Do anybody have an idea how i can use the cell temperature of each cell from zone 1 in zone 2 ? Both zones have same number of cells and same dimensions. by the way, i dont konw how to upload a pitcture in this txt...anybody can give me a message Last edited by bhwcs; November 15, 2021 at 05:24.   November 15, 2021, 04:58 #2 Senior Member   Join Date: Nov 2013 Posts: 1,965 Rep Power: 25 I may be blind, but I don't see your code. Secondly: what does your problem physically represent? You have to zones, and the temperature in one zone determines the source of another zone? The zones are not in the same place, so by what magic should that work? (You have the right to implement this, don't get me wrong, but I just want to know for sure that I understand what you are trying to do, because from what I understand now it is very, very strange...) __________________ "The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".   November 15, 2021, 05:07 #3
New Member

wcs
Join Date: Mar 2021
Posts: 8
Rep Power: 3 Quote:
 Originally Posted by pakk I may be blind, but I don't see your code. Secondly: what does your problem physically represent? You have to zones, and the temperature in one zone determines the source of another zone? The zones are not in the same place, so by what magic should that work? (You have the right to implement this, don't get me wrong, but I just want to know for sure that I understand what you are trying to do, because from what I understand now it is very, very strange...)

DEFINE_SOURCE(primary,c,t,dS,eqn)
{

int i;
real D_X=0.002;
real D_Y=0.001;
real D_Z=0.0025;
real pri_tem=0.0;
double ppri_x;
int num_x=0;
int num_y=0;
int num_z=0;
real tem_1=0.0,tem_2=0.0;
real source=0.0;
real volume=0.0;
real cp=0.0;
double x[ND_ND]; //array for storing the centroid position

face_t f;
real massflow=0;
double tem;
double *m;int n;
double pri_x=0.0;
double pri_y=0.0;
double pri_z=0.0;
double weizhi;

C_CENTROID(x,c,t);

pri_x=x;
pri_y=x;
pri_z=x;

tem= temp(pri_x,pri_y,pri_z);
volume=C_VOLUME(c,t);
cp=C_CP(c,t);
num_x=ceil(x/D_X);
num_y=ceil((x-0.005)/D_Y);
num_z=ceil(x/D_Z);
c_face_loop(c,t,n)
{
f=C_FACE(c,t,n);
{
}
}

weizhi=C_UDMI(c,t,0);
Message( "pri_x=%g pri_y=%g pri_z=%g weizhi=%g\n", pri_x,pri_y,pri_z,weizhi);
source = fabs(massflow)*cp*(600-C_T(c,t))/(volume);
dS[eqn] = 0;

return source;

}

double temp(double x, double y,double z)
{
double aux_tem,aux_temp;
double a_x,a_y,a_z;
int ID=12;
double aux_x[ND_ND];

Domain *domain;
cell_t aux_c;
domain=Get_Domain(1);

{
{
begin_c_loop(aux_c,aux_t)
{
C_CENTROID(aux_x,aux_c,aux_t);
a_x=aux_x;
a_y=aux_x;
a_z=aux_x;
if(a_x==x && a_y==y && a_z==z )
{
aux_tem=C_T(aux_c,aux_t);

}
}
end_c_loop(aux_c,aux_t)
}
}

return aux_tem;
}

THe problem is :in the fluent,zone 2 copy from zone1,and it's thread ID is 12, so in the UDF i use if(THREAD_ID(aux_t) == 12) to loop cell value,but it can't loop .
I want to use this kind of problem to simulate a heat exchanger. You know, one side（zone1）is cold flow, and the other side(zone2) is heat flow.
In addition, my question is very similar to the one mentioned in this article, you can refer to his question and picture。https://forum.ansys.com/discussion/1...-a-written-udf   November 15, 2021, 07:45 #4 Senior Member   Join Date: Nov 2013 Posts: 1,965 Rep Power: 25 So you have two 3D volumes, and the temperature of volume 1 determines the source of volume 2? Huh? That is not how heat exchangers work... Please explain better, because how I understand it is so silly, I'm sure that's not what you mean, but I can't guess what you really mean. Normally, hot zones and cold zones interact through the surface in between them. Isn't that what you are after? __________________ "The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".   November 15, 2021, 08:41 #5
New Member

wcs
Join Date: Mar 2021
Posts: 8
Rep Power: 3 Quote:
 Originally Posted by pakk So you have two 3D volumes, and the temperature of volume 1 determines the source of volume 2? Huh? That is not how heat exchangers work... Please explain better, because how I understand it is so silly, I'm sure that's not what you mean, but I can't guess what you really mean. Normally, hot zones and cold zones interact through the surface in between them. Isn't that what you are after?
Let me explain in detail. In fact, this is a process of simulating a double grid heat exchanger in Fluent. The heat source formula q=KA(T,cell,aT,cell,p); through this formula, we can see that zone1 is used to represent the heat source , Zone2 represents cold flow. They have the same structure during grid division, but belong to different parts, so they have different threads in fluent, so when calculating q in zone2, you need to get the temperature of each grid in zone1, so as to get the heat source term , Similarly applying similar heat source terms in zone1, the two zones can be coupled to calculate heat exchange.
Refer to the UDF I wrote so far. The problem I have encountered is that when I apply the sorce item in zone2, the temperature of zone1 cannot be returned. The reason I guess is that zone2 and zone1 are physically separated, but I don’t have a better Solution.
NOW i find the problem is the macro begin_c_loop_int(c,tt){...}end_c_loop_int(c,tt) Not work when running in parallel, but when running in serial,do u know how to fix this problem?

Last edited by bhwcs; November 15, 2021 at 10:30.   November 15, 2021, 13:39 #6 Senior Member   Join Date: Nov 2013 Posts: 1,965 Rep Power: 25 No, but I would then advice to look in the manual for begin_c_loop_int. I don't think you should explain further, I don't think that is useful, but just in case: I still don't follow. You say about the volumes "They have the same structure during grid division, but belong to different parts", but that is unclear... Does that mean that they share the same physical volume? If not, are they far away from each other or touching? I indicated what was strange about your setup, but your answer kind of ignores these issues. Maybe you did not understand what I meant, in that case I only have myself to blame. __________________ "The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".   November 16, 2021, 00:58 #7 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,249 Rep Power: 32  from my point of view in case zones are phisically separated (so cell/thread loop starts counting cell again when you go from one zone to another) you need to find the link between each cell from zone 1 to each cell in zone 2. to do that I would make a loop over all cells in zone 1 (zone where is your temperature) and in each cell would loop over cells from zone 2, checking coordinates. as you know how far zone 1 from zone 2 its pretty easy. (we assume that grids are identical as you've mentioned) So using DEFINE_ON_DEMAND(name) function you may find this link code could look like this compile code, I didn't debug Code: ```#include "udf.h" DEFINE_ON_DEMAND(get_link) { Domain *d; cell_t c1,c2; Thread *t1,*t2; static int ID_1 = 1; static int ID_2 = 2; real cell1[ND_ND],cell2[ND_ND]; real distance_x = 0.1; // distance between zone 1 and zone 2 in x-direction real delta = 1e-6; // half of smallest cell in grid d = Get_Domain(1); t1= Lookup_Thread(d, ID_1); t2= Lookup_Thread(d, ID_2); begin_c_loop_int(c1,t1) { C_CENTROID(cell1,c1,t1); begin_c_loop_int(c2,t2) { C_CENTROID(cell2,c2,t2); if (cell2 <= cell2 + distance + delta) && (cell2 >= cell2 + distance - delta) { C_UDMI(c2,t2,0) = c1; C_UDMI(c2,t2,1) = C_T(c1,t1); // no nessesary here break; } } end_c_loop_int(c2,t2) } end_c_loop_int(c1,t1) Message0("On_demand has beeen executed\n"); } DEFINE_ADJUST(apply_temperature,d) { cell_t c1,c2; Thread *t1,*t2; static int ID_1 = 1; static int ID_2 = 2; t1= Lookup_Thread(d, ID_1); t2= Lookup_Thread(d, ID_2); begin_c_loop_int(c2,t2) { c1 = C_UDMI(c2,t2,0); C_T(c2,t2) = C_T(c1, t1); C_UDMI(c2,t2,1) = C_T(c1, t1); // just to have additional monitor with modifications } end_c_loop_int(c2,t2) Message0("temperature has been applied\n"); }``` __________________ best regards ****************************** press LIKE if this message was helpful   November 16, 2021, 07:34 #8
New Member

wcs
Join Date: Mar 2021
Posts: 8
Rep Power: 3 Quote:
 Originally Posted by AlexanderZ from my point of view in case zones are phisically separated (so cell/thread loop starts counting cell again when you go from one zone to another) you need to find the link between each cell from zone 1 to each cell in zone 2. to do that I would make a loop over all cells in zone 1 (zone where is your temperature) and in each cell would loop over cells from zone 2, checking coordinates. as you know how far zone 1 from zone 2 its pretty easy. (we assume that grids are identical as you've mentioned) So using DEFINE_ON_DEMAND(name) function you may find this link code could look like this compile code, I didn't debug Code: ```#include "udf.h" DEFINE_ON_DEMAND(get_link) { Domain *d; cell_t c1,c2; Thread *t1,*t2; static int ID_1 = 1; static int ID_2 = 2; real cell1[ND_ND],cell2[ND_ND]; real distance_x = 0.1; // distance between zone 1 and zone 2 in x-direction real delta = 1e-6; // half of smallest cell in grid d = Get_Domain(1); t1= Lookup_Thread(d, ID_1); t2= Lookup_Thread(d, ID_2); begin_c_loop_int(c1,t1) { C_CENTROID(cell1,c1,t1); begin_c_loop_int(c2,t2) { C_CENTROID(cell2,c2,t2); if (cell2 <= cell2 + distance + delta) && (cell2 >= cell2 + distance - delta) { C_UDMI(c2,t2,0) = c1; C_UDMI(c2,t2,1) = C_T(c1,t1); // no nessesary here break; } } end_c_loop_int(c2,t2) } end_c_loop_int(c1,t1) Message0("On_demand has beeen executed\n"); } DEFINE_ADJUST(apply_temperature,d) { cell_t c1,c2; Thread *t1,*t2; static int ID_1 = 1; static int ID_2 = 2; t1= Lookup_Thread(d, ID_1); t2= Lookup_Thread(d, ID_2); begin_c_loop_int(c2,t2) { c1 = C_UDMI(c2,t2,0); C_T(c2,t2) = C_T(c1, t1); C_UDMI(c2,t2,1) = C_T(c1, t1); // just to have additional monitor with modifications } end_c_loop_int(c2,t2) Message0("temperature has been applied\n"); }```
Dear AlexanderZ, thank you very much for your recovery, your UDF is very helpful. I have tried to run your UDF, and the problem I encountered is the same as I described before, that is,whem FLUENT run in parallel, the following loop,
begin_c_loop_int(c1,t1){..}end_c_loop_int(c1,t1) is accessible, but begin_c_loop_int(c2,t2){...}end_c_loop_int(c2,t2) cant run, . I tried to fix it and found that it can go from c1 to c2 in serial, but not in parallel. The reason is that FLUENT loops in zone1 area when parallel with multi computer nodes (that is, begin_c_loop_int(c1,t1){..}end_c_loop_int( c1,t1)) is on the computing node node(i), but the loop in zone1 (that is, begin_c_loop_int(c2,t2){...}end_c_loop_int(c2,t2)) is on another computing node node(j). This is the crux of the problem, and I cannot get the temperature of zone2 from zone1. Do you have any good suggestions for parallel and serial.   November 17, 2021, 01:02 #9 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,249 Rep Power: 32  well, I have no idea how to fix this issue with loops. you may go other way, write profile. It will contain coordinates and temperature (for instance), modify coordinates and apply it: -you may try to read that modified profile and apply directly. In that case fluent will interpolate automatically. THIS MUST BE CHECKED -you may read it through UDF and interpolate by your own function (or applied in other way) __________________ best regards ****************************** press LIKE if this message was helpful   November 17, 2021, 03:20 #10
New Member

wcs
Join Date: Mar 2021
Posts: 8
Rep Power: 3 Quote:
 Originally Posted by AlexanderZ well, I have no idea how to fix this issue with loops. you may go other way, write profile. It will contain coordinates and temperature (for instance), modify coordinates and apply it: -you may try to read that modified profile and apply directly. In that case fluent will interpolate automatically. THIS MUST BE CHECKED -you may read it through UDF and interpolate by your own function (or applied in other way)  Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post jane Fluent UDF and Scheme Programming 37 February 20, 2018 05:17 MarcusW FLUENT 3 March 7, 2012 07:32 [Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50 kris Siemens 2 August 3, 2005 01:32 [Commercial meshers] Trimmed cell and embedded refinement mesh conversion issues michele OpenFOAM Meshing & Mesh Conversion 2 July 15, 2005 05:15