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 primaryexpression before 'if' Fabian 
Hi,
me again... does nobody
Hi,
me again... does nobody has an idea!? Regards! Fabian 
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); 
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 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 
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 
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 ifcondition in this 'template' (this is an template, isn't?)? Fabian 
I normally put stuff like that
I normally put stuff like that in "createFields.H", but it doesn't really matter.

Thanks!
Thanks!

Thanks!
Thanks!

All times are GMT 4. The time now is 17:08. 