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
Domain *d = Get_Domain(1); // Get domain using Fluent API, assuming single-phase flow
/* Loop over all cells to initialize UDM values */
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
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;
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) * V + C_R_G(c,t) * V) * 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;
October 27, 2023 at 11:53 amAtharva NagarkarSubscriber
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 user-defined 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. Model-Specific 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 184.108.40.206
C_UDMI - 3.2. Data Access Macros (ansys.com) -> Check section 220.127.116.11
If you are not able to access the link, please refer to this forum discussion: Using Help with links (ansys.com)
- You must be logged in to reply to this topic.
Boost Ansys Fluent Simulations with AWS
Earth Rescue – An Ansys Online Series
- How can i get stress-strain 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
© 2023 Copyright ANSYS, Inc. All rights reserved.