CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   gSum: no matching function call (https://www.cfd-online.com/Forums/openfoam-programming-development/182853-gsum-no-matching-function-call.html)

Gunther January 20, 2017 08:16

gSum: no matching function call
 
Hey,

I try to compile a code which used to compile in OF 2.3, but in version 4.1 it doesn't do so any more. I receive the error: no matching function for call to gSum... (see below) Does anyone know if a gSum function is relocated or removed in the latest OF? Many thanks in advance!

The piece of the code which the error is called from is as follows:
Code:

#include "pollutant.H"
#include "fvCFD.H"
#include "IOmanip.H"

void pollutant::balance()
{
    forAllConstIter(HashTable<isotope*>, isotopes_, iter)
    {
        const isotope& nuclide = *iter();
        const volScalarField& Ci = nuclide.C();
        Info << "Total amount of " << Ci.name()
            << " in the system: " << gSum(Ci.internalField()*mesh_.V())
            << endl;
    }
}

The complete error message is the following:
HTML Code:

pollutant.C: In member function ‘void Foam::pollutant::balance()’:
pollutant/pollutant.C:443:72: error: no matching function for call to ‘gSum(Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >)’
              << " in the system: " << gSum(Ci.internalField()*mesh_.V())
                                                                        ^
pollutant/pollutant.C:443:72: note: candidates are:
In file included from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/Field.C:870:0,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/Field.H:405,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/scalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionSet.H:46,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedType.H:40,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedScalar.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedTypes.H:31,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricField.H:43,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricScalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricFields.H:34,
                from OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/volFields.H:37,
                from pollutant/pollutant.H:37,
                from pollutant/pollutant.C:26:
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:24: note: template<class Type>
Type Foam::gSum(const Foam::UList<T>&, Foam::label)
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:533:12: note: in definition of macro ‘G_UNARY_FUNCTION’
 ReturnType gFunc(const UList<Type>& f, const label comm)                      \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:24: note:  template argument deduction/substitution failed:
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:533:12: note: in definition of macro ‘G_UNARY_FUNCTION’
 ReturnType gFunc(const UList<Type>& f, const label comm)                      \
            ^
pollutant/pollutant.C:443:72: note:  ‘Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >’ is not derived from ‘const Foam::UList<T>
              << " in the system: " << gSum(Ci.internalField()*mesh_.V())
                                                                        ^
In file included from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/Field.C:870:0,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/Field.H:405,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/scalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionSet.H:46,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedType.H:40,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedScalar.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/dimensionedTypes.H:31,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricField.H:43,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricScalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricFields.H:34,
                from OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/volFields.H:37,
                from pollutant/pollutant.H:37,
                from pollutant/pollutant.C:26:
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:24: note: template<class Type>
Type Foam::gSum(const Foam::tmp<Foam::Field<Type> >&)
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:303:12: note: in definition of macro ‘TMP_UNARY_FUNCTION’
 ReturnType Func(const tmp<Field<Type>>& tf1)                                  \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:1: note: in expansion of macro ‘G_UNARY_FUNCTION’
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
 ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:24: note:  template argument deduction/substitution failed:
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:303:12: note: in definition of macro ‘TMP_UNARY_FUNCTION’
 ReturnType Func(const tmp<Field<Type>>& tf1)                                  \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFunctions.C:543:1: note: in expansion of macro ‘G_UNARY_FUNCTION’
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
 ^
pollutant/pollutant.C:443:72: note:  mismatched types ‘Foam::Field<Type>’ and ‘Foam::DimensionedField<double, Foam::volMesh>
              << " in the system: " << gSum(Ci.internalField()*mesh_.V())
                                                                        ^
pollutant/pollutant.C:443:72: note:  ‘Foam::tmp<Foam::DimensionedField<double, Foam::volMesh>
>’ is not derived from ‘const Foam::tmp<Foam::Field<Type> >’
In file included from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldField.C:390:0,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldField.H:198,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricField.H:45,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricScalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricFields.H:34,
                from OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/volFields.H:37,
                from pollutant/pollutant.H:37,
                from pollutant/pollutant.C:26:
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:24: note: template<template<class> class Field, class Type> Type Foam::gSum(const Foam::FieldField<Field, Type>&)
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:549:12: note: in definition of macro ‘G_UNARY_FUNCTION’
 returnType gFunc(const FieldField<Field, Type>& f)                            \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:24: note:  template argument deduction/substitution failed:
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:549:12: note: in definition of macro ‘G_UNARY_FUNCTION’
 returnType gFunc(const FieldField<Field, Type>& f)                            \
            ^
pollutant/pollutant.C:443:72: note:  ‘Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >’ is not derived from ‘const Foam::FieldField<Field, Type>
              << " in the system: " << gSum(Ci.internalField()*mesh_.V())
                                                                        ^
In file included from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldField.C:390:0,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldField.H:198,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricField.H:45,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricScalarField.H:38,
                from OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/GeometricFields.H:34,
                from OpenFOAM/OpenFOAM-4.1/src/finiteVolume/lnInclude/volFields.H:37,
                from pollutant/pollutant.H:37,
                from pollutant/pollutant.C:26:
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:24: note: template<template<class>
class Field, class Type> Type Foam::gSum(const Foam::tmp<Foam::FieldField<Field, Type> >&)
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:400:12: note: in definition of macro ‘TMP_UNARY_FUNCTION’
 returnType func(const tmp<FieldField<Field, Type>>& tf1)                      \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:1: note: in expansion of macro ‘G_UNARY_FUNCTION’
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
 ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:24: note:  template argument deduction/substitution failed:
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
                        ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:400:12: note: in definition of macro ‘TMP_UNARY_FUNCTION’
 returnType func(const tmp<FieldField<Field, Type>>& tf1)                      \
            ^
OpenFOAM/OpenFOAM-4.1/src/OpenFOAM/lnInclude/FieldFieldFunctions.C:559:1: note: in expansion of macro ‘G_UNARY_FUNCTION’
 G_UNARY_FUNCTION(Type, gSum, sum, sum)
 ^
pollutant/pollutant.C:443:72: note:  mismatched types ‘Foam::FieldField<Field, Type>’ and ‘Foam::DimensionedField<double, Foam::volMesh>
              << " in the system: " << gSum(Ci.internalField()*mesh_.V())
                                                                        ^
pollutant/pollutant.C:443:72: note:  ‘Foam::tmp<Foam::DimensionedField<double, Foam::volMesh>
>’ is not derived from ‘const Foam::tmp<Foam::FieldField<Field, Type> >’
make: *** [Make/linux64GccDPInt32Opt/pollutant/pollutant.o] Error 1


GerhardHolzinger January 23, 2017 03:36

If you run
Code:

git grep gSum
in the OpenFOAM-dev repository, you will find that OpenFOAM still uses gSum().
I assume that the necessary headers changed, have a look on current code which uses gSum().

alexeym January 23, 2017 03:43

Hi,

Code:

pollutant/pollutant.C:443:72: error: no matching function for call to ‘gSum(Foam::tmp<Foam::DimensionedField<double, Foam::volMesh> >)’
Well, error is rather self-explanatory. * operation returns tmp object, gSum can not operate on tmp objects. You need either to dereference tmp using () operator, so your call becomes something like:

Code:

gSum((Ci.internalField()*mesh_.V())())
or you can try to create volScalarField from tmp before doing gSum.

Gunther January 24, 2017 16:38

Hey Alexey and Gerhard,

Thank you both for your answers. The dereferencing with the () operator worked. So, special thanks to you Alexey! Nice solution ;)


All times are GMT -4. The time now is 13:36.