View Issue Details

IDProjectCategoryView StatusLast Update
0000912OpenFOAMBugpublic2014-02-10 13:23
Reporteruser700Assigned Tohenry  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
PlatformLinuxOSOpenSuseOS Version11.1
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.

Activities

user700

2013-07-04 12:21

  ~0002305

I wrote basicThermo - of course its a virtual function, I have seen that until now using rhoThermo and solidThermo.

henry

2013-07-04 12:35

manager   ~0002306

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 12:17 user700 New Issue
2013-07-04 12:21 user700 Note Added: 0002305
2013-07-04 12:35 henry Note Added: 0002306
2013-07-04 12:35 henry Status new => resolved
2013-07-04 12:35 henry Resolution open => no change required
2013-07-04 12:35 henry Assigned To => henry