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

Site Contact