2.3.10.  DEFINE_EC_RATE

2.3.10.1. Description

You can use DEFINE_EC_RATE to specify a custom electrochemical reaction rate. A custom electrochemical reaction rate function defined using this macro will overwrite the default reaction rate specified in the Create/Edit Materials dialog box.

2.3.10.2. Usage

DEFINE_EC_RATE (name,f,t,r,V,i,didV,Eeq)

Argument Type

Description

symbol name

UDF name.

face_t f

Index that identifies a face within the given thread.

Thread *t

Pointer to face thread on which the surface rate reaction is to be applied.

Reaction *r

Pointer to data structure for the reaction.

double V

Potential difference between electrode and electrolyte .

double *i

Pointer to the electric current density, .

double *didV

Pointer to the derivative of current density with respect to potential difference , .

double *Eeq

Pointer to the Equilibrium potential

Function returns

void

There are eight arguments to DEFINE_EC_RATE: name, f, t, r, V, i, didV, and Eeq. You supply name, the name of the UDF. f, t, r, and V are variables that are passed by the ANSYS Fluent solver to your UDF. After your UDF is compiled and linked, the name that you have chosen for your function will become visible and selectable in the graphical user interface in ANSYS Fluent. Your UDF will need to set three values referenced by the real pointers i didV, and Eeq.

2.3.10.3. Example - Electrochemical Reaction Rate Using UDF

The following compiled UDF, named user_ec_rate, implements the solver default Butler-Volmer equation through the UDF approach. You can customize a term (for example, the exchange current density i0 or the equilibrium potential Eeq) or the whole rate formula.

/*******************************************************************
 Custom electrochemical reaction rate UDF
 ********************************************************************/
 #include "udf.h"
 DEFINE_EC_RATE(user_ec_rate, f, fthread, r, V, current, didV, Eeq)
 {
   double alpha_a = r->alpha_a, alpha_c = r->alpha_c;
   double io = r->io
   double T = F_T(f,fthread);
   double arg1, arg2;
   cxboolean tafelmethod = r->tafelmethod;
   int i;
   double eta;
 
   if (tafelmethod) 
   {
     alpha_a = 2.303 * UNIVERSAL_GAS_CONSTANT * 298.15 /(alpha_a * FARADAY_CONSTANT);
     alpha_c = 2.303 * UNIVERSAL_GAS_CONSTANT * 298.15 /(alpha_c * FARADAY_CONSTANT);
   }
   *Eeq = r->Eeq; 
   eta = V - *Eeq;
   for(i = 0; i<r->n_reactants; i++)
     if( ABS( r->exp_reactant[i] ) > SMALL_S )
     {
       int ni = r->reactant[i];
       io *= pow((F_YI(f,fthread,ni)/MAX(r->yi_ref[ni],SMALL) + 1.0e-20), r->exp_reactant[i]);
     }
   for(i = 0; i<r->n_products; i++)
     if( ABS( r->exp_product[i] ) > SMALL_S )
     {
       int ni = r->product[i];
       io *= pow((F_YI(f,fthread,ni)/MAX(r->yi_ref[ni],SMALL) + 1.0e-20), r->exp_product[i]);
     }
   arg1 = FARADAY_CONSTANT / (UNIVERSAL_GAS_CONSTANT*T);
   arg2 = arg1*eta;
   *current = io*( exp( arg2*alpha_a ) - exp( -arg2*alpha_c ) );
   *didV = io*( arg1*alpha_a*exp( arg2*alpha_a ) + arg1*alpha_c*exp( -arg2*alpha_c ) );

   /* If multiple electrochemical reactions are used, you can define rate for each reaction
      using the following if-statement */
   /*
   if (STREQ(r->name, "reaction-1"))
   {
     ...
   }
   else if (STREQ(r->name, "reaction-2"))
   {
     ...
   }
 */
 } 

2.3.10.4. Hooking an Electrochemical Reaction Rate UDF to ANSYS Fluent

After the UDF that you have defined using DEFINE_EC_RATE is compiled (Compiling UDFs), the name of the argument that you supplied as the first DEFINE macro argument (for example, user_ec_rate) will become visible and selectable in the User-Defined Function Hooks dialog box in ANSYS Fluent. See Hooking DEFINE_EC_RATE UDFs for details.


Release 18.2 - © ANSYS, Inc. All rights reserved.