CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for mass transfer through a boundary (mt-sofc case) (https://www.cfd-online.com/Forums/fluent-udf/69877-udf-mass-transfer-through-boundary-mt-sofc-case.html)

vlawlor November 7, 2009 16:42

UDF for mass transfer through a boundary (mt-sofc case)
 
Dear Community,

Outline of the Problem:

In a simple model that just has a source term (oxygen sink kg/(m^3).(s) applied to a "cathode" volume wrapped around a cylinder in cross flow (like a microtubular solid oxide fuel cell)

I am trying to mimick the consumption of oxygen for a single cell in cross flow and see the effects on mass transfer in the wake of the cell. I can get values for species concentration etc. in fluent but I would like to get a reading for the rate at which oxygen passes through the cathode wall. Something like kg/(m^2) .(s)

I would like to compare mass comsumption rates in simple models without the fuel cell module, with it and also hand caluclations.

Possible solution:

I know very little about C programming and less about how all this works in fluent but I have found the following code on the net that says it should do what I would like to do. the problem is that when I try to compile it in fluent I ger the following error.



File path: line 12: THREAD_STORE: undeclared variable

/************************************************** ********************/
/* UDF that implements a simplified advective term in the */
/* scalar transport equation */
/************************************************** ********************/

#include "udf.h"

DEFINE_UDS_FLUX(my_uds_flux, f, t, i)
{
Thread *t0, *t1 = NULL;
cell_t c0, c1 = -1;

real NV_VEC(psi_vec), NV_VEC(A);

/* neighboring cells of face f, and their (corresponding) threads */

t0 = F_C0_THREAD(f,t);
c0 = F_C0(f,t);

if (NULL != F_C1_THREAD(f,t))
/* Alternative: if (! BOUNDARY_FACE_THREAD_P(t)) */
{
t1 = F_C1_THREAD(f,t);
c1 = F_C1(f,t);
}
else
{
t1 = NULL;
c1 = -1;
}

/* If Face lies at domain boundary, use face values; */
/* If Face lies IN the domain, use average of adjacent cells. */

if (NULL == t1)
/* Alternative: if (BOUNDARY_FACE_THREAD_P(t)) */
{
NV_D(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t));
NV_S(psi_vec, *=, F_R(f,t));
}
else
{
NV_D(psi_vec, =, C_U(c0,t0), C_V(c0,t0), C_W(c0,t0));
NV_D(psi_vec, +=, C_U(c1,t1), C_V(c1,t1), C_W(c1,t1));
NV_S(psi_vec, /=, 2.); /* averaging. */
NV_S(psi_vec, *=, (((C_R(c0,t0) + C_R(c1,t1)) / 2.)));
}

/* Now psi_vec contains our "psi" from above. */
/* Next, get the face normal vector: */

F_AREA(A, f, t);

/* Finally, return the dot product of both. */
/* Fluent will multiply the returned value */
/* by phi_f (the scalar's value at the face) */
/* to get the "complete" advective term... */

return NV_DOT(psi_vec, A);
}




Many thanks for any help in advance

dmoroian November 9, 2009 01:24

The code seems to be correct
 
Are you sure this is what you're compiling?
First of all, there is nothing on line 12, and second, I compiled the code you posted on my fluent 6.3, and no erros appeared.

vlawlor November 9, 2009 04:48

Many thanks for checking this,

So I will list the steps I am taking to compile it.

1. I copy the code as it is into the text editor in windows and call it udfmasstransfer.c

2. I copy the file to the working directory.

3. define--> user defined-->functions-->interpreted

4. I then browse to the file and leave the CPP command name to CPP and stack size to 10000

5. Then i hit interpret

And the error line 17 THREAD_STORE: undeclared variable appears (it has changed from 12 to 17 now.

I know very little about this but can the error be with the CPP command?

MAny thanks once agian

dmoroian November 9, 2009 05:09

Instead of interpreted, try compiled.

sircorp November 9, 2009 07:31

UDF for mass transfer through a boundary (mt-sofc case)
 
One tiny thing

t1 is assigned to NULL and later compared to NULL. Best in such sitation is try to check the t1 condition. If it is within place then it should be true else not.

Try one of the two option

eitther
(1) (t1==NULL) change this.

or Change the code this way

if ( F_C1_THREAD(f,t) == NULL)
/* Alternative: if (! BOUNDARY_FACE_THREAD_P(t)) */
{
t1 = NULL;
c1 = -1;
}
else
{
t1 = F_C1_THREAD(f,t);
c1 = F_C1(f,t);
}


All times are GMT -4. The time now is 03:04.