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 "SundanceUnaryMinusEvaluator.hpp"
00043 #include "SundanceEvalManager.hpp"
00044 #include "SundanceUnaryMinus.hpp"
00045
00046 #include "PlayaTabs.hpp"
00047 #include "SundanceOut.hpp"
00048
00049 using namespace Sundance;
00050 using namespace Sundance;
00051 using namespace Sundance;
00052 using namespace Teuchos;
00053
00054
00055
00056
00057
00058 UnaryMinusEvaluator
00059 ::UnaryMinusEvaluator(const UnaryMinus* expr,
00060 const EvalContext& context)
00061 : UnaryEvaluator<UnaryMinus>(expr, context)
00062 {
00063 try
00064 {
00065 int vecResultIndex = 0;
00066 int constResultIndex = 0;
00067
00068 for (int i=0; i<this->sparsity()->numDerivs(); i++)
00069 {
00070
00071 bool resultIsConstant = this->sparsity()->state(i)==ConstantDeriv;
00072
00073 if (!resultIsConstant)
00074 {
00075 addVectorIndex(i, vecResultIndex);
00076 vecResultIndex++;
00077 }
00078 else
00079 {
00080 addConstantIndex(i, constResultIndex);
00081 constResultIndex++;
00082 }
00083 }
00084 }
00085 catch(std::exception& e)
00086 {
00087 TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00088 "exception detected in UnaryMinusEvaluator: expr="
00089 << expr->toString() << std::endl
00090 << "exception=" << e.what());
00091 }
00092 }
00093
00094 void UnaryMinusEvaluator
00095 ::internalEval(const EvalManager& mgr,
00096 Array<double>& constantResults,
00097 Array<RCP<EvalVector> >& vectorResults) const
00098 {
00099 Tabs tab;
00100 SUNDANCE_MSG1(mgr.verb(),
00101 tab << "UnaryMinusEvaluator::eval() expr=" << expr()->toString());
00102
00103
00104
00105 evalOperand(mgr, constantResults, vectorResults);
00106
00107
00108 if (mgr.verb() > 2)
00109 {
00110 Out::os() << tab << "UnaryMinus operand results" << std::endl;
00111 argSparsitySuperset()->print(Out::os(), vectorResults,
00112 constantResults);
00113 }
00114
00115 for (int i=0; i<constantResults.size(); i++)
00116 {
00117 constantResults[i] *= -1;
00118 }
00119
00120 for (int i=0; i<vectorResults.size(); i++)
00121 {
00122 vectorResults[i]->multiply_S(-1.0);
00123 }
00124
00125
00126 if (mgr.verb() > 1)
00127 {
00128 Out::os() << tab << "UnaryMinus results" << std::endl;
00129 sparsity()->print(Out::os(), vectorResults,
00130 constantResults);
00131 }
00132
00133
00134 }
00135
00136