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 "SundanceCellDiameterExpr.hpp"
00034 #include "PlayaExceptions.hpp"
00035 #include "SundanceSet.hpp"
00036 #include "PlayaTabs.hpp"
00037 #include "SundanceOut.hpp"
00038 
00039 using namespace Sundance;
00040 using namespace Sundance;
00041 
00042 using namespace Sundance;
00043 using namespace Teuchos;
00044 
00045 
00046 CellDiameterExprEvaluator::CellDiameterExprEvaluator(
00047   const CellDiameterExpr* expr, 
00048   const EvalContext& context)
00049   : SubtypeEvaluator<CellDiameterExpr>(expr, context), 
00050     stringRep_(expr->toString())
00051 {
00052 
00053   Tabs tabs;
00054   int verb = context.setupVerbosity();
00055   SUNDANCE_MSG1(verb, tabs << "initializing cell diameter expr evaluator for " 
00056                     << expr->toString());
00057   SUNDANCE_MSG2(verb, tabs << "return sparsity " << std::endl << *(this->sparsity)());
00058 
00059   TEUCHOS_TEST_FOR_EXCEPTION(this->sparsity()->numDerivs() > 1, std::logic_error,
00060                      "CellDiameterExprEvaluator ctor found a sparsity table "
00061                      "with more than one entry. The bad sparsity table is "
00062                      << *(this->sparsity)());
00063 
00064   
00065 
00066 
00067 
00068   
00069   for (int i=0; i<this->sparsity()->numDerivs(); i++)
00070     {
00071       const MultipleDeriv& d = this->sparsity()->deriv(i);
00072 
00073       TEUCHOS_TEST_FOR_EXCEPTION(d.order()!=0, std::logic_error,
00074                          "CellDiameterExprEvaluator ctor found an entry in the "
00075                          "sparsity superset that is not a zeroth-order derivative. "
00076                          "The bad entry is " << this->sparsity()->deriv(i) 
00077                          << ". The superset is " 
00078                          << *(this->sparsity)());
00079       addVectorIndex(i, 0);
00080     }
00081 }
00082 
00083 
00084 
00085 void CellDiameterExprEvaluator::internalEval(const EvalManager& mgr,
00086   Array<double>& constantResults,
00087   Array<RCP<EvalVector> >& vectorResults) const 
00088 {
00089   Tabs tabs(0);
00090 
00091   SUNDANCE_MSG2(mgr.verb(), tabs << "CellDiameterExprEvaluator::eval() expr=" 
00092     << expr()->toString());
00093 
00094   if (mgr.verb() > 2)
00095     {
00096       Out::os() << tabs << "sparsity = " 
00097                 << std::endl << tabs << *(this->sparsity)() << std::endl;
00098     }
00099 
00100   if (this->sparsity()->numDerivs() > 0)
00101     {
00102       vectorResults.resize(1);
00103       vectorResults[0] = mgr.popVector();
00104       SUNDANCE_MSG3(mgr.verb(), tabs << "forwarding to evaluation manager");
00105       mgr.evalCellDiameterExpr(expr(), vectorResults[0]);
00106       mgr.stack().setVecSize(vectorResults[0]->length());
00107       if (EvalVector::shadowOps()) vectorResults[0]->setString(stringRep_);
00108     }
00109   else
00110   {
00111     SUNDANCE_MSG4(mgr.verb(), tabs << "no results requested");
00112   }
00113 
00114   if (mgr.verb() > 1)
00115     {
00116       Out::os() << tabs << "results " << std::endl;
00117       mgr.showResults(Out::os(), this->sparsity(), vectorResults,
00118           constantResults);
00119     }
00120 }
00121