Sierra Toolkit Version of the Day
CoordinateSystems.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 
00018 #include <stk_util/util/string_case_compare.hpp>
00019 #include <stk_util/environment/ReportHandler.hpp>
00020 
00021 #include <stk_mesh/fem/CoordinateSystems.hpp>
00022 
00023 namespace stk {
00024 namespace mesh {
00025 
00026 //----------------------------------------------------------------------
00027 
00028 namespace {
00029 
00030 unsigned get_index( const char * const func ,
00031                     const unsigned number_names ,
00032                     const char * const * names ,
00033                     const unsigned size ,
00034                     const char * const select )
00035 {
00036   unsigned index = size <= number_names ? 0 : size ;
00037 
00038   for ( ; index < size && not_equal_case(select,names[index]) ; ++index );
00039 
00040   ThrowErrorMsgIf( index == size,
00041                    func << ", size = " << size << " label = " << select );
00042   return index ;
00043 }
00044 
00045 const char * get_string( const char * const func ,
00046                          const unsigned number_names ,
00047                          const char * const * names ,
00048                          const unsigned size ,
00049                          const unsigned index )
00050 {
00051   ThrowErrorMsgIf( size < number_names || size <= index,
00052                    func << ", size = " << size << " index = " << index );
00053 
00054   return names[index];
00055 }
00056 
00057 }
00058 
00059 //----------------------------------------------------------------------
00060 
00061 SHARDS_ARRAY_DIM_TAG_SIMPLE_IMPLEMENTATION( SimpleArrayTag )
00062 
00063 //----------------------------------------------------------------------
00064 
00065 const Cartesian2d & Cartesian2d::tag()
00066 { static const Cartesian2d self ; return self ; }
00067 
00068 const char * Cartesian2d::name() const
00069 { static const char n[] = "Cartesian2d" ; return n ; }
00070 
00071 namespace {
00072 const char * const * Cartesian2d_label() {
00073   static const char x[] = "x" ;
00074   static const char y[] = "y" ;
00075   static const char * label[] = { x , y };
00076   return label;
00077 }
00078 }
00079 std::string Cartesian2d::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00080 {
00081   return std::string( get_string( Cartesian2d::tag().name() ,
00082                                   2 , Cartesian2d_label() , size , index ) );
00083 }
00084 
00085 shards::ArrayDimTag::size_type Cartesian2d::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00086 {
00087   return get_index( Cartesian2d::tag().name() ,
00088                     2 , Cartesian2d_label() , size , arg.c_str() );
00089 }
00090 
00091 //----------------------------------------------------------------------
00092 
00093 const Cartesian3d & Cartesian3d::tag()
00094 { static const Cartesian3d self ; return self ; }
00095 
00096 const char * Cartesian3d::name() const
00097 { static const char n[] = "Cartesian3d" ; return n ; }
00098 
00099 namespace {
00100 const char * const * Cartesian3d_label() {
00101   static const char x[] = "x" ;
00102   static const char y[] = "y" ;
00103   static const char z[] = "z" ;
00104   static const char * label[] = { x , y , z };
00105   return label;
00106 }
00107 }
00108 std::string Cartesian3d::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00109 {
00110   return std::string( get_string( Cartesian3d::tag().name() ,
00111                                   3 , Cartesian3d_label() , size , index ) );
00112 }
00113 
00114 shards::ArrayDimTag::size_type Cartesian::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00115 {
00116   return get_index( Cartesian3d::tag().name() ,
00117                     3 , Cartesian3d_label() , size , arg.c_str() );
00118 }
00119 
00120 //----------------------------------------------------------------------
00121 
00122 const Cylindrical & Cylindrical::tag()
00123 { static const Cylindrical self ; return self ; }
00124 
00125 const char * Cylindrical::name() const
00126 { static const char n[] = "Cylindrical" ; return n ; }
00127 
00128 namespace {
00129 const char * const * Cylindrical_label() {
00130   static const char r[] = "r" ;
00131   static const char a[] = "a" ;
00132   static const char z[] = "z" ;
00133   static const char * label[] = { r , a , z };
00134   return label;
00135 }
00136 }
00137 std::string Cylindrical::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00138 {
00139   return std::string( get_string( Cylindrical::tag().name() ,
00140                                   3 , Cylindrical_label() , size , index ) );
00141 }
00142 
00143 shards::ArrayDimTag::size_type Cylindrical::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00144 {
00145   return get_index( Cylindrical::tag().name() ,
00146                     3 , Cylindrical_label() , size , arg.c_str() );
00147 }
00148 
00149 //----------------------------------------------------------------------
00150 
00151 const FullTensor & FullTensor::tag()
00152 { static const FullTensor self ; return self ; }
00153 
00154 const char * FullTensor::name() const
00155 { static const char n[] = "FullTensor" ; return n ; }
00156 
00157 namespace {
00158 const char * const * FullTensor36_label() {
00159   static const char xx[] = "xx" ;
00160   static const char yx[] = "yx" ;
00161   static const char zx[] = "zx" ;
00162   static const char xy[] = "xy" ;
00163   static const char yy[] = "yy" ;
00164   static const char zy[] = "zy" ;
00165   static const char xz[] = "xz" ;
00166   static const char yz[] = "yz" ;
00167   static const char zz[] = "zz" ;
00168   static const char * label[] = { xx , yy , zz , 
00169                                   xy , yz , zx , 
00170                                   yx , zy , xz };
00171   return label;
00172 }
00173 }
00174 std::string FullTensor36::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00175 {
00176   return std::string( get_string( FullTensor36::tag().name() ,
00177                                   9 , FullTensor36_label() , size , index ) );
00178 }
00179 
00180 shards::ArrayDimTag::size_type FullTensor::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00181 {
00182   return get_index( FullTensor36::tag().name() ,
00183                     9 , FullTensor36_label() , size , arg.c_str() );
00184 }
00185 
00186 //----------------------------------------------------------------------
00187 
00188 const FullTensor22 & FullTensor22::tag()
00189 { static const FullTensor22 self ; return self ; }
00190 
00191 const char * FullTensor22::name() const
00192 { static const char n[] = "FullTensor22" ; return n ; }
00193 
00194 namespace {
00195 const char * const * FullTensor22_label() {
00196   static const char xx[] = "xx" ;
00197   static const char yy[] = "yy" ;
00198   static const char xy[] = "xy" ;
00199   static const char yx[] = "yx" ;
00200   static const char * label[] = { xx, yy, xy, yx };
00201   return label;
00202 }
00203 }
00204 std::string FullTensor22::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00205 {
00206   return std::string( get_string( FullTensor22::tag().name() ,
00207                                   4 , FullTensor22_label() , size , index ) );
00208 }
00209 
00210 shards::ArrayDimTag::size_type FullTensor22::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00211 {
00212   return get_index( FullTensor22::tag().name() ,
00213                     4 , FullTensor22_label() , size , arg.c_str() );
00214 }
00215 
00216 //----------------------------------------------------------------------
00217 
00218 const SymmetricTensor33 & SymmetricTensor33::tag()
00219 { static const SymmetricTensor33 self ; return self ; }
00220 
00221 const char * SymmetricTensor::name() const
00222 { static const char n[] = "SymmetricTensor" ; return n ; }
00223 
00224 namespace {
00225 const char * const * SymmetricTensor33_label() {
00226   static const char xx[] = "xx" ;
00227   static const char yy[] = "yy" ;
00228   static const char zz[] = "zz" ;
00229   static const char xy[] = "xy" ;
00230   static const char yz[] = "yz" ;
00231   static const char xz[] = "xz" ;
00232   static const char * label[] = { xx , yy , zz , xy , yz , xz };
00233   return label;
00234 }
00235 }
00236 std::string SymmetricTensor33::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00237 {
00238   return std::string( get_string( SymmetricTensor33::tag().name() ,
00239                                   6 , SymmetricTensor33_label() , size , index ) );
00240 }
00241 
00242 shards::ArrayDimTag::size_type SymmetricTensor33::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00243 {
00244   return get_index( SymmetricTensor33::tag().name() ,
00245                     6 , SymmetricTensor33_label() , size , arg.c_str() );
00246 }
00247 
00248 //----------------------------------------------------------------------
00249 
00250 const SymmetricTensor31 & SymmetricTensor31::tag()
00251 { static const SymmetricTensor31 self ; return self ; }
00252 
00253 const char * SymmetricTensor31::name() const
00254 { static const char n[] = "SymmetricTensor31" ; return n ; }
00255 
00256 namespace {
00257 const char * const * SymmetricTensor31_label() {
00258   static const char rr[] = "rr" ;
00259   static const char zz[] = "zz" ;
00260   static const char rz[] = "rz" ;
00261   static const char zr[] = "zr" ;
00262   static const char * label[] = { rr, zz, rz, zr };
00263   return label;
00264 }
00265 }
00266 std::string SymmetricTensor31::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00267 {
00268   return std::string( get_string( SymmetricTensor31::tag().name() ,
00269                                   4 , SymmetricTensor31_label() , size , index ) );
00270 }
00271 
00272 shards::ArrayDimTag::size_type SymmetricTensor31::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00273 {
00274   return get_index( SymmetricTensor31::tag().name() ,
00275                     4 , SymmetricTensor31_label() , size , arg.c_str() );
00276 }
00277 
00278 //----------------------------------------------------------------------
00279 
00280 const SymmetricTensor21 & SymmetricTensor21::tag()
00281 { static const SymmetricTensor21 self ; return self ; }
00282 
00283 const char * SymmetricTensor21::name() const
00284 { static const char n[] = "SymmetricTensor21" ; return n ; }
00285 
00286 namespace {
00287 const char * const * SymmetricTensor21_label() {
00288   static const char xx[] = "xx" ;
00289   static const char yy[] = "yy" ;
00290   static const char xy[] = "xy" ;
00291   static const char * label[] = { xx, yy, xy };
00292   return label;
00293 }
00294 }
00295 std::string SymmetricTensor21::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00296 {
00297   return std::string( get_string( SymmetricTensor21::tag().name() ,
00298                                   3 , SymmetricTensor21_label() , size , index ) );
00299 }
00300 
00301 shards::ArrayDimTag::size_type SymmetricTensor21::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00302 {
00303   return get_index( SymmetricTensor21::tag().name() ,
00304                     3 , SymmetricTensor21_label() , size , arg.c_str() );
00305 }
00306 
00307 //----------------------------------------------------------------------
00308 
00309 const AsymmetricTensor03 & AsymmetricTensor03::tag()
00310 { static const AsymmetricTensor03 self ; return self ; }
00311 
00312 const char * AsymmetricTensor03::name() const
00313 { static const char n[] = "AsymmetricTensor03" ; return n ; }
00314 
00315 namespace {
00316 const char * const * AsymmetricTensor03_label() {
00317   static const char yz[] = "yz" ;
00318   static const char xz[] = "xz" ;
00319   static const char xy[] = "xy" ;
00320   static const char * label[] = { xy, yz, xz };
00321   return label;
00322 }
00323 }
00324 std::string AsymmetricTensor03::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00325 {
00326   return std::string( get_string( AsymmetricTensor03::tag().name() ,
00327                                   3 , AsymmetricTensor03_label() , size , index ) );
00328 }
00329 
00330 shards::ArrayDimTag::size_type AsymmetricTensor03::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00331 {
00332   return get_index( AsymmetricTensor03::tag().name() ,
00333                     3 , AsymmetricTensor03_label() , size , arg.c_str() );
00334 }
00335 
00336 //----------------------------------------------------------------------
00337 
00338 const Matrix22 & Matrix22::tag()
00339 { static const Matrix22 self ; return self ; }
00340 
00341 const char * Matrix22::name() const
00342 { static const char n[] = "Matrix22" ; return n ; }
00343 
00344 namespace {
00345 const char * const * Matrix22_label() {
00346   static const char xx[] = "xx" ;
00347   static const char yx[] = "yx" ;
00348   static const char xy[] = "xy" ;
00349   static const char yy[] = "yy" ;
00350   static const char * label[] = { xx , yx, xy, yy };
00351   return label;
00352 }
00353 }
00354 std::string Matrix22::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00355 {
00356   return std::string( get_string( Matrix22::tag().name() ,
00357                                   4 , Matrix22_label() , size , index ) );
00358 }
00359 
00360 shards::ArrayDimTag::size_type Matrix22::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00361 {
00362   return get_index( Matrix22::tag().name() ,
00363                     4 , Matrix22_label() , size , arg.c_str() );
00364 }
00365 
00366 //----------------------------------------------------------------------
00367 
00368 const Matrix33 & Matrix33::tag()
00369 { static const Matrix33 self ; return self ; }
00370 
00371 const char * Matrix33::name() const
00372 { static const char n[] = "Matrix33" ; return n ; }
00373 
00374 namespace {
00375 const char * const * Matrix33_label() {
00376   static const char xx[] = "xx" ;
00377   static const char yx[] = "yx" ;
00378   static const char zx[] = "zx" ;
00379   static const char xy[] = "xy" ;
00380   static const char yy[] = "yy" ;
00381   static const char zy[] = "zy" ;
00382   static const char xz[] = "xz" ;
00383   static const char yz[] = "yz" ;
00384   static const char zz[] = "zz" ;
00385   static const char * label[] = { xx , yx , zx , xy , yy , zy , xz , yz , zz };
00386   return label;
00387 }
00388 }
00389 std::string Matrix33::to_string( shards::ArrayDimTag::size_type size , shards::ArrayDimTag::size_type index ) const
00390 {
00391   return std::string( get_string( Matrix33::tag().name() ,
00392                                   9 , Matrix33_label() , size , index ) );
00393 }
00394 
00395 shards::ArrayDimTag::size_type Matrix33::to_index( shards::ArrayDimTag::size_type size , const std::string & arg ) const
00396 {
00397   return get_index( Matrix33::tag().name() ,
00398                     9 , Matrix33_label() , size , arg.c_str() );
00399 }
00400 
00401 //----------------------------------------------------------------------
00402 
00403 } // namespace mesh
00404 } // namespace stk
00405 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines