CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Avoid PETSc overload OF functions

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 10, 2019, 07:54
Default Avoid PETSc overload OF functions
  #1
Member
 
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8
palarcon is on a distinguished road
Hello everybody

I'm trying to include PETSc into my OpenFOAM code in order to be able to perform some topology optimization developments (mainly becase there is a version of the MMA optimizer already coded with PETSc).

So far, I have been able to include petsc.hand the related directories/libraries in the "options" file and everything seems OK before compiling.

My problem is that OF and PETSc, both have the same "pow" function, so when I try to compile my code there is a call to an overloaded function and I don't really know how to solve it.

Code:
/home/pablo/PETSC/3.11.2/include/petscmath.h:400:38: error: call of overloaded ‘pow(PetscScalar&, PetscScalar&)’ is ambiguous
 #define PetscPowScalar(a,b)   pow(a,b)
One option that I can think about is to add the :: symbol in the pow definition on PETSc to avoid the overloading, but I'm not sure if that is a good idea/solution, something like this:

#define PetscPowScalar(a,b) ::pow(a,b)

If anybody has a way to include PETSc into OpenFOAM (the simples way will do the job actually) or how can I avoid this overloading I will be really thankful.

Last edited by palarcon; December 16, 2019 at 02:58.
palarcon is offline   Reply With Quote

Old   December 16, 2019, 01:13
Default
  #2
Member
 
Join Date: Feb 2014
Posts: 32
Rep Power: 12
yeharav is on a distinguished road
Hi,

I think that namespaces should solve this.

Do you use the OF namespace?
that is do you have

Code:
using namespace Foam;
in your code?
yeharav is offline   Reply With Quote

Old   December 16, 2019, 02:59
Default
  #3
Member
 
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8
palarcon is on a distinguished road
Quote:
Originally Posted by yeharav View Post
Hi,

I think that namespaces should solve this.

Do you use the OF namespace?
that is do you have

Code:
using namespace Foam;
in your code?
I just did that and nothing changes, there is still conflict between OpenFOAM pow definition and PETSc pow definition.
palarcon is offline   Reply With Quote

Old   December 16, 2019, 03:58
Default
  #4
Member
 
Join Date: Feb 2014
Posts: 32
Rep Power: 12
yeharav is on a distinguished road
Hi,

Sorry for confusing you, you should not use
Code:
using namespace Foam
in order to segregate between the two namespaces.

However you said that it doesn't work even without it...
Thats interesting because the pow (at leasat for the geometricFields) was defined inside the Foam namespace.

I couldn't find another definition of pow in OF (at least not in OF-7).
yeharav is offline   Reply With Quote

Old   December 16, 2019, 04:05
Default
  #5
Member
 
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8
palarcon is on a distinguished road
What I'm doing is to use at the same time PETSc (to perform an optimization) with OpenFOAM and it happens that both have a definition for the pow operator.
Either if I use

Code:
using namespace foam;
or not, nothing changes, the operator is still overloaded.

A temporary solution (and the simplest one that I found until now) is to add :: into the PETSc pow definition (because I prefer to modify anything but OpenFOAM, following the coding philosophy of my projet).
palarcon is offline   Reply With Quote

Old   December 17, 2019, 07:28
Default
  #6
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,685
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
There is no quick solution to this, other than pretty much what you've done. You cannot, however, in general use the "::" qualifier since PETSc is pure C.

On the assumption that someone, somewhere has included <cmath>, you could have the following - but you'd probably wish that the PETSc team changes this upstream:

Code:
#ifdef __cplusplus
#define PetscPowScalar(a,b) std::pow(a,b)
#else
#define PetscPowScalar(a,b)   pow(a,b)
#endif
olesen is offline   Reply With Quote

Old   December 17, 2019, 10:29
Default
  #7
Member
 
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8
palarcon is on a distinguished road
Quote:
Originally Posted by olesen View Post
There is no quick solution to this, other than pretty much what you've done. You cannot, however, in general use the "::" qualifier since PETSc is pure C.

On the assumption that someone, somewhere has included <cmath>, you could have the following - but you'd probably wish that the PETSc team changes this upstream:

Code:
#ifdef __cplusplus
#define PetscPowScalar(a,b) std::pow(a,b)
#else
#define PetscPowScalar(a,b)   pow(a,b)
#endif
Thank you for your answer. And yes, you are right, I don't want to "modify further" PETSc, in order to avoid future complications within the code.
palarcon is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to solve the boundary layer without wall functions? WhiteW OpenFOAM Running, Solving & CFD 4 January 20, 2020 04:55
Objective functions khavart SU2 Shape Design 3 June 11, 2019 07:01
[Commercial meshers] CCM+ Mesh Conversion Ingenieur OpenFOAM Meshing & Mesh Conversion 17 February 2, 2014 09:34
Adding PETSc to my userdefined Makefile Mahnaz Main CFD Forum 9 January 26, 2014 13:51
Delta Functions within Ansys Mechanical Stephen Waite Structural Mechanics 2 July 29, 2013 08:56


All times are GMT -4. The time now is 09:06.