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

Site Contact