MOAB: Mesh Oriented datABase  (version 5.4.1)
Exponent.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2004 Sandia Corporation and Argonne National
00005     Laboratory.  Under the terms of Contract DE-AC04-94AL85000
00006     with Sandia Corporation, the U.S. Government retains certain
00007     rights in this software.
00008 
00009     This library is free software; you can redistribute it and/or
00010     modify it under the terms of the GNU Lesser General Public
00011     License as published by the Free Software Foundation; either
00012     version 2.1 of the License, or (at your option) any later version.
00013 
00014     This library is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017     Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     (lgpl.txt) along with this library; if not, write to the Free Software
00021     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 
00023     [email protected], [email protected], [email protected],
00024     [email protected], [email protected], [email protected],
00025     [email protected]
00026 
00027   ***************************************************************** */
00028 /*!
00029   \file   Exponent.cpp
00030   \brief
00031 
00032   \author Jason Kraftcheck
00033   \date   2005-5-2
00034 */
00035 
00036 #include "Exponent.hpp"
00037 
00038 namespace MBMesquite
00039 {
00040 
00041 Exponent::constMemberPtr Exponent::get_func_ptr( double exponent )
00042 {
00043     if( exponent == 0.0 )
00044         return &Exponent::pow0;
00045     else if( exponent == 1.0 )
00046         return &Exponent::pow1;
00047     else if( exponent == 0.5 )
00048         return &Exponent::squareRoot;
00049     else if( exponent == 1. / 3. )
00050         return &Exponent::cubeRoot;
00051     else if( exponent == -1. / 3. )
00052         return &Exponent::invCubeRoot;
00053     else if( exponent == 2. / 3. )
00054         return &Exponent::powTwoThirds;
00055     else if( exponent == -2. / 3. )
00056         return &Exponent::invTwoThirds;
00057     else if( exponent == 2.0 )
00058         return &Exponent::pow2;
00059     else if( exponent == -1.0 )
00060         return &Exponent::inverse;
00061     else if( exponent == -0.5 )
00062         return &Exponent::invSquareRoot;
00063     else if( exponent == 1.5 )
00064         return &Exponent::powThreeHalves;
00065     else if( exponent == -2.0 )
00066         return &Exponent::invSquare;
00067     else if( std::floor( exponent ) == exponent )
00068     {
00069         if( exponent > 0.0 )
00070             return &Exponent::powPositiveInt;
00071         else
00072             return &Exponent::powNegativeInt;
00073     }
00074     else
00075         return &Exponent::std_pow;
00076 }
00077 
00078 void Exponent::set_exponent( double exponent )
00079 {
00080     mExponent   = exponent;
00081     funcPointer = get_func_ptr( exponent );
00082 }
00083 
00084 double Exponent::pow0( double ) const
00085 {
00086     return 1.0;
00087 }
00088 double Exponent::pow1( double x ) const
00089 {
00090     return x;
00091 }
00092 double Exponent::pow2( double x ) const
00093 {
00094     return x * x;
00095 }
00096 double Exponent::squareRoot( double x ) const
00097 {
00098     return std::sqrt( x );
00099 }
00100 double Exponent::cubeRoot( double x ) const
00101 {
00102     return MBMesquite::cbrt( x );
00103 }
00104 double Exponent::invCubeRoot( double x ) const
00105 {
00106     return 1.0 / MBMesquite::cbrt( x );
00107 }
00108 double Exponent::powTwoThirds( double x ) const
00109 {
00110     return MBMesquite::cbrt_sqr( x );
00111 }
00112 double Exponent::invTwoThirds( double x ) const
00113 {
00114     return 1.0 / MBMesquite::cbrt_sqr( x );
00115 }
00116 double Exponent::std_pow( double x ) const
00117 {
00118     return std::pow( x, mExponent );
00119 }
00120 double Exponent::inverse( double x ) const
00121 {
00122     return 1.0 / x;
00123 }
00124 double Exponent::invSquareRoot( double x ) const
00125 {
00126     return 1.0 / std::sqrt( x );
00127 }
00128 double Exponent::powThreeHalves( double x ) const
00129 {
00130     return x * x * x / std::sqrt( x );
00131 }
00132 double Exponent::invSquare( double x ) const
00133 {
00134     return 1.0 / ( x * x );
00135 }
00136 
00137 double Exponent::powPositiveInt( double x ) const
00138 {
00139     double result = x;
00140     for( int i = (int)mExponent - 1; i > 0; --i )
00141         result *= x;
00142     return result;
00143 }
00144 
00145 double Exponent::powNegativeInt( double x ) const
00146 {
00147     double result = x;
00148     for( int i = ( -(int)mExponent ) - 1; i > 0; --i )
00149         result *= x;
00150     return 1.0 / result;
00151 }
00152 
00153 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines