TAGGED: energysourceterm, fluent, porosity, porous, udf


October 17, 2023 at 5:48 pmRobbie CrosbySubscriber
Hello, I am unsure if this is the place to ask this, however I am really struggling to create UDFs to fit a numerical model which must be applied as UDFs in ANSYS Fluent to model a phase change material in a porous medium for thermal energy transfer. I have attached the mathematical model I am trying to follow as well as my current code. I am stuck on how to add the source term Sl, currently it crashes each time I try to run it.
#define UDM_RHO_F_PREV 0 // UDM index for storing previous rho_f
#define UDM_LAMBDA_PREV 1 // UDM index for storing previous lambda
DEFINE_EXECUTE_ON_LOADING(init_values, udf_name)
{
Thread *t;
cell_t c;
Domain *d = Get_Domain(1); // Get domain using Fluent API, assuming singlephase flow
/* Loop over all cells to initialize UDM values */
thread_loop_c(t, d)
{
begin_c_loop_all(c, t)
{
C_UDMI(c,t,UDM_RHO_F_PREV) = 1000.0; //initializing previous rho_f
C_UDMI(c,t,UDM_LAMBDA_PREV) = 0.0; //initializing previous lambda
}
end_c_loop_all(c, t)
}
}
DEFINE_SOURCE(energy_sourceN, c, t, dS, eqn)
{
real lambda, lambda_prev, V[ND_ND], rho_f, Sl, d_lambda_dt, grad_lambda_dot_V, T, rho_f_prev;
T = C_T(c, t);
rho_f = C_R(c, t);
C_CENTROID(V, c, t);
rho_f_prev = C_UDMI(c, t, UDM_RHO_F_PREV); // Fetch the previous value of rho_f from UDM
lambda_prev = C_UDMI(c, t, UDM_LAMBDA_PREV); // Fetch the previous value of lambda from UDM
// Calculate lambda
if (T < Tsolidus)
lambda = 0.0;
else if (T > Tliquidus)
lambda = 1.0;
else
lambda = (T  Tsolidus) / (Tliquidus  Tsolidus);
// Calculate d(lambda*rho_f*L_f)/dt
d_lambda_dt = ((rho_f * lambda * L_f * 0.85)  (rho_f_prev * lambda_prev * L_f * 0.85)) / CURRENT_TIMESTEP;
// The gradient calculation requires more attention. Below is just a placeholder, and you need to implement the correct gradient calculation.
grad_lambda_dot_V = (C_R_G(c,t)[0] * V[0] + C_R_G(c,t)[1] * V[1]) * lambda * L_f;
Sl = d_lambda_dt + grad_lambda_dot_V;
dS[eqn] = 0; // Adjust the source term linearization if necessary
// Store the current time step values of rho_f and lambda to UDM
C_UDMI(c, t, UDM_RHO_F_PREV) = rho_f;
C_UDMI(c, t, UDM_LAMBDA_PREV) = lambda;
return Sl;
}

October 27, 2023 at 11:53 amAtharva NagarkarSubscriber
Hello,
As Ansys employees, we cannot debug UDFs on this platform. However, can you share more details about the error you receive when you run the solution?
One possible issue could be with the C_UDMI macro. You can use the C_UDMI macro to access or store the value of the userdefined memory in a cell. It can be used to allocate up to 500 memory locations in order to store and retrieve the values of cell field variables computed by UDFs. If the number of field variable values to be stored exceed 500, you may receive a memory storage error. Please find the link from the Ansys UDF Manual for this macro below.
Additionally, I have attached links from the Ansys UDF Manual for the DEFINE_SOURCE, DEFINE_EXECUTE_ON_LOADING and Gradient macros. Please ensure that you have appropriately used these macros.
DEFINE_SOURCE  2.3. ModelSpecific DEFINE Macros (ansys.com) > Check section 2.3.43
DEFINE_EXECUTE_ON_LOADING  2.2. General Purpose DEFINE Macros (ansys.com) > Check section 2.2.6
Gradient  3.2. Data Access Macros (ansys.com) > Check section 3.2.3.7
C_UDMI  3.2. Data Access Macros (ansys.com) > Check section 3.2.12.4
If you are not able to access the link, please refer to this forum discussion: Using Help with links (ansys.com)
Thanks!

 You must be logged in to reply to this topic.
Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
 How can i get stressstrain data points for defining Multilinear isotropic hardening in Ansys
 Error: WorkBench Error: Could not handle event: SolutionStatusUpdate Error Object: #f
 Reynolds Number in Fully Developed Turbulent Flow
 Opening course files using ANSYS 19.1
 WHAT THIS WARNING ERROR MEANS( WATERTIGHT FLUENT MESHING)?
 Coriolis Flowmeter 2 way FSI workshop files
 Formula SAE Composite Monocoque Chassis Analysis – Geometry File
 Mesh fail
 Ansys innvoation course files
 Turbulent flow

8738

4658

3151

1678

1452
© 2023 Copyright ANSYS, Inc. All rights reserved.