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