SundanceEvaluator.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_EVALUATOR_H
00043 #define SUNDANCE_EVALUATOR_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "Teuchos_RefCountPtr.hpp"
00047 #include "SundanceEvalVector.hpp"
00048 #include "SundanceObjectWithVerbosity.hpp"
00049 #include "SundanceSparsitySuperset.hpp"
00050 #include "SundanceSparsitySubset.hpp"
00051 #include "SundanceSet.hpp"
00052 #include "SundanceMultiIndex.hpp"
00053 #include "PlayaTabs.hpp"
00054 #include "SundanceOut.hpp"
00055 
00056 namespace Sundance 
00057 {
00058 class CoordExpr;
00059 
00060 class EvalContext;
00061   
00062 
00063 
00064 class EvalManager;
00065 
00066 /**
00067  * Base class for evaluator objects. Each EvaluatableExpr type will 
00068  * have an associated Evaluator subtype.
00069  */
00070 class Evaluator : public ObjectWithClassVerbosity<Evaluator>
00071 {
00072 public:
00073   /** */
00074   Evaluator();
00075 
00076   /** */
00077   virtual ~Evaluator(){;}
00078 
00079   /** 
00080    * Client-level evaluation method. Computes new results on the
00081    * first call, makes copies on subsequent calls up to the last client, 
00082    * and finally returns the original result vector upon the 
00083    * last client's call. 
00084    */
00085   void eval(const EvalManager& mgr,
00086     Array<double>& constantResults,
00087     Array<RCP<EvalVector> >& vectorResults) const ;
00088 
00089   /** Reset the number of calls to zero. This should be called
00090    * at the beginning of every new evaluation cycle. */
00091   virtual void resetNumCalls() const {numCalls_=0;}
00092 
00093   /** */
00094   virtual void 
00095   internalEval(const EvalManager& mgr,
00096     Array<double>& constantResults,
00097     Array<RCP<EvalVector> >& vectorResults) const = 0 ;
00098 
00099   /** Add one to the number of clients. */
00100   void addClient() {numClients_++;}
00101 
00102   /** */
00103   void addConstantIndex(int index, int constantIndex);
00104 
00105   /** */
00106   void addVectorIndex(int index, int vectorIndex);
00107 
00108       
00109 
00110   /** */
00111   const Sundance::Map<int, int>& constantIndexMap() const 
00112     {return constantIndexMap_;}
00113 
00114   /** */
00115   const Sundance::Map<int, int>& vectorIndexMap() const 
00116     {return vectorIndexMap_;}
00117 protected:
00118 
00119   /** Return the number of clients that will require results
00120    * from this evaluator */
00121   int numClients() const {return numClients_;}
00122 
00123   /** */
00124   bool isOne(int x) const {return x==1;}
00125 
00126   /** */
00127   bool isOne(const double& x) const {return isZero(x-1.0);}
00128 
00129   /** */
00130   bool isZero(const double& x) const {return fabs(x-0.0)<1.0e-15;}
00131 
00132   /** */
00133   const Array<int>& constantIndices() const {return constantIndices_;}
00134 
00135   /** */
00136   const Array<int>& vectorIndices() const {return vectorIndices_;}
00137 
00138 
00139 private:
00140   int numClients_;
00141 
00142   mutable int numCalls_;
00143 
00144   mutable Array<RCP<EvalVector> > vectorResultCache_;
00145 
00146   mutable Array<double> constantResultCache_;
00147 
00148   Sundance::Map<int, int> constantIndexMap_;
00149 
00150   Sundance::Map<int, int> vectorIndexMap_;
00151 
00152   Array<int> vectorIndices_;
00153 
00154   Array<int> constantIndices_;
00155 };
00156 
00157 
00158     
00159 
00160 }
00161 
00162 #endif

Site Contact