Skip to content

Compile error for boundaryInternalField() in v2406

Summary

Compiling a program using the GeometricBoundaryField<>::boundaryInternalField() function throws an error:

/home/itvjg/OpenFOAM/OpenFOAM-v2406/src/OpenFOAM/lnInclude/stdFoam.H:354:36: error: ‘class Foam::tmp<Foam::GeometricBoundaryField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh> >’ has no member named ‘size’
  354 |     for (Foam::label i=0; i<(list).size(); ++i)

Reason

In GeometricBoundaryField<>::boundaryInternalField() the auto keyword is used on the tmp<> object without calling the tmp<>::operator() on it to get the const reference. The forAll macro then throws an error as the tmp<> object has no size() function.

Solution

Use the tmp<>::ref() to get the reference to the field.

template<class Type, template<class> class PatchField, class GeoMesh>
Foam::tmp<Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>>
Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::
boundaryInternalField() const
{
    auto tresult = tmp<GeometricBoundaryField<Type, PatchField, GeoMesh>>::New
    (
        DimensionedField<Type, GeoMesh>::null(),
        *this
    );

    auto& result = result.ref(); // <--- Here is the change for non const access

    forAll(result, patchi)
    {
        result[patchi] == this->operator[](patchi).patchInternalField();
    }

    return tresult;
}

Environment information

  • OpenFOAM version : v2406
  • Operating system : Ubuntu 22.04 LTS
  • Hardware info : -
  • Compiler : GCC 11
Edited by Jan Gärtner