CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Confused about how OF handles operation between volScalarField and dimensionedScalar (http://www.cfd-online.com/Forums/openfoam/80592-confused-about-how-handles-operation-between-volscalarfield-dimensionedscalar.html)

Edy September 30, 2010 07:40

Confused about how OF handles operation between volScalarField and dimensionedScalar
 
Hi,

I created two fields volScalarField called Tsub and B. They both have the dimension dimTemp. Tsat is a dimensionedScalar read from the transportProperties and has the dimension dimTemp as well. In substance, I implemented this simple thing :

volScalarField TsatField
(
IOobject
(
"TsatField",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
Tsat
);

const dimensionedScalar BCons = 0.5/(1.0-rhoa/rhob);
//BCons is actually dimensionless

volScalarField Tsub = TsatField - Tb;

B[iCell] = Tsub[iCell]*BCons;


But i got this error message while compiling :
"error: cannot convert ‘Foam::dimensioned<double>’ to ‘double’ in assignment"

Could someone explain me what is wrong here?
Thanks a lot,

Regards

akidess September 30, 2010 08:23

Accessing Tsat and B using cell labels gives you the raw values, which are double, not dimensionedScalar. So to work like this you will need BCons.value(). And I think B = TSub * BCons should work too.

Edy September 30, 2010 09:45

Hi,

ok, thanks a lot, thats clear now. Got stucked the whole day because of that... :)

I wanted to do simply B = Tsub * BCons in the beginning but this assignment is in reality done within an if-scope whose argument in the if-test is Tsub as well and I would like to modify the variable Tsub within this scope too; i.e :

if (Tsub < 2.0)
{
B = Tsub * BCons
// code lines
Tsub = 4.0 // for example
}

But OF requires references to const volScalarfield as arguments of the if-test, which means that I would not be able to modify Tsub.

I was adviced to do it component-wise to avoid this problem but if you have any other idea, please let me know.

Thanks again!

Best

akidess September 30, 2010 10:07

As I said, if you need to do it component-wise, use BCons.value() to get a double out of your dimensionedScalar. I'd do it the that way.


All times are GMT -4. The time now is 07:00.