
[Sponsors] 
February 14, 2002, 10:05 
Preventing negative scalar (UDS) values??

#1 
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 
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 
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 
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 

May 3, 2017, 03:48 

#5 
New Member
rarnaunot Rosi
Join Date: Feb 2017
Location: Spain
Posts: 26
Rep Power: 2 
Hi everyone,
I know that this post is really old...But we have been working on this issue. We set the code in Fluent v16.2 and we got confussing results. In Fluent Help https://www.sharcnet.ca/Software/Flu...udf/node46.htm Eq 2.3.7. it is said that A gets the value of the tangent equation explained in Patankar page 49 and B is the derivative term. The above described is the same that is described by the Greg Perkins code as Sc and Sp. Now I am guessing... Do I trully need the code described by Greg for the terms Sc and Sp or is it directly applied in new versions of Fluent as Help says? (The same code with modifications is needed to define the bounds of my scalar.) Thanks 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Solving for an additional species CO in coalChemistryFoam  N. A.  OpenFOAM Programming & Development  2  November 13, 2014 09:43 
User defined scalar transport problem (UDS)  jpcfd  FLUENT  0  June 8, 2010 04:50 
Contour plot with negative velocity  J  CFX  11  November 3, 2008 17:46 
Getting scalar values at physical coordinates  Miha Rothl  CFX  1  August 3, 2002 13:50 
UDFs for Scalar Eqn  Fluid/Solid HT  Greg Perkins  FLUENT  0  October 11, 2000 03:43 