SundanceSumOfIntegrals.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 "SundanceSumOfIntegrals.hpp"
00032 #include "SundanceSpatiallyConstantExpr.hpp"
00033 #include "SundanceSpectralPreprocessor.hpp"
00034 #include "PlayaTabs.hpp"
00035 
00036 using namespace Sundance;
00037 using namespace Teuchos;
00038 
00039 SumOfIntegrals::SumOfIntegrals(const RCP<CellFilterStub>& region,
00040   const Expr& expr,
00041   const RCP<QuadratureFamilyStub>& quad,
00042   const WatchFlag& watch)
00043   : ScalarExpr(), rqcToExprMap_()
00044 {
00045    addTerm(region, expr, quad, ParametrizedCurve::returnDummyCurve() , watch, 1);
00046 }
00047 
00048 SumOfIntegrals::SumOfIntegrals(const RCP<CellFilterStub>& region,
00049   const Expr& expr,
00050   const RCP<QuadratureFamilyStub>& quad,
00051   const ParametrizedCurve& curve,
00052   const WatchFlag& watch)  : ScalarExpr(), rqcToExprMap_()
00053 {
00054   addTerm(region, expr, quad, curve , watch, 1);
00055 }
00056 
00057 
00058 Expr SumOfIntegrals::filterSpectral(const Expr& expr) const 
00059 {
00060   return SpectralPreprocessor::projectSpectral(expr);
00061 }
00062 
00063 
00064 
00065 void SumOfIntegrals::addTerm(const RCP<CellFilterStub>& regionPtr,
00066   const Expr& expr,
00067   const RCP<QuadratureFamilyStub>& quadPtr, 
00068   const ParametrizedCurve& paramCurve,
00069   const WatchFlag& watch, int sign)
00070 {
00071   Expr ex = filterSpectral(expr);
00072 
00073   RegionQuadCombo rqc(regionPtr, quadPtr, paramCurve ,watch);
00074 
00075   if (rqcToExprMap_.containsKey(rqc))
00076   {
00077     Expr e = rqcToExprMap_.get(rqc);
00078     rqcToExprMap_.put(rqc, e + sign*ex);
00079   }
00080   else
00081   {
00082     rqcToExprMap_.put(rqc, sign*ex);
00083   }
00084 }
00085 
00086 
00087 void SumOfIntegrals::merge(const SumOfIntegrals* other, int sign) 
00088 {
00089   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00090          i=other->rqcToExprMap_.begin(); i!=other->rqcToExprMap_.end(); i++)
00091   {
00092     const RegionQuadCombo& rqc = i->first;
00093     const Expr& e = i->second;
00094     addTerm(rqc.domain(), e, rqc.quad(), rqc.paramCurve() , rqc.watch(), sign);
00095   }
00096 }
00097 
00098 void SumOfIntegrals::multiplyByConstant(const SpatiallyConstantExpr* expr) 
00099 {
00100   double a = expr->value();
00101   Sundance::Map<RegionQuadCombo, Expr> newMap;
00102   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00103          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00104   {
00105     Expr e = i->second;
00106     newMap.put(i->first, a*e);
00107   }
00108   rqcToExprMap_ = newMap;
00109 }
00110 
00111 void SumOfIntegrals::changeSign()
00112 {
00113   Sundance::Map<RegionQuadCombo, Expr> newMap;
00114   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00115          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00116   {
00117     Expr e = i->second;
00118     newMap.put(i->first, -e);
00119   }
00120   rqcToExprMap_ = newMap;
00121 }
00122 
00123 Set<int> SumOfIntegrals::funcsOnRegion(const OrderedHandle<CellFilterStub>& d, const Set<int>& funcSet) const 
00124 {
00125   Set<int> rtn;
00126   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00127          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00128   {
00129     const RegionQuadCombo& rqc = i->first;
00130     if (OrderedHandle<CellFilterStub>(rqc.domain()) != d) continue;
00131     Expr e = i->second;
00132     e.ptr()->accumulateFuncSet(rtn, funcSet);
00133   }
00134   return rtn;
00135 }
00136 
00137 
00138 bool SumOfIntegrals::integralHasTestFunctions(const OrderedHandle<CellFilterStub>& d) const 
00139 {
00140   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00141          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00142   {
00143     const RegionQuadCombo& rqc = i->first;
00144     if (OrderedHandle<CellFilterStub>(rqc.domain()) != d) continue;
00145     Expr e = i->second;
00146     if (e.hasTestFunctions()) return true;
00147   }
00148   return false;
00149 }
00150 
00151 
00152 
00153 RCP<CellFilterStub> SumOfIntegrals::nullRegion() const
00154 {
00155   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00156          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00157   {
00158     const RegionQuadCombo& rqc = i->first;
00159     if (!rqc.domain()->isNullRegion())
00160     {
00161       return rqc.domain()->makeNullRegion();
00162     }
00163   }
00164   
00165   TEUCHOS_TEST_FOR_EXCEPTION(true, std::runtime_error,
00166                      "SumOfIntegrals::nullRegion() called on a sum "
00167                      "of integrals with no non-null regions");
00168 
00169   return RCP<CellFilterStub>();
00170 }
00171 
00172 bool SumOfIntegrals::isIndependentOf(const Expr& u) const
00173 {
00174   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00175          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00176   {
00177     Expr e = i->second;
00178     if (!e.isIndependentOf(u)) return false;
00179   }
00180   return true;
00181 }
00182 
00183 bool SumOfIntegrals::isLinearForm(const Expr& u) const
00184 {
00185   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00186          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00187   {
00188     Expr e = i->second;
00189     if (!e.isLinearForm(u)) return false;
00190   }
00191   return true;
00192 }
00193 
00194 bool SumOfIntegrals::isQuadraticForm(const Expr& u) const
00195 {
00196   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00197          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00198   {
00199     Expr e = i->second;
00200     if (!e.isQuadraticForm(u)) return false;
00201   }
00202   return true;
00203 }
00204 
00205 
00206 bool SumOfIntegrals::everyTermHasTestFunctions() const
00207 {
00208   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00209          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00210   {
00211     Expr e = i->second;
00212     if (!e.everyTermHasTestFunctions()) return false;
00213   }
00214   return true;
00215 }
00216 
00217 
00218 bool SumOfIntegrals::isLinearInTests() const
00219 {
00220   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00221          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00222   {
00223     Expr e = i->second;
00224     if (!e.isLinearInTests()) return false;
00225   }
00226   return true;
00227 }
00228 
00229 bool SumOfIntegrals::hasTestFunctions() const
00230 {
00231   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00232          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00233   {
00234     Expr e = i->second;
00235     if (e.hasTestFunctions()) return true;
00236   }
00237   return false;
00238 }
00239 
00240 
00241 
00242 std::ostream& SumOfIntegrals::toText(std::ostream& os, bool paren) const
00243 {
00244   os << "Sum of Integrals[" << std::endl;
00245   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00246          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00247   {
00248     const RegionQuadCombo& rqc = i->first;
00249     Expr e = i->second;
00250     os << "Integral[" << std::endl;
00251     os << "rqc=" << rqc.toString() << std::endl;
00252     os << "expr=" << e.toString() << std::endl;
00253     os << "]" << std::endl;
00254   }
00255   os << "]" << std::endl;
00256 
00257   return os;
00258 }
00259 
00260 
00261 XMLObject SumOfIntegrals::toXML() const 
00262 {
00263   XMLObject rtn("SumOfIntegrals");
00264   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00265          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00266   {
00267     const RegionQuadCombo& rqc = i->first;
00268     Expr e = i->second;
00269     XMLObject child("Integral");
00270     rtn.addChild(child);
00271     child.addChild(rqc.quad()->toXML());
00272     child.addChild(rqc.domain()->toXML());
00273     child.addChild(rqc.watch().toXML());
00274     child.addChild(e.toXML());
00275   }
00276 
00277   return rtn;
00278 }
00279 
00280 
00281 bool SumOfIntegrals::lessThan(const ScalarExpr* other) const
00282 {
00283   const SumOfIntegrals* f = dynamic_cast<const SumOfIntegrals*>(other);
00284   TEUCHOS_TEST_FOR_EXCEPTION(f==0, std::logic_error, "cast should never fail at this point");
00285   
00286   return rqcToExprMap_ < f->rqcToExprMap_;
00287 }
00288 
00289 bool SumOfIntegrals::hasWatchedTerm() const 
00290 {
00291   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00292          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00293   {
00294     const RegionQuadCombo& rqc = i->first;
00295     if (rqc.watch().isActive()) return true;
00296   }
00297   return false;
00298 }
00299 
00300 
00301 
00302 int SumOfIntegrals::eqnSetSetupVerb() const 
00303 {
00304   int rtn = 0;
00305   for (Sundance::Map<RegionQuadCombo, Expr>::const_iterator 
00306          i=rqcToExprMap_.begin(); i!=rqcToExprMap_.end(); i++)
00307   {
00308     const RegionQuadCombo& rqc = i->first;
00309     int v = rqc.watch().param("equation set setup");
00310     if (v > rtn) rtn = v;
00311   }
00312   return rtn;
00313 }
00314 
00315 

Site Contact