


{"id":367254,"date":"2024-05-17T06:40:58","date_gmt":"2024-05-17T06:40:58","guid":{"rendered":"\/forum\/forums\/topic\/udf-error-4\/"},"modified":"2024-05-17T06:40:58","modified_gmt":"2024-05-17T06:40:58","slug":"udf-error-4","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/udf-error-4\/","title":{"rendered":"UDF Error"},"content":{"rendered":"<p><span style=\"font-size: 10pt\">I have attached the UDF at the end. I am trying to use the heat flux to update the mass flow rate at different x values on the inlet surface. I keep getting errors and the temp distribution is weird. On some faces it make sense and others its completely wrong<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 391: -nan(ind) K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Heat flux on face 392: -4.41347e+07 W\/m^2<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 392: -nan(ind) K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Heat flux on face 393: -2.6595e+06 W\/m^2<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 393: 99.0877 K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Heat flux on face 408: 6.20341e+06 W\/m^2<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 408: 1249.73 K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Heat flux on face 409: 4.17052e+06 W\/m^2<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 409: 921.292 K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Heat flux on face 410: 3.9361e+06 W\/m^2<\/span><\/p>\n<p><span style=\"font-size: 10pt\">Temp of face 410: 900.957 K<\/span><\/p>\n<p><span style=\"font-size: 10pt\">pdf_initial_enthalpy: failed to converge for T = -nan(ind), fmean = 0.7, fvar = 0, error = -nan(ind)<\/span><\/p>\n<p><span style=\"font-size: 10pt\">pdf_initial_enthalpy: failed to converge for T = -nan(ind), fmean = 0.7, fvar = 0, error = -nan(ind)<\/span><\/p>\n<p><span style=\"font-size: 10pt\">pdf_initial_enthalpy: failed to converge for T = -nan(ind), fmean = 0.7, fvar = 0, error = -nan(ind)<\/span><\/p>\n<p>&nbsp;<\/p>\n<div><span style=\"font-size: 10pt\">#include &#8220;udf.h&#8221;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#include &lt;math.h&gt;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define rho 754 \/\/kg\/m^3<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define Hg 2033631 \/\/J\/Kg<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define Hf -310000 \/\/J\/Kg<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define T_ref 298 \/\/T<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define A 0.01104 \/\/m\/s<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define Cp 1500 \/\/J\/(Kg*K)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define E 20557.188 \/\/J\/mol<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define R_u 8.314 \/\/J(m*K)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define D_p 0.04064 \/\/port diameter (m)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define L 0.43815 \/\/Length (m)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">#define alpha .1<\/span><\/div>\n<div><span style=\"font-size: 10pt\">DEFINE_PROFILE(surface_temperature_profile, t, position)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">{<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; face_t f;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; real Ts, heat_flux, heat, a_face, Hv, r, Ts_old, Ts_new_prime, Ts_new, error, Area[ND_ND];<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; int iter;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; begin_f_loop(f, t)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; {<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; if (THREAD_ID(t) == 8)&nbsp; \/\/ Adjust the surface thread ID as per your case<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; {<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts = F_T(f, t);&nbsp; \/\/ Current temperature at the face<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; heat = BOUNDARY_HEAT_FLUX(f, t);&nbsp; \/\/ Calculating the heat flux at face f in watts<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_AREA(Area, f, t);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a_face = NV_MAG(Area);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; heat_flux = heat \/ a_face; \/\/ Heat flux in w\/m^2<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printf(&#8220;Heat flux on face %d: %g W\/m^2\\n&#8221;, f, heat_flux);<\/span><\/div>\n<div>&nbsp;<\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Iterative calculation for new surface temperature<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_old = Ts;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iter = 0;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error = 1;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (error &gt; 1e-6 &amp;&amp; iter &lt; 100)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hv = Hg &#8211; Hf + Cp * (Ts_old &#8211; T_ref);&nbsp; \/\/ Calculation heat of formation<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = (fabs(heat_flux)) \/ (Hv * rho);&nbsp; \/\/ Regression rate<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_new = E \/ (R_u * (log(A) &#8211; log(r)));&nbsp; \/\/ New surface temperature<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; error = fabs(Ts_new &#8211; Ts_old);&nbsp; \/\/ Error calculation<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts_old = Ts_new;&nbsp; \/\/ Update Ts_old for next iteration<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; iter++;&nbsp; \/\/ Increment iteration count<\/span><\/div>\n<div>&nbsp;<\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; Ts_new_prime = Ts+(alpha*(Ts_new-Ts));<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; printf(&#8220;Temp of face %d: %g K\\n&#8221;, f, Ts_new_prime);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_PROFILE(f, t, position) = Ts_new_prime;&nbsp; \/\/ Update the face temperature profile<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; }<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; }<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; end_f_loop(f, t)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">}<\/span><\/div>\n<div><span style=\"font-size: 10pt\">DEFINE_PROFILE(mass_flow_rate_profile, t, position)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">{<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; face_t f;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; real heat_flux, heat, a_face, Hv, r, m_dot, Ts, Area[ND_ND];<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; begin_f_loop(f, t)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; {<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; if (THREAD_ID(t) == 8)&nbsp; \/\/ Adjust the inlet thread ID as per your case<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; {<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ts = F_T(f, t);&nbsp; \/\/ Get the current temperature at the face<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; heat = BOUNDARY_HEAT_FLUX(f, t);&nbsp; \/\/ Calculating the heat flux at face f<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_AREA(Area, f, t);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a_face = NV_MAG(Area);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; heat_flux = heat \/ a_face;<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hv = Hg &#8211; Hf + Cp * (Ts &#8211; T_ref);&nbsp; \/\/ Adjusted Hv calculation with temperature dependency<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = (fabs(heat_flux)) \/ (Hv * rho);&nbsp; \/\/ Regression rate calculation<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_dot = rho * r * a_face;&nbsp; \/\/ Mass flow rate calculation<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; printf(&#8220;m_dot fuel %d: %g kg\/s\\n&#8221;, f, m_dot);<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_PROFILE(f, t, position) = m_dot;&nbsp; \/\/ Set the profile for the mass flow rate<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; &nbsp; &nbsp; }<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; }<\/span><\/div>\n<div><span style=\"font-size: 10pt\">&nbsp; &nbsp; end_f_loop(f, t)<\/span><\/div>\n<div><span style=\"font-size: 10pt\">}<\/span><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"template":"","class_list":["post-367254","topic","type-topic","status-closed","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["343144","199"],"_bbp_author_ip":["23.11.229.223"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["280"],"_bbp_topic_status":["unanswered"],"_bbp_topic_id":["367254"],"_bbp_forum_id":["27792"],"_bbp_engagement":["199","343144"],"_bbp_voice_count":["2"],"_bbp_reply_count":["6"],"_bbp_last_reply_id":["367971"],"_bbp_last_active_id":["367971"],"_bbp_last_active_time":["2024-05-22 00:02:40"]},"test":"zwernjaydengmail-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/367254","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\/367254\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=367254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}