CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF gradient (https://www.cfd-online.com/Forums/fluent-udf/251804-udf-gradient.html)

emmakateh September 7, 2023 14:01

UDF gradient
 
Hi, I am having trouble getting a gradient to work properly with UDSI. I have a calculation to calculate Hmag of a magnetic field. and then I am trying to get the gradient of this USDI in the x, y, z, directions. The simulation will run without throwing errors, but the gradient returns zeros for everywhere in my mesh. I found this setup on 8.2.5 User-Defined Scalars of UDF manual

#include "udf.h"
#include "sg.h"
#include <math.h>

DEFINE_INIT(HFIELD, domain)
{
Thread *t;
cell_t c;
face_t f;
real pos[ND_ND];

thread_loop_c(t,domain) /* loops over all cell threads in domain */
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(HMAG)))
{
begin_c_loop_all(c,t) /* loop over cells in a thread to get information stored in cells */
{
C_CENTROID(pos,c,t);
.
.
.
Hmag = sqrt(Hz*Hz + Hx*Hx + Hy*Hy) ; /* (A/m) Magnetic Field Strength */
C_UDSI(c,t,HMAG) = Hmag;
}
end_c_loop_all(c,t) /* END: Looping over all cells */
}
}

thread_loop_c (t,domain)
{
if (NULL != THREAD_STORAGE(t,SV_UDS_I(HMAG)) &&
NULL != T_STORAGE_R_NV(t,SV_UDSI_G(HMAG)))
{
begin_c_loop (c,t)
{
C_UDSI(c,t,HGRADX) = C_UDSI_G(c,t,HMAG)[0];
}
end_c_loop (c,t)
}
}
}


All times are GMT -4. The time now is 00:54.