TAGGED: udf
-
-
March 31, 2023 at 5:33 pmHello,Â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'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Â#include#include#include#include//#include#include#include#includeÂ#define PI 3.1415926535#define domain_ID 3DEFINE_ADJUST(adjust_gradient, domain){  Thread *t;  cell_t c;  face_t f;  domain = Get_Domain(domain_ID);  /* Fill UDS with the variable. */  thread_loop_c (t,domain)  {    begin_c_loop (c,t)    {      C_UDSI(c,t,0) = C_VOF(c,t);    }    end_c_loop (c,t)  }  thread_loop_f (t,domain)  {    if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)    begin_f_loop (f,t)    {      F_UDSI(f,t,0) = F_VOF(f,t);    }    end_f_loop (f,t)  }  domain=Get_Domain(1);  /* Fill the UDM with magnitude of gradient. */  thread_loop_c (t,domain)  {    begin_c_loop (c,t)    {      C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0));    }    end_c_loop (c,t)  }}ÂÂDEFINE_SOURCE(surface_laser,c,t,dS,eqn){Âreal current_time=CURRENT_TIME;Thread *tp;//parametersreal r=35e-6; // 100 micronreal P=50.0; //PowerÂDomain *subdomain;  int phase_domain_index;real v_d=0.12;Âreal source;real eta=0.5;Â//start posreal xs=1.5e-5+current_time*v_d;real ys=6e-5;// cell paramtersreal x[ND_ND];real T;real Q;Âreal Sb;real x1;real y1;  real z1;  real vf;real I_z;real H_s; //real gamma; // liq fractionÂreal h; // HT coefreal T_a;real n_fact; // normalizing factorreal Cpg;real Cpl;real Cpm;real Cps;real Cp; // avg cell specific heatreal rho; // avg cell densityreal rhog; // density of argon gasÂreal rhos; // solid densityreal rhol; // liquid densityreal rhom; // mixture densityÂreal vf_g; //magnitude of volume fraction gradientÂÂreal s=15e-6;ÂSb=5.67e-8;h=25;T_a=298;C_CENTROID(x,c,t);ÂÂÂx1=x[0];y1=x[1];  z1=x[2]-5e-5+1.25e-6;  tp = THREAD_SUB_THREAD(t,1);  vf=C_VOF(c,tp); // get cell volume fraction  T = C_T(c,tp); // get cell temperature  gamma = C_LIQF(c,tp);// cell liquid fraction  Â  //Get the volume fraction gradient magnitude  vf_g=C_UDMI(c,tp,0);  Â  //calculate mixture specific heat  Cpg=520.64;  Cps=462.656+0.1338*T;  Cpl=790;  Cpm=Cpl*gamma+Cps*(1-gamma);  Cp=Cpm*vf+Cpg*(1-vf);  Â  // calculate mixture density  rhog=1.6228;  rhos=8000.0-800.0/1385.0*(T-273);  rhol=6900.0-900.0/1277.0*(T-1723);  rhom=rhol*gamma+rhos*(1-gamma);  rho = vf*rhom + rhog*(1-vf);  // calculate stabilizing factor  n_fact=(2*rho*Cp)/(rhom*Cpm + rhog*Cpg);  Q=0.23*P/(PI*r*r) * exp(-2*(pow(x1-xs,2)+pow(y1-ys,2))/pow(r,2));  Â  Â  source=0;  dS[eqn]=0;if(vf>0.05 && vf<1){    source= (Q-h*(T-T_a)-Sb*0.5*(pow(T,4)-pow(T_a,4)))*n_fact*vf_g;  dS[eqn]=(-h-Sb*2*pow(C_T(c,tp),3))*n_fact*vf_g;}return source;Â}
-
April 21, 2023 at 3:13 pm
Konstantin
Ansys EmployeeÂ
Â
this is a multiphase model so you need to be careful with memory access. You define UDM in DEFINE_ADJUST on the thread, but then try to access them on the subthread in DEFINE_SOURCE. Are you assigning DEFINE_SOURCE to the mixture or to phases?
Â
Â
-
Viewing 1 reply thread
- The topic ‘Volume Fraction Gradient UDF’ is closed to new replies.
Innovation Space
Trending discussions
Top Contributors
-
6625
-
1906
-
1469
-
1311
-
1022
Top Rated Tags
© 2026 Copyright ANSYS, Inc. All rights reserved.
Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.