SundanceSparsitySuperset.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_SPARSITYSUPERSET_H
00043 #define SUNDANCE_SPARSITYSUPERSET_H
00044 
00045 
00046 
00047 #include "SundanceDefs.hpp"
00048 #include "SundanceDefs.hpp"
00049 #include "SundanceDerivSet.hpp"
00050 #include "SundanceDeriv.hpp"
00051 #include "SundanceMultipleDeriv.hpp"
00052 #include "SundanceMap.hpp"
00053 #include "SundanceEvalVector.hpp"
00054 #include "Teuchos_RefCountPtr.hpp"
00055 #include "Teuchos_Array.hpp"
00056 
00057 
00058 namespace Sundance
00059 {
00060 using namespace Sundance;
00061 using namespace Teuchos;
00062 
00063 /**
00064  * DerivState can be used to classify the known state of
00065  * each functional derivative at any node in the expression
00066  * tree.  ZeroDeriv means the derivative is structurally
00067  * zero at that node -- note that derivatives that are
00068  * nonzero at a root node can be structurally zero at some
00069  * child node. ConstantDeriv means that the derivative is
00070  * known to be a constant (in space) at that
00071  * node. VectorDeriv means that the derivative is non-zero,
00072  * non-constant, i.e., a vector of values.
00073  */
00074 enum DerivState {ZeroDeriv, ConstantDeriv, VectorDeriv};
00075 
00076 /**
00077  *
00078  */
00079 class SparsitySuperset 
00080   : public ObjectWithClassVerbosity<SparsitySuperset>
00081 {
00082 public:
00083           
00084   /** Create a sparsity set */
00085   SparsitySuperset(const Set<MultipleDeriv>& C,
00086     const Set<MultipleDeriv>& V);
00087 
00088   /** \name Access to information about individual derivatives */
00089   //@{
00090   /** Detect whether a given derivative exists in this set */
00091   bool containsDeriv(const MultipleDeriv& d) const ;
00092 
00093   /** Find the index at which the results for the
00094       given functional derivative are stored in the results array */
00095   int getIndex(const MultipleDeriv& d) const ;
00096 
00097   /** Return the results stored at index i */
00098   inline const MultipleDeriv& deriv(int i) const
00099     {return derivs_[i];}
00100 
00101   /** Return the constancy state of deriv i */
00102   inline const DerivState& state(int i) const
00103     {return states_[i];}
00104 
00105   /** */
00106   inline int numDerivs() const {return derivs_.size();}
00107 
00108   /** */
00109   int numConstantDerivs() const {return numConstantDerivs_;}
00110 
00111   /** */
00112   int numVectorDerivs() const {return numVectorDerivs_;}
00113 
00114           
00115           
00116   /** */
00117   int maxOrder() const {return maxOrder_;}
00118 
00119 
00120   /** Indicate whether the specified derivative is
00121    * spatially constant at this node */
00122   bool isConstant(int i) const {return states_[i]==ConstantDeriv;}
00123 
00124   /** Indicate whether the specified multiple derivative contains
00125    * at least one order of spatial differentiation */
00126   bool isSpatialDeriv(int i) const 
00127     {
00128       return multiIndex_[i].order() != 0;
00129     }
00130 
00131   /** Return the spatial multi index for the i-th derivative */
00132   const MultiIndex& multiIndex(int i) const 
00133     {return multiIndex_[i];}
00134   //@}
00135           
00136   /** */
00137   void print(std::ostream& os) const ;
00138   /** */
00139   void print(std::ostream& os, 
00140     const Array<RCP<EvalVector> >& vecResults,
00141     const Array<double>& constantResults) const ;
00142 
00143   /** */
00144   std::string toString() const ;
00145 
00146   /** */
00147   DerivSet derivSet() const ;
00148 
00149 private:
00150 
00151   /** Add a derivative to the set. Called by the subset's addDeriv()
00152    * method. */
00153   void addDeriv(const MultipleDeriv& d, 
00154     const DerivState& state);
00155 
00156   /** Add a derivative to the set. Called by the subset's addDeriv()
00157    * method. */
00158   void addDeriv(const Deriv& d, 
00159     const DerivState& state);
00160 
00161   /** */
00162   int maxOrder_;
00163 
00164   /** Map from deriv to position of the derivative's
00165    * value in the results array */
00166   Sundance::Map<MultipleDeriv, int> derivToIndexMap_;
00167 
00168   /** The list of functional derivatives whose values are
00169    * stored in this results set */
00170   Array<MultipleDeriv> derivs_;
00171 
00172   /** The state of each derivative at this node in the expression */
00173   Array<DerivState> states_;
00174 
00175   /** Multiindices */
00176   Array<MultiIndex> multiIndex_;
00177 
00178   /** */
00179   int numConstantDerivs_;
00180 
00181   /** */
00182   int numVectorDerivs_;
00183 
00184           
00185 
00186 };
00187 
00188 }
00189 
00190 namespace std
00191 {
00192 /** \relates SparsitySuperset */
00193 inline std::ostream& operator<<(std::ostream& os,
00194   const Sundance::SparsitySuperset& s)
00195 {
00196   s.print(os);
00197   return os;
00198 }
00199 }
00200 
00201 
00202 
00203 #endif

Site Contact