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/)
-   -   Issues with mass source macros in a multiphase system (https://www.cfd-online.com/Forums/fluent-udf/151328-issues-mass-source-macros-multiphase-system.html)

cp703 April 8, 2015 16:43

Issues with mass source macros in a multiphase system
 
1 Attachment(s)
Hi everyone,

I'm trying to write a UDF that describes phase change (just working on getting evaporation right now). I've been trying out my UDF on a "1D" Stefan problem (see attached PDF). My biggest problem right now is with an if statement in the mass source macro (DEFINE_SOURCE) that is hooked to my primary phase, the vapor. Here's the macro in question:

Code:

DEFINE_SOURCE(gas, cell, thread, dS, eqn)
{
   
    real source = 0.0; /* Initialize the variable "source"*/

real a_c = 0.04;
    real a_c_coeff=(2.0*a_c)/(2.0-a_c);
    real M = 0.018015; /* molar mass [kg/mol] */
    real R = 8.314; /* universal gas constant [J/molK] */
    real Tsat = 373.1; /* saturation temperature [K] */
    real Psat = 101325.0; /* saturation pressure [Pa] */
    real DeltaH = 2256560.0; /*vaporization enthalpy [J/kg] */
    real rho_L = 958.4; /* liquid density [kg/m3] */
    real rho_V = 0.597; /* vapor density [kg/m3] */

    /* Initialize and define thread pointer/pointer array  */
    Thread *tm = THREAD_SUPER_THREAD(thread); /* *tm is a pointer to the mixture-level thread */
    Thread **pt = THREAD_SUB_THREADS(tm); /* **pt is a pointer ARRAY, whose elements contain pointers to the phase-level threads */
   
 

    /* If the temperature of the cell (located in a primary phase cell thread) is greater than Tsat */
    /* AND the volume fraction of the primary phase is less than one (i.e. there is some liquid in the cell), then... */
   
        if (C_T(cell, thread) > 373.1 && C_VOF(cell,thread) < 1.0)
        {

        source = C_UDMI(cell,tm,0)*a_c_coeff*sqrt(M/(2.0*M_PI*R))*((C_P(cell,thread)/sqrt(C_T(cell,thread)))-(Pvaporavg/sqrt(Tvaporavg)));
     
        }
        else
        {
            source = 0.0;
        }
   

    /* Set the user-defined memory location, labeled 1, as the mass source term for the vapor phase*/
    C_UDMI(cell, tm, 1) = source;
 
    /* Set the user-defined memory location, labeled 2, as the energy source term, which is just the mass source term multiplied */
    /* by the latent heat of vaporization. */
    C_UDMI(cell, tm, 2) = -1.*source*DeltaH;

    dS[eqn] = 0;
 
    return source;
}

FYI: My operating pressure is set to be 0 Pa.

My specific issue is that the solver doesn't always enter into the if statement when it should. When the interface temperature gets above 373.1K, I would expect a mass source to appear along the entire length interface. However, I don't see that at all. Instead, it's just one localized circular region where a mass source appears.

Does anyone have any experience with if statements inside DEFINE_SOURCE macros for a mass source in a multiphase simulation? Have I formatted it correctly? I've been trying to figure out if it's something to do with the data structures in multiphase situations, i.e. phase-level threads versus mixture-level threads, or a data type problem, or a problem with the if statement syntax. I haven't been able to find anything helpful in the UDF manual or elsewhere online. I've submitted my question to ANSYS but am waiting to hear back.

Thank you!!

`e` April 8, 2015 19:00

You're multiplying C_UDMI(cell,tm,0) by other terms to evaluate 'source'. If this UDM value is zero, then your 'source' would also be zero: could this case be true, and what does your UDM-0 represent?

I see no reason for the solver not to enter the if statement when it should; try some debugging to be sure this logic isn't the cause of your problem. Add in a Message(); line where 'source' is evaluated in the if statement to print the cell details to screen and compare the number of these messages with the number of nonzero source terms in your simulation.

cp703 April 9, 2015 09:35

Quote:

Originally Posted by `e` (Post 540659)
You're multiplying C_UDMI(cell,tm,0) by other terms to evaluate 'source'. If this UDM value is zero, then your 'source' would also be zero: could this case be true, and what does your UDM-0 represent?

I see no reason for the solver not to enter the if statement when it should; try some debugging to be sure this logic isn't the cause of your problem. Add in a Message(); line where 'source' is evaluated in the if statement to print the cell details to screen and compare the number of these messages with the number of nonzero source terms in your simulation.

Hi 'e' - thanks for your reply. C_UDMI(cell,tm,0) is calculated in a DEFINE_ADJUST macro. It's the magnitude of the gradient of the volume fraction of the vapor. So it is zero far away from the interface. This value is output as I expect it so I'm only looking near the interface where it is nonzero (I verified this in CFD-post).

Thanks for your idea re: debugging the if statement. Could you clarify how to add in the Message(); line? I've never used that before, and I haven't seen it in the UDF manual. Thank you again!

`e` April 9, 2015 19:20

The Message() function is similar to printf() where you can print text to the screen. Note that in parallel every process will print this same message (for example on DEFINE_ADJUST outside a cell loop), so you could use Message0() for only node 0 to print the message to screen (and has the same functions as Message() in serial mode).

Start with adding these lines of code (I've assumed you're running in 3-D, if you're solving in 2-D remove the z-direction components) to see at which cells your DEFINE_SOURCE macro is being called:

Code:

real cellcentroid[ND_ND];

...

if (C_T(cell, thread) > 373.1 && C_VOF(cell,thread) < 1.0)
{
    C_CENTROID(cellcentroid,cell,thread);
    Message("This cell has T > 373.1 and VOF < 1.0 and is located at [x,y,z] = [%e,%e,%e]\n",cellcentroid[0],cellcentroid[1],cellcentroid[2]);
    source = C_UDMI(cell,tm,0)*a_c_coeff*sqrt(M/(2.0*M_PI*R))*((C_P(cell,thread)/sqrt(C_T(cell,thread)))-(Pvaporavg/sqrt(Tvaporavg)));
    Message("This cell has a source term = %e\n",source);
}
else
{
    source = 0.0;
}

Are the cells printed to screen what you expected (compared to the temperature and VOF requirements)? Are the source terms the magnitude you expected?

mostafa_zeynalabedini April 14, 2015 03:34

store_vof_norm
 
hi every body
I'm modeling a three-phase problem with Eulerian (+Multi fluid VOF model) model. I also use Population balance model. I want to use a UDF for nucleation rate for third phase (second secondary phase). bellow are some part of this UDF:

#include "udf.h"
#include "sg_pb.h"
#include "sg_mphase.h"
DEFINE_PB_NUCLEATION_RATE(nuc, cell, thread)
{
real Epsilon_Entrainment;
real Vof_CutOff = 0.05;
int phase1_domain_index = 0;
int phase2_domain_index = 1;
Thread *mixture_thread = THREAD_SUPER_THREAD(thread);
Thread *ContinuousPhaseThread = THREAD_SUB_THREAD(mixture_thread,phase1_domain_ind ex);
Thread *LargeBubbles = THREAD_SUB_THREAD(mixture_thread,phase2_domain_ind ex);
Vof_CutOff= C_VOF(cell, LargeBubbles);
if (C_U(cell,LargeBubbles) > 8)
{
Epsilon_Entrainment = 100000;
}
return (Epsilon_Entrainment);
}

But when I interpret this UDF, I encounter this error:
Error: D:\\xxx: line 20: label "store_vof_norm" not found (pc=74).

this UDF has 19 lines. this error refers to line 20.I found that this error is from sg_mphase.h file. In this file there is "store_vof_norm", But I don't know what is the problem????

please help me. it is very important to me.
thanks of all

SJSW October 14, 2015 07:18

should C_UDMI(cell,tm,0) be re-calculated in DEFINE_SOURCE if it is not global variable?
Or should it be in a begin_c_loop?

`e` October 17, 2015 00:59

User-defined memory is stored within Fluent and C_UDMI is a macro which accesses this memory (it's not a variable which would require initialising or being globally defined).


All times are GMT -4. The time now is 07:28.