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 #include "SundanceSubtypeEvaluator.hpp"
00032 #include "SundanceEvalManager.hpp"
00033 #include "SundanceSpatiallyConstantExpr.hpp"
00034 #include "SundanceSet.hpp"
00035 #include "PlayaTabs.hpp"
00036 #include "SundanceOut.hpp"
00037 
00038 using namespace Sundance;
00039 using namespace Sundance;
00040 
00041 using namespace Sundance;
00042 using namespace Teuchos;
00043 
00044 
00045 
00046 
00047 ConstantEvaluator::ConstantEvaluator(const SpatiallyConstantExpr* expr, 
00048                                      const EvalContext& context)
00049   : SubtypeEvaluator<SpatiallyConstantExpr>(expr, context)
00050 {
00051   Tabs tab;
00052   SUNDANCE_MSG1(context.setupVerbosity(), tab << "in ConstantEvaluator ctor");
00053   
00054 
00055 
00056 
00057 
00058 
00059 
00060   TEUCHOS_TEST_FOR_EXCEPTION(this->sparsity()->numDerivs() > 1, std::logic_error,
00061                      "ConstantEvaluator ctor found a sparsity table "
00062                      "without more than one entry. The bad sparsity table is "
00063                      << *(this->sparsity)());
00064 
00065   if (this->sparsity()->numDerivs() > 0)
00066     {
00067       const MultipleDeriv& d = this->sparsity()->deriv(0);
00068 
00069       TEUCHOS_TEST_FOR_EXCEPTION(d.order() != 0, std::logic_error,
00070                          "ConstantEvaluator ctor found a nonzero derivative "
00071                          "of order greater than zero. The bad sparsity "
00072                          "table is " << *(this->sparsity)());
00073       addConstantIndex(0,0);
00074     }
00075 }
00076 
00077 
00078 
00079 
00080 
00081 void ConstantEvaluator::internalEval(const EvalManager& mgr,
00082   Array<double>& constantResults,
00083   Array<RCP<EvalVector> >& vectorResults) const 
00084 {
00085   Tabs tabs;
00086   SUNDANCE_MSG1(mgr.verb(), tabs << "ConstantEvaluator::eval() expr="
00087     << expr()->toString());
00088 
00089   if (this->sparsity()->numDerivs() > 0)
00090   {
00091     constantResults.resize(1);
00092     constantResults[0] = expr()->value();
00093     
00094     SUNDANCE_MSG2(mgr.verb(), tabs << "result=" << constantResults[0]);
00095   }
00096   else
00097   {
00098     SUNDANCE_MSG2(mgr.verb(), tabs << "no results requested");
00099   }
00100 }