SundanceCurveNormEvaluator.cpp
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 #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    * There is only one possible entry in the nozeros table for a
00064    * cell diameter expression: a zeroth derivative.
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 

Site Contact