


{"id":311895,"date":"2023-10-17T17:48:47","date_gmt":"2023-10-17T17:48:47","guid":{"rendered":"\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/"},"modified":"2023-10-17T17:48:47","modified_gmt":"2023-10-17T17:48:47","slug":"udfs-for-adding-energy-source-term-in-pcm-in-porous-medium","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/","title":{"rendered":"UDFs for adding Energy source term in PCM in Porous medium"},"content":{"rendered":"<p>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.<img decoding=\"async\" src=\"\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy Source Equation.png\" alt=\"\"><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #c586c0;background: #1F1F1F\">#define<\/span><span style=\"color: #569cd6;background: #1F1F1F\"> UDM_RHO_F_PREV <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/ UDM index for storing previous rho_f<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #c586c0;background: #1F1F1F\">#define<\/span><span style=\"color: #569cd6;background: #1F1F1F\"> UDM_LAMBDA_PREV <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/ UDM index for storing previous lambda<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #dcdcaa;background: #1F1F1F\">DEFINE_EXECUTE_ON_LOADING<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(init_values, udf_name)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\">{<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>Thread <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\">t;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #4ec9b0;background: #1F1F1F\">cell_t<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> c;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>Domain <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\">d <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">Get_Domain<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(<\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1<\/span><span style=\"color: #cccccc;background: #1F1F1F\">);<\/span><span style=\"color: #6a9955;background: #1F1F1F\"> \/\/ Get domain using Fluent API, assuming single-phase flow<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #6a9955\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>\/* Loop over all cells to initialize UDM values *\/<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">thread_loop_c<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(t, d)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">begin_c_loop_all<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>{<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c,t,UDM_RHO_F_PREV) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1000.0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">;<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/initializing previous rho_f<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c,t,UDM_LAMBDA_PREV) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0.0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">;<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/initializing previous lambda<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">end_c_loop_all<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>}<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\">}<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #dcdcaa;background: #1F1F1F\">DEFINE_SOURCE<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(energy_sourceN, c, t, dS, eqn)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\">{<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>real lambda, lambda_prev, <\/span><span style=\"color: #9cdcfe;background: #1F1F1F\">V<\/span><span style=\"color: #cccccc;background: #1F1F1F\">[ND_ND], rho_f, Sl, d_lambda_dt, grad_lambda_dot_V, T, rho_f_prev;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp; <\/span><\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>T <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_T<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t);<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>rho_f <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_R<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t);<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_CENTROID<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(V, c, t);<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\"><span>&nbsp; <\/span><\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>rho_f_prev <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t, UDM_RHO_F_PREV);<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/ Fetch the previous value of rho_f from UDM<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>lambda_prev <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t, UDM_LAMBDA_PREV);<\/span><span style=\"color: #6a9955;background: #1F1F1F\"><span>&nbsp; <\/span>\/\/ Fetch the previous value of lambda from UDM<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #6a9955;background: #1F1F1F\">\/\/ Calculate lambda<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #c586c0;background: #1F1F1F\">if<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (T <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">&lt;<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> Tsolidus)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>lambda <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0.0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #c586c0;background: #1F1F1F\">else if<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (T <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">&gt;<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> Tliquidus)<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>lambda <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1.0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #c586c0;background: #1F1F1F\">else<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp;&nbsp;&nbsp; <\/span>lambda <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (T <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">&#8211;<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> Tsolidus) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">\/<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (Tliquidus <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">&#8211;<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> Tsolidus);<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #6a9955;background: #1F1F1F\">\/\/ Calculate d(lambda*rho_f*L_f)\/dt<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>d_lambda_dt <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> ((rho_f <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> lambda <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> L_f <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">* <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0.85<\/span><span style=\"color: #cccccc;background: #1F1F1F\">) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">&#8211;<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (rho_f_prev <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> lambda_prev <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> L_f <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">* <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0.85<\/span><span style=\"color: #cccccc;background: #1F1F1F\">)) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">\/<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> CURRENT_TIMESTEP;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #6a9955;background: #1F1F1F\">\/\/ The gradient calculation requires more attention. Below is just a placeholder, and you need to implement the correct gradient calculation.<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>grad_lambda_dot_V <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> (<\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_R_G<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c,t)[<\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">] <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">* <\/span><span style=\"color: #9cdcfe;background: #1F1F1F\">V<\/span><span style=\"color: #cccccc;background: #1F1F1F\">[<\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">] <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">+ <\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_R_G<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c,t)[<\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1<\/span><span style=\"color: #cccccc;background: #1F1F1F\">] <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">* <\/span><span style=\"color: #9cdcfe;background: #1F1F1F\">V<\/span><span style=\"color: #cccccc;background: #1F1F1F\">[<\/span><span style=\"color: #b5cea8;background: #1F1F1F\">1<\/span><span style=\"color: #cccccc;background: #1F1F1F\">]) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> lambda <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">*<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> L_f;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span>Sl <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> d_lambda_dt <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">+<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> grad_lambda_dot_V;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #9cdcfe;background: #1F1F1F\">dS<\/span><span style=\"color: #cccccc;background: #1F1F1F\">[eqn] <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">= <\/span><span style=\"color: #b5cea8;background: #1F1F1F\">0<\/span><span style=\"color: #cccccc;background: #1F1F1F\">;<\/span><span style=\"color: #6a9955;background: #1F1F1F\"> \/\/ Adjust the source term linearization if necessary<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #6a9955;background: #1F1F1F\">\/\/ Store the current time step values of rho_f and lambda to UDM<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t, UDM_RHO_F_PREV) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> rho_f;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #dcdcaa;background: #1F1F1F\">C_UDMI<\/span><span style=\"color: #cccccc;background: #1F1F1F\">(c, t, UDM_LAMBDA_PREV) <\/span><span style=\"color: #d4d4d4;background: #1F1F1F\">=<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> lambda;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Calibri;font-size: 11.0pt\">&nbsp;<\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt\"><span style=\"color: #cccccc;background: #1F1F1F\"><span>&nbsp; <\/span><\/span><span style=\"color: #c586c0;background: #1F1F1F\">return<\/span><span style=\"color: #cccccc;background: #1F1F1F\"> Sl;<\/span><\/p>\n<p style=\"margin: 0in;line-height: 14pt;font-family: Consolas;font-size: 10.5pt;color: #cccccc\"><span style=\"background: #1F1F1F\">}<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","class_list":["post-311895","topic","type-topic","status-closed","hentry","topic-tag-energy-source-term-2","topic-tag-fluent","topic-tag-porosity-1","topic-tag-porous","topic-tag-udf"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"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\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Ansys Learning Forum | Ansys Innovation Space\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum\" \/>\n\t\t<meta property=\"og:description\" content=\"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\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy%20Source%20Equation.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy%20Source%20Equation.png\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-10-17T17:48:47+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-10-17T17:48:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum\" \/>\n\t\t<meta name=\"twitter:description\" content=\"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\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy Source Equation.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/topics\\\/#listItem\",\"name\":\"Topics\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/topics\\\/#listItem\",\"position\":2,\"name\":\"Topics\",\"item\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/topics\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic-tag\\\/fluent\\\/#listItem\",\"name\":\"fluent\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic-tag\\\/fluent\\\/#listItem\",\"position\":3,\"name\":\"fluent\",\"item\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic-tag\\\/fluent\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/#listItem\",\"name\":\"UDFs for adding Energy source term in PCM in Porous medium\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/topics\\\/#listItem\",\"name\":\"Topics\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/#listItem\",\"position\":4,\"name\":\"UDFs for adding Energy source term in PCM in Porous medium\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic-tag\\\/fluent\\\/#listItem\",\"name\":\"fluent\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/#organization\",\"name\":\"Ansys Learning Forum\",\"description\":\"Ansys Innovation Space\",\"url\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/#webpage\",\"url\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/\",\"name\":\"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum\",\"description\":\"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\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/forums\\\/topic\\\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\\\/#breadcrumblist\"},\"datePublished\":\"2023-10-17T17:48:47+00:00\",\"dateModified\":\"2023-10-17T17:48:47+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/#website\",\"url\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/\",\"name\":\"Ansys Learning Forum\",\"description\":\"Ansys Innovation Space\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/innovationspace.ansys.com\\\/forum\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum","description":"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","canonical_url":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BreadcrumbList","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum#listItem","position":1,"name":"Home","item":"https:\/\/innovationspace.ansys.com\/forum","nextItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/topics\/#listItem","name":"Topics"}},{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/topics\/#listItem","position":2,"name":"Topics","item":"https:\/\/innovationspace.ansys.com\/forum\/topics\/","nextItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/#listItem","name":"fluent"},"previousItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/#listItem","position":3,"name":"fluent","item":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/","nextItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/#listItem","name":"UDFs for adding Energy source term in PCM in Porous medium"},"previousItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/topics\/#listItem","name":"Topics"}},{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/#listItem","position":4,"name":"UDFs for adding Energy source term in PCM in Porous medium","previousItem":{"@type":"ListItem","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/#listItem","name":"fluent"}}]},{"@type":"Organization","@id":"https:\/\/innovationspace.ansys.com\/forum\/#organization","name":"Ansys Learning Forum","description":"Ansys Innovation Space","url":"https:\/\/innovationspace.ansys.com\/forum\/"},{"@type":"WebPage","@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/#webpage","url":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/","name":"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum","description":"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","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/innovationspace.ansys.com\/forum\/#website"},"breadcrumb":{"@id":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/#breadcrumblist"},"datePublished":"2023-10-17T17:48:47+00:00","dateModified":"2023-10-17T17:48:47+00:00"},{"@type":"WebSite","@id":"https:\/\/innovationspace.ansys.com\/forum\/#website","url":"https:\/\/innovationspace.ansys.com\/forum\/","name":"Ansys Learning Forum","description":"Ansys Innovation Space","inLanguage":"en-US","publisher":{"@id":"https:\/\/innovationspace.ansys.com\/forum\/#organization"}}]},"og:locale":"en_US","og:site_name":"Ansys Learning Forum | Ansys Innovation Space","og:type":"article","og:title":"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum","og:description":"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","og:url":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/","og:image":"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy%20Source%20Equation.png","og:image:secure_url":"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy%20Source%20Equation.png","article:published_time":"2023-10-17T17:48:47+00:00","article:modified_time":"2023-10-17T17:48:47+00:00","twitter:card":"summary_large_image","twitter:title":"UDFs for adding Energy source term in PCM in Porous medium | Ansys Learning Forum","twitter:description":"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","twitter:image":"https:\/\/innovationspace.ansys.com\/forum\/forum\/wp-content\/uploads\/sites\/2\/2023\/10\/17-10-2023-1697564906-Energy Source Equation.png"},"aioseo_meta_data":{"post_id":"311895","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"content","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":true,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"limit_modified_date":false,"created":"2024-10-28 17:40:11","updated":"2024-10-28 17:40:11","ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/innovationspace.ansys.com\/forum\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/innovationspace.ansys.com\/forum\/topics\/\" title=\"Topics\">Topics<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/\" title=\"fluent\">fluent<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUDFs for adding Energy source term in PCM in Porous medium\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/innovationspace.ansys.com\/forum"},{"label":"Topics","link":"https:\/\/innovationspace.ansys.com\/forum\/topics\/"},{"label":"fluent","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic-tag\/fluent\/"},{"label":"UDFs for adding Energy source term in PCM in Porous medium","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udfs-for-adding-energy-source-term-in-pcm-in-porous-medium\/"}],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["33161","14311"],"_bbp_author_ip":["23.52.43.81"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_bbp_likes_count":["1"],"_btv_view_count":["2850"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["311895"],"_bbp_forum_id":["27825"],"_bbp_engagement":["14311","33161"],"_bbp_voice_count":["2"],"_bbp_reply_count":["1"],"_bbp_last_reply_id":["313626"],"_bbp_last_active_id":["313626"],"_bbp_last_active_time":["2023-10-27 11:53:15"]},"test":"2462918cstudent-gla-ac-uk"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/311895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics"}],"about":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/311895\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=311895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}