


{"id":377965,"date":"2024-08-12T14:46:15","date_gmt":"2024-08-12T14:46:15","guid":{"rendered":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/laser-melting-heat-source-udf-issue-fluent-crashing\/"},"modified":"2024-08-12T14:46:15","modified_gmt":"2024-08-12T14:46:15","slug":"laser-melting-heat-source-udf-issue-fluent-crashing","status":"publish","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/laser-melting-heat-source-udf-issue-fluent-crashing\/","title":{"rendered":"Laser Melting heat source UDF issue [FLUENT Crashing]"},"content":{"rendered":"<p>Hello everyone,<\/p>\n<p>I am trying to simulate Selective Laser Melting in Ansys Fluent. Its a two phase problem. So I am using VOF model.<\/p>\n<p>my domain dimension is :<\/p>\n<p>L = 0.8 mm (X axis)<br \/>W = 0.2 mm (Y axis)<br \/>H = 0.28 mm (Z axis)<\/p>\n<p>In this domain , I patched the domain ( x = 0.8 mm, y = 0.2 mm , z= 0.2 mm) as solid and the rest is gas.<\/p>\n<p>I am trying to model the heat source as surface heat source and place it at x = 0 mm , y = 0.1 mm and z is undefined as I will use if statement to find the interface ( where 0&lt;VOF&lt;1)<\/p>\n<p>My UDF code is given below. After Compiling and initialising , when I try to view the user defined volumetric heat source under the contour tab , FLUENT Crashes instantly. I am not sure what went wrong. Yes I also created 5 user defined memory locations. Can anyone help?<\/p>\n<p>#include &#8220;udf.h&#8221;<br \/>#include &#8220;sg_mphase.h&#8221;<br \/>#include &#8220;mem.h&#8221;<br \/>#include &#8220;sg_mem.h&#8221;<br \/>#include &#8220;math.h&#8221;<br \/>#include &#8220;flow.h&#8221;<br \/>#include &#8220;unsteady.h&#8221;<br \/>#include &#8220;metric.h&#8221;<\/p>\n<p>\/\/ Constants<br \/>#define A 0.4 \/\/ Absorption coefficient<br \/>#define P 200 \/\/ Laser power (W)<br \/>#define R 40e-6 \/\/ Spot radius (m)<br \/>#define v 0.5 \/\/ Scan speed of laser (m\/s)<br \/>#define Pi 3.1415926535 \/\/ Pi constant<br \/>#define x0 0.0 \/\/ Initial x position of the laser (m)<br \/>#define y0 0.1e-3 \/\/ Initial y position of the laser (m)<\/p>\n<p>\/\/ UDF for adjusting the gradient heat<br \/>DEFINE_ADJUST(adjust_gradient_heat, domain)<br \/>{<br \/>Thread *t;<br \/>Thread **pt;<br \/>cell_t c;<br \/>int phase_domain_index = 3.0; \/\/ thjats my metal domain<br \/>Domain *pDomain = DOMAIN_SUB_DOMAIN(domain, phase_domain_index);<\/p>\n<p>Alloc_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);<br \/>Scalar_Reconstruction(pDomain, SV_VOF, -1, SV_VOF_RG, NULL);<br \/>Scalar_Derivatives(pDomain, SV_VOF, -1, SV_VOF_G, SV_VOF_RG, Vof_Deriv_Accumulate);<\/p>\n<p>mp_thread_loop_c(t, domain, pt)<br \/>if (FLUID_THREAD_P(t))<br \/>{<br \/>Thread *ppt = pt[phase_domain_index];<\/p>\n<p>begin_c_loop(c, t)<br \/>{<br \/>C_UDMI(c, t, 0) = C_VOF_G(c, ppt)[0];<br \/>C_UDMI(c, t, 1) = C_VOF_G(c, ppt)[1];<br \/>C_UDMI(c, t, 2) = C_VOF_G(c, ppt)[2];<br \/>C_UDMI(c, t, 3) = sqrt(C_UDMI(c, t, 0) * C_UDMI(c, t, 0) +<br \/>C_UDMI(c, t, 1) * C_UDMI(c, t, 1) +<br \/>C_UDMI(c, t, 2) * C_UDMI(c, t, 2)); \/\/ Magnitude of gradient of volume fraction<\/p>\n<p>}<br \/>end_c_loop(c, t)<br \/>}<\/p>\n<p>Free_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);<br \/>}<\/p>\n<p>\/\/ UDF for defining the heat source<br \/>DEFINE_SOURCE(heat_source, c, t, dS, eqn)<br \/>{<br \/>Thread *pri_th; \/\/ Gas phase<br \/>Thread *sec_th; \/\/ solid phase<br \/>real source;<br \/>real x[ND_ND], time;<br \/>time = CURRENT_TIME; \/\/ Acquire time from Fluent solver<br \/>C_CENTROID(x, c, t); \/\/ Acquire the cell centroid location<br \/>real T = C_T(c, t);<\/p>\n<p>pri_th = THREAD_SUB_THREAD(t, 0);<br \/>sec_th = THREAD_SUB_THREAD(t, 1);<\/p>\n<p>real rho = C_R(c,t);<br \/>real Cp = C_CP(c,t);<\/p>\n<p>real rhom = C_R(c,sec_th);<br \/>real Cpm = C_CP(c,sec_th);<\/p>\n<p>real rhog = C_R(c,pri_th);<br \/>real Cpg = C_CP(c,pri_th);<br \/>real factor = (2 * rho * Cp) \/ (rhom * Cpm + rhog * Cpg);<\/p>\n<p>real r = sqrt(pow(x[0] &#8211; x0 &#8211; v * time, 2.0) + pow(x[1] &#8211; y0, 2.0));<\/p>\n<p>if (C_VOF(c, t) &gt; 0.05 &amp;&amp; C_VOF(c, t) &lt; 1)<br \/>{<br \/>source = ((2 * A * P) \/ (Pi * R * R)) * exp((-2 * (r * r)) \/ (R * R))*factor * C_UDMI(c,t,3);<br \/>dS[eqn] = 0.0;<br \/>}<br \/>else<br \/>{<br \/>source = 0.0;<br \/>dS[eqn] = 0.0;<br \/>}<\/p>\n<p>return source;<br \/>}<\/p>\n","protected":false},"template":"","class_list":["post-377965","topic","type-topic","status-publish","hentry"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_subscription":["440817","199"],"_bbp_author_ip":["118.179.2.146"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["165"],"_bbp_topic_status":["unanswered"],"_bbp_topic_id":["377965"],"_bbp_forum_id":["27792"],"_bbp_engagement":["199","440817"],"_bbp_voice_count":["2"],"_bbp_reply_count":["15"],"_bbp_last_reply_id":["379982"],"_bbp_last_active_id":["379982"],"_bbp_last_active_time":["2024-08-23 10:08:13"]},"test":"rakibul-buet19gmail-com"}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/377965","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\/377965\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=377965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}