SundanceSparsitySuperset.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_SPARSITYSUPERSET_H
00032 #define SUNDANCE_SPARSITYSUPERSET_H
00033 
00034 
00035 
00036 #include "SundanceDefs.hpp"
00037 #include "SundanceDefs.hpp"
00038 #include "SundanceDerivSet.hpp"
00039 #include "SundanceDeriv.hpp"
00040 #include "SundanceMultipleDeriv.hpp"
00041 #include "SundanceMap.hpp"
00042 #include "SundanceEvalVector.hpp"
00043 #include "Teuchos_RefCountPtr.hpp"
00044 #include "Teuchos_Array.hpp"
00045 
00046 
00047 namespace Sundance
00048 {
00049 using namespace Sundance;
00050 using namespace Teuchos;
00051 
00052 /**
00053  * DerivState can be used to classify the known state of
00054  * each functional derivative at any node in the expression
00055  * tree.  ZeroDeriv means the derivative is structurally
00056  * zero at that node -- note that derivatives that are
00057  * nonzero at a root node can be structurally zero at some
00058  * child node. ConstantDeriv means that the derivative is
00059  * known to be a constant (in space) at that
00060  * node. VectorDeriv means that the derivative is non-zero,
00061  * non-constant, i.e., a vector of values.
00062  */
00063 enum DerivState {ZeroDeriv, ConstantDeriv, VectorDeriv};
00064 
00065 /**
00066  *
00067  */
00068 class SparsitySuperset 
00069   : public ObjectWithClassVerbosity<SparsitySuperset>
00070 {
00071 public:
00072           
00073   /** Create a sparsity set */
00074   SparsitySuperset(const Set<MultipleDeriv>& C,
00075     const Set<MultipleDeriv>& V);
00076 
00077   /** \name Access to information about individual derivatives */
00078   //@{
00079   /** Detect whether a given derivative exists in this set */
00080   bool containsDeriv(const MultipleDeriv& d) const ;
00081 
00082   /** Find the index at which the results for the
00083       given functional derivative are stored in the results array */
00084   int getIndex(const MultipleDeriv& d) const ;
00085 
00086   /** Return the results stored at index i */
00087   inline const MultipleDeriv& deriv(int i) const
00088     {return derivs_[i];}
00089 
00090   /** Return the constancy state of deriv i */
00091   inline const DerivState& state(int i) const
00092     {return states_[i];}
00093 
00094   /** */
00095   inline int numDerivs() const {return derivs_.size();}
00096 
00097   /** */
00098   int numConstantDerivs() const {return numConstantDerivs_;}
00099 
00100   /** */
00101   int numVectorDerivs() const {return numVectorDerivs_;}
00102 
00103           
00104           
00105   /** */
00106   int maxOrder() const {return maxOrder_;}
00107 
00108 
00109   /** Indicate whether the specified derivative is
00110    * spatially constant at this node */
00111   bool isConstant(int i) const {return states_[i]==ConstantDeriv;}
00112 
00113   /** Indicate whether the specified multiple derivative contains
00114    * at least one order of spatial differentiation */
00115   bool isSpatialDeriv(int i) const 
00116     {
00117       return multiIndex_[i].order() != 0;
00118     }
00119 
00120   /** Return the spatial multi index for the i-th derivative */
00121   const MultiIndex& multiIndex(int i) const 
00122     {return multiIndex_[i];}
00123   //@}
00124           
00125   /** */
00126   void print(std::ostream& os) const ;
00127   /** */
00128   void print(std::ostream& os, 
00129     const Array<RCP<EvalVector> >& vecResults,
00130     const Array<double>& constantResults) const ;
00131 
00132   /** */
00133   std::string toString() const ;
00134 
00135   /** */
00136   DerivSet derivSet() const ;
00137 
00138 private:
00139 
00140   /** Add a derivative to the set. Called by the subset's addDeriv()
00141    * method. */
00142   void addDeriv(const MultipleDeriv& d, 
00143     const DerivState& state);
00144 
00145   /** Add a derivative to the set. Called by the subset's addDeriv()
00146    * method. */
00147   void addDeriv(const Deriv& d, 
00148     const DerivState& state);
00149 
00150   /** */
00151   int maxOrder_;
00152 
00153   /** Map from deriv to position of the derivative's
00154    * value in the results array */
00155   Sundance::Map<MultipleDeriv, int> derivToIndexMap_;
00156 
00157   /** The list of functional derivatives whose values are
00158    * stored in this results set */
00159   Array<MultipleDeriv> derivs_;
00160 
00161   /** The state of each derivative at this node in the expression */
00162   Array<DerivState> states_;
00163 
00164   /** Multiindices */
00165   Array<MultiIndex> multiIndex_;
00166 
00167   /** */
00168   int numConstantDerivs_;
00169 
00170   /** */
00171   int numVectorDerivs_;
00172 
00173           
00174 
00175 };
00176 
00177 }
00178 
00179 namespace std
00180 {
00181 /** \relates SparsitySuperset */
00182 inline std::ostream& operator<<(std::ostream& os,
00183   const Sundance::SparsitySuperset& s)
00184 {
00185   s.print(os);
00186   return os;
00187 }
00188 }
00189 
00190 
00191 
00192 #endif

Site Contact