|
[Sponsors] |
November 30, 2012, 10:42 |
function within solver
|
#1 |
Senior Member
Join Date: Nov 2010
Posts: 113
Rep Power: 16 |
Hi Foamers,
I was wondering about a defintion of a little function within a solver. If I, for example, want to calculate the square of x in a function within a solver it would look like this: Code:
scalar xsquare ( const scalar& x ) const { return pow(x,2); } Any advises? Thanks in advance! |
|
November 30, 2012, 10:54 |
|
#2 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
Did you try putting them in front of "int main()"? If I remember correctly, functions are always defined outside the main program. createFields.H is included in the main program.
|
|
November 30, 2012, 11:00 |
|
#3 |
Senior Member
Join Date: Nov 2010
Posts: 113
Rep Power: 16 |
Good hint, but then I need to set the namespace correctly, right?
Code:
interFoam.C:57:4: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] interFoam.C:57:4: error: non-member function 'const scalar xsquare(const scalar&)' cannot have cv-qualifier thanks! |
|
November 30, 2012, 11:14 |
|
#4 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
The only other hint I can give you, is to put it below other includes like fvCFD.H, but probably you tried that.
|
|
November 30, 2012, 11:17 |
|
#5 |
Senior Member
Join Date: Nov 2010
Posts: 113
Rep Power: 16 |
Yes, what I did was
Code:
#include "fvCFD.H" #include "MULES.H" #include "subCycle.H" #include "interfaceProperties.H" #include "twoPhaseMixture.H" #include "turbulenceModel.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // scalar xsquare ( const scalar& x ) const { return pow(x,2); } int main(int argc, char *argv[]) { #include "setRootCase.H" ... Greetings |
|
November 30, 2012, 11:21 |
|
#6 |
Senior Member
Bernhard
Join Date: Sep 2009
Location: Delft
Posts: 790
Rep Power: 22 |
In that case you can try Foam::scalar instead of just scalar, but I am absolutely not sure about that. Good luck!
|
|
November 30, 2012, 11:23 |
|
#7 |
Senior Member
Join Date: Nov 2010
Posts: 113
Rep Power: 16 |
Yeah, tried several of these combinations, but unsuccessfully. I got to understand that, otherwise it's just trial and error..
|
|
November 30, 2012, 12:01 |
|
#8 |
Senior Member
Lieven
Join Date: Dec 2011
Location: Leuven, Belgium
Posts: 299
Rep Power: 22 |
Hey all,
This is how I would do it. Add Code:
scalar xsquare(const scalar& x); This way you can simply add your function at the bottom of the file so after the } of int main. But you should remove the 'const' after the (const scalar& x). So the function becomes: Code:
scalar xsquare(const scalar& x) { return pow(x,2); } |
|
November 30, 2012, 12:20 |
|
#9 |
Senior Member
Join Date: Nov 2010
Posts: 113
Rep Power: 16 |
Thank you! Just works
Greetings |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
LiencubiclowRemodel | nzy102 | OpenFOAM Bugs | 14 | January 10, 2012 09:53 |
Problems in compiling paraview in Suse 10.3 platform | chiven | OpenFOAM Installation | 3 | December 1, 2009 08:21 |
Installation 1.5 as a user of server (New bird) | chiven | OpenFOAM Installation | 15 | April 26, 2009 23:33 |
Control function in Elliptic solver | Hoang Anh Duong | Main CFD Forum | 4 | July 9, 2007 04:32 |
DecomposePar links against liblamso0 with OpenMPI | jens_klostermann | OpenFOAM Bugs | 11 | June 28, 2007 18:51 |