Fluids

Fluids

Passing variables between DEFINE macros

    • ehsan.sadeghi
      Subscriber

      Hello

      I have the following UDF structure for calculating gradients of UDS0 (potential). I start with calculation the UDS0 gradients in ADJUST macro, then I want to pass the calculated Ex, Ey and Ez to a SOURCE macro. My problem is that I am not sure if in my code structure Ex, Ey and Ez pass to Source function or not? how can I do that?

      ```

      #include "udf.h"
      DEFINE_EXECUTE_ON_LOADING(uds_names, uds_libnames)
      {
          void Set_User_Scalar_Name(int i,char *name);
          Set_User_Scalar_Name(0,"potential");
          Set_User_Scalar_Name(1,"E_x");
          Set_User_Scalar_Name(2,"E_y");
          Set_User_Scalar_Name(3,"E_z");
          Set_User_Scalar_Name(4,"E");
          Set_User_Scalar_Name(5,"n");
      }

      enum
      {
          potential,
          E_x,
          E_y,
          E_z,
          E,
          n,
          N_REQUIRED_UDS
      };

      DEFINE_ADJUST(grad_calc, domain)

      {

      /* calculate E_x, E_y, E_z; */

      }

      DEFINE_SOURCE(potential_source, cell, thread, dS, eqn)
      {
      real source;
      source = 2.0*E_x;
      return source;
      }

      ```

    • Rob
      Ansys Employee

      I tend to calculate the values for the source terms directly, so E_x etc would be in the DEFINE_SOURCE part of the code. 

    • ehsan.sadeghi
      Subscriber

      so you mean I implment another DEFINE_ADJUST inside the DEFINE_SOURCE? or only the thread loop and face loop?

      In DEFINE_ADJUST I calculate E_x, etc... then I need that parameter in source.

    • Rob
      Ansys Employee

      Do you need the DEFINE_ADJUST bit? 

      • ehsan.sadeghi
        Subscriber

        I don´t understand what you mean?

    • Rob
      Ansys Employee

      What does the DEFINE_ADJUST do that can't be done in the DEFINE_SOURCE routine?

      • ehsan.sadeghi
        Subscriber

        That´s what I was asking. I didn´t know that it already loops over domain and executes per iteration. Thanks for being so nice!!

    • ehsan.sadeghi
      Subscriber

       

      I did as you said, but for some reason I get error:

      999999: mpt_accept: error: accept failed: No such file or directory

       

      ===================================================================================

      = BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES

      = RANK 0 PID 1228 RUNNING AT PC-ANSYS-157

      = EXIT STATUS: -1 (ffffffff)

       

      My code is:

      #include”udf.h”
      #define e 1.6e-19
      #define epsilon0 8.854e-12
      #define mu_p 1.35e-4
      #define Dp 3.5e-6
      DEFINE_EXECUTE_ON_LOADING(on_loading, libname)
      {
          Set_User_Memory_Name(0,”Potential Source”);
          Set_User_Memory_Name(1,”Potential”);
          Set_User_Memory_Name(2,”Ex”);
          Set_User_Memory_Name(3,”Ey”);
          Set_User_Memory_Name(4,”Ez”);
          Set_User_Memory_Name(5,”Electric Field”);
          Set_User_Memory_Name(7,”x-Momentum Source”);
          Set_User_Memory_Name(8,”y-Momentum Source”);
          Set_User_Memory_Name(9,”z-Momentum Source”);
          Set_User_Scalar_Name(0,”Potential”);
          Set_User_Scalar_Name(1,”ion concentration”);
      }

      DEFINE_ADJUST(E_xyz,d)
      {
      Thread *t;
      cell_t c;
      thread_loop_c(t,d)
      {
      begin_c_loop(c,t)
      {
      C_UDMI(c,t,1) = C_UDSI(c,t,0) ;
      C_UDMI(c,t,2) = -C_UDSI_G(c,t,0)[0] ;
      C_UDMI(c,t,3) = -C_UDSI_G(c,t,0)[1] ;
      C_UDMI(c,t,4) = -C_UDSI_G(c,t,0)[2] ;
      C_UDMI(c,t,5) = NV_MAG(C_UDSI_G(c,t,0)) ;
      C_UDMI(c,t,6) = C_UDSI(c,t,1) ;
      }
      end_c_loop(c,t)
      }
      }

      /* Sets the gradient of phi (UDS-0) to equal E_x (UDS-1) and E_y (UDS-2), and sets face values */
      DEFINE_SOURCE(phi_source,c,t,dS,eqn)
      {    
      real phi_source;
      dS[eqn] = 0.0;
      phi_source = -(e/epsilon0)*C_UDSI(c,t,1);
      C_UDMI(c,t,0) = phi_source;
      return phi_source;
      }

      DEFINE_SOURCE(momentum_x, c, t, dS, eqn)
      {
      real source;
      dS[eqn] = 0.0;
      source = e*C_UDMI(c,t,2)*C_UDSI(c,t,1);
      C_UDMI(c,t,7) = source;
      return source;
      }

      DEFINE_SOURCE(momentum_y, c, t, dS, eqn)
      {
      real source;
      dS[eqn] = 0.0;
      source = e*C_UDMI(c,t,3)*C_UDSI(c,t,1);
      C_UDMI(c,t,8) = source;
      return source;
      }

      DEFINE_SOURCE(momentum_z, c, t, dS, eqn)
      {
      real source;
      dS[eqn] = 0.0;
      source = e*C_UDMI(c,t,4)*C_UDSI(c,t,1);
      C_UDMI(c,t,9) = source;
      return source;
      }


      DEFINE_UDS_FLUX(flux_ions,f,t,i)
      {
          cell_t c;
          cell_t c0, c1= -1;
          Thread *t0, *t1 = NULL;
          real NV_VEC(A), NV_VEC(E_vec), E_flux = 0.;
          real rho = C_R(c0,t0)+C_R(c1,t1);
          c0 = F_C0(f,t);
          t0 = F_C0_THREAD(f,t);
          F_AREA(A,f,t);
          if (BOUNDARY_FACE_THREAD_P(t))
          {
              E_flux = 0.0;
          }
          else
          {
              begin_c_loop(c,t)
              {
                  F_UDMI(c,t,2) = C_UDMI(c,t,2) ;
                  F_UDMI(c,t,3) = C_UDMI(c,t,2) ;
                  F_UDMI(c,t,4) = C_UDMI(c,t,2) ;
              }
              end_c_loop(c,t)
          
          c1 = F_C1(f,t);
          t1 = F_C1_THREAD(f,t);
          NV_DS(E_vec, =, F_UDMI(c0, t0, 2), F_UDMI(c0, t0, 3), F_UDMI(c0, t0, 4), *, Dp);
          NV_DS(E_vec, +=, F_UDMI(c1, t1, 2), F_UDMI(c1, t1, 3), F_UDMI(c1, t1, 4), *, Dp);
          E_flux = NV_DOT(E_vec,A)/2.0;
          }

          if (i==1)
          {
              return (F_FLUX(f,t)/rho+E_flux);
          }
          else
              return (0.);
      }

       

Viewing 5 reply threads
  • You must be logged in to reply to this topic.