00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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