CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Calculate variable div zero

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 16, 2008, 13:44
Default Hi, a pretty simple one... I
  #1
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Hi,
a pretty simple one... I hope...

I would like to create a new postprocessing variable using:

volScalarField test
(
IOobject
(
"test",
runTime.timeName(),
mesh,
IOobject::NO_READ
),

(fvc::grad(U))/mag(fvc::laplacian(U.component(i)))
);
test.write();

This works fine as long as U.component(i) has some kind of value, but if the denominator is zero I get obviously an error. Can anyone give me an advice, how an 'if' question could look like? I tried somehting like: if (U.component(i)==0.0){...}

but I get:

test.C: In function 'int main(int, char**)':
test.C:128: error: expected primary-expression before 'if'

Fabian
braennstroem is offline   Reply With Quote

Old   January 21, 2008, 12:08
Default Hi, me again... does nobody
  #2
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Hi,
me again... does nobody has an idea!?

Regards!
Fabian
braennstroem is offline   Reply With Quote

Old   January 21, 2008, 12:41
Default General practice is to add a s
  #3
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
General practice is to add a small constant to the denominator:

fvc::grad(U)/(smallU + mag(fvc::laplacian(U.component(i))

where smallU is something like:

dimensionedScalar("smallU", dimensionSet(0,0,-1,0,0), SMALL);
eugene is offline   Reply With Quote

Old   January 21, 2008, 13:07
Default Your "if" statement would not
  #4
Senior Member
 
Gavin Tabor
Join Date: Mar 2009
Posts: 181
Rep Power: 17
grtabor is on a distinguished road
Your "if" statement would not work because U.component(i) would never be identically equal to 0.0. Eugene is correct; the usual thing is to add a small value to the denominator. However you might also want to think about what the value of the numerator is when the denominator is zero. If the denominator is non-zero, then the expression is diverging at that point; you might want to think whether your modelling is correct at this point.
introducing smallU on the denominator will set this to an artificial (if quite large) number - is this what you want?

On the other hand, if the denominator is also zero, you have 0/0 from the fraction. This is not zero; it is UNDEFINED. The fraction may in fact tend towards a non-zero value; you need to look at 1st and higher derivatives of the numerator/denominator to determine this. Again, using smallU will fix the value to zero, which may not be what you want in practice.

Gavin
grtabor is offline   Reply With Quote

Old   January 21, 2008, 14:10
Default Hi Eugene, thanks, good ide
  #5
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Hi Eugene,

thanks, good idea! It works with a small adjustmentdimensionedScalar smallU ("smallU", dimensionSet(0,1,-1,0,0), SMALL);
. Is there any recommendation where to put the smallU declaration? I put it on top of the .C file!?

Regards!
Fabian
braennstroem is offline   Reply With Quote

Old   January 21, 2008, 15:14
Default Hi Gavin, I was a bit to sl
  #6
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Hi Gavin,

I was a bit to slow submitting the post... Thanks for your help. The SMALL number will actually work for my case, but is there a chance to use some kind of range for the if-condition in this 'template' (this is an template, isn't?)?

Fabian
braennstroem is offline   Reply With Quote

Old   January 22, 2008, 09:37
Default I normally put stuff like that
  #7
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 21
eugene is on a distinguished road
I normally put stuff like that in "createFields.H", but it doesn't really matter.
eugene is offline   Reply With Quote

Old   January 24, 2008, 15:55
Default Thanks!
  #8
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Thanks!
braennstroem is offline   Reply With Quote

Old   January 28, 2008, 11:02
Default Thanks!
  #9
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Thanks!
braennstroem 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
RP_Set_Real("variable-name", variable name) bohis FLUENT 1 March 9, 2009 08:44
Post, Calculate Variable in plane Kordou CFX 1 October 14, 2008 17:39
hi how to calculate the HTC kathir Siemens 0 March 26, 2006 10:31
how to calculate y+ in cfx? micaheal CFX 3 November 21, 2005 15:45
how to calculate CL and CD zhaoyu FLUENT 1 April 24, 2001 10:56


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