00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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
00078
00079 if (constantResultCache_.size() > 0) constantResults = constantResultCache_;
00080
00081
00082
00083 if (numCalls_ == numClients_)
00084 {
00085 SUNDANCE_VERB_MEDIUM(tabs << "surrendering cached results");
00086 vectorResults = vectorResultCache_;
00087 }
00088 else
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