CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Calculate variable div zero (http://www.cfd-online.com/Forums/openfoam-post-processing/61413-calculate-variable-div-zero.html)

braennstroem January 16, 2008 13:44

Hi, a pretty simple one... I
 
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 January 21, 2008 12:08

Hi, me again... does nobody
 
Hi,
me again... does nobody has an idea!?

Regards!
Fabian

eugene January 21, 2008 12:41

General practice is to add a s
 
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);

grtabor January 21, 2008 13:07

Your "if" statement would not
 
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

braennstroem January 21, 2008 14:10

Hi Eugene, thanks, good ide
 
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 January 21, 2008 15:14

Hi Gavin, I was a bit to sl
 
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

eugene January 22, 2008 09:37

I normally put stuff like that
 
I normally put stuff like that in "createFields.H", but it doesn't really matter.

braennstroem January 24, 2008 15:55

Thanks!
 
Thanks!

braennstroem January 28, 2008 11:02

Thanks!
 
Thanks!


All times are GMT -4. The time now is 23:41.