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

Site Contact