10 #ifndef stk_mesh_Selector_hpp 11 #define stk_mesh_Selector_hpp 15 #include <stk_mesh/base/Types.hpp> 25 template<
typename PartIterator>
26 struct GetPartIterOrdinal {
27 unsigned operator()(PartIterator p_it)
const 28 {
return (*p_it)->mesh_meta_data_ordinal(); }
32 struct GetPartIterOrdinal<const unsigned*> {
33 unsigned operator()(
const unsigned* p_it)
const 38 struct GetPartIterOrdinal<unsigned*> {
39 unsigned operator()(
unsigned* p_it)
const 46 bool operator()(
unsigned lhs,
unsigned rhs)
const 55 template<
typename PartIterator,
class Compare>
56 bool part_is_present(
unsigned part_ord,
57 const std::pair<PartIterator, PartIterator>& part_range,
60 GetPartIterOrdinal<PartIterator> get_part_ordinal;
63 PartIterator p_it = std::lower_bound(part_range.first, part_range.second, part_ord, comp);
64 return (p_it != part_range.second && get_part_ordinal(p_it) == part_ord);
75 unsigned short m_unary ;
76 unsigned short m_count ;
79 OpType() : m_part_id(0), m_unary(0), m_count(0), m_op(INVALID) {}
80 OpType(
unsigned part_id ,
unsigned unary ,
unsigned count, Op op=INVALID )
81 : m_part_id( part_id ), m_unary( unary ), m_count(
count ), m_op(op) {}
83 bool operator == (
const OpType & opType )
const 85 return m_part_id == opType.m_part_id &&
86 m_unary == opType.m_unary &&
87 m_count == opType.m_count &&
90 bool operator != (
const OpType & opType )
const 91 {
return !(*
this == opType); }
117 bool operator == (
const Selector & rhs)
const 118 {
return m_op == rhs.m_op; }
120 bool operator != (
const Selector & rhs)
const 121 {
return m_op != rhs.m_op; }
164 template<
typename PartIterator,
class Compare>
165 bool apply(
const std::pair<PartIterator,PartIterator>& part_range, Compare comp)
const 166 {
return apply(m_op.begin(), m_op.end(), part_range, comp); }
173 const std::vector<OpType>& get_ops()
const {
return m_op; }
174 void set_ops(
const std::vector<OpType>& ops) { m_op = ops; }
182 const MetaData * m_mesh_meta_data ;
185 std::vector< OpType > m_op ;
188 void verify_compatible(
const Selector & B )
const;
191 void verify_compatible(
const Bucket & B )
const;
194 template<
typename PartIterator,
class Compare>
196 std::vector<OpType>::const_iterator i,
197 std::vector<OpType>::const_iterator j,
198 const std::pair<PartIterator,PartIterator>& part_range,
201 bool result = i != j ;
202 while ( result && i != j ) {
203 const unsigned statement_length = i->m_count;
204 if ( statement_length > 0 ) {
205 result = i->m_unary ^
apply( i + 1 , i + statement_length , part_range , comp );
206 i += statement_length;
209 result = i->m_unary ^ part_is_present( i->m_part_id , part_range , comp );
217 std::string printExpression(
218 const std::vector<OpType>::const_iterator start,
219 const std::vector<OpType>::const_iterator finish
227 std::ostream &
operator<<( std::ostream & out,
const Selector & selector);
233 Selector operator & (
const Part & A ,
const Part & B );
238 Selector operator & (
const Part & A ,
const Selector & B );
243 Selector operator & (
const Selector & A,
const Part & B );
248 Selector operator & (
const Selector & A,
const Selector & B );
253 Selector operator | (
const Part & A ,
const Part & B );
258 Selector operator | (
const Part & A ,
const Selector & B );
263 Selector operator | (
const Selector & A,
const Part & B );
268 Selector operator | (
const Selector & A ,
const Selector & B );
273 Selector operator ! (
const Part & A );
279 Selector selectUnion(
const PartVector& union_part_vector );
284 Selector selectIntersection(
const PartVector& intersection_part_vector );
289 Selector selectField(
const FieldBase& field );
296 #endif // stk_mesh_Selector_hpp Selector & operator&=(const Selector &selector)
Intersection: this = this INTERSECT ( expression )
friend std::ostream & operator<<(std::ostream &out, const Selector &selector)
Pretty print the set-expression with part names.
Selector & complement()
Complement: this = !(this) Postcondition: this is a compound expression.
This is a class for selecting buckets based on a set of meshparts and set logic.
Selector()
A default Selector selects nothing.
An application-defined subset of a problem domain.
Selector operator!() const
Complement: return !(this)
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Selector & operator|=(const Selector &selector)
Union: this = this UNION ( expression )
A fundamental unit within the discretization of a problem domain, including but not limited to nodes...
bool apply(const std::pair< PartIterator, PartIterator > &part_range, Compare comp) const
Is the intersection of the 'part_ords' parts a member of the set defined by the selector expression...
void compoundAll()
Turn the entire expression into a compound.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
A container for the field data of a homogeneous collection of entities.
bool operator()(const Part &part) const
Is this part a member of the set defined by the selector expression.
eastl::iterator_traits< InputIterator >::difference_type count(InputIterator first, InputIterator last, const T &value)