CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Bugs (http://www.cfd-online.com/Forums/openfoam-bugs/)
-   -   Tmp class (http://www.cfd-online.com/Forums/openfoam-bugs/62435-tmp-class.html)

maka August 20, 2008 12:23

(1) The following code produce
 
(1) The following code produce wrong value of yFieldTmp. Only two patch faces are wrong and the rest is correct. No warning messages or error.
(2) The code works well if we replace the marked line with:
const scalarField yFieldTmp = ...
(3) The code prints an error message as expected if we replace the marked line with:
scalarField yFieldTmp = ...

The difference between case 1 and 2 is just added & which can easily be done even if you remember that you are working with tmp field.

---------------------------------------

const Foam::fvPatchList& plTmp(mesh.boundary());
label topPatch = mesh.boundaryMesh().findPatchID("topWall");
label patchII=topPatch;
const scalarField& yFieldTmp = plTmp[patchII].Cf().component(1); // marked line.
Info <<plTmp[patchII].name() << " " << gSum(yFieldTmp)/yFieldTmp.size() << endl;
Info <<plTmp[patchII].name() << " " << min(yFieldTmp) << endl;
Info <<plTmp[patchII].name() << " " << max(yFieldTmp) << endl;

maka August 20, 2008 12:26

V 1.3; could be tested on chan
 
V 1.3; could be tested on channelOodles case.

henry August 20, 2008 14:53

const scalarField& yFieldTmp =
 
const scalarField& yFieldTmp = plTmp[patchII].Cf().component(1); // marked line.

is incorrect in a way the compiler and the code cannot warn you about but valgrind will probably pick it up.

Correct alternatives are

scalarField yFieldTmp = ...

or

tmp<scalarfield> yFieldTmp = ...

with the latter being very slightly more efficient than the first but not so much to be something to compromise the code clarity over.

H


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