SundanceEvaluator.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 "SundanceEvaluator.hpp"
00032 #include "SundanceEvalManager.hpp"
00033 #include "SundanceCoordExpr.hpp"
00034 #include "SundanceZeroExpr.hpp"
00035 #include "SundanceSpatiallyConstantExpr.hpp"
00036 #include "SundanceSymbolicFuncElement.hpp"
00037 #include "SundanceDiscreteFuncElement.hpp"
00038 #include "SundanceSet.hpp"
00039 #include "PlayaTabs.hpp"
00040 #include "SundanceOut.hpp"
00041 
00042 using namespace Sundance;
00043 using namespace Sundance;
00044 
00045 using namespace Sundance;
00046 using namespace Teuchos;
00047 
00048 
00049 
00050 
00051 Evaluator::Evaluator()
00052   : numClients_(0),
00053     numCalls_(0),
00054     vectorResultCache_(),
00055     constantResultCache_(),
00056     constantIndexMap_(),
00057     vectorIndexMap_(),
00058     vectorIndices_(),
00059     constantIndices_()
00060 {}
00061 
00062 
00063 
00064 void Evaluator::eval(const EvalManager& mgr,
00065                      Array<double>& constantResults,
00066                      Array<RCP<EvalVector> >& vectorResults) const
00067 {
00068   Tabs tabs;
00069 
00070   if (numCalls_ == 0)
00071     {
00072       internalEval(mgr, constantResultCache_, vectorResultCache_);
00073     }
00074   
00075   numCalls_++;
00076 
00077   /* Go ahead and copy the constant results every time, 
00078    * since this is cheap */
00079   if (constantResultCache_.size() > 0) constantResults = constantResultCache_;
00080 
00081   /* If all clients have called, we can return the original data
00082    * which can then be changed by the client. */
00083   if (numCalls_ == numClients_)
00084     {
00085       SUNDANCE_VERB_MEDIUM(tabs << "surrendering cached results");
00086       vectorResults = vectorResultCache_;
00087     }
00088   else /* Otherwise, make a copy of the data */
00089     {
00090       SUNDANCE_VERB_MEDIUM(tabs << "cloning cached results");
00091       vectorResults.resize(vectorResultCache_.size());
00092       for (int i=0; i < vectorResults.size(); i++)
00093         {
00094           vectorResults[i] = vectorResultCache_[i]->clone();
00095         }
00096     }
00097 }
00098 
00099 
00100 void Evaluator::addConstantIndex(int index, int constantIndex)
00101 {
00102   TEUCHOS_TEST_FOR_EXCEPTION(constantIndexMap_.containsKey(index), std::logic_error,
00103                      "duplicate index " << index 
00104                      << " found in Evaluator::addConstantIndex");
00105   constantIndexMap_.put(index, constantIndex);
00106   constantIndices_.append(index);
00107 }
00108 
00109 void Evaluator::addVectorIndex(int index, int vectorIndex)
00110 {
00111   TEUCHOS_TEST_FOR_EXCEPTION(vectorIndexMap_.containsKey(index), std::logic_error,
00112                      "duplicate index " << index 
00113                      << " found in Evaluator::addVectorIndex");
00114   vectorIndexMap_.put(index, vectorIndex);
00115   vectorIndices_.append(index);
00116 }
00117 

Site Contact