Sierra Toolkit  Version of the Day
FieldRestriction.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 
10 #ifndef stk_mesh_baseImpl_FieldRestriction_hpp
11 #define stk_mesh_baseImpl_FieldRestriction_hpp
12 
13 #include <vector>
14 #include <Shards_Array.hpp>
15 #include <stk_mesh/base/Types.hpp>
16 #include <stk_mesh/base/EntityKey.hpp>
17 #include <stk_mesh/base/Selector.hpp>
18 
19 #include <stk_util/util/SimpleArrayOps.hpp>
20 
21 namespace stk_classic {
22 namespace mesh {
23 
32  public:
33 
34  typedef shards::array_traits::int_t size_type ;
35 
37  : m_entityrank_partordinal(InvalidEntityRank,InvalidPartOrdinal),
38  m_selector()
39  {
40  Copy<MaximumFieldDimension>( m_stride , size_type(0) );
41  }
42 
43  FieldRestriction( const FieldRestriction & rhs )
44  : m_entityrank_partordinal( rhs.m_entityrank_partordinal ),
45  m_selector( rhs.m_selector )
46  {
47  Copy< MaximumFieldDimension >( m_stride , rhs.m_stride );
48  }
49 
50  FieldRestriction & operator = ( const FieldRestriction & rhs )
51  {
52  m_entityrank_partordinal = rhs.m_entityrank_partordinal ;
53  m_selector = rhs.m_selector;
54  Copy< MaximumFieldDimension >( m_stride , rhs.m_stride );
55  return *this ;
56  }
57 
58  FieldRestriction( EntityRank input_rank , PartOrdinal input_ordinal)
59  : m_entityrank_partordinal( input_rank, input_ordinal ),
60  m_selector()
61  {
62  Copy< MaximumFieldDimension >( m_stride , size_type(0) );
63  }
64 
65  FieldRestriction( EntityRank input_rank, const Selector& input_selector)
66  : m_entityrank_partordinal( input_rank, InvalidPartOrdinal ),
67  m_selector(input_selector)
68  {
69  }
70 
71  void set_entity_rank(EntityRank ent_rank) { m_entityrank_partordinal.first = ent_rank; }
72 
73  EntityRank entity_rank() const
74  {
75  return m_entityrank_partordinal.first;
76  }
77 
78  void set_part_ordinal(PartOrdinal ord) { m_entityrank_partordinal.second = ord; }
79 
80  PartOrdinal part_ordinal() const
81  {
82  return m_entityrank_partordinal.second;
83  }
84 
85  const Selector& selector() const
86  {
87  return m_selector;
88  }
89 
90  size_type & stride( Ordinal index ) { return m_stride[index]; }
91  const size_type & stride( Ordinal index ) const { return m_stride[index]; }
92 
93  size_type dimension() const { return m_stride[0]; }
94 
95  bool operator < ( const FieldRestriction & rhs ) const
96  {
97  return this->m_entityrank_partordinal < rhs.m_entityrank_partordinal;
98  }
99  bool operator == ( const FieldRestriction & rhs ) const
100  {
101  return this->m_entityrank_partordinal == rhs.m_entityrank_partordinal &&
102  this->m_selector == rhs.m_selector;
103  }
104  bool operator != ( const FieldRestriction & rhs ) const
105  {
106  return this->m_entityrank_partordinal != rhs.m_entityrank_partordinal ||
107  this->m_selector != rhs.m_selector;
108  }
109 
110  bool not_equal_stride( const FieldRestriction & rhs ) const
111  {
112  return Compare< MaximumFieldDimension >::not_equal( this->m_stride , rhs.m_stride );
113  }
114 
115  void print(
116  std::ostream & os,
117  const EntityRank & entity_rank,
118  const Part & part,
119  FieldArrayRank field_rank
120  ) const;
121 
122  private:
123  std::pair<EntityRank,PartOrdinal> m_entityrank_partordinal;
124  Selector m_selector;
125  size_type m_stride[ MaximumFieldDimension ];
126 };
127 
128 typedef std::vector<FieldRestriction> FieldRestrictionVector;
129 
130 std::string print_restriction(
131  const FieldRestriction & restr,
132  const EntityRank & entity_rank,
133  const Part & part,
134  FieldArrayRank field_rank
135  );
136 
137 } // namespace mesh
138 } // namespace stk_classic
139 
140 #endif // stk_mesh_baseImpl_FieldRestriction_hpp
This is a class for selecting buckets based on a set of meshparts and set logic.
Definition: Selector.hpp:112
An application-defined subset of a problem domain.
Definition: Part.hpp:49
Sierra Toolkit.
EntityRank entity_rank(const EntityKey &key)
Given an entity key, return an entity type (rank).