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

Preventing negative scalar (UDS) values??

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By Matthew Brannock
  • 3 Post By Greg Perkins

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 14, 2002, 10:05
Default 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.

rarnaunot likes this.
  Reply With Quote

Old   February 14, 2002, 18:53
Default 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
rarnaunot, vincentztl and kckcc like this.
  Reply With Quote

Old   February 15, 2002, 04:15
Default 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.
  Reply With Quote

Old   February 15, 2002, 08:10
Default 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
  Reply With Quote

Old   May 3, 2017, 04:48
Default
  #5
Member
 
Rosario Arnau
Join Date: Feb 2017
Location: Spain
Posts: 57
Rep Power: 9
rarnaunot is on a distinguished road
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
rarnaunot is offline   Reply With Quote

Old   September 1, 2020, 13:32
Default
  #6
Member
 
Deutschland
Join Date: Jun 2020
Location: https://t.me/pump_upp
Posts: 43
Rep Power: 6
schwaral is on a distinguished road
Send a message via ICQ to schwaral Send a message via AIM to schwaral Send a message via Yahoo to schwaral
Hello there,

I have the same problem I think. I wonder where to add the code from above? should it stand alone above my UDF that define the source? I receive warning: garbage at end of `#ifdef' argument and unterminated `#if' conditional error.
schwaral is offline   Reply With Quote

Reply


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
Solving for an additional species CO in coalChemistryFoam N. A. OpenFOAM Programming & Development 3 February 18, 2019 06:58
User defined scalar transport problem (UDS) jpcfd FLUENT 0 June 8, 2010 05: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 14:50
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 04:43


All times are GMT -4. The time now is 22:46.