SundanceSpatialDerivSpecifier.cpp
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 #include "SundanceSpatialDerivSpecifier.hpp"
00032 
00033 using namespace Sundance;
00034 using namespace Sundance;
00035 
00036 
00037 
00038 SpatialDerivSpecifier::SpatialDerivSpecifier()
00039   : EnumTypeField<SpatialDerivType>(IdentitySDT), 
00040     mi_(), normalDerivOrder_(-1)
00041 {}
00042 
00043 SpatialDerivSpecifier::SpatialDerivSpecifier(const MultiIndex& mi)
00044   : EnumTypeField<SpatialDerivType>(PartialSDT), 
00045     mi_(mi), normalDerivOrder_(-1)
00046 {}
00047 
00048 SpatialDerivSpecifier::SpatialDerivSpecifier(
00049   const SpatialDerivType& sdt,
00050   int order)
00051   : EnumTypeField<SpatialDerivType>(sdt),
00052     mi_(), normalDerivOrder_(order)
00053 {
00054   assertNotType(PartialSDT);
00055 
00056   if (order > 0)
00057   {
00058     assertNotType(DivSDT);
00059   }
00060 }
00061 
00062 const MultiIndex& SpatialDerivSpecifier::mi() const
00063 {
00064   assertNotType(DivSDT);
00065   assertNotType(NormalSDT);
00066   return mi_;
00067 }
00068 
00069 bool SpatialDerivSpecifier::isDivergence() const
00070 {
00071   return isType(DivSDT);
00072 }
00073 
00074 bool SpatialDerivSpecifier::isNormal() const
00075 {
00076   return isType(NormalSDT);
00077 }
00078 
00079 bool SpatialDerivSpecifier::isPartial() const
00080 {
00081   return isType(PartialSDT);
00082 }
00083 
00084 bool SpatialDerivSpecifier::isIdentity() const
00085 {
00086   return isType(IdentitySDT)
00087     || (isPartial() && mi().order()==0)
00088     || (isNormal() && normalDerivOrder()==0);
00089 }
00090 
00091 int SpatialDerivSpecifier::normalDerivOrder() const
00092 {
00093   assertType(NormalSDT);
00094   return normalDerivOrder_;
00095 }
00096 
00097 int SpatialDerivSpecifier::derivOrder() const
00098 {
00099   if (isDivergence()) return 1;
00100   if (isPartial()) return mi_.order();
00101   if (isNormal()) return normalDerivOrder_;
00102   return 0;
00103 }
00104 
00105 
00106 std::string SpatialDerivSpecifier::toString() const 
00107 {
00108   TeuchosOStringStream os;
00109   os << *this;
00110   return os.str();
00111 }
00112 
00113 
00114 
00115 bool SpatialDerivSpecifier::operator<(const SpatialDerivSpecifier& other) const
00116 {
00117   if (type() < other.type()) return true;
00118   if (type() > other.type()) return false;
00119 
00120   if (isPartial()) return mi() < other.mi();
00121   if (isNormal()) return normalDerivOrder() < other.normalDerivOrder();
00122 
00123   return false;
00124 }
00125 
00126 
00127 SpatialDerivSpecifier SpatialDerivSpecifier::derivWrtMultiIndex(const MultiIndex& mi) const 
00128 {
00129   if (isPartial() || isIdentity()) 
00130   {
00131     return SpatialDerivSpecifier(mi_+mi);
00132   }
00133   else if (mi.order()==0)
00134   {
00135     return *this;
00136   }
00137   else
00138   {
00139     TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, "cannot take an arbitrary "
00140       "spatial derivative of SDS=" << *this);
00141     return *this; // -Wall
00142   }
00143   
00144 }
00145 
00146 
00147 namespace std
00148 {
00149 /** \relates SpatialDerivSpecifier */
00150 ostream& operator<<(std::ostream& os, const Sundance::SpatialDerivSpecifier& sds)
00151 {
00152   os << sds.type();
00153   if (sds.isPartial()) os << "(d=" << sds.mi() << ")";
00154   else os << "()";
00155   return os;
00156 }
00157 
00158 
00159 /** \relates SpatialDerivSpecifier */
00160 ostream& operator<<(std::ostream& os, const Sundance::SpatialDerivType& sdt)
00161 {
00162   static Array<string> names = tuple<string>("Identity", "Partial", "Normal", "Divergence");
00163   os << names[sdt];
00164   return os;
00165 }
00166 
00167 }

Site Contact