Sierra Toolkit Version of the Day
FieldRestriction.hpp
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 
00010 #ifndef stk_mesh_baseImpl_FieldRestriction_hpp
00011 #define stk_mesh_baseImpl_FieldRestriction_hpp
00012 
00013 #include <vector>
00014 #include <Shards_Array.hpp>
00015 #include <stk_mesh/base/Types.hpp>
00016 #include <stk_mesh/base/EntityKey.hpp>
00017 #include <stk_mesh/base/Selector.hpp>
00018 
00019 #include <stk_util/util/SimpleArrayOps.hpp>
00020 
00021 namespace stk {
00022 namespace mesh {
00023 
00031 class FieldRestriction {
00032   public:
00033 
00034   typedef shards::array_traits::int_t size_type ;
00035 
00036   FieldRestriction()
00037     : m_entityrank_partordinal(InvalidEntityRank,InvalidPartOrdinal),
00038       m_selector()
00039   {
00040     Copy<MaximumFieldDimension>( m_stride , size_type(0) );
00041   }
00042 
00043   FieldRestriction( const FieldRestriction & rhs )
00044     : m_entityrank_partordinal( rhs.m_entityrank_partordinal ),
00045       m_selector( rhs.m_selector )
00046   {
00047     Copy< MaximumFieldDimension >( m_stride , rhs.m_stride );
00048   }
00049 
00050   FieldRestriction & operator = ( const FieldRestriction & rhs )
00051   {
00052     m_entityrank_partordinal = rhs.m_entityrank_partordinal ;
00053     m_selector = rhs.m_selector;
00054     Copy< MaximumFieldDimension >( m_stride , rhs.m_stride );
00055     return *this ;
00056   }
00057 
00058   FieldRestriction( EntityRank input_rank , PartOrdinal input_ordinal)
00059     : m_entityrank_partordinal( input_rank, input_ordinal ),
00060       m_selector()
00061   {
00062     Copy< MaximumFieldDimension >( m_stride , size_type(0) );
00063   }
00064 
00065   FieldRestriction( EntityRank input_rank, const Selector& input_selector)
00066    : m_entityrank_partordinal( input_rank, InvalidPartOrdinal ),
00067      m_selector(input_selector)
00068   {
00069   }
00070 
00071   void set_entity_rank(EntityRank ent_rank) { m_entityrank_partordinal.first = ent_rank; }
00072 
00073   EntityRank entity_rank() const
00074   {
00075     return m_entityrank_partordinal.first;
00076   }
00077 
00078   void set_part_ordinal(PartOrdinal ord) { m_entityrank_partordinal.second = ord; }
00079 
00080   PartOrdinal part_ordinal() const
00081   {
00082     return m_entityrank_partordinal.second;
00083   }
00084 
00085   const Selector& selector() const
00086   {
00087     return m_selector;
00088   }
00089 
00090   size_type & stride( Ordinal index ) { return m_stride[index]; }
00091   const size_type & stride( Ordinal index ) const { return m_stride[index]; }
00092 
00093   size_type dimension() const { return m_stride[0]; }
00094 
00095   bool operator < ( const FieldRestriction & rhs ) const
00096   {
00097     return this->m_entityrank_partordinal < rhs.m_entityrank_partordinal;
00098   }
00099   bool operator == ( const FieldRestriction & rhs ) const
00100   {
00101     return this->m_entityrank_partordinal == rhs.m_entityrank_partordinal &&
00102            this->m_selector == rhs.m_selector;
00103   }
00104   bool operator != ( const FieldRestriction & rhs ) const
00105   {
00106     return this->m_entityrank_partordinal != rhs.m_entityrank_partordinal ||
00107            this->m_selector != rhs.m_selector;
00108   }
00109 
00110   bool not_equal_stride( const FieldRestriction & rhs ) const
00111   {
00112     return Compare< MaximumFieldDimension >::not_equal( this->m_stride , rhs.m_stride );
00113   }
00114 
00115   void print(
00116       std::ostream & os,
00117       const EntityRank & entity_rank,
00118       const Part & part,
00119       FieldArrayRank field_rank
00120       ) const;
00121 
00122   private:
00123   std::pair<EntityRank,PartOrdinal> m_entityrank_partordinal;
00124   Selector m_selector;
00125   size_type m_stride[ MaximumFieldDimension ];
00126 };
00127 
00128 typedef std::vector<FieldRestriction> FieldRestrictionVector;
00129 
00130 std::string print_restriction(
00131     const FieldRestriction & restr,
00132     const EntityRank & entity_rank,
00133     const Part & part,
00134     FieldArrayRank field_rank
00135     );
00136 
00137 } // namespace mesh
00138 } // namespace stk
00139 
00140 #endif // stk_mesh_baseImpl_FieldRestriction_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines