CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   How to change the value of an argument of an if-test within the if-scope (http://www.cfd-online.com/Forums/openfoam/80540-how-change-value-argument-if-test-within-if-scope.html)

Edy September 29, 2010 04:57

How to change the value of an argument of an if-test within the if-scope
 
Hi,

I have a problem which is probably very simple to solve.
In my program, I would like to change, within an if-scope, the value of the variable used in the if-test.
Basically, what i want to do looks like this :

volScalarField Tsub = Tsat - Tb;
if (Tsub <= 0.05)
{
Tsub = 0.0;
}

BHowever, OpenFOAM operator<= should normally take references to constant volScalarField as arguments. But then I cannot modify these arguments within the if-scope...

Thanks in advance.


/Edouard

herbert September 29, 2010 07:04

Hi Edy,

you have to do the change element-wise:

Code:

forAll(Tsub, iCell)
{
    if (Tsub[iCell] <= 0.05)
    {
        Tsub[iCell] = 0.0;
    }
}

Regards,
Stefan

Edy September 29, 2010 08:25

Hi Stefan,

It works. It was obviously something quite easy but I am still not very familiar with OF, i just started few days ago and have a lot to learn.

Vielen Dank!

Edy September 30, 2010 07:11

Hi,

One more question.
Tsub is defined as a volScalarField with the dimension of temperature. Is it licit to write a test as you wrote though the LHS has a dimension and the RHS is just a scalar: Or should i define a new temperature dimensioned variable equal to 2 for the RHS of the test?

Thanks


All times are GMT -4. The time now is 01:09.