CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

const qualifier problems

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 17, 2016, 08:55
Default const qualifier problems
  #1
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
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
Zhiheng Wang is offline   Reply With Quote

Old   August 17, 2016, 09:37
Default
  #2
Senior Member
 
Join Date: Oct 2013
Posts: 397
Rep Power: 18
chriss85 will become famous soon enough
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).
chriss85 is offline   Reply With Quote

Old   August 17, 2016, 10:48
Default
  #3
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Quote:
Originally Posted by chriss85 View Post
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().
Zeppo is offline   Reply With Quote

Old   August 17, 2016, 14:18
Default
  #4
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 52
Rep Power: 12
Jerryfan is on a distinguished road
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.
Jerryfan is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Foam::error::printStack(Foam::Ostream&) with simpleFoam -parallel U.Golling OpenFOAM Running, Solving & CFD 52 September 23, 2023 03:35
Viscoelastic Fluid Flows using OpenFOAM The solver viscoelasticFluidFoam jovani OpenFOAM Running, Solving & CFD 475 January 13, 2023 08:21
[snappyHexMesh] Error snappyhexmesh - Multiple outside loops avinashjagdale OpenFOAM Meshing & Mesh Conversion 53 March 8, 2019 09:42
k-e & GAMG interFoam Schemitisation Stability Issue JFM OpenFOAM Running, Solving & CFD 3 December 1, 2015 05:58
problem in defining the temperature dependent viscosity!!! adambarfi OpenFOAM Programming & Development 0 March 5, 2013 06:25


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