MOAB: Mesh Oriented datABase  (version 5.4.1)
Mesquite.hpp
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 
00026   ***************************************************************** */
00027 #ifndef MESQUITE_HPP
00028 #define MESQUITE_HPP
00029 
00030 #include "moab/MOABConfig.h"
00031 
00032 #ifdef _WIN32                // if vc
00033 #ifdef MESQUITE_DLL_EXPORTS  // if we are exporting as dll
00034 #define MESQUITE_EXPORT __declspec( dllexport )
00035 #else                       // else we aren't exporting as dll
00036 #ifdef MESQUITE_STATIC_LIB  // are we compiling a static lib?
00037 
00038 #define MESQUITE_EXPORT
00039 #else  // Calling codes need to do nothing if
00040 // they are calling as a dll
00041 #define MESQUITE_EXPORT __declspec( dllimport )
00042 #endif
00043 #endif
00044 #elif defined( __GNUC__ ) && __GNUC__ >= 4
00045 #define MESQUITE_EXPORT __attribute__( ( visibility( "default" ) ) )
00046 #else  // else not vc
00047 #define MESQUITE_EXPORT
00048 #endif
00049 
00050 #ifdef WIN32               /* windows */
00051 #define _USE_MATH_DEFINES  // For M_PI
00052 #endif
00053 
00054 #include <cmath>
00055 #include <cfloat>
00056 #include <climits>
00057 #include <cstddef>
00058 #ifdef HAVE_CBRT
00059 #include <math.h>
00060 #endif
00061 
00062 #include <limits>
00063 #include <vector>
00064 #include <cassert>
00065 
00066 /*! \file Mesquite.hpp
00067  */
00068 
00069 /*!
00070   \namespace Mesquite
00071   Copyright 2003 Sandia Corporation and the University of Chicago. Under
00072   the terms of Contract DE-AC04-94AL85000 with Sandia Corporation and
00073   Contract W-31-109-ENG-38 with the University of Chicago, the U.S.
00074   Government retains certain rights in this software.
00075 
00076 */
00077 namespace MBMesquite
00078 {
00079 
00080 typedef int StatusCode;
00081 
00082 typedef double real;
00083 
00084 enum StatusCodeValues
00085 {
00086     MSQ_FAILURE = 0,
00087     MSQ_SUCCESS
00088 };
00089 
00090 enum EntityTopology
00091 {
00092     POLYGON       = 7,
00093     TRIANGLE      = 8,
00094     QUADRILATERAL = 9,
00095     POLYHEDRON    = 10,
00096     TETRAHEDRON   = 11,
00097     HEXAHEDRON    = 12,
00098     PRISM         = 13,
00099     PYRAMID       = 14,
00100     SEPTAHEDRON   = 15,
00101     MIXED
00102 };
00103 
00104 enum AssessSchemes
00105 {
00106     NO_SCHEME          = 0,
00107     ELEMENT_AVG_QM     = 1,
00108     ELEMENT_MAX_QM     = 2,
00109     TMP_QUALITY_METRIC = 3,
00110     QUALITY_METRIC     = 4
00111 };
00112 
00113 // Version information
00114 MESQUITE_EXPORT const char* version_string( bool );
00115 MESQUITE_EXPORT unsigned int major_version_number();
00116 MESQUITE_EXPORT unsigned int minor_version_number();
00117 MESQUITE_EXPORT unsigned int patch_version_number();
00118 enum ReleaseType
00119 {
00120     RELEASE,
00121     BETA,
00122     ALPHA
00123 };
00124 MESQUITE_EXPORT MBMesquite::ReleaseType release_type();
00125 
00126 const bool OF_FREE_EVALS_ONLY = true;
00127 
00128 // GLOBAL variables
00129 const int MSQ_MAX_NUM_VERT_PER_ENT              = 8;
00130 const int MSQ_HIST_SIZE                         = 7;  // number of division in histogram
00131 static const double MSQ_SQRT_TWO                = std::sqrt( 2.0 );
00132 static const double MSQ_SQRT_THREE              = std::sqrt( 3.0 );
00133 static const double MSQ_SQRT_THREE_DIV_TWO      = MSQ_SQRT_THREE / 2.0;
00134 static const double MSQ_SQRT_THREE_INV          = 1.0 / MSQ_SQRT_THREE;
00135 static const double MSQ_SQRT_TWO_INV            = 1.0 / MSQ_SQRT_TWO;
00136 static const double MSQ_SQRT_TWO_DIV_SQRT_THREE = MSQ_SQRT_TWO / MSQ_SQRT_THREE;
00137 static const double MSQ_ONE_THIRD               = 1.0 / 3.0;
00138 static const double MSQ_TWO_THIRDS              = 2.0 / 3.0;
00139 static const double MSQ_3RT_2_OVER_6RT_3        = std::pow( 2 / MSQ_SQRT_THREE, MSQ_ONE_THIRD );
00140 
00141 #ifdef UINT_MAX
00142 const unsigned MSQ_UINT_MAX = UINT_MAX;
00143 #else
00144 const unsigned MSQ_UINT_MAX = ~(unsigned)0;
00145 #endif
00146 
00147 #ifdef INT_MAX
00148 const int MSQ_INT_MAX = INT_MAX;
00149 #else
00150 const int MSQ_INT_MAX       = MSQ_UINT_MAX >> 1;
00151 #endif
00152 
00153 #ifdef INT_MIN
00154 const int MSQ_INT_MIN = INT_MIN;
00155 #else
00156 const int MSQ_INT_MIN       = ~MSQ_INT_MAX;
00157 #endif
00158 
00159 #ifdef DBL_MIN
00160 const double MSQ_DBL_MIN = DBL_MIN;
00161 #else
00162 /* This value is rather large - DBL_MIN is normally about 2e-308
00163    Put an error here to see if any platform really doesn't
00164    have DBL_MIN or DBL_MAX defined, and evaluate what to do then.
00165 */
00166 #error DBL_MIN not defined
00167 const double MSQ_DBL_MIN = 1.0E-30;
00168 #endif
00169 const double MSQ_MIN = MSQ_DBL_MIN;
00170 
00171 #ifdef DBL_MAX
00172 const double MSQ_DBL_MAX = DBL_MAX;
00173 #else
00174 /* This value is rather small - DBL_MAX is normally about 2e308
00175    Put an error here to see if any platform really doesn't
00176    have DBL_MIN or DBL_MAX defined, and evaluate what to do then.
00177 */
00178 #error DBL_MAX not defined
00179 const double MSQ_DBL_MAX = 1.0E30;
00180 #endif
00181 const double MSQ_MAX     = MSQ_DBL_MAX;
00182 const double MSQ_MAX_CAP = 1.e6;
00183 
00184 // macro to return the min/max of a set of arguements.  The integer
00185 // (e.g., '2') tells how many arguements should be passed for comparison.
00186 template < class T >
00187 inline T MSQ_MIN_2( T a, T b )
00188 {
00189     return a < b ? a : b;
00190 }
00191 template < class T >
00192 inline T MSQ_MAX_2( T a, T b )
00193 {
00194     return a > b ? a : b;
00195 }
00196 
00197 // Utility functions
00198 inline double cbrt( double d )
00199 {
00200 #ifdef MOAB_HAVE_CBRT
00201     return ::cbrt( d );
00202 #else
00203     return std::pow( d, MSQ_ONE_THIRD );
00204 #endif
00205 }
00206 
00207 inline double cbrt_sqr( double d )
00208 {
00209 #ifdef MOAB_HAVE_CBRT
00210     return ::cbrt( d * d );
00211 #else
00212     return std::pow( d, MSQ_TWO_THIRDS );
00213 #endif
00214 }
00215 
00216 /**\brief Perform safe division (no overflow or div by zero).
00217  *
00218  * Do result = num/den iff it would not result in an overflow or div by zero
00219  *\param num  Numerator of division.
00220  *\param den  Denominator of division
00221  *\param result The result of the division if valid, zero otherwise.
00222  *\return false if the result of the division would be invalid (inf or nan),
00223  *        true otherwise.
00224  */
00225 inline bool divide( double num, double den, double& result )
00226 {
00227     const double fden = fabs( den );
00228     // NOTE: First comparison is necessary to avoid overflow in second.
00229     // NOTE: Comparison in second half of condition must be '<'
00230     //       rather than '<=' to correctly handle 0/0.
00231     if( fden >= 1 || fabs( num ) < fden * std::numeric_limits< double >::max() )
00232     {
00233         result = num / den;
00234         return true;
00235     }
00236     else
00237     {
00238         result = 0.0;
00239         return false;
00240     }
00241 }
00242 
00243 /**\brief get array pointer from std::vector */
00244 template < typename T >
00245 inline T* arrptr( std::vector< T >& v, bool check_zero_size = false )
00246 {
00247     if( check_zero_size && !v.size() ) return 0;
00248     assert( !v.empty() );
00249     return &v[0];
00250 }
00251 template < typename T >
00252 inline const T* arrptr( const std::vector< T >& v, bool check_zero_size = false )
00253 {
00254     if( check_zero_size && !v.size() ) return 0;
00255     assert( !v.empty() );
00256     return &v[0];
00257 }
00258 
00259 }  // namespace MBMesquite
00260 
00261 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines