|
[Sponsors] |
July 1, 2019, 15:26 |
Writing udf regarding adjacent cells
|
#1 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
I have a problem where a mass source term is dependent on the temperature of the adjacent cells. The equation which i want to put in the udf form is given like this:
Smj = (A * ▲ Tj)/ Vj Where Smj = Mass source of a species in jth cell A - constant ▲ Tj - Temperature diff between two adjacent cells Vj - Volume of Jth cell I think i understand the basic udf, and I dont know how do i put temperature of two adjacent cells in the udf. If any one help writing a UDF , i would be very grateful I am trying to write but stuck, It may be simple for those who are experienced in this. DEFINE_SOURCE(_mass, c, t, dS, eqn) { real source; real temp = C_T(c,t); if (673<=C_T(c,t)<=1073) source = -----------------------??? else source = 0; dS[eqn] = 0; return source; } Thanks Varun |
|
July 1, 2019, 22:53 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
I didn't test it. May be it should be something like this:
Code:
#include "udf.h" DEFINE_ADJUST(calculate_source, d) { face_t f cell_t c,c0, c1 = -1; Thread *t,*t0, *t1 = NULL; real Temp0, Temp1; // get temperature thread_loop_f (t,domain) { begin_f_loop (f,t) { c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/ { // you should define something here for case, when there is no more adjusted cells (external boundary) Temp0 = C_T(c0,t0); Temp1 = 0.0; } else{ c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); Temp0 = C_T(c0,t0); Temp1 = C_T(c1,t1); } C_UDMI(c0,t0,0) = Temp0; C_UDMI(c1,t1,1) = Temp1; } end_f_loop (f,t) } //calculate source thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDMI(c,t,2) = C_UDMI(c,t,0) - C_UDMI(c,t,1); } end_c_loop (c,t) } } DEFINE_SOURCE(_mass, c, t, dS, eqn) { real source; real temp = C_T(c,t); if (673<=C_T(c,t)<=1073) source = C_UDMI(c,t,2); else source = 0; dS[eqn] = 0; return source; } best regards |
|
July 2, 2019, 11:19 |
Structural reference error
|
#3 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Thank you very much for the help.
However when I tried to interpret the udf, it is giving structure reference not implemented on the following line. t0 = F_C0_THREAD(f,t); Any idea why? Thanks |
|
July 3, 2019, 01:16 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
compile udf
best regards |
|
July 15, 2019, 17:12 |
|
#5 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Thank you for your help
I did download the visual studio and managed to compiled it. It was loaded successfully I did assign 3 UDM for the memory and then hook the define adjust function in the fluent and ran the calculation, However it is giving me segmentation fault. Not sure why. I think it is to do with UDMI Any help and input I would appreciate. I feel I am close, but not there yet. THank you very much for your time |
|
July 15, 2019, 23:18 |
|
#6 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
show your code and output logs always
if you are using code above than there was mistake Code:
thread_loop_f (t,domain) Code:
thread_loop_f (t,d) |
|
July 16, 2019, 09:49 |
|
#7 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Hello
I actually did that change and it is after the fact I am getting the segmentation fault Here is complete code. The segmentation fault occurs when I ran the calculation with "Define adjust function hook up". If I don't hook the define adjust , it works (at least the iteration parts) #include "udf.h" DEFINE_ADJUST(calculate_source, d) { face_t f; cell_t c,c0, c1 = -1; Thread *t,*t0, *t1 = NULL; real Temp0, Temp1; // get temperature thread_loop_f (t,d) { begin_f_loop (f,t) { c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/ { // you should define something here for case, when there is no more adjusted cells (external boundary) Temp0 = C_T(c0,t0); Temp1 = 0.0; } else{ c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); Temp0 = C_T(c0,t0); Temp1 = C_T(c1,t1); } C_UDMI(c0,t0,0) = Temp0; C_UDMI(c1,t1,1) = Temp1; } end_f_loop (f,t) } //calculate source thread_loop_c (t,d) { begin_c_loop (c,t) { C_UDMI(c,t,2) = C_UDMI(c,t,0) - C_UDMI(c,t,1); } end_c_loop (c,t) } } DEFINE_SOURCE(Ch4_mass, c, t, dS, eqn) { real source; real temp = C_T(c,t); if (673<=C_T(c,t)<=1073) source = (-0.000000081917+2*0.00000000011114*C_T(c,t)-3*0.000000000000045649*C_T(c,t)*C_T(c,t))*C_UDMI(c ,t,2)/C_VOLUME(c,t); else source = 0; if (source<0) source = 0; else source = source; dS[eqn] = 0; return source; } P.S I changed the Define Adjust code, in order to see where the problem is to Temp0 = C_T(c0,t0); Temp1 = C_T(c1,t1); } } end_f_loop (f,t) } //calculate source thread_loop_c (t,d) { begin_c_loop (c,t) { C_UDMI(c,t,0) = C_T(c0,t0)-C_T(c1,t1); } end_c_loop (c,t) } } And it works but I belive it may be wrong and not doing what it is supposed to ? Thank you for you time Last edited by vkumar12; July 16, 2019 at 15:59. |
|
July 16, 2019, 23:08 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
was
Code:
else{ c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); Temp0 = C_T(c0,t0); Temp1 = C_T(c1,t1); } C_UDMI(c0,t0,0) = Temp0; C_UDMI(c1,t1,1) = Temp1; } Code:
else{ c1 = F_C1(f,t); /* Get cell on other side of face */ t1 = F_C1_THREAD(f,t); Temp0 = C_T(c0,t0); Temp1 = C_T(c1,t1); C_UDMI(c1,t1,1) = Temp1; } C_UDMI(c0,t0,0) = Temp0; } Code:
DEFINE_INIT(my_init_func,d) { cell_t c; Thread *t; /* loop over all cell threads in the domain */ thread_loop_c(t,d) { /* loop over all cells */ begin_c_loop(c,t) { C_UDMI(c,t,0) = 0.0; C_UDMI(c,t,1) = 0.0; C_UDMI(c,t,2) = 0.0; } end_c_loop_all(c,t) } } Last edited by AlexanderZ; July 23, 2019 at 22:43. |
|
July 23, 2019, 11:51 |
|
#9 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Thank you very much for your help.
The new UDF you provide is working and compiled successfully. P.s I used 2019 VS community version and Ansys 17.1 It was essential to open the Ansys workbench file with VS studio command prompt. Thank you again for your kind help. I really appreciate. |
|
August 1, 2019, 11:21 |
|
#10 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Dear Alexander
I need your help on the same topic. As I mentioned earlier the UDF compiled properly but the values for the adjacent cells temperatures coming to be same and hence the C_UDMI 2 came to be zero and making all the results goes to zero. I think it would be better if I explain my problem here in detail. My model contains a solid porous body (fiber) which is 1/8" thick and 100" long and it is heated in a furnace. Fiber is travelling at a speed so I used MRF model to simulate that. Furnace is 7 zones and alls are heated electrically. What I was trying to do is to calculate the mass fraction of gases coming out of the fiber. See the attached picture for the geometry (attachment 1) and meshing (attachment 2) And that source term is dependent on how is the rate of fiber heating and hence I need the adjacent cell temperatures. I think I am still confused what are the adjacent cells in my problem and hence I highlighted in the attached picture. Some observation after I calculation finishes: When I plot C_UDMI (0) and C_UDMI (1) for the interior fiber with respect to direction of furnace length , it gives me a profile (attached) but only problem is the profile of C_UDMI (0) and C_UDMI (1) are exactly same. and hence C_UDMI 2 which is the difference of adjacent cells gives value of zero. Thanks in advance for your help. |
|
August 2, 2019, 01:28 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Am I right, that adjusted cells your are interested in are cells of fiber only?
You want to get temperature difference between adjusted cells of fiber? best regards |
|
August 2, 2019, 06:50 |
|
#12 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
Yes that is correct.
|
|
August 2, 2019, 09:15 |
|
#13 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
unfortunately have no idea now
best regards |
|
August 2, 2019, 09:29 |
|
#14 |
New Member
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8 |
I think it automatically chooses that domain when I put the source term in cell zone condition of fiber . So I believe it will automatically chooses the fiber domain to calculate the temp of adjacent cells .
In the meshing picture i attached , do you think my assumption of adjacent cell is right , it is the cells adjacent to the face of a particular cell right ? |
|
August 4, 2019, 23:04 |
|
#15 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may try to monitor temperatures only in fiber part (make it explicitly)
you should add following In DEFINE_ADJUST macro above begin_f_loop(f, thread){ Code:
int ID = 1; /* Zone ID for wall-1 zone from Boundary Conditions task page */ Thread *thread = Lookup_Thread(domain, ID); Go to GUI -> boundary conditions -> select interior-fiber -> under zone window you may check ID best regards |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF about Searching the Adjacent cells: Please help me to find out the error | Hotpig1100 | Fluent UDF and Scheme Programming | 6 | July 9, 2018 20:37 |
Fluent UDF wrong number of cells in parallel - correct in serial | dralexpe | Fluent UDF and Scheme Programming | 7 | May 17, 2018 09:26 |
[snappyHexMesh] No layers in a small gap | bobburnquist | OpenFOAM Meshing & Mesh Conversion | 6 | August 26, 2015 10:38 |
[Netgen] Import netgen mesh to OpenFOAM | hsieh | OpenFOAM Meshing & Mesh Conversion | 32 | September 13, 2011 06:50 |
UDF: neighbour cells, upwind cells | Dmitriy Makarov | FLUENT | 0 | February 18, 2001 14:53 |