Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Misc/Exponent.cpp
Go to the documentation of this file.
1 /* *****************************************************************
2  MESQUITE -- The Mesh Quality Improvement Toolkit
3 
4  Copyright 2004 Sandia Corporation and Argonne National
5  Laboratory. Under the terms of Contract DE-AC04-94AL85000
6  with Sandia Corporation, the U.S. Government retains certain
7  rights in this software.
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public License
20  (lgpl.txt) along with this library; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 
23  diachin2@llnl.gov, djmelan@sandia.gov, mbrewer@sandia.gov,
24  pknupp@sandia.gov, tleurent@mcs.anl.gov, tmunson@mcs.anl.gov,
25  kraftche@cae.wisc.edu
26 
27  ***************************************************************** */
36 #include "Exponent.hpp"
37 
38 namespace Mesquite {
39 
40 
41 
43 {
44  if (exponent == 0.0)
45  return &Exponent::pow0;
46  else if (exponent == 1.0)
47  return &Exponent::pow1;
48  else if (exponent == 0.5)
49  return &Exponent::squareRoot;
50  else if (exponent == 1./3.)
51  return &Exponent::cubeRoot;
52  else if (exponent == 2./3.)
53  return &Exponent::powTwoThirds;
54  else if (exponent == 2.0)
55  return &Exponent::pow2;
56  else if (exponent == -1.0)
57  return &Exponent::inverse;
58  else if (exponent == -0.5)
60  else if (exponent == 1.5)
62  else if (exponent == -2.0)
63  return &Exponent::invSquare;
64  else if (msq_stdc::floor(exponent) == exponent)
65  {
66  if (exponent > 0.0)
68  else
70  }
71  else
72  return &Exponent::std_pow;
73 }
74 
75 void Exponent::set_exponent( double exponent )
76 {
77  mExponent = exponent;
78  funcPointer = get_func_ptr( exponent );
79 }
80 
81 double Exponent::pow0( double ) const { return 1.0; }
82 double Exponent::pow1( double x ) const { return x; }
83 double Exponent::pow2( double x ) const { return x * x; }
84 double Exponent::squareRoot( double x ) const { return msq_stdc::sqrt( x ); }
85 double Exponent::cubeRoot( double x ) const { return Mesquite::cbrt( x ); }
86 double Exponent::powTwoThirds( double x ) const { return Mesquite::cbrt_sqr(x); }
87 double Exponent::std_pow( double x ) const { return msq_stdc::pow( x, mExponent ); }
88 double Exponent::inverse( double x ) const { return 1.0 / x; }
89 double Exponent::invSquareRoot( double x ) const { return 1.0 / msq_stdc::sqrt(x); }
90 double Exponent::powThreeHalves( double x ) const{ return x*x*x / msq_stdc::sqrt(x); }
91 double Exponent::invSquare( double x ) const { return 1.0 / (x*x); }
92 
93 double Exponent::powPositiveInt( double x ) const
94 {
95  double result = x;
96  for (int i = (int)mExponent - 1; i > 0; --i)
97  result *= x;
98  return result;
99 }
100 
101 double Exponent::powNegativeInt( double x ) const
102 {
103  double result = x;
104  for (int i = (-(int)mExponent) - 1; i > 0; --i)
105  result *= x;
106  return 1.0/result;
107 }
108 
109 
110 } // namespace Mesquite
double pow1(double x) const
double powNegativeInt(double x) const
double pow0(double x) const
double sqrt(double d)
Definition: double.h:73
double std_pow(double x) const
void set_exponent(double exponent)
double cbrt_sqr(double d)
Definition: Mesquite.hpp:191
double invSquareRoot(double x) const
double invSquare(double x) const
double powThreeHalves(double x) const
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
double powTwoThirds(double x) const
double cubeRoot(double x) const
double cbrt(double d)
Definition: Mesquite.hpp:182
double powPositiveInt(double x) const
double(Exponent::* constMemberPtr)(double) const
double pow2(double x) const
static constMemberPtr get_func_ptr(double exponent)
double pow(double value, const Exponent &exp)
double squareRoot(double x) const
double inverse(double x) const