10 #ifndef stk_mesh_base_FindRestriction_hpp 11 #define stk_mesh_base_FindRestriction_hpp 13 #include <stk_mesh/base/Types.hpp> 14 #include <stk_mesh/base/FieldBase.hpp> 15 #include <stk_mesh/base/FieldRestriction.hpp> 16 #include <stk_mesh/base/Selector.hpp> 23 const FieldBase::Restriction & empty_field_restriction()
26 static const FieldBase::Restriction empty ;
34 template<
typename PartIterator,
class Compare>
35 const FieldBase::Restriction& find_restriction(
const FieldBase& field,
41 GetPartIterOrdinal<PartIterator> get_part_ordinal;
43 const FieldBase::Restriction & empty = empty_field_restriction();
44 const FieldBase::Restriction * restriction = & empty ;
46 const std::vector<FieldBase::Restriction> & restr_vec = field.restrictions();
47 const std::vector<FieldBase::Restriction>::const_iterator iend = restr_vec.end();
48 std::vector<FieldBase::Restriction>::const_iterator ibeg = restr_vec.begin();
51 static FieldRestriction restr;
53 for ( PartIterator it = pbegin; it != pend && iend != ibeg ; ++it ) {
55 restr.set_entity_rank(erank);
56 restr.set_part_ordinal(get_part_ordinal(it));
65 ibeg = std::lower_bound( ibeg , iend , restr );
67 if ( (iend != ibeg) && (*ibeg == restr) ) {
68 if ( restriction == & empty ) { restriction = & *ibeg ; }
70 if ( ibeg->not_equal_stride(*restriction) ) {
72 Part & p_old = MetaData::get(field).get_part( ibeg->part_ordinal() );
73 Part & p_new = MetaData::get(field).get_part( restriction->part_ordinal() );
75 std::ostringstream msg ;
76 msg <<
" FAILED WITH INCOMPATIBLE DIMENSIONS FOR " ;
78 msg <<
" Part[" << p_old.name() ;
79 msg <<
"] and Part[" << p_new.name() ;
82 ThrowErrorMsg( msg.str() );
87 const std::vector<FieldBase::Restriction> & sel_res = field.selector_restrictions();
88 std::pair<PartIterator,PartIterator> part_range = std::make_pair(pbegin, pend);
89 for(std::vector<FieldBase::Restriction>::const_iterator it=sel_res.begin(), it_end=sel_res.end(); it != it_end; ++it) {
90 const Selector& selector = it->selector();
91 if (it->entity_rank() == erank && selector.apply(part_range, comp)) {
92 if (restriction == &empty) {
95 if (it->not_equal_stride(*restriction)) {
96 ThrowErrorMsg(
"find_restriction calculation failed with different field-restriction selectors giving incompatible sizes.");
101 return *restriction ;
107 #endif // stk_mesh_base_FindRestriction_hpp