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

Site Contact