From: wolf Date: Thu, 12 Sep 2002 22:46:44 +0000 (+0000) Subject: Unify the places where we use pi. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54e76a608d62401fa61b7a42d1322b571b79dd6b;p=dealii-svn.git Unify the places where we use pi. git-svn-id: https://svn.dealii.org/trunk@6417 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/base/include/base/config.h.in b/deal.II/base/include/base/config.h.in index d7a8f74822..8c15a906ee 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -191,6 +191,67 @@ #undef __PRETTY_FUNCTION__ - +/** + * Have a namespace into which we declare some numeric constants, such + * as pi. Unfortunately, these are not always available, on all systems + * or depending on compiler flags, so we duplicate their declarations + * here to make them unconditionally available to all other parts of the + * library. + * + * The constants defined here are a subset of the constants sometimes + * declared in the system include file , but without the + * prefix . + */ +namespace deal_II_numbers { + /** + * e + */ + static const double E = 2.7182818284590452354; + + /** + * log_2 e + */ + static const double LOG2E = 1.4426950408889634074; + + /** + * log_10 e + */ + static const double LOG10E = 0.43429448190325182765; + + /** + * log_e 2 + */ + static const double LN2 = 0.69314718055994530942; + + /** + * log_e 10 + */ + static const double LN10 = 2.30258509299404568402; + + /** + * pi + */ + static const double PI = 3.14159265358979323846; + + /** + * pi/2 + */ + static const double PI_2 = 1.57079632679489661923; + + /** + * pi/4 + */ + static const double PI_4 = 0.78539816339744830962; + + /** + * sqrt(2) + */ + static const double SQRT2 = 1.41421356237309504880; + + /** + * 1/sqrt(2) + */ + static const double SQRT1_2 = 0.70710678118654752440; +}; #endif diff --git a/deal.II/base/source/data_out_base.cc b/deal.II/base/source/data_out_base.cc index 2cafaf6929..12feb958d6 100644 --- a/deal.II/base/source/data_out_base.cc +++ b/deal.II/base/source/data_out_base.cc @@ -1760,8 +1760,7 @@ void DataOutBase::write_eps (const std::vector > &patches, // the height field, I don't know // it. EpsCell2d eps_cell; -//TODO:[?] Unify the various places where PI is defined to a central instance - const double pi = 3.141592653589793238462; + const double pi = deal_II_numbers::PI; const double cx = -std::cos(pi-flags.azimut_angle * 2*pi / 360.), cz = -std::cos(flags.turn_angle * 2*pi / 360.), sx = std::sin(pi-flags.azimut_angle * 2*pi / 360.), diff --git a/deal.II/base/source/function_lib_cutoff.cc b/deal.II/base/source/function_lib_cutoff.cc index e122076160..9c9e2ae8fc 100644 --- a/deal.II/base/source/function_lib_cutoff.cc +++ b/deal.II/base/source/function_lib_cutoff.cc @@ -20,20 +20,6 @@ #include -// in strict ANSI C mode, the following constants are not defined by -// default, so we do it ourselves -//TODO:[?] Unify the various places where PI is defined to a central instance -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif - -#ifndef M_PI_2 -# define M_PI_2 1.57079632679489661923 -#endif - -#ifndef M_E -# define M_E 2.7182818284590452354 -#endif namespace Functions { @@ -239,7 +225,7 @@ namespace Functions if (d>=r) return 0.; const double e = -r*r/(r*r-d*d); - return ((e<-50) ? 0. : M_E * exp(e)); + return ((e<-50) ? 0. : deal_II_numbers::E * exp(e)); } return 0.; } @@ -267,7 +253,7 @@ namespace Functions values[i] = 0.; } else { const double e = -r*r/(r*r-d*d); - values[i] = (e<-50) ? 0. : M_E * exp(e); + values[i] = (e<-50) ? 0. : deal_II_numbers::E * exp(e); } } else @@ -294,7 +280,7 @@ namespace Functions { e = -r*r/(r*r-d*d); if (e>-50) - val = M_E * exp(e); + val = deal_II_numbers::E * exp(e); } if (this->selected==CutOffFunctionBase::no_component) diff --git a/deal.II/configure b/deal.II/configure index 51648cfd7f..52ac087fed 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.in Revision: 1.119 . +# From configure.in Revision: 1.120 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.53a. # diff --git a/deal.II/configure.in b/deal.II/configure.in index e64f48b2f9..7fb5765ed7 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -398,7 +398,68 @@ AH_TOP( AH_BOTTOM( [ - +/** + * Have a namespace into which we declare some numeric constants, such + * as pi. Unfortunately, these are not always available, on all systems + * or depending on compiler flags, so we duplicate their declarations + * here to make them unconditionally available to all other parts of the + * library. + * + * The constants defined here are a subset of the @p{M_XXX} constants sometimes + * declared in the system include file @p{math.h}, but without the + * prefix @p{M_}. + */ +namespace deal_II_numbers { + /** + * e + */ + static const double E = 2.7182818284590452354; + + /** + * log_2 e + */ + static const double LOG2E = 1.4426950408889634074; + + /** + * log_10 e + */ + static const double LOG10E = 0.43429448190325182765; + + /** + * log_e 2 + */ + static const double LN2 = 0.69314718055994530942; + + /** + * log_e 10 + */ + static const double LN10 = 2.30258509299404568402; + + /** + * pi + */ + static const double PI = 3.14159265358979323846; + + /** + * pi/2 + */ + static const double PI_2 = 1.57079632679489661923; + + /** + * pi/4 + */ + static const double PI_4 = 0.78539816339744830962; + + /** + * sqrt(2) + */ + static const double SQRT2 = 1.41421356237309504880; + + /** + * 1/sqrt(2) + */ + static const double SQRT1_2 = 0.70710678118654752440; +}; #endif ]) diff --git a/deal.II/deal.II/source/grid/grid_generator.cc b/deal.II/deal.II/source/grid/grid_generator.cc index 497d6f9e9b..b7d5ba629b 100644 --- a/deal.II/deal.II/source/grid/grid_generator.cc +++ b/deal.II/deal.II/source/grid/grid_generator.cc @@ -371,8 +371,7 @@ void GridGenerator::hyper_shell (Triangulation<2> &tria, Assert ((inner_radius > 0) && (inner_radius < outer_radius), ExcInvalidRadii ()); -//TODO:[?] Unify the various places where PI is defined to a central instance - const double pi = 3.141592653589793238462; + const double pi = deal_II_numbers::PI; // determine the number of cells // for the grid. if not provided by @@ -465,7 +464,7 @@ GridGenerator::half_hyper_shell (Triangulation<2> &tria, Assert ((inner_radius > 0) && (inner_radius < outer_radius), ExcInvalidRadii ()); - const double pi = 3.14159265359; + const double pi = deal_II_numbers::PI; // determine the number of cells // for the grid. if not provided by // the user determine it such that diff --git a/deal.II/deal.II/source/grid/grid_out.cc b/deal.II/deal.II/source/grid/grid_out.cc index 7f3468a47f..68014e6a0e 100644 --- a/deal.II/deal.II/source/grid/grid_out.cc +++ b/deal.II/deal.II/source/grid/grid_out.cc @@ -889,8 +889,7 @@ void GridOut::write_eps (const Triangulation &tria, // is in direction of the viewer, but // I am too tired at present to fix // this -//TODO:[?] Unify the various places where PI is defined to a central instance - const double pi = 3.141592653589793238462; + const double pi = deal_II_numbers::PI; const double z_angle = eps_flags_3.azimut_angle; const double turn_angle = eps_flags_3.turn_angle; const Point view_direction(-std::sin(z_angle * 2.*pi / 360.) * std::sin(turn_angle * 2.*pi / 360.), diff --git a/deal.II/deal.II/source/numerics/data_out_rotation.cc b/deal.II/deal.II/source/numerics/data_out_rotation.cc index c07fad9426..92dff26e01 100644 --- a/deal.II/deal.II/source/numerics/data_out_rotation.cc +++ b/deal.II/deal.II/source/numerics/data_out_rotation.cc @@ -67,18 +67,19 @@ void DataOutRotation::build_some_patches (Data data) // place. for simplicity add the // initial direction at the end // again -//TODO:[?] Unify the various places where PI is defined to a central instance - const double pi = 3.141592653589793238462; std::vector > angle_directions (n_patches_per_circle+1); for (unsigned int i=0; i<=n_patches_per_circle; ++i) { - angle_directions[i][0] = std::cos(2*pi*i/n_patches_per_circle); - angle_directions[i][1] = std::sin(2*pi*i/n_patches_per_circle); + angle_directions[i][0] = std::cos(2*deal_II_numbers::PI * + i/n_patches_per_circle); + angle_directions[i][1] = std::sin(2*deal_II_numbers::PI * + i/n_patches_per_circle); }; unsigned int cell_number = 0; - typename std::vector< ::DataOutBase::Patch >::iterator patch = this->patches.begin(); + typename std::vector< ::DataOutBase::Patch >::iterator + patch = this->patches.begin(); typename DoFHandler::cell_iterator cell=first_cell(); // get first cell in this thread diff --git a/deal.II/deal.II/source/numerics/derivative_approximation.cc b/deal.II/deal.II/source/numerics/derivative_approximation.cc index 72b8c8dbef..663bdc90ef 100644 --- a/deal.II/deal.II/source/numerics/derivative_approximation.cc +++ b/deal.II/deal.II/source/numerics/derivative_approximation.cc @@ -275,8 +275,6 @@ C DEFINE A TEST MATRIX */ -//TODO:[?] Unify the various places where PI is defined to a central instance - const double pi = 3.141592653589793238462; const double am = trace(d) / 3.; // s := d - trace(d) I @@ -328,8 +326,8 @@ C DEFINE A TEST MATRIX { const double theta = std::acos(XX) / 3.; EE[0] = am + R*std::cos(theta); - EE[1] = am + R*std::cos(theta + 2./3.*pi); - EE[2] = am + R*std::cos(theta + 4./3.*pi); + EE[1] = am + R*std::cos(theta + 2./3.*deal_II_numbers::PI); + EE[2] = am + R*std::cos(theta + 4./3.*deal_II_numbers::PI); }; };