Fluids

Fluids

How to sum the molar concentration of species in every cell ?

    • Chananun
      Subscriber

      Hi Everyone,

      I'm new to Fluent, and I want to sum the molar concentration of species in every cell. I used loop over cells in cell thread to sum the molar concentration of carbon (C_C), and after that I will use this sum value to calculate the rate of reaction. Before I used the loop, I can complie the UDF kinetic code in fluent. After I added the loop, I can't complie my UDF code. So, I'm sure that the error occurs from the loop that I just add in the UDF. Can you help me to check my UDF code? or Does someone know how to do a loop in every cells? Is it correct to used loop over cells in cell thread to sum molar concentration in every cells?

      Here is my udf code.


       #include "udf.h"

      #define R_U 8.314    /*J/(mol*K)*/

      DEFINE_VR_RATE(reactionsv,c,t,r,mw,yi,rr,rr_t)

      {

        real k,K_H,K_P,r_max,Tg,a,k_a,C_max;

        real C_CH4,C_H2,C_C;        /* Define the molar concentration of each component of the gas mixture*/

        real Y_CH4,Y_H2,Y_C;     /* Define the mass fraction of each component of the gas mixture*/

        real P_CH4,P_H2;          /* Define the partial pressure of each component of the gas mixture*/

        real sum =0.0;   /* Define the intitial sum value */

        cell_t c ;

        Thread *t;

      Y_CH4 = C_YI(c,t,0);          /*mass fraction of species in gas phase*/

        Y_H2 = C_YI(c,t,1);

        Y_C = C_YI(c,t,2);

            if(Data_Valid_P())

          { Tg = C_T(c,t);

            C_CH4 = (C_YI(c,t,0)/16)*C_R(c,t);   /*molar concentration of each component of the gas mixture*/

            C_H2 = (C_YI(c,t,1)/2)*C_R(c,t);   

      C_C = (C_YI(c,t,2)/12)*C_R(c,t);

      C_UDMI(c,t,0)=C_C; 

            P_CH4 = C_CH4*8314*Tg;              /*Partial pressure of each component of the gas mixture Pa*/

            P_H2 = C_H2*8314*Tg;  ;

            /*CH4--C+2H2*/

        begin_c_loop(c, c_thread)   /* loops over cells in a cell thread */

        {   

                sum += C_UDMI(c,t,0);

      }             

         end_c_loop(c, c_thread)

            k = exp(20.492-(104200/(R_U*Tg)));      /*Kinetics Constants */

            K_H = exp((163200/(R_U*Tg))-22.426);     /* Equilibrium Constants*/

            K_P = (5.088e5)*exp(-91200/(R_U*Tg));

        k_a = exp((135600/(R_U*Tg))-32.077);

        r_max=(k*((P_CH4/100000)-((pow((P_H2/100000),2))/K_P))/(1+K_H*pow((P_H2/100000),0.5))/(1+K_H*pow((P_H2/100000),0.5)));

          C_max = 164.5*0.15;           /*kmol/m3*/

        a = 1-((sum/C_max)*(sum/C_max));

            *rr =r_max*a*0.0457;  /*kmol/m3-s*/

            *rr_t = *rr;

          }

      }

      Any help would be really appreciated.

      Thanks for your help

      Chananun

    • wcao
      Ansys Employee
      Hello In the loop code, the thread variable c_thread has never been claimed. This might cause the compilation error.
      Besides, I would suggest you to use a global variable for the sum of UDMI, instead of doing the loop in the DEFINE_VR_RATE function. Thanks.
Viewing 1 reply thread
  • You must be logged in to reply to this topic.