CFD Online Logo CFD Online URL
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

How to use mathematical constants?

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 2 Post By alexeym

LinkBack Thread Tools Search this Thread Display Modes
Old   January 19, 2016, 06:05
Default How to use mathematical constants?
Senior Member
Join Date: Aug 2015
Posts: 127
Rep Power: 10
arieljeds is on a distinguished road
Hi everyone! Ok very simple question here but oddly I can't find an answer that works!

I am using codeStream in my blockMeshDict file and one of the things I'm trying to calculate involves multiplying by pi...oddly though, I can't seem to use pi correctly. (I have left in #calc and $r1 in the examples just to demonstrate the sort of thing I have in my blockMeshDict)

I have so far tried:

#calc pi*$r1
#calc \pi*$r1
#calc Pi*$r1
#calc mathematicalConstant::pi*$r1
Apologies for what is probably a stupid question!
arieljeds is offline   Reply With Quote

Old   January 19, 2016, 09:17
Senior Member
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym

And why not:


Though for example

would be shorter

Also here is excerpt from $FOAM_SRC/OpenFOAM/global/constants/mathematical/mathematicalConstants.H (just for reference)

namespace Foam
namespace constant
namespace mathematical
    const scalar pi(M_PI);
    const scalar twoPi(2*pi);
    const scalar piByTwo(0.5*pi);
} // End namespace mathematical
} // End namespace constant
} // End namespace Foam
fumiya and robob like this.
alexeym is offline   Reply With Quote

Old   January 12, 2022, 04:58
New Member
Join Date: Dec 2021
Posts: 23
Rep Power: 4
MamboJambo is on a distinguished road
Other stuff like, should work too:

M_PI_2        /* pi/2 */
M_PI_4        /* pi/4 */
M_1_PI        /* 1/pi */
M_2_PI        /* 2/pi */
M_2_SQRTPI    /* 2/sqrt(pi) */
Any particular reason to group some variables inside a particular namespace? Wouldn't it be better to just use the standard stuff in the math.h ?
MamboJambo is offline   Reply With Quote


calc, codestream, mathematical expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
scotch and metis's mathematical knowledge sharonyue OpenFOAM Programming & Development 1 September 9, 2015 11:33
How are the integration constants for the JANAFthermo class derived? tomf OpenFOAM Running, Solving & CFD 2 May 15, 2015 07:47
what constants to choose for std k-e model daniel.struwig FLUENT 0 April 18, 2009 06:51
k-e turbulence model, empirical constants mrs Main CFD Forum 4 June 27, 2006 00:28
Modelling a turbulent jet and k-epsilon constants Ant Siemens 3 January 24, 2005 15:56

All times are GMT -4. The time now is 20:35.