Go to the documentation of this file.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
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;
00153 }
00154
00155 }
00156
00157
00158 namespace std
00159 {
00160
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
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 }