SundanceUnaryEvaluator.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_UNARYEVALUATOR_H
00032 #define SUNDANCE_UNARYEVALUATOR_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSubtypeEvaluator.hpp"
00036 #include "SundanceEvaluatableExpr.hpp"
00037 
00038 
00039 namespace Sundance 
00040 {
00041 class EvalContext;
00042 
00043 
00044 /**
00045  * 
00046  */
00047 template <class ExprType> class UnaryEvaluator 
00048   : public SubtypeEvaluator<ExprType>
00049 {
00050 public:
00051   /** */
00052   UnaryEvaluator(const ExprType* expr,
00053     const EvalContext& context)
00054     : SubtypeEvaluator<ExprType>(expr, context),
00055       argExpr_(expr->evaluatableArg()),
00056       argSparsitySuperset_(argExpr_->sparsitySuperset(context)),
00057       argEval_(argExpr_->evaluator(context))
00058     {
00059       try
00060       {
00061         Tabs tab;
00062 
00063         SUNDANCE_MSG3(this->verb(), tab << "UnaryEvaluator ctor: expr = " << expr->toString());
00064 
00065         SUNDANCE_MSG3(this->verb(), tab << "arg sparsity superset maxOrder: " 
00066           << argSparsitySuperset_->maxOrder());
00067             
00068         argEval_->addClient();
00069             
00070         SUNDANCE_MSG3(this->verb(), tab << "done unary evalulator ctor");
00071       }
00072       catch(std::exception& e)
00073       {
00074         TEST_FOR_EXCEPTION(true, RuntimeError, 
00075           "exception detected in UnaryEvaluator: expr="
00076           << expr->toString() << std::endl
00077           << "arg=" << expr->evaluatableArg()->toString() << std::endl
00078           << "exception=" << e.what());
00079       }
00080     }
00081 
00082   /** */
00083   virtual ~UnaryEvaluator(){;}
00084 
00085   /** */
00086   virtual void resetNumCalls() const 
00087     {
00088       argEval_->resetNumCalls();
00089       Evaluator::resetNumCalls();
00090     }
00091 
00092 protected:
00093 
00094   /** */
00095   const RCP<SparsitySuperset>& argSparsitySuperset() const 
00096     {return argSparsitySuperset_;}
00097       
00098   /** */
00099   const EvaluatableExpr* argExpr() const {return argExpr_;}
00100 
00101   /** */
00102   const RCP<Evaluator>& argEval() const {return argEval_;}
00103       
00104 
00105   /** */
00106   void evalOperand(const EvalManager& mgr,
00107     Array<double>& argConstantResults,
00108     Array<RCP<EvalVector> >& argVectorResults) const 
00109     {
00110       Tabs tabs;
00111       SUNDANCE_MSG1(this->verb(),  tabs << "UnaryEvaluator: evaluating operand: ");
00112       argEval()->eval(mgr, argConstantResults, argVectorResults);
00113       SUNDANCE_MSG1(this->verb(),  tabs << "UnaryEvaluator: done eval operand ");
00114     }
00115 private:
00116   const EvaluatableExpr* argExpr_;
00117 
00118   RCP<SparsitySuperset> argSparsitySuperset_;
00119 
00120   RCP<Evaluator> argEval_;
00121 };
00122 }
00123 
00124 #endif

Site Contact