SundanceConstantEvaluator.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 "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    * There is only one possible nonzero derivative of this expression: the
00055    * zeroth-order derivative. 
00056    *
00057    * There's nothing to do in this ctor other than running some sanity checks.
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 }

Site Contact