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 00032 #ifndef SUNDANCE_USERDEFOPCOMMONEVALUATOR_H 00033 #define SUNDANCE_USERDEFOPCOMMONEVALUATOR_H 00034 00035 #include "SundanceDefs.hpp" 00036 #include "SundanceUserDefFunctor.hpp" 00037 #include "SundanceEvaluator.hpp" 00038 #include "SundanceEvalVector.hpp" 00039 #include "Teuchos_Array.hpp" 00040 #include "Teuchos_RefCountPtr.hpp" 00041 #include "Teuchos_TimeMonitor.hpp" 00042 00043 namespace Sundance { 00044 00045 class UserDefOpElement; 00046 class EvalContext; 00047 00048 /** 00049 * UserDefOpCommonEvaluator provides a single evaluation point for all 00050 * components of a vector-valued functor. 00051 */ 00052 class UserDefOpCommonEvaluator : public ObjectWithClassVerbosity<Evaluator> 00053 { 00054 public: 00055 /** */ 00056 UserDefOpCommonEvaluator(const UserDefFunctor* op, 00057 const UserDefOpElement* expr, 00058 const EvalContext& context); 00059 00060 /** */ 00061 virtual ~UserDefOpCommonEvaluator(){;} 00062 00063 /** Evaluate all vector components at the specified argument values. */ 00064 void evalAllComponents(const EvalManager& mgr, 00065 const Array<RCP<Array<double> > >& constArgDerivVals, 00066 const Array<RCP<Array<RCP<EvalVector> > > >& vArgDerivVals) const ; 00067 00068 00069 00070 /** Get the cached constant-valued argument derivative values 00071 * for the specified vector component */ 00072 const Array<double>& constArgDerivCache(int elemIndex) const 00073 {return *(constArgDerivCache_[elemIndex]);} 00074 00075 /** Get the cached vector-valued argument derivative values 00076 * for the specified vector component */ 00077 const Array<RCP<EvalVector> >& varArgDerivCache(int elemIndex) const 00078 {return varArgDerivCache_[elemIndex];} 00079 00080 /** Indicate whether the cached argument derivative values are valid */ 00081 bool cacheIsValid() const {return cacheIsValid_;} 00082 00083 /** Mark the cache as valid. */ 00084 void markCacheAsValid() const {cacheIsValid_ = true;} 00085 00086 /** Mark the cache as invalid */ 00087 void markCacheAsInvalid() const {cacheIsValid_ = false;} 00088 00089 /** */ 00090 int maxDiffOrder() const {return maxOrder_;} 00091 00092 /** */ 00093 void updateMaxOrder(int maxOrder) const {maxOrder_ = maxOrder;} 00094 00095 00096 protected: 00097 00098 /** Access the functor that implements this operator */ 00099 const UserDefFunctor* functor() const {return functor_;} 00100 00101 private: 00102 mutable int maxOrder_; 00103 Array<int> argValueIndex_; 00104 Array<int> argValueIsConstant_; 00105 mutable Array<RCP<Array<double> > > constArgDerivCache_; 00106 mutable Array<Array<RCP<EvalVector> > > varArgDerivCache_; 00107 mutable bool cacheIsValid_; 00108 const UserDefFunctor* functor_; 00109 00110 }; 00111 } 00112 00113 00114 #endif