Sierra Toolkit  Version of the Day
AlgorithmRunner.cpp
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 #include <stdexcept>
11 
12 #include <stk_mesh/base/Bucket.hpp>
13 #include <stk_mesh/base/BulkData.hpp>
14 #include <stk_algsup/AlgorithmRunner.hpp>
15 
16 namespace stk_classic {
17 
18 //----------------------------------------------------------------------
19 
20 AlgorithmInterface::~AlgorithmInterface(){}
21 
22 //----------------------------------------------------------------------
23 
24 void AlgorithmInterface::apply_one(
25  const mesh::Selector & selector ,
26  const mesh::PartVector & union_part_vector ,
27  const mesh::Bucket & bucket ,
28  void * reduce ) const
29 {
30  mesh::PartVector parts ;
31 
32  const bool run_it = selector( bucket );
33  get_involved_parts( union_part_vector, bucket, parts );
34 
35  if ( run_it ) {
36  if ( 0 < m_maximum_entity_count ) {
37  for ( mesh::Bucket::iterator j = bucket.begin(); j != bucket.end() ; ) {
38  mesh::Bucket::iterator e = j ;
39  if ( static_cast<ptrdiff_t>( bucket.end() - e ) < static_cast<ptrdiff_t>(m_maximum_entity_count) ) {
40  e = bucket.end();
41  }
42  else {
43  e += m_maximum_entity_count ;
44  }
45  apply( j , e , parts , reduce );
46  j = e ;
47  }
48  }
49  else {
50  apply( bucket.begin() , bucket.end() , parts , reduce );
51  }
52  }
53 }
54 
55 //void AlgorithmInterface::apply_one(
56 // const mesh::Selector & selector ,
57 // const mesh::Bucket & bucket ,
58 // void * reduce ) const
59 //{
60 // const mesh::PartVector empty_union_part_vector;
61 // apply_one(selector,empty_union_part_vector,bucket,reduce);
62 //}
63 
64 //----------------------------------------------------------------------
65 
66 namespace {
67 
68 class AlgorithmRunnerNonThread : public AlgorithmRunnerInterface {
69 public:
70 
71  void run_alg( const mesh::Selector & selector,
72  const mesh::PartVector & union_parts ,
73  const std::vector< mesh::Bucket * > & buckets,
74  const AlgorithmInterface & algorithm,
75  void * reduce ) const ;
76 
77  AlgorithmRunnerNonThread() {}
78  ~AlgorithmRunnerNonThread() {}
79 };
80 
81 void AlgorithmRunnerNonThread::run_alg(
82  const mesh::Selector & selector ,
83  const mesh::PartVector & union_parts ,
84  const std::vector< mesh::Bucket * > & buckets ,
85  const AlgorithmInterface & algorithm ,
86  void * reduce ) const
87 {
88  for ( std::vector< mesh::Bucket * >::const_iterator
89  i = buckets.begin() ; i != buckets.end() ; ++i ) {
90  algorithm.apply_one( selector , union_parts, **i , reduce );
91  }
92 }
93 
94 }
95 
96 //----------------------------------------------------------------------
97 
98 AlgorithmRunnerInterface * algorithm_runner_non_thread()
99 {
100  static AlgorithmRunnerNonThread runner ;
101  return & runner ;
102 }
103 
104 } // namespace stk_classic
105 
106 
AlgorithmRunnerInterface * algorithm_runner_non_thread()
This is a class for selecting buckets based on a set of meshparts and set logic.
Definition: Selector.hpp:112
iterator begin() const
Beginning of the bucket.
Definition: Bucket.hpp:113
iterator end() const
End of the bucket.
Definition: Bucket.hpp:116
Sierra Toolkit.
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31
A container for the field data of a homogeneous collection of entities.
Definition: Bucket.hpp:94