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() : setupVerbosity_(0), evalSetupVerbosity_(0), 
00069                   maxDiffOrder_(0),
00070                   data_() {;}
00071 
00072   /** Construct with a region-quadrature combination and
00073    * an identifier of the construcing context. */
00074   EvalContext(const RegionQuadCombo& rqc,
00075     const Set<int>& needsDiffOrder,
00076     int contextID)
00077     : setupVerbosity_(0), evalSetupVerbosity_(0),
00078       maxDiffOrder_(*std::max_element(needsDiffOrder.begin(), needsDiffOrder.end())),
00079       data_(rcp(new OrderedTriple<Set<int>, int, RegionQuadCombo>(needsDiffOrder, contextID, rqc)))
00080     {}
00081 
00082   /** Set the verbosity level to be used during preprocessing 
00083    * of expressions in this context */
00084   void setSetupVerbosity(int v) const {setupVerbosity_ = v;}
00085 
00086   /** Return the verbosity level to be used during preprocessing 
00087    * of expressions in this context */
00088   int setupVerbosity() const {return setupVerbosity_;}
00089 
00090   /** Set the verbosity level to be used during setup of evaluators
00091    * for expressions in this context */
00092   void setEvalSetupVerbosity(int v) const {evalSetupVerbosity_ = v;}
00093 
00094   /** Get the verbosity level to be used during setup of evaluators
00095    * for expressions in this context */
00096   int evalSetupVerbosity() const {return evalSetupVerbosity_;}
00097 
00098   /** Comparison operator for use in maps */
00099   bool operator<(const EvalContext& other) const 
00100     {return *data_ < *other.data_;}
00101           
00102   /** Write to a std::string */
00103   std::string toString() const
00104     {return "EvalContext[diffOrder=" 
00105         + Teuchos::toString(data_->a())
00106         + ", id=" 
00107         + Teuchos::toString(data_->b())
00108         + ", " + data_->c().toString() + "]";}
00109           
00110   /** Write a short description to a std::string */
00111   std::string brief() const
00112     {return "EvalContext[diffOrder=" 
00113         + Teuchos::toString(data_->a())
00114         + ", id=" 
00115         + Teuchos::toString(data_->b())
00116         + "]";}
00117 
00118   /** */
00119   int topLevelDiffOrder() const {return maxDiffOrder_;}
00120 
00121   /** Indicate whether or not a given order of differentiation 
00122    * is needed in this context */
00123   bool needsDerivOrder(int order) const {return data_->a().contains(order);}
00124   
00125 
00126   /** Return a unique context ID */
00127   static int nextID() {static int rtn=0; return rtn++;}
00128 private:
00129   mutable int setupVerbosity_;
00130   mutable int evalSetupVerbosity_;
00131   int maxDiffOrder_;
00132   RCP<OrderedTriple<Set<int>, int, RegionQuadCombo> > data_;
00133 };
00134 
00135 }
00136 
00137 
00138 namespace std
00139 {
00140 /** \relates Sundance::EvalContext */
00141 inline ostream& operator<<(std::ostream& os, 
00142   const Sundance::EvalContext& c)
00143 {
00144   os << c.toString();
00145   return os;
00146 }
00147 }
00148 
00149 namespace Teuchos
00150 {
00151 /** \relates Sundance::EvalContext */
00152 inline std::string toString(const Sundance::EvalContext& h)
00153 {return h.toString();}
00154 
00155 }
00156 
00157 
00158 #endif

Site Contact