MOAB: Mesh Oriented datABase  (version 5.4.1)
Settings.cpp
Go to the documentation of this file.
00001 /* *****************************************************************
00002     MESQUITE -- The Mesh Quality Improvement Toolkit
00003 
00004     Copyright 2007 Sandia National Laboratories.  Developed at the
00005     University of Wisconsin--Madison under SNL contract number
00006     624796.  The U.S. Government and the University of Wisconsin
00007     retain certain rights to 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     (2009) [email protected]
00024 
00025   ***************************************************************** */
00026 
00027 /** \file Settings.cpp
00028  *  \brief
00029  *  \author Jason Kraftcheck
00030  */
00031 
00032 #include "Mesquite.hpp"
00033 #include "Settings.hpp"
00034 #include "TriLagrangeShape.hpp"
00035 #include "QuadLagrangeShape.hpp"
00036 #include "TetLagrangeShape.hpp"
00037 #include "LinearPyramid.hpp"
00038 #include "LinearPrism.hpp"
00039 #include "LinearHexahedron.hpp"
00040 
00041 namespace MBMesquite
00042 {
00043 
00044 #ifdef MSQ_TRAP_FPE
00045 const bool IQ_TRAP_FPE_DEFAULT = true;
00046 #else
00047 const bool IQ_TRAP_FPE_DEFAULT = false;
00048 #endif
00049 
00050 struct SettingData
00051 {
00052     SettingData();  //!< Initialize to default settings.
00053     SettingData( const SettingData& other );
00054     SettingData& operator=( const SettingData& other );
00055     bool trapFPE;
00056     Settings::FixedVertexMode fixedMode;
00057     Settings::HigherOrderSlaveMode slaveMode;
00058     std::vector< const MappingFunction* > mapArray;
00059     std::vector< const MappingFunction2D* > mapArray2D;
00060     std::vector< const MappingFunction3D* > mapArray3D;
00061 
00062     TriLagrangeShape defTriFunc;
00063     QuadLagrangeShape defQuadFunc;
00064     TetLagrangeShape defTetFunc;
00065     LinearPyramid defPyrFunc;
00066     LinearPrism defPriFunc;
00067     LinearHexahedron defHexFunc;
00068 
00069   private:
00070     void fix_copy( const SettingData& other );
00071 };
00072 
00073 SettingData::SettingData()
00074     : trapFPE( IQ_TRAP_FPE_DEFAULT ), fixedMode( Settings::FIXED_FLAG ), slaveMode( Settings::SLAVE_ALL ),
00075       mapArray( MIXED, 0 ), mapArray2D( MIXED, 0 ), mapArray3D( MIXED, 0 )
00076 {
00077     mapArray[TRIANGLE]        = &defTriFunc;
00078     mapArray[QUADRILATERAL]   = &defQuadFunc;
00079     mapArray[TETRAHEDRON]     = &defTetFunc;
00080     mapArray[PYRAMID]         = &defPyrFunc;
00081     mapArray[PRISM]           = &defPriFunc;
00082     mapArray[HEXAHEDRON]      = &defHexFunc;
00083     mapArray2D[TRIANGLE]      = &defTriFunc;
00084     mapArray2D[QUADRILATERAL] = &defQuadFunc;
00085     mapArray3D[TETRAHEDRON]   = &defTetFunc;
00086     mapArray3D[PYRAMID]       = &defPyrFunc;
00087     mapArray3D[PRISM]         = &defPriFunc;
00088     mapArray3D[HEXAHEDRON]    = &defHexFunc;
00089 }
00090 
00091 SettingData::SettingData( const SettingData& other )
00092     : trapFPE( other.trapFPE ), fixedMode( other.fixedMode ), slaveMode( other.slaveMode ), mapArray( other.mapArray ),
00093       mapArray2D( other.mapArray2D ), mapArray3D( other.mapArray3D )
00094 {
00095     fix_copy( other );
00096 }
00097 
00098 SettingData& SettingData::operator=( const SettingData& other )
00099 {
00100     trapFPE    = other.trapFPE;
00101     fixedMode  = other.fixedMode;
00102     slaveMode  = other.slaveMode;
00103     mapArray   = other.mapArray;
00104     mapArray2D = other.mapArray2D;
00105     mapArray3D = other.mapArray3D;
00106     fix_copy( other );
00107     return *this;
00108 }
00109 
00110 void SettingData::fix_copy( const SettingData& other )
00111 {
00112     if( mapArray[TRIANGLE] == &other.defTriFunc ) mapArray[TRIANGLE] = &defTriFunc;
00113     if( mapArray[QUADRILATERAL] == &other.defQuadFunc ) mapArray[QUADRILATERAL] = &defQuadFunc;
00114     if( mapArray[TETRAHEDRON] == &other.defTetFunc ) mapArray[TETRAHEDRON] = &defTetFunc;
00115     if( mapArray[PYRAMID] == &other.defPyrFunc ) mapArray[PYRAMID] = &defPyrFunc;
00116     if( mapArray[PRISM] == &other.defPriFunc ) mapArray[PRISM] = &defPriFunc;
00117     if( mapArray[HEXAHEDRON] == &other.defHexFunc ) mapArray[HEXAHEDRON] = &defHexFunc;
00118     if( mapArray2D[TRIANGLE] == &other.defTriFunc ) mapArray2D[TRIANGLE] = &defTriFunc;
00119     if( mapArray2D[QUADRILATERAL] == &other.defQuadFunc ) mapArray2D[QUADRILATERAL] = &defQuadFunc;
00120     if( mapArray3D[TETRAHEDRON] == &other.defTetFunc ) mapArray3D[TETRAHEDRON] = &defTetFunc;
00121     if( mapArray3D[PYRAMID] == &other.defPyrFunc ) mapArray3D[PYRAMID] = &defPyrFunc;
00122     if( mapArray3D[PRISM] == &other.defPriFunc ) mapArray3D[PRISM] = &defPriFunc;
00123     if( mapArray3D[HEXAHEDRON] == &other.defHexFunc ) mapArray3D[HEXAHEDRON] = &defHexFunc;
00124 }
00125 
00126 Settings::Settings() : mData( new SettingData ) {}
00127 Settings::Settings( const Settings& other ) : mData( new SettingData( *other.mData ) ) {}
00128 Settings::~Settings()
00129 {
00130     delete mData;
00131 }
00132 Settings& Settings::operator=( const Settings& other )
00133 {
00134     *mData = *( other.mData );
00135     return *this;
00136 }
00137 
00138 void Settings::set_mapping_function( const MappingFunction* func )
00139 {
00140     EntityTopology type = func->element_topology();
00141     if( mData->mapArray.size() <= (size_t)type ) mData->mapArray.resize( type + 1, 0 );
00142     mData->mapArray[type] = func;
00143     if( TopologyInfo::dimension( type ) == 2 && mData->mapArray2D.size() > (size_t)type )
00144         mData->mapArray2D[type] = 0;
00145     else if( TopologyInfo::dimension( type ) == 3 && mData->mapArray3D.size() > (size_t)type )
00146         mData->mapArray3D[type] = 0;
00147 }
00148 
00149 void Settings::set_mapping_function( const MappingFunction2D* func )
00150 {
00151     unsigned type = func->element_topology();
00152     if( mData->mapArray.size() <= type ) mData->mapArray.resize( type + 1, 0 );
00153     mData->mapArray[type] = func;
00154     if( mData->mapArray2D.size() <= type ) mData->mapArray2D.resize( type + 1, 0 );
00155     mData->mapArray2D[type] = func;
00156 }
00157 
00158 void Settings::set_mapping_function( const MappingFunction3D* func )
00159 {
00160     unsigned type = func->element_topology();
00161     if( mData->mapArray.size() <= type ) mData->mapArray.resize( type + 1, 0 );
00162     mData->mapArray[type] = func;
00163     if( mData->mapArray3D.size() <= type ) mData->mapArray3D.resize( type + 1, 0 );
00164     mData->mapArray3D[type] = func;
00165 }
00166 
00167 void Settings::set_mapping_functions( const MappingFunction* const* array, size_t array_len )
00168 {
00169     for( size_t i = 0; i < array_len; ++i )
00170         set_mapping_function( array[i] );
00171 }
00172 void Settings::set_mapping_functions( const MappingFunction2D* const* array, size_t array_len )
00173 {
00174     for( size_t i = 0; i < array_len; ++i )
00175         set_mapping_function( array[i] );
00176 }
00177 void Settings::set_mapping_functions( const MappingFunction3D* const* array, size_t array_len )
00178 {
00179     for( size_t i = 0; i < array_len; ++i )
00180         set_mapping_function( array[i] );
00181 }
00182 
00183 const MappingFunction* Settings::get_mapping_function( EntityTopology type ) const
00184 {
00185     return (size_t)type < mData->mapArray.size() ? mData->mapArray[type] : 0;
00186 }
00187 
00188 const MappingFunction2D* Settings::get_mapping_function_2D( EntityTopology type ) const
00189 {
00190     return (size_t)type < mData->mapArray2D.size() ? mData->mapArray2D[type] : 0;
00191 }
00192 
00193 const MappingFunction3D* Settings::get_mapping_function_3D( EntityTopology type ) const
00194 {
00195     return (size_t)type < mData->mapArray3D.size() ? mData->mapArray3D[type] : 0;
00196 }
00197 
00198 void Settings::set_fixed_vertex_mode( Settings::FixedVertexMode mode )
00199 {
00200     mData->fixedMode = mode;
00201 }
00202 
00203 Settings::FixedVertexMode Settings::get_fixed_vertex_mode() const
00204 {
00205     return mData->fixedMode;
00206 }
00207 
00208 void Settings::set_slaved_ho_node_mode( Settings::HigherOrderSlaveMode mode )
00209 {
00210     mData->slaveMode = mode;
00211 }
00212 
00213 Settings::HigherOrderSlaveMode Settings::get_slaved_ho_node_mode() const
00214 {
00215     return mData->slaveMode;
00216 }
00217 
00218 void Settings::trap_floating_point_exception( bool enable )
00219 {
00220     mData->trapFPE = enable;
00221 }
00222 bool Settings::trap_floating_point_exception() const
00223 {
00224     return mData->trapFPE;
00225 }
00226 
00227 }  // namespace MBMesquite
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines