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 "SundanceFunctionIdentifier.hpp"
00032 #include "SundanceOrderedTuple.hpp"
00033
00034 using namespace Sundance;
00035 using namespace Sundance;
00036
00037 FunctionIdentifier::FunctionIdentifier()
00038 : dofID_(-1), algSpec_(ScalarAT)
00039 {}
00040
00041 FunctionIdentifier::FunctionIdentifier(
00042 const AlgebraSpecifier& algSpec)
00043 : dofID_(nextID()), algSpec_(algSpec)
00044 {}
00045
00046 FunctionIdentifier::FunctionIdentifier(
00047 const FunctionIdentifier* parent,
00048 const AlgebraSpecifier& algSpec)
00049 : dofID_(-1), algSpec_(algSpec)
00050 {
00051
00052 TEUCHOS_TEST_FOR_EXCEPT(parent==0);
00053 dofID_ = parent->dofID();
00054
00055
00056 TEUCHOS_TEST_FOR_EXCEPTION(!parent->algSpec_.isVector(), std::logic_error,
00057 "attempted to form a function ID for a component of a non-vector object:"
00058 "parent=" << parent->toString() << " component spec=" << algSpec);
00059 TEUCHOS_TEST_FOR_EXCEPTION(algSpec.isVector() || algSpec.isScalar(), std::runtime_error,
00060 "attempted to define a vector or scalar as a component of another object."
00061 "parent=" << parent->toString() << " component spec=" << algSpec);
00062 }
00063
00064
00065
00066 int FunctionIdentifier::componentIndex() const
00067 {
00068 TEUCHOS_TEST_FOR_EXCEPTION(!(algSpec_.isCoordinateComponent() || algSpec_.isScalar()), std::logic_error,
00069 "attempted to find component index for a FID that is not a "
00070 "scalar or a coordinate component of a vector");
00071 if (algSpec_.isScalar()) return 0;
00072 return algSpec_.direction();
00073 }
00074
00075 string FunctionIdentifier::toString() const
00076 {
00077 TeuchosOStringStream os;
00078 os << *this;
00079 return os.str();
00080 }
00081
00082 FunctionIdentifier FunctionIdentifier::createNormal() const
00083 {
00084 TEUCHOS_TEST_FOR_EXCEPTION(!isVector(), std::logic_error,
00085 "attempted to find normal component of a FID that is not a vector");
00086
00087 return FunctionIdentifier(this, normalAlgebraSpec());
00088 }
00089
00090 bool FunctionIdentifier::operator<(const FunctionIdentifier& other) const
00091 {
00092 OrderedPair<int, AlgebraSpecifier> me(dofID_, algSpec_);
00093 OrderedPair<int, AlgebraSpecifier> you(other.dofID_, other.algSpec_);
00094 return me < you;
00095 }
00096
00097 FunctionIdentifier FunctionIdentifier::createComponent(int d) const
00098 {
00099 TEUCHOS_TEST_FOR_EXCEPTION(!isVector(), std::logic_error,
00100 "attempted to find component of a FID that is not a vector");
00101
00102 return FunctionIdentifier(this, coordAlgebraSpec(d));
00103 }
00104
00105 namespace Sundance
00106 {
00107
00108 FunctionIdentifier makeFuncID(int tensorOrder)
00109 {
00110 if (tensorOrder==0)
00111 return FunctionIdentifier(scalarAlgebraSpec());
00112 else if (tensorOrder==1)
00113 return FunctionIdentifier(vectorAlgebraSpec());
00114 else
00115 TEUCHOS_TEST_FOR_EXCEPT(true);
00116 return FunctionIdentifier(scalarAlgebraSpec());
00117 }
00118
00119 }
00120
00121
00122 namespace std
00123 {
00124
00125 ostream& operator<<(std::ostream& os,
00126 const Sundance::FunctionIdentifier& fid)
00127 {
00128 os << "FuncID(dofID=" << fid.dofID() << ", component type=" << fid.algSpec() << ")";
00129 return os;
00130 }
00131
00132 }
00133