# How to use mathematical constants?

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

 January 19, 2016, 06:05 How to use mathematical constants? #1 Senior Member   ArielJ Join Date: Aug 2015 Posts: 127 Rep Power: 10 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: Code: #calc pi*$r1 #calc \pi*$r1 #calc Pi*$r1 #calc mathematicalConstant::pi*$r1 Apologies for what is probably a stupid question!  January 19, 2016, 09:17 #2 Senior Member Alexey Matveichev Join Date: Aug 2011 Location: Nancy, France Posts: 1,938 Rep Power: 38 Hi, And why not: Code: constant::mathematical::pi ? Though for example Code: degToRad(180) would be shorter Also here is excerpt from$FOAM_SRC/OpenFOAM/global/constants/mathematical/mathematicalConstants.H (just for reference) Code: 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.

 January 12, 2022, 04:58 #3 New Member   Join Date: Dec 2021 Posts: 23 Rep Power: 4 Other stuff like, should work too: Code: 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 ?

 Tags calc, codestream, mathematical expressions