# Different values for identical UDS and UDM

 Register Blogs Members List Search Today's Posts Mark Forums Read

 August 7, 2015, 14:19 Different values for identical UDS and UDM #1 Member   Farzin Join Date: Jul 2014 Posts: 42 Rep Power: 11 Hello everyone, I wrote a UDF that calculates a quantity for a User Defined Scalar, then in another c_loop values of UDS are stored in a User Defined Memory. After calculations, contours of the UDM and UDS differ from each other significantly. It seems that UDM contour is the correct one. But why they are different? Thanks for any suggestion, Farzin

 August 11, 2015, 05:32 #2 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 Could you post the part of the code you are talking about? Them we can see if there is any mistake and help you.

August 11, 2015, 07:59
#3
Member

Farzin
Join Date: Jul 2014
Posts: 42
Rep Power: 11
Quote:
 Originally Posted by Bruno Machado Could you post the part of the code you are talking about? Them we can see if there is any mistake and help you.
One thing I'm suspicious of is that I didn't allocate face values of UDM and the contours are face values indeed.
Here's the related part of the UDF:
Code:
{
int n;
cell_t c,c0,c1;
face_t f;

//Calculating Vorticity for Cell Centers
{
begin_c_loop(c,t)
{
C_UDSI(c,t,Vorticity_I) = VORI(c,t);
C_UDSI(c,t,Vorticity_J) = VORJ(c,t);
C_UDSI(c,t,Vorticity_K) = VORK(c,t);
}
end_c_loop(c,t);
}

//Calculating Vorticity Derivatives
for (n=Vorticity_I; n<Vorticity_I+3; n++)
{
uds_derivatives(domain,n);
}

{
begin_c_loop(c,t)
{
C_UDMI(c,t,Vorticity_I) = C_UDSI(c,t,Vorticity_I);
C_UDMI(c,t,Vorticity_J) = C_UDSI(c,t,Vorticity_J);
C_UDMI(c,t,Vorticity_K) = C_UDSI(c,t,Vorticity_K);
ND_D(C_UDSI(c,t,G_Vorticity_Ix),C_UDSI(c,t,G_Vorticity_Iy),C_UDSI(c,t,G_Vorticity_Iz),=,\
C_UDSI_G(c,t,Vorticity_I)[0],C_UDSI_G(c,t,Vorticity_I)[1],C_UDSI_G(c,t,Vorticity_I)[2]);
ND_D(C_UDSI(c,t,G_Vorticity_Jx),C_UDSI(c,t,G_Vorticity_Jy),C_UDSI(c,t,G_Vorticity_Jz),=,\
C_UDSI_G(c,t,Vorticity_J)[0],C_UDSI_G(c,t,Vorticity_J)[1],C_UDSI_G(c,t,Vorticity_J)[2]);
ND_D(C_UDSI(c,t,G_Vorticity_Kx),C_UDSI(c,t,G_Vorticity_Ky),C_UDSI(c,t,G_Vorticity_Kz),=,\
C_UDSI_G(c,t,Vorticity_K)[0],C_UDSI_G(c,t,Vorticity_K)[1],C_UDSI_G(c,t,Vorticity_K)[2]);
}
end_c_loop(c,t);
}
}

