Go to the documentation of this file.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "SundanceEFDEEvaluator.hpp"
00043 #include "SundanceEvalManager.hpp"
00044 #include "PlayaExceptions.hpp"
00045 #include "SundanceSet.hpp"
00046 #include "PlayaTabs.hpp"
00047 #include "SundanceOut.hpp"
00048
00049 using namespace Sundance;
00050 using namespace Sundance;
00051
00052 using namespace Sundance;
00053 using namespace Teuchos;
00054
00055
00056 EFDEEvaluator::EFDEEvaluator(
00057 const ExplicitFunctionalDerivativeElement* expr,
00058 const EvalContext& context
00059 )
00060 : UnaryEvaluator<ExplicitFunctionalDerivativeElement>(expr, context),
00061 constValIndexToArgIndexMap_(),
00062 varValIndexToArgIndexMap_()
00063 {
00064
00065 Tabs tabs;
00066 SUNDANCE_VERB_LOW(tabs << "initializing EFDE evaluator for "
00067 << expr->toString());
00068 SUNDANCE_VERB_MEDIUM(tabs << "return sparsity " << std::endl << *(this->sparsity)());
00069
00070
00071
00072
00073
00074
00075
00076
00077 int vecResultIndex = 0;
00078 int constResultIndex = 0;
00079
00080 const Deriv& fd = expr->fd();
00081
00082 for (int i=0; i<this->sparsity()->numDerivs(); i++)
00083 {
00084 const MultipleDeriv& d = this->sparsity()->deriv(i);
00085 const DerivState& myState = this->sparsity()->state(i);
00086
00087 if (myState==ConstantDeriv)
00088 {
00089 Tabs tab2;
00090 SUNDANCE_VERB_HIGH(tab2
00091 << "deriv is constant, will be stored at index "
00092 << constResultIndex << " in the const result array");
00093 addConstantIndex(i, constResultIndex++);
00094 }
00095 else
00096 {
00097 Tabs tab2;
00098 SUNDANCE_VERB_HIGH(tab2
00099 << "deriv is variable, will be stored at index "
00100 << vecResultIndex << " in the var result array");
00101 addVectorIndex(i, vecResultIndex++);
00102 }
00103
00104 MultipleDeriv dArg = d;
00105 dArg.put(fd);
00106
00107 int argIndex = argSparsitySuperset()->getIndex(dArg);
00108
00109
00110 TEUCHOS_TEST_FOR_EXCEPTION(argIndex==-1, std::runtime_error,
00111 "Derivative " << dArg << " expected in argument but not found");
00112
00113
00114 const DerivState& argState = argSparsitySuperset()->state(argIndex);
00115 TEUCHOS_TEST_FOR_EXCEPTION(argState != myState, std::logic_error,
00116 "mismatched states");
00117
00118 if (argState==ConstantDeriv)
00119 {
00120 int constArgIndex = argEval()->constantIndexMap().get(argIndex);
00121 constValIndexToArgIndexMap_.append(constArgIndex);
00122 }
00123 else
00124 {
00125 int vectorArgIndex = argEval()->vectorIndexMap().get(argIndex);
00126 varValIndexToArgIndexMap_.append(vectorArgIndex);
00127 }
00128 }
00129
00130 SUNDANCE_VERB_HIGH(tabs
00131 << " constant index map "
00132 << constValIndexToArgIndexMap_ << std::endl
00133 << " vector index map "
00134 << varValIndexToArgIndexMap_
00135 );
00136 }
00137
00138
00139
00140 void EFDEEvaluator::internalEval(const EvalManager& mgr,
00141 Array<double>& constantResults,
00142 Array<RCP<EvalVector> >& vectorResults) const
00143 {
00144 TimeMonitor timer(efdeEvalTimer());
00145 Tabs tabs(0);
00146
00147 SUNDANCE_MSG1(mgr.verb(), tabs << "EFDEEvaluator::eval() expr="
00148 << expr()->toString());
00149
00150 SUNDANCE_MSG3(mgr.verb(), tabs << "sparsity = " << std::endl
00151 << *(this->sparsity)());
00152
00153 constantResults.resize(constValIndexToArgIndexMap_.size());
00154 vectorResults.resize(varValIndexToArgIndexMap_.size());
00155
00156
00157 Array<RCP<EvalVector> > argVectorResults;
00158 Array<double> argConstantResults;
00159
00160 evalOperand(mgr, argConstantResults, argVectorResults);
00161
00162
00163 if (mgr.verb() > 2)
00164 {
00165 Tabs tab1;
00166 Out::os() << tab1 << "EFDE operand results" << std::endl;
00167 mgr.showResults(Out::os(), argSparsitySuperset(), argVectorResults,
00168 argConstantResults);
00169 }
00170
00171
00172 for (int i=0; i<constantResults.size(); i++)
00173 {
00174 constantResults[i] = argConstantResults[constValIndexToArgIndexMap_[i]];
00175 }
00176
00177
00178 for (int i=0; i<vectorResults.size(); i++)
00179 {
00180 vectorResults[i] = mgr.popVector();
00181 const RCP<EvalVector>& v = argVectorResults[varValIndexToArgIndexMap_[i]];
00182 vectorResults[i]->setTo_V(v.get());
00183 }
00184
00185
00186
00187
00188 if (mgr.verb() > 2)
00189 {
00190 Tabs tab1;
00191 Out::os() << tab1 << "EFDE results " << std::endl;
00192 mgr.showResults(Out::os(), this->sparsity(), vectorResults,
00193 constantResults);
00194 }
00195 }
00196