SundanceCellVectorEvaluator.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 "SundanceCellVectorExpr.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 CellVectorEvaluator::CellVectorEvaluator(const CellVectorExpr* expr, 
00047   const EvalContext& context)
00048   : SubtypeEvaluator<CellVectorExpr>(expr, context), 
00049     dim_(expr->dimension()),
00050     isTangentVector_(expr->isTangent()),
00051     basisVectorIndex_(expr->basisMemberIndex()),
00052     componentIndex_(expr->componentIndex()),
00053     stringRep_(expr->toString())
00054 {
00055 
00056   Tabs tabs;
00057   int verb = context.setupVerbosity();
00058   SUNDANCE_MSG1(verb, tabs << "initializing cell vector evaluator for " 
00059     << expr->toString());
00060   SUNDANCE_MSG2(verb, tabs << "return sparsity " 
00061     << std::endl << *(this->sparsity)());
00062 
00063   TEUCHOS_TEST_FOR_EXCEPTION(this->sparsity()->numDerivs() >1 , std::logic_error,
00064     "CellVectorEvaluator ctor found a sparsity table "
00065     "with more than one entry. The bad sparsity table is "
00066     << *(this->sparsity)());
00067 
00068   /* 
00069    * There is only one possible entries in the nozeros table for a
00070    * cell vector expression: a zeroth derivative.
00071    */
00072   
00073   for (int i=0; i<this->sparsity()->numDerivs(); i++)
00074   {
00075     const MultipleDeriv& d = this->sparsity()->deriv(i);
00076 
00077     /* for a zeroth-order derivative, evaluate the coord expr */
00078     TEUCHOS_TEST_FOR_EXCEPTION(d.order() != 0, std::runtime_error, 
00079       "Derivative " << d << " is not valid for "
00080       "CellVectorEvaluator");
00081     addVectorIndex(i, 0);
00082   }
00083   
00084 }
00085 
00086 
00087 
00088 void CellVectorEvaluator::internalEval(const EvalManager& mgr,
00089   Array<double>& constantResults,
00090   Array<RCP<EvalVector> >& vectorResults) const 
00091 {
00092   Tabs tabs(0);
00093 
00094   SUNDANCE_MSG1(mgr.verb(), tabs << "CellVectorEvaluator::eval() expr=" 
00095     << expr()->toString());
00096 
00097   SUNDANCE_MSG3(mgr.verb(), 
00098     tabs << "sparsity = " << std::endl << tabs << *(this->sparsity)());
00099   
00100   vectorResults.resize(1);
00101   vectorResults[0] = mgr.popVector();
00102   SUNDANCE_MSG4(mgr.verb(), tabs << "forwarding to evaluation manager");
00103   mgr.evalCellVectorExpr(expr(), vectorResults[0]);
00104   mgr.stack().setVecSize(vectorResults[0]->length());
00105   vectorResults[0]->setString(stringRep_);
00106 
00107   if (mgr.verb() > 1)
00108   {
00109     Tabs tab1;
00110     Out::os() << tab1 << "results " << std::endl;
00111     mgr.showResults(Out::os(), this->sparsity(), vectorResults,
00112         constantResults);
00113   }
00114 
00115 }
00116 

Site Contact