FieldTraits.cpp

00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00013 #include <stdlib.h>
00014 
00015 #include <sstream>
00016 #include <stdexcept>
00017 #include <stk_util/util/string_case_compare.hpp>
00018 #include <stk_mesh/fem/FieldTraits.hpp>
00019 
00020 namespace stk {
00021 namespace mesh {
00022 
00023 //----------------------------------------------------------------------
00024 
00025 namespace {
00026 
00027 unsigned get_index( const char * const func ,
00028                     const unsigned number_names ,
00029                     const char * const * names ,
00030                     const unsigned size ,
00031                     const char * const select )
00032 {
00033   unsigned index = size <= number_names ? 0 : size ;
00034 
00035   for ( ; index < size && not_equal_case(select,names[index]) ; ++index );
00036 
00037   if ( index == size ) {
00038     std::ostringstream msg ;
00039     msg << func ;
00040     msg << " ERROR size = " << size ;
00041     msg << " label = " << select ;
00042     throw std::runtime_error( msg.str() );
00043   }
00044   return index ;
00045 }
00046 
00047 const char * get_string( const char * const func ,
00048                          const unsigned number_names ,
00049                          const char * const * names ,
00050                          const unsigned size ,
00051                          const unsigned index )
00052 {
00053   if ( size < number_names || size <= index ) {
00054     std::ostringstream msg ;
00055     msg << func ;
00056     msg << " ERROR size = " << size ;
00057     msg << " index = " << index ;
00058     throw std::runtime_error( msg.str() );
00059   }
00060 
00061   return names[index];
00062 }
00063 
00064 }
00065 
00066 //----------------------------------------------------------------------
00067 
00068 const Cartesian & Cartesian::tag()
00069 { static const Cartesian self ; return self ; }
00070 
00071 const char * Cartesian::name() const
00072 { static const char n[] = "Cartesian" ; return n ; }
00073 
00074 std::string Cartesian::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00075 {
00076   static const char x[] = "x" ;
00077   static const char y[] = "y" ;
00078   static const char z[] = "z" ;
00079   static const char * label[] = { x , y , z };
00080 
00081   return std::string( get_string( Cartesian::tag().name() ,
00082                                   3 , label , size , index ) );
00083 }
00084 
00085 shards::ArrayDimTag::size_type Cartesian::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00086 {
00087   static const char x[] = "x" ;
00088   static const char y[] = "y" ;
00089   static const char z[] = "z" ;
00090   static const char * label[] = { x , y , z };
00091 
00092   return get_index( Cartesian::tag().name() ,
00093                     3 , label , size , arg.c_str() );
00094 }
00095 
00096 //----------------------------------------------------------------------
00097 
00098 const Cylindrical & Cylindrical::tag()
00099 { static const Cylindrical self ; return self ; }
00100 
00101 const char * Cylindrical::name() const
00102 { static const char n[] = "Cylindrical" ; return n ; }
00103 
00104 std::string Cylindrical::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00105 {
00106   static const char r[] = "r" ;
00107   static const char a[] = "a" ;
00108   static const char z[] = "z" ;
00109   static const char * label[] = { r , a , z };
00110 
00111   return std::string( get_string( Cylindrical::tag().name() ,
00112                                   3 , label , size , index ) );
00113 }
00114 
00115 shards::ArrayDimTag::size_type Cylindrical::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00116 {
00117   static const char r[] = "r" ;
00118   static const char a[] = "a" ;
00119   static const char z[] = "z" ;
00120   static const char * label[] = { r , a , z };
00121 
00122   return get_index( Cylindrical::tag().name() ,
00123                     3 , label , size , arg.c_str() );
00124 }
00125 
00126 //----------------------------------------------------------------------
00127 
00128 const FullTensor & FullTensor::tag()
00129 { static const FullTensor self ; return self ; }
00130 
00131 const char * FullTensor::name() const
00132 { static const char n[] = "FullTensor" ; return n ; }
00133 
00134 std::string FullTensor::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00135 {
00136   static const char xx[] = "xx" ;
00137   static const char yx[] = "yx" ;
00138   static const char zx[] = "zx" ;
00139   static const char xy[] = "xy" ;
00140   static const char yy[] = "yy" ;
00141   static const char zy[] = "zy" ;
00142   static const char xz[] = "xz" ;
00143   static const char yz[] = "yz" ;
00144   static const char zz[] = "zz" ;
00145   static const char * label[] = { xx , yx , zx , xy , yy , zy , xz , yz , zz };
00146 
00147   return std::string( get_string( FullTensor::tag().name() ,
00148                                   9 , label , size , index ) );
00149 }
00150 
00151 shards::ArrayDimTag::size_type FullTensor::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00152 {
00153   static const char xx[] = "xx" ;
00154   static const char yx[] = "yx" ;
00155   static const char zx[] = "zx" ;
00156   static const char xy[] = "xy" ;
00157   static const char yy[] = "yy" ;
00158   static const char zy[] = "zy" ;
00159   static const char xz[] = "xz" ;
00160   static const char yz[] = "yz" ;
00161   static const char zz[] = "zz" ;
00162   static const char * label[] = { xx , yx , zx , xy , yy , zy , xz , yz , zz };
00163 
00164   return get_index( FullTensor::tag().name() ,
00165                     9 , label , size , arg.c_str() );
00166 }
00167 
00168 //----------------------------------------------------------------------
00169 
00170 const SymmetricTensor & SymmetricTensor::tag()
00171 { static const SymmetricTensor self ; return self ; }
00172 
00173 const char * SymmetricTensor::name() const
00174 { static const char n[] = "SymmetricTensor" ; return n ; }
00175 
00176 std::string SymmetricTensor::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00177 {
00178   static const char xx[] = "xx" ;
00179   static const char yx[] = "yx" ;
00180   static const char zx[] = "zx" ;
00181   static const char xy[] = "xy" ;
00182   static const char yy[] = "yy" ;
00183   static const char zy[] = "zy" ;
00184   static const char xz[] = "xz" ;
00185   static const char yz[] = "yz" ;
00186   static const char zz[] = "zz" ;
00187   static const char * label[] = { xx , yx , zx , xy , yy , zy , xz , yz , zz };
00188 
00189   return std::string( get_string( SymmetricTensor::tag().name() ,
00190                                   9 , label , size , index ) );
00191 }
00192 
00193 shards::ArrayDimTag::size_type SymmetricTensor::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00194 {
00195   static const char xx[] = "xx" ;
00196   static const char yy[] = "yy" ;
00197   static const char zz[] = "zz" ;
00198 
00199   static const char xy[] = "xy" ;
00200   static const char yz[] = "yz" ;
00201   static const char xz[] = "xz" ;
00202 
00203   static const char * label[] = { xx , yy , zz , xy , yz , xz };
00204 
00205   return get_index( SymmetricTensor::tag().name() ,
00206                     6 , label , size , arg.c_str() );
00207 }
00208 
00209 //----------------------------------------------------------------------
00210 
00211 }//namespace mesh
00212 }//namespace stk
00213 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7