void uds_derivatives(Domain *domain, int n)
{
MD_Alloc_Storage_Vars(domain, SV_UDSI_RG(n), SV_UDSI_G(n), SV_NULL);
Scalar_Reconstruction(domain, SV_UDS_I(n), -1, SV_UDSI_RG(n), NULL);
Scalar_Derivatives(domain, SV_UDS_I(n), -1, SV_UDSI_G(n), SV_UDSI_RG(n), NULL);
return;
}

 August 11, 2015, 08:52 #4 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 Are you plotting in the Fluent software or in the CFD-Post? If fluent, plot the results of the CELL and try to compare both. Should be same. If you are plotting the NODE values, it can be different since it is a average. rarnaunot likes this.

 August 11, 2015, 09:21 #5 Member   Farzin Join Date: Jul 2014 Posts: 42 Rep Power: 11 I'm plotting computed cell values in FLUENT, not node values. This order of difference cannot be made by averaging; UDS-UDM.jpg

 August 11, 2015, 09:39 #6 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 Make a test, plot the values of the UDS and UDM in the GUI. Add this in your code, after saying UDS=UDM and run one iteration. if((c%2000) == 0) Message("UDM Vor_I %f UDS Vor_I%f\n UDM Vor_J %f UDS Vor_J%f\n UDM Vor_K %f UDS Vor_K%f\n" C_UDMI(c,t,Vorticity_I), C_UDSI(c,t,Vorticity_I), C_UDMI(c,t,Vorticity_J), C_UDSI(c,t,Vorticity_J), C_UDMI(c,t,Vorticity_K), C_UDSI(c,t,Vorticity_K));

 August 11, 2015, 09:55 #7 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 What I would also suggest is to add this part in an EXECUTE_AT_THE_END macro instead of putting it in the ADJUST macro thread_loop_c(t,domain) { begin_c_loop(c,t) { C_UDMI(c,t,Vorticity_I) = C_UDSI(c,t,Vorticity_I); C_UDMI(c,t,Vorticity_J) = C_UDSI(c,t,Vorticity_J); C_UDMI(c,t,Vorticity_K) = C_UDSI(c,t,Vorticity_K); ND_D(C_UDSI(c,t,G_Vorticity_Ix),C_UDSI(c,t,G_Vorti city_Iy),C_UDSI(c,t,G_Vorticity_Iz),=,\ C_UDSI_G(c,t,Vorticity_I)[0],C_UDSI_G(c,t,Vorticity_I)[1],C_UDSI_G(c,t,Vorticity_I)[2]); ND_D(C_UDSI(c,t,G_Vorticity_Jx),C_UDSI(c,t,G_Vorti city_Jy),C_UDSI(c,t,G_Vorticity_Jz),=,\ C_UDSI_G(c,t,Vorticity_J)[0],C_UDSI_G(c,t,Vorticity_J)[1],C_UDSI_G(c,t,Vorticity_J)[2]); ND_D(C_UDSI(c,t,G_Vorticity_Kx),C_UDSI(c,t,G_Vorti city_Ky),C_UDSI(c,t,G_Vorticity_Kz),=,\ C_UDSI_G(c,t,Vorticity_K)[0],C_UDSI_G(c,t,Vorticity_K)[1],C_UDSI_G(c,t,Vorticity_K)[2]); } end_c_loop(c,t); }

 August 11, 2015, 10:34 #8 Member   Farzin Join Date: Jul 2014 Posts: 42 Rep Power: 11 Thank you Bruno, for your time and effort. Printed values of the UDMs and UDSs are all equal. Plus, plot of vorticity values calculated by FLUENT is very similar to UDM (which should be the same as UDS values). So the problem should be due to the way they're plotted. My concern was vorticity (UDS) and its gradient which are used in another UDF, are not correct.

 August 11, 2015, 10:50 #9 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 Glad I could help you. Just to make sure the value you are getting is the correct one and the difference is in the plotting, you could compute the other UDF using the value of the UDM and from the UDS. You should get the same value.

 August 11, 2015, 11:04 #10 Member   Farzin Join Date: Jul 2014 Posts: 42 Rep Power: 11 I just replaced the whole ADJUST function by AT_THE_END, and now the vorticity UDS and UDM plots are both exactly the same as the one calculated by FLUENT. Still don't know why but this solved the problem. Thank you Bruno for the suggestion.

 August 11, 2015, 11:33 #11 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 I think it is because fluent solve all the equations you imputed before solving the governing equations, so your current value of some variables actually were the value of previous iteration. But glad you solve the problem.

 January 26, 2016, 11:07 #12 Senior Member   Przemek Join Date: Jun 2011 Posts: 249 Rep Power: 15 Hi Bruno, I have such a code: Code: /******************************************************************** *********************************************************************/ #include "udf.h" DEFINE_EXECUTE_AT_END(myFunc) { Domain *d; Thread *t; /* Integrate dissipation. */ real sum_diss=0.; cell_t c; d = Get_Domain(1); /* mixture domain if multiphase */ thread_loop_c(t,d) { if (FLUID_THREAD_P(t)) { begin_c_loop(c,t) C_UDMI(c,t,0) = C_T(c,t); end_c_loop(c,t) } } } I wanto to write temperature to my UDM. However after the calculations in the post Static temperature and User memory 0 differ (exactly only in one location = at boundary). Can you tell what I am doing wrong? __________________ best regards pblasiak

January 26, 2016, 12:17
#13
Member

Farzin
Join Date: Jul 2014
Posts: 42
Rep Power: 11
Quote:
 Originally Posted by gaza Hi Bruno, I have such a code: Code: /******************************************************************** *********************************************************************/ #include "udf.h" DEFINE_EXECUTE_AT_END(myFunc) { Domain *d; Thread *t; /* Integrate dissipation. */ real sum_diss=0.; cell_t c; d = Get_Domain(1); /* mixture domain if multiphase */ thread_loop_c(t,d) { if (FLUID_THREAD_P(t)) { begin_c_loop(c,t) C_UDMI(c,t,0) = C_T(c,t); end_c_loop(c,t) } } } I wanto to write temperature to my UDM. However after the calculations in the post Static temperature and User memory 0 differ (exactly only in one location = at boundary). Can you tell what I am doing wrong?

