SundanceFunctionIdentifier.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 "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   /* make sure the parent exists */
00052   TEUCHOS_TEST_FOR_EXCEPT(parent==0);
00053   dofID_ = parent->dofID();
00054 
00055   /* check for various stupid cases that should never happen */
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()); // -Wall
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 

Site Contact