CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Issues with mass source macros in a multiphase system

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 8, 2015, 16:43
Default Issues with mass source macros in a multiphase system
  #1
New Member
 
Christina P.
Join Date: Oct 2012
Posts: 22
Rep Power: 13
cp703 is on a distinguished road
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!!
Attached Files
File Type: pdf Stefan.pdf (44.0 KB, 72 views)
cp703 is offline   Reply With Quote

Old   April 8, 2015, 19:00
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   April 9, 2015, 09:35
Default
  #3
New Member
 
Christina P.
Join Date: Oct 2012
Posts: 22
Rep Power: 13
cp703 is on a distinguished road
Quote:
Originally Posted by `e` View Post
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!
cp703 is offline   Reply With Quote

Old   April 9, 2015, 19:20
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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?
`e` is offline   Reply With Quote

Old   April 14, 2015, 03:34
Default store_vof_norm
  #5
New Member
 
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 13
mostafa_zeynalabedini is on a distinguished road
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
mostafa_zeynalabedini is offline   Reply With Quote

Old   October 14, 2015, 07:18
Default
  #6
Senior Member
 
Join Date: Jun 2014
Location: Taiwan
Posts: 100
Rep Power: 12
SJSW is on a distinguished road
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?
SJSW is offline   Reply With Quote

Old   October 17, 2015, 00:59
Default
  #7
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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).
`e` is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
wmake compiling new solver mksca OpenFOAM Programming & Development 14 June 22, 2018 06:29
SparceImage v1.7.x Issue on MAC OS X rcarmi OpenFOAM Installation 4 August 14, 2014 06:42
Trouble compiling utilities using source-built OpenFOAM Artur OpenFOAM Programming & Development 14 October 29, 2013 10:59
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


All times are GMT -4. The time now is 00:32.