SundanceUnaryMinusEvaluator.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 "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           /* Determine the index into which the result will be written */
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   /* evaluate the argument */
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 

Site Contact