SundanceBinaryEvaluator.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_BINARYEVALUATOR_H
00032 #define SUNDANCE_BINARYEVALUATOR_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceSubtypeEvaluator.hpp"
00036 #include "SundanceEvaluatableExpr.hpp"
00037 #include "SundanceEvalManager.hpp"
00038 
00039 namespace Sundance 
00040 {
00041 class EvalContext;
00042   
00043 
00044 
00045 /**
00046  * 
00047  */
00048 template <class ExprType> class BinaryEvaluator 
00049   : public SubtypeEvaluator<ExprType>
00050 {
00051 public:
00052   /** */
00053   BinaryEvaluator(const ExprType* expr,
00054     const EvalContext& context)
00055     : SubtypeEvaluator<ExprType>(expr, context),
00056       leftExpr_(expr->leftEvaluatable()),
00057       rightExpr_(expr->rightEvaluatable()),
00058       leftSparsity_(leftExpr_->sparsitySuperset(context)),
00059       rightSparsity_(rightExpr_->sparsitySuperset(context)),
00060       leftEval_(leftExpr_->evaluator(context)),
00061       rightEval_(rightExpr_->evaluator(context))
00062     {
00063       Tabs tab;
00064       leftEval_->addClient();
00065       rightEval_->addClient();
00066     }
00067 
00068   /** */
00069   virtual ~BinaryEvaluator(){;}
00070 
00071   /** */
00072   virtual void resetNumCalls() const 
00073     {
00074       leftEval_->resetNumCalls();
00075       rightEval_->resetNumCalls();
00076       Evaluator::resetNumCalls();
00077     }
00078 
00079 protected:
00080       
00081   /** */
00082   const RCP<SparsitySuperset>& leftSparsity() const 
00083     {return leftSparsity_;}
00084       
00085   /** */
00086   const RCP<SparsitySuperset>& rightSparsity() const 
00087     {return rightSparsity_;}
00088 
00089   /** */
00090   const EvaluatableExpr* leftExpr() const {return leftExpr_;}
00091 
00092   /** */
00093   const EvaluatableExpr* rightExpr() const {return rightExpr_;}
00094 
00095   /** */
00096   const RCP<Evaluator>& leftEval() const {return leftEval_;}
00097 
00098   /** */
00099   const RCP<Evaluator>& rightEval() const {return rightEval_;}
00100 
00101   /** */
00102   void evalChildren(const EvalManager& mgr,
00103     Array<double>& leftConstResults,
00104     Array<RCP<EvalVector> >& leftVecResults,
00105     Array<double>& rightConstResults,
00106     Array<RCP<EvalVector> >& rightVecResults) const 
00107     {
00108       Tabs tabs;
00109       SUNDANCE_MSG2(mgr.verb(), 
00110         tabs << "Evaluating left and right children: "
00111         << std::endl << tabs << "left=" << leftExpr_->toString()
00112         << std::endl << tabs << "right=" << rightExpr_->toString());
00113       SUNDANCE_MSG2(mgr.verb(),
00114         tabs << "Evaluating left=" << leftExpr_->toString());
00115       leftEval()->eval(mgr, leftConstResults, leftVecResults);
00116         
00117       SUNDANCE_MSG2(mgr.verb(),
00118         tabs << "Evaluating right=" << rightExpr_->toString());
00119       rightEval()->eval(mgr, rightConstResults, rightVecResults);
00120     }
00121 
00122 private:
00123   const EvaluatableExpr* leftExpr_;
00124 
00125   const EvaluatableExpr* rightExpr_;
00126 
00127   RCP<SparsitySuperset> leftSparsity_;
00128 
00129   RCP<SparsitySuperset> rightSparsity_;
00130 
00131   RCP<Evaluator> leftEval_;
00132 
00133   RCP<Evaluator> rightEval_;
00134 };
00135 }
00136 
00137 
00138 #endif

Site Contact