SundanceEvalContext.hpp
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 #ifndef SUNDANCE_EVALCONTEXT_H
00032 #define SUNDANCE_EVALCONTEXT_H
00033 
00034 
00035 #include "SundanceDefs.hpp"
00036 #include "SundanceRegionQuadCombo.hpp"
00037 #include "SundanceSet.hpp"
00038 #include "Teuchos_Utils.hpp"
00039 #include <algorithm>
00040 
00041 
00042 namespace Sundance
00043 {
00044 using namespace Teuchos;
00045 using namespace Sundance;
00046 using Sundance::Set;
00047 
00048 /** 
00049  * Different contexts might require the same expression to be
00050  * evaluated to different orders of functional differentiation; for
00051  * example, in setting up a linear system, second-order derivatives
00052  * are required, but in evaluating a functional only zeroth derivs
00053  * are required. 
00054  * An EvaluationContext is used as a key to associate an evaluator and
00055  * its corresponding set of
00056  * functional derivatives with a context.
00057  *
00058  * They key consists of three parts: first, an integer identifier
00059  * indicating the caller, e.g., an assembler or functional evaluator,
00060  * second, a set indicating which orders of 
00061  * differentiation are required by the top level caller, and third,
00062  a region-quadrature combination.  
00063 */
00064 class EvalContext
00065 {
00066 public:
00067   /** Empty ctor */
00068   EvalContext() : data_() {;}
00069 
00070   /** Construct with a region-quadrature combination and
00071    * an identifier of the construcing context. */
00072   EvalContext(const RegionQuadCombo& rqc,
00073     const Set<int>& needsDiffOrder,
00074     int contextID)
00075     : setupVerbosity_(0), 
00076       maxDiffOrder_(*std::max_element(needsDiffOrder.begin(), needsDiffOrder.end())),
00077       data_(rcp(new OrderedTriple<Set<int>, int, RegionQuadCombo>(needsDiffOrder, contextID, rqc)))
00078     {}
00079 
00080   /** Set the verbosity level to be used during preprocessing 
00081    * of expressions in this context */
00082   void setSetupVerbosity(int v) {setupVerbosity_ = v;}
00083 
00084   /** Return the verbosity level to be used during preprocessing 
00085    * of expressions in this context */
00086   int setupVerbosity() const {return setupVerbosity_;}
00087 
00088   /** Comparison operator for use in maps */
00089   bool operator<(const EvalContext& other) const 
00090     {return *data_ < *other.data_;}
00091           
00092   /** Write to a std::string */
00093   std::string toString() const
00094     {return "EvalContext[diffOrder=" 
00095         + Teuchos::toString(data_->a())
00096         + ", id=" 
00097         + Teuchos::toString(data_->b())
00098         + ", " + data_->c().toString() + "]";}
00099           
00100   /** Write a short description to a std::string */
00101   std::string brief() const
00102     {return "EvalContext[diffOrder=" 
00103         + Teuchos::toString(data_->a())
00104         + ", id=" 
00105         + Teuchos::toString(data_->b())
00106         + "]";}
00107 
00108   /** */
00109   int topLevelDiffOrder() const {return maxDiffOrder_;}
00110 
00111   /** Indicate whether or not a given order of differentiation 
00112    * is needed in this context */
00113   bool needsDerivOrder(int order) const {return data_->a().contains(order);}
00114   
00115 
00116   /** Return a unique context ID */
00117   static int nextID() {static int rtn=0; return rtn++;}
00118 private:
00119   int setupVerbosity_;
00120   int maxDiffOrder_;
00121   RCP<OrderedTriple<Set<int>, int, RegionQuadCombo> > data_;
00122 };
00123 
00124 }
00125 
00126 
00127 namespace std
00128 {
00129 /** \relates Sundance::EvalContext */
00130 inline ostream& operator<<(std::ostream& os, 
00131   const Sundance::EvalContext& c)
00132 {
00133   os << c.toString();
00134   return os;
00135 }
00136 }
00137 
00138 namespace Teuchos
00139 {
00140 /** \relates Sundance::EvalContext */
00141 inline std::string toString(const Sundance::EvalContext& h)
00142 {return h.toString();}
00143 
00144 }
00145 
00146 
00147 #endif

Site Contact