Sierra Toolkit Version of the Day
AlgorithmRunner.cpp
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 #include <stdexcept>
00011 
00012 #include <stk_mesh/base/Bucket.hpp>
00013 #include <stk_mesh/base/BulkData.hpp>
00014 #include <stk_algsup/AlgorithmRunner.hpp>
00015 
00016 namespace stk {
00017 
00018 //----------------------------------------------------------------------
00019 
00020 AlgorithmInterface::~AlgorithmInterface(){}
00021 
00022 //----------------------------------------------------------------------
00023 
00024 void AlgorithmInterface::apply_one(
00025   const mesh::Selector          & selector ,
00026   const mesh::PartVector & union_part_vector ,
00027   const mesh::Bucket            & bucket ,
00028   void                          * reduce ) const
00029 {
00030   mesh::PartVector parts ;
00031 
00032   const bool run_it = selector( bucket );
00033   get_involved_parts( union_part_vector, bucket, parts );
00034 
00035   if ( run_it ) {
00036     if ( 0 < m_maximum_entity_count ) {
00037       for ( mesh::Bucket::iterator j = bucket.begin(); j != bucket.end() ; ) {
00038         mesh::Bucket::iterator e = j ;
00039         if ( static_cast<ptrdiff_t>( bucket.end() - e ) < static_cast<ptrdiff_t>(m_maximum_entity_count) ) {
00040           e = bucket.end();
00041         }
00042         else {
00043           e += m_maximum_entity_count ;
00044         }
00045         apply( j , e , parts , reduce );
00046         j = e ;
00047       }
00048     }
00049     else {
00050       apply( bucket.begin() , bucket.end() , parts , reduce );
00051     }
00052   }
00053 }
00054 
00055 //void AlgorithmInterface::apply_one(
00056 //  const mesh::Selector          & selector ,
00057 //  const mesh::Bucket            & bucket ,
00058 //  void                          * reduce ) const
00059 //{
00060 //  const mesh::PartVector empty_union_part_vector;
00061 //  apply_one(selector,empty_union_part_vector,bucket,reduce);
00062 //}
00063 
00064 //----------------------------------------------------------------------
00065 
00066 namespace {
00067 
00068 class AlgorithmRunnerNonThread : public AlgorithmRunnerInterface {
00069 public:
00070  
00071   void run_alg( const mesh::Selector          & selector,
00072                 const mesh::PartVector & union_parts ,
00073                 const std::vector< mesh::Bucket * > & buckets,
00074                 const AlgorithmInterface & algorithm,
00075                 void * reduce ) const ;
00076  
00077   AlgorithmRunnerNonThread() {}
00078   ~AlgorithmRunnerNonThread() {}
00079 };
00080 
00081 void AlgorithmRunnerNonThread::run_alg(
00082   const mesh::Selector                 & selector ,
00083   const mesh::PartVector               & union_parts ,
00084   const std::vector< mesh::Bucket * >  & buckets ,
00085   const AlgorithmInterface             & algorithm ,
00086   void                                 * reduce ) const
00087 {
00088   for ( std::vector< mesh::Bucket * >::const_iterator
00089         i = buckets.begin() ; i != buckets.end() ; ++i ) {
00090     algorithm.apply_one( selector , union_parts, **i , reduce );
00091   }
00092 }
00093 
00094 }
00095 
00096 //----------------------------------------------------------------------
00097 
00098 AlgorithmRunnerInterface * algorithm_runner_non_thread()
00099 {
00100   static AlgorithmRunnerNonThread runner ;
00101   return & runner ;
00102 }
00103 
00104 } // namespace stk
00105 
00106 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends