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/)
-   -   const qualifier problems (https://www.cfd-online.com/Forums/openfoam-programming-development/176393-const-qualifier-problems.html)

Zhiheng Wang August 17, 2016 08:55

const qualifier problems
 
Hi my createField.H has defination of T as

const volScalarField& T = thermo.T();
I want to impliment my code on boundaryCondition correction as

forAll(T.boundaryField()[patchID],i)
{

T.boundaryField)([patchID][i] = T.boundaryField()[patchID][i]-DT;
------------
-------------------------- (some code for spoces) ........
T.write();

}

I am getting following error

error: assignment of read-only location ‘(&(&(& T)->Foam::GeometricField<Type, PatchField, GeoMesh>::boundaryField<double,.....

How to resolve this condition I want to correct the temperature T with some differet function based on spices flux. please help

chriss85 August 17, 2016 09:37

As of OpenFOAM 4.0 you need to use boundaryFieldRef() instead of boundaryField() if you want a non-const access to the boundaries. Same goes for internalField() and internalFieldRef() (and possibly other functions as well).

Zeppo August 17, 2016 10:48

Quote:

Originally Posted by chriss85 (Post 614377)
As of OpenFOAM 4.0 you need to use boundaryFieldRef() instead of boundaryField() if you want a non-const access to the boundaries. Same goes for internalField() and internalFieldRef() (and possibly other functions as well).

And also:
instead of
Code:

const volScalarField& T = thermo.T();
use
Code:

volScalarField& T = thermo.T();
otherwise it won't even allow you to call boundaryFieldRef().

Jerryfan August 17, 2016 14:18

Hi wang,


As others have already mentioned above, you shouldn't use that
Quote:

const
qualifier. In C++, a variable defined as const-qualifier is ready-only so that you can't change the value of the variable. So in your case, const should be removed.


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