Compiled error while using DimensionedField<tensor, volMesh>
I encountered a compiled error while using Dimensioned<tensor, volMesh>. Here is what I wrote in the createFields.H of the icoFoam:
volTensorField Ut = fvc::grad(U);
DimensionedField<tensor, volMesh> Ud = Ut.internalField();
Info << Ud << endl;
Info << Ud.T() << endl;
And the compiled error was:
error: no matching function for call to ‘T(const Foam::Field<Foam::Tensor<double> >&, const Foam::Field<Foam::Tensor<double> >&)’ Foam::T(result(), *this);
Then I found the Foam::T() functions in the FieldFunctions.H is declared as
template<class Type> void T(Field<Type>& res, const UList<Type>& f);
However, the member function T() of the class dimensionedField<Type, GeoMesh> is defined as
template<class Type, class GeoMesh> tmp<DimensionedField<Type, GeoMesh>> DimensionedField<Type, GeoMesh>::T() const
{
tmp<DimensionedField<Type, GeoMesh>> result
(
DimensionedField<Type, GeoMesh>::New
(
name() + ".T()",
mesh_,
dimensions_
)
);
Foam::T(result(), *this);
return result;
}
where the operator() of the tmp return a const reference of T rather than a non-const reference which is required by Foam::T() global function. So, I modify the above code:
Foam::T(result(), *this);
into:
Foam::T(result.ref(), *this);
After this modification, the compilation can be done successfully. Actually I encountered this problem in openFOAM 8 version. But I checked the corresponding source codes of OpenFOAM V2006. The same problem seems also exists.