|
[Sponsors] |
December 10, 2019, 08:54 |
Avoid PETSc overload OF functions
|
#1 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
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) #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 03:58. |
|
December 16, 2019, 02:13 |
|
#2 |
Member
Join Date: Feb 2014
Posts: 32
Rep Power: 12 |
Hi,
I think that namespaces should solve this. Do you use the OF namespace? that is do you have Code:
using namespace Foam; |
|
December 16, 2019, 03:59 |
|
#3 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
||
December 16, 2019, 04:58 |
|
#4 |
Member
Join Date: Feb 2014
Posts: 32
Rep Power: 12 |
Hi,
Sorry for confusing you, you should not use Code:
using namespace Foam 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). |
|
December 16, 2019, 05:05 |
|
#5 |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
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; 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). |
|
December 17, 2019, 08:28 |
|
#6 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
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 |
|
December 17, 2019, 11:29 |
|
#7 | |
Member
Pablo Alarcón
Join Date: Mar 2018
Location: Liège
Posts: 59
Rep Power: 8 |
Quote:
|
||
|
|
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 05:55 |
Objective functions | khavart | SU2 Shape Design | 3 | June 11, 2019 08:01 |
[Commercial meshers] CCM+ Mesh Conversion | Ingenieur | OpenFOAM Meshing & Mesh Conversion | 17 | February 2, 2014 10:34 |
Adding PETSc to my userdefined Makefile | Mahnaz | Main CFD Forum | 9 | January 26, 2014 14:51 |
Delta Functions within Ansys Mechanical | Stephen Waite | Structural Mechanics | 2 | July 29, 2013 09:56 |