kavatar
Subscriber

Dear Dr. Amine,

My problem does not involve resolved droplet or bubble. Its oxygen transfer from ambient to hot metal bath via free surface. 

I have tried the udf multiple time (through multiple ways) incorporating all your suggestions but still not able to get the realistic normal distance of interface from cell centre. I am attaching my latest user defined function and test cases which i tried along with tables showing printed messages in TUI.

Could you please check the udf once (including the headers) and guide me where am I going wrong?. your suggestion or hint would be of great help to me. 

UDF and test cases I tried are attached: 

#include “udf.h”
#include “sg.h”
#include “sg_mphase.h”
#include “sg_vof.h”
 
DEFINE_ADJUST(gradient, domain)
{
#if !RP_HOST
Thread *t;
cell_t c;
 
int phase_domain_index = 0;
Domain *d = DOMAIN_SUB_DOMAIN(domain,phase_domain_index);
 
int vof_flag = -1;  /*VOF flag == 1 -> C_VOF is available somewhere*/
 
/* Check if 4UDMs are available */
if (N_UDM < 4) 
{
     Message0(“Error: At least four user-defined memory location required.\n”);
     return;
}
 
  /* Check if VOF is available somewhere */
  /* Loop over all cell threads */
  thread_loop_c(t, d)
  {
          /* Check if VOF is available */
          if (SV_ALLOCATED_P(t, SV_VOF)) 
          {
                  vof_flag = 1;
                  break; /* Abort loop after the first zone with available VOF macro is found */
          }
}
 
#if RP_NODE
    /* Synchronize all compute nodes. Let all compute nodes know if VOF macros are available somewhere */
    vof_flag = PRF_GIHIGH1(vof_flag);
#endif
 
 /* Abort if VOF macros cannot be accessed in all threads on all nodes */
  if (vof_flag < 1) 
  {
         Message0(“Either not a multiphase simulation of Phase id is wrong.\n”);
         return;
  }
 
  Alloc_Storage_Vars(d, SV_VOF_RG, SV_VOF_G, SV_NULL);
  Scalar_Reconstruction(d, SV_VOF, -1, SV_VOF_RG, NULL);
  Scalar_Derivatives(d, SV_VOF, -1, SV_VOF_G, SV_VOF_RG,Vof_Deriv_Accumulate);
 
  /* Loop over all cell threads */
  thread_loop_c(t, d)
  {
              /* If current thread if fluid and VOF macro available*/
              if (FLUID_THREAD_P(t) && SV_ALLOCATED_P(t, SV_VOF_G))
              {
                      /* Loop over all cells */
                      begin_c_loop(c, t)
                      {
                             /* Condition to check if cell is having mixture */
                            if(C_VOF(c,t)!=0 && C_VOF(c,t)!=1)
                            {
                                    if(NV_MAG(C_VOF_G(c,t))!=0)
                                    {
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 0)=C_VOF_G(c,t)[0]/NV_MAG(C_VOF_G(c,t));
                                            Message(” x_normal: %g,  “,C_UDMI(c, THREAD_SUPER_THREAD(t), 0));
 
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 1)=C_VOF_G(c,t)[1]/NV_MAG(C_VOF_G(c,t));
                                            Message(” y_normal: %g,  “,C_UDMI(c, THREAD_SUPER_THREAD(t), 1));
 
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 2)=C_VOF_G(c,t)[2]/NV_MAG(C_VOF_G(c,t));
                                            Message(” z_normal: %g,  “,C_UDMI(c, THREAD_SUPER_THREAD(t), 2));
 
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 3)=fabs(Get_Surface_Distance(c,t));
                                            Message(” Normal Dist: %g \n”,C_UDMI(c, THREAD_SUPER_THREAD(t), 3));
                                    }
                                    else
                                    {
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 0)=0;
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 1)=0;
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 2)=0;
                                            C_UDMI(c, THREAD_SUPER_THREAD(t), 3)=0;
                                    }
                            }
                           else 
                           {
                                    C_UDMI(c, THREAD_SUPER_THREAD(t), 0)=0;
                                    C_UDMI(c, THREAD_SUPER_THREAD(t), 1)=0;
                                    C_UDMI(c, THREAD_SUPER_THREAD(t), 2)=0;
                                    C_UDMI(c, THREAD_SUPER_THREAD(t), 3)=0;
                           }
                    }
                    end_c_loop(c ,t)
            } 
            else 
            {
                    Message0(“Zone is either not a fluid or C_VOF_G not available.\n”, THREAD_ID(t));
            }
    }
 
  Free_Storage_Vars(d, SV_VOF_G, SV_VOF_RG, SV_NULL);
  /* Free memory, not required */
 
  #endif
}
 
Image of domain and tables showing the test cases which I tried are shown below. In case-1 output is segmentation fault while in case-2 udf runs but normal distance is not realistic.
 
Curiously waiting for your positive response.
 
Thanks and regards
 
Sincerely
Krishna