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         int verb = context.evalSetupVerbosity();
00063 
00064         SUNDANCE_MSG2(verb, tab << "UnaryEvaluator ctor: expr = " << expr->toString());
00065 
00066         SUNDANCE_MSG2(verb, tab << "arg sparsity superset maxOrder: " 
00067           << argSparsitySuperset_->maxOrder());
00068             
00069         argEval_->addClient();
00070             
00071         SUNDANCE_MSG2(verb, tab << "done unary evalulator ctor");
00072       }
00073       catch(std::exception& e)
00074       {
00075         TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error, 
00076           "exception detected in UnaryEvaluator: expr="
00077           << expr->toString() << std::endl
00078           << "arg=" << expr->evaluatableArg()->toString() << std::endl
00079           << "exception=" << e.what());
00080       }
00081     }
00082 
00083   /** */
00084   virtual ~UnaryEvaluator(){;}
00085 
00086   /** */
00087   virtual void resetNumCalls() const 
00088     {
00089       argEval_->resetNumCalls();
00090       Evaluator::resetNumCalls();
00091     }
00092 
00093 protected:
00094 
00095   /** */
00096   const RCP<SparsitySuperset>& argSparsitySuperset() const 
00097     {return argSparsitySuperset_;}
00098       
00099   /** */
00100   const EvaluatableExpr* argExpr() const {return argExpr_;}
00101 
00102   /** */
00103   const RCP<Evaluator>& argEval() const {return argEval_;}
00104       
00105 
00106   /** */
00107   void evalOperand(const EvalManager& mgr,
00108     Array<double>& argConstantResults,
00109     Array<RCP<EvalVector> >& argVectorResults) const 
00110     {
00111       Tabs tabs;
00112       SUNDANCE_MSG1(this->verb(),  tabs << "UnaryEvaluator: evaluating operand: ");
00113       argEval()->eval(mgr, argConstantResults, argVectorResults);
00114       SUNDANCE_MSG1(this->verb(),  tabs << "UnaryEvaluator: done eval operand ");
00115     }
00116 private:
00117   const EvaluatableExpr* argExpr_;
00118 
00119   RCP<SparsitySuperset> argSparsitySuperset_;
00120 
00121   RCP<Evaluator> argEval_;
00122 };
00123 }
00124 
00125 #endif

Site Contact