SundanceEvaluator.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_EVALUATOR_H
00032 #define SUNDANCE_EVALUATOR_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "Teuchos_RefCountPtr.hpp"
00036 #include "SundanceEvalVector.hpp"
00037 #include "SundanceObjectWithVerbosity.hpp"
00038 #include "SundanceSparsitySuperset.hpp"
00039 #include "SundanceSparsitySubset.hpp"
00040 #include "SundanceSet.hpp"
00041 #include "SundanceMultiIndex.hpp"
00042 #include "PlayaTabs.hpp"
00043 #include "SundanceOut.hpp"
00044 
00045 namespace Sundance 
00046 {
00047 class CoordExpr;
00048 
00049 class EvalContext;
00050   
00051 
00052 
00053 class EvalManager;
00054 
00055 /**
00056  * Base class for evaluator objects. Each EvaluatableExpr type will 
00057  * have an associated Evaluator subtype.
00058  */
00059 class Evaluator : public ObjectWithClassVerbosity<Evaluator>
00060 {
00061 public:
00062   /** */
00063   Evaluator();
00064 
00065   /** */
00066   virtual ~Evaluator(){;}
00067 
00068   /** 
00069    * Client-level evaluation method. Computes new results on the
00070    * first call, makes copies on subsequent calls up to the last client, 
00071    * and finally returns the original result vector upon the 
00072    * last client's call. 
00073    */
00074   void eval(const EvalManager& mgr,
00075     Array<double>& constantResults,
00076     Array<RCP<EvalVector> >& vectorResults) const ;
00077 
00078   /** Reset the number of calls to zero. This should be called
00079    * at the beginning of every new evaluation cycle. */
00080   virtual void resetNumCalls() const {numCalls_=0;}
00081 
00082   /** */
00083   virtual void 
00084   internalEval(const EvalManager& mgr,
00085     Array<double>& constantResults,
00086     Array<RCP<EvalVector> >& vectorResults) const = 0 ;
00087 
00088   /** Add one to the number of clients. */
00089   void addClient() {numClients_++;}
00090 
00091   /** */
00092   void addConstantIndex(int index, int constantIndex);
00093 
00094   /** */
00095   void addVectorIndex(int index, int vectorIndex);
00096 
00097       
00098 
00099   /** */
00100   const Sundance::Map<int, int>& constantIndexMap() const 
00101     {return constantIndexMap_;}
00102 
00103   /** */
00104   const Sundance::Map<int, int>& vectorIndexMap() const 
00105     {return vectorIndexMap_;}
00106 protected:
00107 
00108   /** Return the number of clients that will require results
00109    * from this evaluator */
00110   int numClients() const {return numClients_;}
00111 
00112   /** */
00113   bool isOne(int x) const {return x==1;}
00114 
00115   /** */
00116   bool isOne(const double& x) const {return isZero(x-1.0);}
00117 
00118   /** */
00119   bool isZero(const double& x) const {return fabs(x-0.0)<1.0e-15;}
00120 
00121   /** */
00122   const Array<int>& constantIndices() const {return constantIndices_;}
00123 
00124   /** */
00125   const Array<int>& vectorIndices() const {return vectorIndices_;}
00126 
00127 
00128 private:
00129   int numClients_;
00130 
00131   mutable int numCalls_;
00132 
00133   mutable Array<RCP<EvalVector> > vectorResultCache_;
00134 
00135   mutable Array<double> constantResultCache_;
00136 
00137   Sundance::Map<int, int> constantIndexMap_;
00138 
00139   Sundance::Map<int, int> vectorIndexMap_;
00140 
00141   Array<int> vectorIndices_;
00142 
00143   Array<int> constantIndices_;
00144 };
00145 
00146 
00147     
00148 
00149 }
00150 
00151 #endif

Site Contact