
[Sponsors] 
January 16, 2008, 13:44 
Hi,
a pretty simple one... I

#1 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
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 primaryexpression before 'if' Fabian 

January 21, 2008, 12:08 
Hi,
me again... does nobody

#2 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
Hi,
me again... does nobody has an idea!? Regards! Fabian 

January 21, 2008, 12:41 
General practice is to add a s

#3 
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12 
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); 

January 21, 2008, 13:07 
Your "if" statement would not

#4 
Senior Member
Gavin Tabor
Join Date: Mar 2009
Posts: 181
Rep Power: 8 
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 nonzero, 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 nonzero 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 

January 21, 2008, 14:10 
Hi Eugene,
thanks, good ide

#5 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
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 

January 21, 2008, 15:14 
Hi Gavin,
I was a bit to sl

#6 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
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 ifcondition in this 'template' (this is an template, isn't?)? Fabian 

January 22, 2008, 09:37 
I normally put stuff like that

#7 
Senior Member
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12 
I normally put stuff like that in "createFields.H", but it doesn't really matter.


January 24, 2008, 15:55 
Thanks!

#8 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
Thanks!


January 28, 2008, 11:02 
Thanks!

#9 
Senior Member
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 10 
Thanks!


Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
RP_Set_Real("variablename", variable name)  bohis  FLUENT  1  March 9, 2009 08:44 
Post, Calculate Variable in plane  Kordou  CFX  1  October 14, 2008 16:39 
hi how to calculate the HTC  kathir  CDadapco  0  March 26, 2006 09: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 09:56 