CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Community Contributions (https://www.cfd-online.com/Forums/openfoam-community-contributions/)
-   -   [swak4Foam] funkySetFields - expression evaluation - error (https://www.cfd-online.com/Forums/openfoam-community-contributions/96549-funkysetfields-expression-evaluation-error.html)

grjmell January 25, 2012 11:02

funkySetFields - expression evaluation - error
 
I have following expression in my funkSetFieldsDict:

Code:

expressions
(
    setInternalField
    {
        field Ub;
        expression  "pos().z >= 0.1 ? vector(log(pos().z-0.08),0,0) : vector(0,0,0) ";
        keepPatches true;
    }
);

I always get a floating point error, unless i remove the "-0.08" bit. due to the condition to only evaluate that equation if pos().z >= 0.1 there should be no log of zero... so i don't understand why i always get that error?? in my mesh pos().z goes from 0 to 0.5.

gschaider January 25, 2012 19:09

Quote:

Originally Posted by grjmell (Post 341133)
I have following expression in my funkSetFieldsDict:

Code:

expressions
(
    setInternalField
    {
        field Ub;
        expression  "pos().z >= 0.1 ? vector(log(pos().z-0.08),0,0) : vector(0,0,0) ";
        keepPatches true;
    }
);

I always get a floating point error, unless i remove the "-0.08" bit. due to the condition to only evaluate that equation if pos().z >= 0.1 there should be no log of zero... so i don't understand why i always get that error?? in my mesh pos().z goes from 0 to 0.5.

The problem is that for "a ? b : c" FSF first evaluates b and c and then picks from them according to a. Avoiding this would mean reprogramming almost all field operations.

The best solution I can think of is "vector(log(pos().z >= 0.1 ? pos().z-0.08 : 1),0,0)" (untested - hope there is no syntax error)

grjmell January 26, 2012 04:46

Thanks for the explanation. It is a clever work around!


All times are GMT -4. The time now is 18:53.