SundanceCoordExpr.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 "SundanceCoordExpr.hpp"
00043 #include "SundanceEvalManager.hpp"
00044 #include "SundanceSparsitySuperset.hpp"
00045 #include "SundanceOut.hpp"
00046 #include "SundanceObjectWithVerbosity.hpp"
00047 
00048 using namespace Sundance;
00049 using namespace Sundance;
00050 using namespace Teuchos;
00051 
00052 
00053 CoordExpr::CoordExpr(int dir, const std::string& name)
00054   : EvaluatableExpr(),
00055     dir_(dir),
00056     name_(coordName(dir, name))
00057 {}
00058 
00059 bool CoordExpr::lessThan(const ScalarExpr* other) const
00060 {
00061   const CoordExpr* c = dynamic_cast<const CoordExpr*>(other);
00062   TEUCHOS_TEST_FOR_EXCEPTION(c==0, std::logic_error, "cast should never fail at this point");
00063   return dir() < c->dir();
00064 }
00065 
00066 XMLObject CoordExpr::toXML() const 
00067 {
00068   XMLObject rtn("CoordExpr");
00069   rtn.addAttribute("dir", Teuchos::toString(dir_));
00070   rtn.addAttribute("name", name());
00071   return rtn;
00072 }
00073 
00074 string CoordExpr::coordName(int dir, const std::string& name)
00075 {
00076   if (name.length() > 0) return name;
00077   switch(dir)
00078     {
00079     case 0:
00080       return "x";
00081     case 1:
00082       return "y";
00083     case 2:
00084       return "z";
00085     default:
00086       TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00087                          "CoordExpr::coordName direction out of range [0,2]");
00088       return "error";
00089     }
00090 }
00091 
00092 
00093 Set<MultipleDeriv> 
00094 CoordExpr::internalFindW(int order, const EvalContext& context) const
00095 {
00096   Tabs tab0;
00097   SUNDANCE_VERB_HIGH(tab0 << "CoordExpr::internalFindW() for " << toString());  
00098   Set<MultipleDeriv> rtn;
00099 
00100   if (order==0) rtn.put(MultipleDeriv());
00101 
00102   if (order==1) 
00103     {
00104       Deriv x = coordDeriv(dir_);
00105       MultipleDeriv md;
00106       md.put(x);
00107       rtn.put(md);
00108     }
00109 
00110   SUNDANCE_VERB_HIGH(tab0 << "W[" << order << "]=" << rtn);
00111   return rtn;
00112 }
00113 
00114 
00115 Set<MultipleDeriv> 
00116 CoordExpr::internalFindV(int order, const EvalContext& context) const
00117 {
00118   Tabs tab0;
00119   SUNDANCE_VERB_HIGH(tab0 << "CoordExpr::internalFindV() for " << toString());  
00120   Set<MultipleDeriv> rtn;
00121 
00122   if (order==0) rtn.put(MultipleDeriv());
00123 
00124   SUNDANCE_VERB_HIGH(tab0 << "V[" << order << "]=" << rtn);
00125   return rtn;
00126 }
00127 
00128 
00129 Set<MultipleDeriv> 
00130 CoordExpr::internalFindC(int order, const EvalContext& context) const
00131 {
00132   Tabs tab0;
00133   SUNDANCE_VERB_HIGH(tab0 << "CoordExpr::internalFindC() for " << toString());  
00134   Set<MultipleDeriv> rtn;
00135 
00136   if (order==1) 
00137     {
00138       Deriv x = coordDeriv(dir_);
00139       MultipleDeriv md;
00140       md.put(x);
00141       rtn.put(md);
00142     }
00143   SUNDANCE_VERB_HIGH(tab0 << "C[" << order << "]=" << rtn);
00144   return rtn;
00145 }
00146 
00147 
00148 
00149 
00150 
00151 

Site Contact