FieldBase.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 
00009 #include <cstring>
00010 #include <iostream>
00011 #include <sstream>
00012 
00013 #include <stk_mesh/base/FieldBase.hpp>
00014 #include <stk_mesh/base/MetaData.hpp>
00015 
00016 namespace stk {
00017 namespace mesh {
00018 
00019 FieldBase::~FieldBase()
00020 {}
00021 
00022 
00023 namespace {
00024 
00025 void print_restriction( std::ostream & os ,
00026                         unsigned type ,
00027                         const Part & part ,
00028                         unsigned rank ,
00029                         const FieldRestriction::size_type * stride )
00030 {
00031   os << "{ entity_rank(" << type << ") part(" << part.name() << ") : " ;
00032   os << stride[0] ;
00033   for ( unsigned i = 1 ; i < rank ; ++i ) {
00034     if ( ! stride[i] ) {
00035       os << " , 0 " ;
00036     }
00037     else if ( stride[i] % stride[i-1] ) {
00038       os << " , " << stride[i] << " / " << stride[i-1] ;
00039     }
00040     else {
00041       os << " , " << stride[i] / stride[i-1] ;
00042     }
00043   }
00044   os << " }" ;
00045 }
00046 
00047 }
00048 
00049 
00050 std::ostream & operator << ( std::ostream & s , const FieldBase & field )
00051 {
00052   s << "FieldBase<" ;
00053   s << field.data_traits().name ;
00054   for ( unsigned i = 0 ; i < field.rank() ; ++i ) {
00055     s << "," << field.dimension_tags()[i]->name();
00056   }
00057   s << ">" ;
00058 
00059   s << "[ name = \"" ;
00060   s << field.name() ;
00061   s << "\" , #states = " ;
00062   s << field.number_of_states();
00063   s << " ]" ;
00064   return s ;
00065 }
00066 
00067 std::ostream & print( std::ostream & s ,
00068                       const char * const b ,
00069                       const FieldBase & field )
00070 {
00071   const PartVector & all_parts = field.mesh_meta_data().get_parts();
00072   const std::vector<FieldBase::Restriction> & rMap = field.restrictions();
00073   s << field ;
00074   s << " {" ;
00075   for ( std::vector<FieldBase::Restriction>::const_iterator
00076         i = rMap.begin() ; i != rMap.end() ; ++i ) {
00077     s << std::endl << b << "  " ;
00078     print_restriction( s, entity_rank( i->key ),
00079                        * all_parts[ entity_id( i->key ) ],
00080                        field.rank(), i->stride);
00081   }
00082   s << std::endl << b << "}" ;
00083   return s ;
00084 }
00085 
00086 //----------------------------------------------------------------------
00087 
00088 } // namespace mesh
00089 } // namespace stk
00090 
Generated on Wed Apr 13 10:05:48 2011 for Sierra Toolkit by  doxygen 1.6.3