00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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;
00142 }
00143
00144 }
00145
00146
00147 namespace std
00148 {
00149
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
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 }