CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Preventing negative scalar (UDS) values?? (

Matthew Brannock February 14, 2002 10:05

Preventing negative scalar (UDS) values??
I'm modelling the transport of chemical species as scalar quantities. These scalar quantities are concentrations (not mass fractions, which is usual, but as kg scalar/m3 - note: I've managed get around the difficulty of density being included in the scalar term). These species react, hence I use the DEFINE_SOURCE macro to define the source/sink term. The question is, how do I prevent this quantity becoming a negative value? I've easily been able to prevent one it has reached a negative value (because I've used the previous step's value for it) but how is it possible to prevent it from getting there? Is there an algorithm that anybody has successfully implemented to do this? I think I need to predict the concentration in advance. How is this simply done?

Any help would be much appreciated.



Greg Perkins February 14, 2002 18:53

Re: Preventing negative scalar (UDS) values??
This was a major headache when I did something similar. I implemented uds's for mass fractions, but essentially you have the same problem.

First read the book by Patankar which explains how to linearise source terms so that you don't get this problem. Even then, I still had a lot of problems with took me several weeks to get nice and stable.

Now, I'm being super nice today, so here's the code:

#ifdef SRM_SOURCE_LINEARIZATION #define m_big 1.0 #define m_sml 0.0 /* #define mlp(m) ((m+1.0)/2.0) #define mln(m) (m/2.0) */ #define mlp(m) 1.0 #define mln(m) 0.0 #define BIG_REAL_NUMBERx 1.0e20 #define SRCE_SPECIES_SC(s,m) (s == 0.0 ? 0.0 : (s > 0.0 ? (m >= m_big ? BIG_REAL_NUMBERx : s*mlp(m)/(mlp(m)-m)) : (m <= m_sml ? 0.0 : s*mln(m)/(mln(m)-m) ))) #define SRCE_SPECIES_SP(s,m) (s == 0.0 ? 0.0 : (s > 0.0 ? (m >= m_big ? -BIG_REAL_NUMBERx : -s/(mlp(m)-m)) : (m <= m_sml ? -BIG_REAL_NUMBERx : -s/(mln(m)-m) ))) #else #define SRCE_SPECIES_SC(s,m) s #define SRCE_SPECIES_SP(s,m) 0.0 #endif

So in your source term say you have a source given by SRCE and the scalar is THI,

you'd do

DEFINE_SOURCE(my_srce,cell,thread,dS,eqn) {



for your app you'll need to modify m_big and m_sml to define the limits of your scalar. In my case mass fraction is limited to 0 to 1.

Hope it helps


Matthew Brannock February 15, 2002 04:15

Woah, thanks for that. Wasn't expecting code. Actually, I think I did read a previous post by you mentioning Patankars method for linearising the source term. So it is back to Patankar for me. Thanks again.

Greg Perkins February 15, 2002 08:10

Re: Thanks
No worries, I know that's a particularly painful thing to get exactly right....even though the code really isn't that long. But working out how to "force" the solution in fluent using this sort of method did take a while, so I thought I'd save you the effort.

Still have a look at the book, because its useful to understand what's going on. And you might be able to improve the way I've done it.


All times are GMT -4. The time now is 15:11.