Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

Volume Fraction Gradient UDF

TAGGED: 

    • Hello,
       
      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 3
      DEFINE_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;
      //parameters
      real r=35e-6; // 100 micron
      real P=50.0; //Power
       
      Domain *subdomain;
       
          int phase_domain_index;
      real v_d=0.12; 
      real source;
      real eta=0.5;
       
      //start pos
      real xs=1.5e-5+current_time*v_d;
      real ys=6e-5;
      // cell paramters
      real 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 coef
      real T_a;
      real n_fact; // normalizing factor
      real Cpg;
      real Cpl;
      real Cpm;
      real Cps;
      real Cp;  // avg cell specific heat
      real rho; // avg cell density
      real rhog; // density of argon gas
       
      real rhos; // solid density
      real rhol; // liquid density
      real 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;
       
      }
    • 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.
[bingo_chatbox]