CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   bound() function of the bound.C file (https://www.cfd-online.com/Forums/openfoam-programming-development/198499-bound-function-bound-c-file.html)

Tobi February 8, 2018 09:46

bound() function of the bound.C file
 
Hi everybody,

yesterday I had a discussion with my colleague about the bound function. We were digging into the code and were finally surprised how interesting this function is working. Actually we needed just the max() function but for unknown reason we went the wrong direction at the beginning. Nevertheless it was good that we discussed about the bound() functionality. However, it is always nice to have the code implementation and be able to understand it but in that particular case, does anybody know if there is a mathematical background behind this interesting expression?

After small drafts we realized that the unbounded values will get some values which are somehow an average of the field values. We can imagine that this makes much more sense than setting it to a - lets say - minimum value e.g. 0.

The question as already mentioned is. Does anybody know if there is some mathematical background / formula behind that? At least there should be some mathematical or physical background for that implementation.

https://cpp.openfoam.org/v5/bound_8C_source.html

Code:

  32 Foam::volScalarField&  33 Foam::bound(volScalarField& vsf, const dimensionedScalar& lowerBound)
  34 {
  35    const scalar minVsf = min(vsf).value();
  36
  37    if (minVsf < lowerBound.value())
  38    {
  39        Info<< "bounding " << vsf.name()
  40            << ", min: " << minVsf
  41            << " max: " << max(vsf).value()
  42            << " average: " << gAverage(vsf.primitiveField())
  43            << endl;
  44
  45        vsf.primitiveFieldRef() = max
  46        (
  47            max
  48            (
  49                vsf.primitiveField(),
  50                fvc::average(max(vsf, lowerBound))().primitiveField()
  51              * pos(-vsf.primitiveField())
  52            ),
  53            lowerBound.value()
  54        );
  55
  56        vsf.boundaryFieldRef() = max(vsf.boundaryField(), lowerBound.value());
  57    }
  58
  59    return vsf;
  60 }


gu1 November 20, 2018 06:55

Hi Tobi,

I'm studying about the bound function... so unfortunately I can not help you in your post. I have a question and maybe you can help me..., related to the kEpsilon model. Based on original file: kEpsilon

On lines 132 and 133 I could substitute for:

Quote:

bound(k_, kMin_);
bound(epsilon_, epsilonMin_);

for

bound(k_, SMALL);
bound(epsilon_, SMALL);
? and lines 259 and 275:

Quote:

bound(epsilon_, epsilonMin_);
bound(k_, kMin_);

for

bound(epsilon_, SMALL);
bound(k_, SMALL);
? I could not understand if kMin and epsilonMin are updated every iteration. Could you explain to me what their function is (these are in RASModel)? Would I disrupt the efficiency of the kEpsilon model if I removed them?

OBS: I understand that SMALL is the default value of this function.

mAlletto November 20, 2018 07:55

Quote:

Originally Posted by Tobi (Post 680868)
Hi everybody,

yesterday I had a discussion with my colleague about the bound function. We were digging into the code and were finally surprised how interesting this function is working. Actually we needed just the max() function but for unknown reason we went the wrong direction at the beginning. Nevertheless it was good that we discussed about the bound() functionality. However, it is always nice to have the code implementation and be able to understand it but in that particular case, does anybody know if there is a mathematical background behind this interesting expression?

After small drafts we realized that the unbounded values will get some values which are somehow an average of the field values. We can imagine that this makes much more sense than setting it to a - lets say - minimum value e.g. 0.

The question as already mentioned is. Does anybody know if there is some mathematical background / formula behind that? At least there should be some mathematical or physical background for that implementation.

https://cpp.openfoam.org/v5/bound_8C_source.html

Code:

  32 Foam::volScalarField&  33 Foam::bound(volScalarField& vsf, const dimensionedScalar& lowerBound)
  34 {
  35    const scalar minVsf = min(vsf).value();
  36
  37    if (minVsf < lowerBound.value())
  38    {
  39        Info<< "bounding " << vsf.name()
  40            << ", min: " << minVsf
  41            << " max: " << max(vsf).value()
  42            << " average: " << gAverage(vsf.primitiveField())
  43            << endl;
  44
  45        vsf.primitiveFieldRef() = max
  46        (
  47            max
  48            (
  49                vsf.primitiveField(),
  50                fvc::average(max(vsf, lowerBound))().primitiveField()
  51              * pos(-vsf.primitiveField())
  52            ),
  53            lowerBound.value()
  54        );
  55
  56        vsf.boundaryFieldRef() = max(vsf.boundaryField(), lowerBound.value());
  57    }
  58
  59    return vsf;
  60 }


from the source code it seams all positive values smaller than lowerBound will be bounded by lowerBound (pos((-vsf.primitiveField()) is 0 for positive values of vsf). For negative values the field is averaged over neighboring cells and after that the maximum between the calculated value and lowerBound is taken.

I quess the averaging is made in order to suppress numerical oscillations.
As far as I know the bounding is performed to help the solver to find a solution or avoid that the solver diverges.


All times are GMT -4. The time now is 12:40.