function sin(), cos(),exp(),pow() in Func1.h confilct with openfoam sin()...function in dimensionScalar.H

359 views
Skip to first unread message

qi yang

unread,
Feb 12, 2018, 10:50:36 PM2/12/18
to Cantera Users' Group
Dear all,

I add zerodim.h in openfoam, however, included header file Func1.h of zerodim.h conflict with openfoam dimensionScalar.H.

sin(), cos() , exp() and pow() are all defined in  Func1.h and dimensionScalar.H.

I didn't use "using namespace cantera ", I don't know why this happened.

Should I write wrapperfile? I don't think it is a easy way to solve this problem..

Is there any better method?


Thank you!

Bruce.

qi yang

unread,
Feb 12, 2018, 11:21:23 PM2/12/18
to Cantera Users' Group
Dear All,

Finally I got the right method, in Func1.h, when function Sin1 returned sin() funtion of std, add std:: infront of std(*)

return std::sin(*)

cos(), exp() and pow() are the same.

Then , there would be no namespace conflicts between cantera and openfoam when you add Fun1.h into openfoam. And also, no need to write wrapper file.

Thanks 

在 2018年2月12日星期一 UTC-5下午10:50:36,qi yang写道:

Ray Speth

unread,
Feb 13, 2018, 2:50:07 PM2/13/18
to Cantera Users' Group

Hi,

Can you provide a minimal working example, and the error output you are getting? Cantera does not define functions named sin, cos, etc. but does call these functions from <cmath>. I think you might have this the other way around, with a using namespace Foam directive causing the Foam functions to clobber the ones in the global namespace from <cmath>.

Regards,
Ray

Message has been deleted
Message has been deleted

qi yang

unread,
Feb 13, 2018, 10:07:27 PM2/13/18
to Cantera Users' Group
Dear Ray,

As you said, when calling thess functions from <cmath> in Func1.h, the code is written as follow:

virtual doublereal eval(doublereal t) const {
        return sin(m_c*t);
    }

however, in some header files of openfoam, member funciton named sin(*)  is also defined.

So when I add #include "zerodim.h" which Func.h in openfoam header files, it goes wrong, the error out put looks like as follow ::

In file included from /usr/include/cantera/zeroD/Wall.h:10:0,
                 from /usr/include/cantera/zerodim.h:6,
                 from /opt/openfoam5/applications/solvers/combustion/RNreactingFoam/CanteraFoam/lnInclude/outputFoam.H:47,
                 from RNreactingFoam.C:41:
/usr/include/cantera/numerics/Func1.h: In member function ‘virtual doublereal Cantera::Sin1::eval(doublereal) const’:
/usr/include/cantera/numerics/Func1.h:162:25: error: call of overloaded ‘sin(doublereal)’ is ambiguous
         return sin(m_c*t);
                         ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/5/bits/c++config.h:482,
                 from /usr/include/c++/5/cstdint:38,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/int32.H:39,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/int.H:38,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/label.H:39,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/labelList.H:47,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/UPstream.H:42,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/Pstream.H:42,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/parRun.H:35,
                 from /opt/openfoam5/src/finiteVolume/lnInclude/fvCFD.H:4,
                 from RNreactingFoam.C:32:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:65:1: note: candidate: double sin(double)
 __MATHCALL_VEC (sin,, (_Mdouble_ __x));
 ^
In file included from /opt/openfoam5/src/OpenFOAM/lnInclude/TimeState.H:38:0,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/Time.H:47,
                 from /opt/openfoam5/src/finiteVolume/lnInclude/fvCFD.H:6,
                 from RNreactingFoam.C:32:
/opt/openfoam5/src/OpenFOAM/lnInclude/dimensionedScalar.H:80:19: note: candidate: Foam::dimensionedScalar Foam::sin(const dimensionedScalar&)
 dimensionedScalar sin(const dimensionedScalar&);
                   ^
In file included from /opt/openfoam5/src/OpenFOAM/lnInclude/scalar.H:40:0,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/IOstream.H:49,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/Ostream.H:39,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/OSstream.H:39,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/messageStream.H:216,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/error.H:51,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/UListI.H:26,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/UList.H:416,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/List.H:43,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/labelList.H:48,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/UPstream.H:42,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/Pstream.H:42,
                 from /opt/openfoam5/src/OpenFOAM/lnInclude/parRun.H:35,
                 from /opt/openfoam5/src/finiteVolume/lnInclude/fvCFD.H:4,
                 from RNreactingFoam.C:32:
/opt/openfoam5/src/OpenFOAM/lnInclude/Scalar.H:119:11: note: candidate: Foam::doubleScalar Foam::sin(Foam::doubleScalar)
 transFunc(sin)
           ^
/opt/openfoam5/src/OpenFOAM/lnInclude/doubleScalar.H:84:15: note: in definition of macro ‘transFunc’
 inline Scalar func(const Scalar s) \
               ^

To solve this problem , you should add  namespace std::  in front of sin(*) for avoiding  ambiguous overloaded ‘sin(*)’ between <cmath> and openfoam :

virtual doublereal eval(doublereal t) const {
        return  std::sin(m_c*t);
    }


Best

Bruce

在 2018年2月13日星期二 UTC-5下午2:50:07,Ray Speth写道:

Ray Speth

unread,
Feb 14, 2018, 11:11:02 AM2/14/18
to Cantera Users' Group

Bruce,

You still aren’t showing a full example, and the details are critical here. The functions Foam::sin(const dimensionedScalar&) and Foam::sin(Foam::doubleScalar) should not participate in overload resolution for the call to sin in Func1.h, which should only be looking in namespace Cantera (where no such definition exists) and the global namespace (where the declaration from <cmath> should be found. The only ways that I know of where this conflict should happen is if you have either (a) written using namespace Foam or using Foam::sin or (b) placed the #include directive for Func1.h inside a namespace Foam block.

That said, I think a pull request to make these calls in Func1.h more explicit would be acceptable, in order to be more accomodating of use cases that cause this kind of problem.

Regards,
Ray

PS please do not delete and re-send posts if you make a typo in a post. Many members of this group receive these messages as e-mail, so doing this results in many near-duplicate messages and makes it hard to follow the conversation.

Reply all
Reply to author
Forward
0 new messages