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