It's because you didn't assign UDM value for the boundary and you're trying to get it.
Actually, the value you get is an interpolated value calculated by fluent.
If you want to set values of a boundary to the UDM, you should also add face UDM.
Try this one:

Code:
#include "udf.h"
DEFINE_EXECUTE_AT_END(myFunc)
{
Domain *d;
/* Integrate dissipation. */
real sum_diss=0.;
cell_t c;
d = Get_Domain(1); /* mixture domain if multiphase */
{
{
begin_c_loop(c,t)
C_UDMI(c,t,0) = C_T(c,t);
end_c_loop(c,t)
}
}
{
{
begin_f_loop(f,t)
F_UDMI(f,t,0) = F_T(f,t);
end_f_loop(f,t);
}
}
}

 January 26, 2016, 13:12 #15 Senior Member   Przemek Join Date: Jun 2011 Posts: 249 Rep Power: 15 I changed the code like that but it does not solve the problem Code: #include "udf.h" DEFINE_EXECUTE_AT_END(myFunc) { Domain *d; /* Integrate dissipation. */ real sum_diss=0.; cell_t c; face_t f; Thread *t; const int ID = 11; d = Get_Domain(1); /* mixture domain if multiphase */ thread_loop_c(t,d) { if (FLUID_THREAD_P(t)) { begin_c_loop(c,t) C_UDMI(c,t,0) = C_T(c,t); end_c_loop(c,t) } } t = Lookup_Thread(d,ID); thread_loop_f(t,d) { //if (FLUID_THREAD_P(t)) if (NNULLP(THREAD_STORAGE(t,SV_UDM_I))) { begin_f_loop(f,t) F_UDMI(f,t,0) = F_T(f,t); end_f_loop(f,t); } else { Message("Skipping FACE thread no. %d..\n", THREAD_ID(t)); } } } Can anybody help? __________________ best regards pblasiak

 January 26, 2016, 13:15 #16 Member   Farzin Join Date: Jul 2014 Posts: 42 Rep Power: 11 Hi, I'm Farzin! I do not get why you added the thread pointer to the boundary; Because the loop in below line provides the thread pointer to all face threads, including that particular boundary. Remove the line you added and try. If you want to keep it, you should remove the face thread loop.

 January 26, 2016, 13:25 #17 Senior Member   Przemek Join Date: Jun 2011 Posts: 249 Rep Power: 15 Ok I deleted it but I got received a fatal signal (Segmentation fault). Do you know what is wrong? __________________ best regards pblasiak

January 26, 2016, 13:34
#18
Member

Farzin
Join Date: Jul 2014
Posts: 42
Rep Power: 11
Quote:
Correct this one, if you're using it: F_UDMI(f,tf,0) = F_T(f,t); >> F_UDMI(f,t,0) = F_T(f,t);

It shouldn't have any problem.

 January 26, 2016, 13:49 #19 Senior Member   Bruno Machado Join Date: May 2014 Posts: 271 Rep Power: 13 I believe the values are different because the macro C_T gives the total temperature, so it might be different from the static temperature. Have a look at this thread http://www.cfd-online.com/Forums/flu...mperature.html

 January 26, 2016, 15:53 #20 Senior Member   Przemek Join Date: Jun 2011 Posts: 249 Rep Power: 15 Hi Bruno and Farzin, @Farzin: I compiled this code: Code: #include "udf.h" DEFINE_EXECUTE_AT_END(myFunc) { Domain *d; /* Integrate dissipation. */ real sum_diss=0.; cell_t c; face_t f; Thread *t; const int ID = 11; d = Get_Domain(1); /* mixture domain if multiphase */ thread_loop_c(t,d) { if (FLUID_THREAD_P(t)) { begin_c_loop(c,t) C_UDMI(c,t,0) = C_T(c,t); end_c_loop(c,t) } } //t = Lookup_Thread(d,ID); thread_loop_f(t,d) { //if (FLUID_THREAD_P(t)) //if (NNULLP(THREAD_STORAGE(t,SV_UDM_I))) begin_f_loop(f,t) F_UDMI(f,t,0) = F_T(f,t); end_f_loop(f,t); } } and it gave the: received a fatal signal (Segmentation fault). @Bruno: I do not agree with you because I compared data for Static temperature and C_T that was assigned to UDM. Each value was the same but boundary value. So I agree with Farzin that I have to set face value also with F_T, however I do not know how??? Here mvee wrote that he solved this problem but he unfortunately didn't provide the code: http://www.cfd-online.com/Forums/flu...g-udm-uds.html __________________ best regards pblasiak

 Tags udf, udm, uds