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.

Unnatural values calculated by UDF

TAGGED: ,

    • James
      Subscriber

      Hello!

      I am trying to model fixed bed adsorption using Linear driving force model given by dq/dt = kf(q* - q) where kf is a constant q* = (KL*qm*C)/(1 + KL*C), where KL and qm are constants and C is the concentration. I defined C as a user defined scalar instead of using mass fraction for convenience with numbers (Does that make any difference?). The dq/dt equation is then applied in the source term as -(1-porosity)*rho*dq/dt. 

      I put messages in my UDF to show me the values of the UDS and other variables calculated and they are absolutely ridiculous. An example is:

      The value of q_i is now -38065484171715682240850117399674880.000000

      q_i is the value of q at the previous time step.

      Anyway, can someone look at my code and see where I am going wrong, please?

      #include
      #include
       
      DEFINE_INIT(Initial,domain)
      {
          Thread *t;
          cell_t c;
          thread_loop_c(t, domain)
          {
              begin_c_loop(c, t)
              {
                  // Initially the contaminant concentration in solid phase is 0
                  C_UDMI(c, t, 0) = 0.0; // q_i at the ith time step
                  C_UDMI(c, t, 1) = 0.0; // q_i+1 at the i+1th time step
              }
              end_c_loop(c, t)
          }
      }


      DEFINE_ADJUST(define_q_ads, domain)  /*Adjust is the first step in the solution loop*/
      {
          Thread *t;
          cell_t c;
          real dt;
          real rp = 1.1/1000;
          real De = 25;
          real qm = 154;
          real KL = 0.63;
          real kf = 15*De/(rp*rp);
          real qe;
         
          thread_loop_c(t, domain)
          {
              begin_c_loop(c, t)
              {
                  dt = RP_Get_Real("physical-time-step");
                  qe = (KL*qm*C_UDSI(c,t,0))/(1+KL*C_UDSI(c,t,0)); // C_UDSI contains the concentration in the liquid phase     
                  C_UDMI(c, t, 1) = C_UDMI(c, t, 0) + kf*dt*((qe - C_UDMI(c, t, 0)));
                  // q_i+1 = q_i + kf*dt*(qe - q_i)          
              }
              end_c_loop(c, t)
          }
      }

      DEFINE_SOURCE(m_src, c, t, dS, eqn) /*Source term calculation happens after the adjust function*/  
      {
          real source;
          real eta = 0.77;
          real rho = 743;

          int ThreadID = THREAD_ID(t);
          source = -(1-eta)*rho*C_UDMI(c,t,1);

          Message("====================================================================\n");
          Message("The value of source in the cell thread %i is %f\n", ThreadID, source);
          Message("====================================================================\n");


          dS[eqn] = 0.0;
          return source;
      }

      DEFINE_EXECUTE_AT_END(execute_at_end)  /*Executes at the end of the iteration. Updates q_i for the next time step*/
      {
          Domain* domain = Get_Domain(1);
          Thread* t;
          cell_t c;
          thread_loop_c(t, domain)
          {
              begin_c_loop(c, t)
              {
                   C_UDMI(c, t, 0)=C_UDMI(c, t, 1);
                   Message("The value of q_i is now %f\n",C_UDMI(c,t,0));
              }
              end_c_loop(c, t)
          }
      }  
    • Atharva Nagarkar
      Ansys Employee

      Hello!

      As part of the Ansys policy, employees cannot debug UDFs on the forum. However, I would suggest you to have a look at the following things.

      For the macro C_UDSI, if you try to use the macro before you have specified the user-defined scalars in your Ansys Fluent model then an error will result.

      3.2. Data Access Macros (ansys.com) -> Check section 3.2.11.3

      Please also have a look at the definition of the macro C_UDMI and how the arguments are defined at the link below.

      3.2. Data Access Macros (ansys.com) -> Check section 3.2.12.4

      Additionally, this is the link from the Ansys manual for defining the source term. Make sure that you have correctly defined the dS[] array with respect to the dependent variable.

      2.3. Model-Specific DEFINE Macros (ansys.com) -> Check section 2.3.43

      Lastly, these are the time dependent macros which you can use to access variables for previous timesteps.

      3.5. Time-Dependent Macros (ansys.com)

      If you are not able to access the link, please refer to this forum discussion: Using Help with links (ansys.com)

      Thanks!

      • James
        Subscriber

        I will take care next time, and thank you!

Viewing 1 reply thread
  • The topic ‘Unnatural values calculated by UDF’ is closed to new replies.
[bingo_chatbox]