View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000912OpenFOAM[All Projects] Bugpublic2013-07-04 11:172014-02-10 13:23
Reportertehache 
Assigned Tohenry 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformLinuxOSOpenSuseOS Version11.1
Product Version2.2.x 
Target VersionFixed in Version 
Summary0000912: basicThermo.kappa(): not all field entries set
DescriptionThe first 4 entries of the patchfields of the resulting field from basicThermo.kappa()are not set/initialized - caused some sigsegv/headache in a
boundary condition where I need to divide by kappa
Steps To Reproduceadd, for example, this in createFields.H of buoyantSimpleFoam:

int numPatches=(mesh.boundary()).size();
for(int ip=0;ip<numPatches;ip++) {
    Info << "patch no. " << ip << ", name=" << mesh.name() << endl;
    const scalarField& k=thermo.kappa(ip);
    forAll(k,ik) {
    Info << k[ik] << " ";
    }
 }

Then run tutorial case buoyantCavity, output is:

patch no. 0, name=region0
6.92022e-310 6.92022e-310 0 0 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0. .....

patch no. 1, name=region0
6.92022e-310 6.92022e-310 0 0 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 0.0260859 .....

patch no. 2, name=region0
6.92022e-310 6.92022e-310 0 0 0.0260859 0.0260859 0.0260859 0.0260 .....

Additional InformationTested using 2.2.x, checked out on July,3, 2013
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0002305)
tehache (reporter)
2013-07-04 11:21

I wrote basicThermo - of course its a virtual function, I have seen that until now using rhoThermo and solidThermo.
(0002306)
henry (manager)
2013-07-04 11:35

When calling a function you should first check the return type which in the case of thermo.kappa(ip) is tmp<scalarField> not const scalarField&. So in your code

   const scalarField& k=thermo.kappa(ip);

you hold k as a reference to a temporary which is deleted at the ; causing the segv when you use k.

What you need to do is cache the temporary e.g.

  tmp<scalarField> tk(thermo.kappa(ip));
  const scalarField& k = tk();

- Issue History
Date Modified Username Field Change
2013-07-04 11:17 tehache New Issue
2013-07-04 11:21 tehache Note Added: 0002305
2013-07-04 11:35 henry Note Added: 0002306
2013-07-04 11:35 henry Status new => resolved
2013-07-04 11:35 henry Resolution open => no change required
2013-07-04 11:35 henry Assigned To => henry