# Preventing negative scalar (UDS) values??

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

 February 14, 2002, 10:05 Preventing negative scalar (UDS) values?? #1 Matthew Brannock Guest   Posts: n/a 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. Cheers, Matthew.

 February 14, 2002, 18:53 Re: Preventing negative scalar (UDS) values?? #2 Greg Perkins Guest   Posts: n/a 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 this....it 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) { dS[eqn] = SRCE_SPECIES_SP(SRCE,THI); return SRCE_SPECIES_SC(SRCE,THI); } 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 Greg

 February 15, 2002, 04:15 Thanks #3 Matthew Brannock Guest   Posts: n/a 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.

 February 15, 2002, 08:10 Re: Thanks #4 Greg Perkins Guest   Posts: n/a 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. Greg

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post N. A. OpenFOAM Programming & Development 2 November 13, 2014 09:43 jpcfd FLUENT 0 June 8, 2010 04:50 J CFX 11 November 3, 2008 17:46 Miha Rothl CFX 1 August 3, 2002 13:50 Greg Perkins FLUENT 0 October 11, 2000 03:43

All times are GMT -4. The time now is 18:14.