


{"id":277444,"date":"2023-03-31T17:33:47","date_gmt":"2023-03-31T17:33:47","guid":{"rendered":"\/forum\/forums\/topic\/volume-fraction-gradient-udf\/"},"modified":"2023-03-31T17:33:47","modified_gmt":"2023-03-31T17:33:47","slug":"volume-fraction-gradient-udf","status":"closed","type":"topic","link":"https:\/\/innovationspace.ansys.com\/forum\/forums\/topic\/volume-fraction-gradient-udf\/","title":{"rendered":"Volume Fraction Gradient UDF"},"content":{"rendered":"<div>Hello,<\/div>\n<div>&nbsp;<\/div>\n<div>I am trying to simulate Selective Laser Melting process at the mesoscale using Ansys Fluent. When writing the source term, I need to multiply it by the magnitude of the volume fraction gradient at the interface. For this, I have written the UDF given below where I store the magnitude of the volume fraction gradient in a UDMI using DEFINE_ADJUST and then call it in the DEFINE_SOURCE macros and assign it to the variable vf_g. If I don&#8217;t call the C_UDMI in the DEFINE_SOURCE term the simulation runs without any issue and I can also visualize the C_UDMI in the contour plots, however, when I call it in DEFINE_SOURCE to multiply it with the source term, fluent simply crashes. Any errors that can be seen here? I have had the same issue regardless of the thread C_UDMI(c,t,0) wherein both the mixture domain thread and the phase thread result in fluent crashing<\/div>\n<div>&nbsp;<\/div>\n<div>#include &lt;udf.h&gt;<\/div>\n<div>#include &lt;sg_mphase.h&gt;<\/div>\n<div>#include &lt;mem.h&gt;<\/div>\n<div>#include &lt;sg_mem.h&gt;<\/div>\n<div>\/\/#include &lt;math.h&gt;<\/div>\n<div>#include &lt;flow.h&gt;<\/div>\n<div>#include &lt;unsteady.h&gt;<\/div>\n<div>#include &lt;metric.h&gt;<\/div>\n<div>&nbsp;<\/div>\n<div>#define PI 3.1415926535<\/div>\n<div>#define domain_ID 3<\/div>\n<div>DEFINE_ADJUST(adjust_gradient, domain)<\/div>\n<div>{<\/div>\n<div>&nbsp; &nbsp; Thread *t;<\/div>\n<div>&nbsp; &nbsp; cell_t c;<\/div>\n<div>&nbsp; &nbsp; face_t f;<\/div>\n<div>&nbsp; &nbsp; domain = Get_Domain(domain_ID);<\/div>\n<div>&nbsp; &nbsp; \/* Fill UDS with the variable. *\/<\/div>\n<div>&nbsp; &nbsp; thread_loop_c (t,domain)<\/div>\n<div>&nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; begin_c_loop (c,t)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C_UDSI(c,t,0) = C_VOF(c,t);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; end_c_loop (c,t)<\/div>\n<div>&nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; thread_loop_f (t,domain)<\/div>\n<div>&nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; begin_f_loop (f,t)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; F_UDSI(f,t,0) = F_VOF(f,t);<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; end_f_loop (f,t)<\/div>\n<div>&nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; domain=Get_Domain(1);<\/div>\n<div>&nbsp; &nbsp; \/* Fill the UDM with magnitude of gradient. *\/<\/div>\n<div>&nbsp; &nbsp; thread_loop_c (t,domain)<\/div>\n<div>&nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; begin_c_loop (c,t)<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; {<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; }<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; end_c_loop (c,t)<\/div>\n<div>&nbsp; &nbsp; }<\/div>\n<div>}<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>DEFINE_SOURCE(surface_laser,c,t,dS,eqn)<\/div>\n<div>{<\/div>\n<div>&nbsp;<\/div>\n<div>real current_time=CURRENT_TIME;<\/div>\n<div>Thread *tp;<\/div>\n<div>\/\/parameters<\/div>\n<div>real r=35e-6; \/\/ 100 micron<\/div>\n<div>real P=50.0; \/\/Power<\/div>\n<div>&nbsp;<\/div>\n<div>Domain *subdomain;<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; int phase_domain_index;<\/div>\n<div>real v_d=0.12;&nbsp;<\/div>\n<div>real source;<\/div>\n<div>real eta=0.5;<\/div>\n<div>&nbsp;<\/div>\n<div>\/\/start pos<\/div>\n<div>real xs=1.5e-5+current_time*v_d;<\/div>\n<div>real ys=6e-5;<\/div>\n<div>\/\/ cell paramters<\/div>\n<div>real x[ND_ND];<\/div>\n<div>real T;<\/div>\n<div>real Q;<\/div>\n<div>&nbsp;<\/div>\n<div>real Sb;<\/div>\n<div>real x1;<\/div>\n<div>real y1;<\/div>\n<div>&nbsp; &nbsp; real z1;<\/div>\n<div>&nbsp; &nbsp; real vf;<\/div>\n<div>real I_z;<\/div>\n<div>real H_s; \/\/<\/div>\n<div>real gamma; \/\/ liq fraction&nbsp;<\/div>\n<div>real h; \/\/ HT coef<\/div>\n<div>real T_a;<\/div>\n<div>real n_fact; \/\/ normalizing factor<\/div>\n<div>real Cpg;<\/div>\n<div>real Cpl;<\/div>\n<div>real Cpm;<\/div>\n<div>real Cps;<\/div>\n<div>real Cp;&nbsp; \/\/ avg cell specific heat<\/div>\n<div>real rho; \/\/ avg cell density<\/div>\n<div>real rhog; \/\/ density of argon gas<\/div>\n<div>&nbsp;<\/div>\n<div>real rhos; \/\/ solid density<\/div>\n<div>real rhol; \/\/ liquid density<\/div>\n<div>real rhom; \/\/ mixture density<\/div>\n<div>&nbsp;<\/div>\n<div>real vf_g; \/\/magnitude of volume fraction gradient<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>real s=15e-6;<\/div>\n<div>&nbsp;<\/div>\n<div>Sb=5.67e-8;<\/div>\n<div>h=25;<\/div>\n<div>T_a=298;<\/div>\n<div>C_CENTROID(x,c,t);<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>x1=x[0];<\/div>\n<div>y1=x[1];<\/div>\n<div>&nbsp; &nbsp; z1=x[2]-5e-5+1.25e-6;<\/div>\n<div>&nbsp; &nbsp; tp = THREAD_SUB_THREAD(t,1);<\/div>\n<div>&nbsp; &nbsp; vf=C_VOF(c,tp); \/\/ get cell volume fraction<\/div>\n<div>&nbsp; &nbsp; T = C_T(c,tp); \/\/ get cell temperature<\/div>\n<div>&nbsp; &nbsp; gamma = C_LIQF(c,tp);\/\/ cell liquid fraction<\/div>\n<div>&nbsp; &nbsp;&nbsp;<\/div>\n<div>&nbsp; &nbsp; \/\/Get the volume fraction gradient magnitude<\/div>\n<div>&nbsp; &nbsp; vf_g=C_UDMI(c,tp,0);<\/div>\n<div>&nbsp; &nbsp;&nbsp;<\/div>\n<div>&nbsp; &nbsp; \/\/calculate mixture specific heat<\/div>\n<div>&nbsp; &nbsp; Cpg=520.64;<\/div>\n<div>&nbsp; &nbsp; Cps=462.656+0.1338*T;<\/div>\n<div>&nbsp; &nbsp; Cpl=790;<\/div>\n<div>&nbsp; &nbsp; Cpm=Cpl*gamma+Cps*(1-gamma);<\/div>\n<div>&nbsp; &nbsp; Cp=Cpm*vf+Cpg*(1-vf);<\/div>\n<div>&nbsp; &nbsp;&nbsp;<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; \/\/ calculate mixture density<\/div>\n<div>&nbsp; &nbsp; rhog=1.6228;<\/div>\n<div>&nbsp; &nbsp; rhos=8000.0-800.0\/1385.0*(T-273);<\/div>\n<div>&nbsp; &nbsp; rhol=6900.0-900.0\/1277.0*(T-1723);<\/div>\n<div>&nbsp; &nbsp; rhom=rhol*gamma+rhos*(1-gamma);<\/div>\n<div>&nbsp; &nbsp; rho = vf*rhom + rhog*(1-vf);<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; \/\/ calculate stabilizing factor<\/div>\n<div>&nbsp; &nbsp; n_fact=(2*rho*Cp)\/(rhom*Cpm + rhog*Cpg);<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp; Q=0.23*P\/(PI*r*r) * exp(-2*(pow(x1-xs,2)+pow(y1-ys,2))\/pow(r,2));<\/div>\n<div>&nbsp;<\/div>\n<div>&nbsp; &nbsp;&nbsp;<\/div>\n<div>&nbsp; &nbsp;&nbsp;<\/div>\n<div>&nbsp; &nbsp; source=0;<\/div>\n<div>&nbsp; &nbsp; dS[eqn]=0;<\/div>\n<div>if(vf&gt;0.05 &amp;&amp; vf&lt;1){<\/div>\n<div>&nbsp; &nbsp; &nbsp; &nbsp; source= (Q-h*(T-T_a)-Sb*0.5*(pow(T,4)-pow(T_a,4)))*n_fact*vf_g;<\/div>\n<div>&nbsp; &nbsp; dS[eqn]=(-h-Sb*2*pow(C_T(c,tp),3))*n_fact*vf_g;<\/div>\n<div>}<\/div>\n<div>return source;<\/div>\n<div>&nbsp;<\/div>\n<div>}<\/div>\n","protected":false},"template":"","class_list":["post-277444","topic","type-topic","status-closed","hentry","topic-tag-udf"],"aioseo_notices":[],"acf":[],"custom_fields":[{"0":{"_bbp_author_ip":["23.56.168.190"]," _bbp_last_reply_id":["0"]," _bbp_likes_count":["0"],"_btv_view_count":["1500"],"_bbp_subscription":["4948"],"_bbp_topic_status":["unanswered"],"_bbp_status":["publish"],"_bbp_topic_id":["277444"],"_bbp_forum_id":["27792"],"_bbp_engagement":["0","4948"],"_bbp_voice_count":["2"],"_bbp_reply_count":["1"],"_bbp_last_reply_id":["280714"],"_bbp_last_active_id":["280714"],"_bbp_last_active_time":["2023-04-21 15:13:26"]},"test":""}],"_links":{"self":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/topics\/277444","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\/277444\/revisions"}],"wp:attachment":[{"href":"https:\/\/innovationspace.ansys.com\/forum\/wp-json\/wp\/v2\/media?parent=277444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}