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

UDF gradient

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 7, 2023, 14:01
Default UDF gradient
  #1
New Member
 
EmmaKate
Join Date: Aug 2023
Posts: 9
Rep Power: 2
emmakateh is on a distinguished road
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)
}
}
}
emmakateh is offline   Reply With Quote

Reply

Tags
ansys, fluent, gradient, udf, udf manual


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
UDF for zero pressure gradient at BC outlet ghordog Fluent UDF and Scheme Programming 1 April 28, 2022 05:12
time-averaged wall shear stress gradient udf Azi Lotfi FLUENT 3 April 16, 2020 15:57
Using Cell gradient Variables in UDF avd28 Fluent UDF and Scheme Programming 8 March 14, 2020 06:26
UDF gradient of time qkhanh189 Fluent UDF and Scheme Programming 0 November 28, 2019 16:15
The gradient of void fraction in UDF summer FLUENT 2 May 20, 2011 03:34


All times are GMT -4. The time now is 09:33.