SundanceStdProductTransformations.hpp
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 #ifndef SUNDANCE_STDPRODUCTTRANSFORMATION_H
00043 #define SUNDANCE_STDPRODUCTTRANSFORMATION_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "SundanceProductTransformationSequence.hpp"
00047 
00048 namespace Sundance
00049 {
00050 using namespace Sundance;
00051 using namespace Teuchos;
00052 using namespace Sundance;
00053 
00054 
00055 
00056 
00057 /**
00058  * Apply a standard set of transformations
00059  */
00060 class StdProductTransformations : public ProductTransformationSequence
00061 {
00062 public:
00063   StdProductTransformations();
00064 
00065   virtual ~StdProductTransformations(){;}
00066 };
00067     
00068 /** 
00069  * Transform a product by removing a zero term: 
00070  * \f[
00071  * x \times 0 \rightarrow 0. 
00072  * \f]
00073  * \f[
00074  * 0 \times x \rightarrow 0. 
00075  * \f]
00076  */
00077 class RemoveZeroFromProduct : public ProductTransformation
00078 {
00079 public:
00080   /** */
00081   RemoveZeroFromProduct() : ProductTransformation() {;}
00082 
00083   /** */
00084   virtual ~RemoveZeroFromProduct(){;}
00085 
00086   /** */
00087   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00088     const RCP<ScalarExpr>& right,
00089     RCP<ScalarExpr>& rtn) const ;
00090 };
00091 
00092     
00093 /** 
00094  * Transform a product by removing multiplication by 1.0: 
00095  * \f[
00096  * x \times 1.0 \rightarrow x. 
00097  * \f]
00098  * \f[
00099  * 1.0 \times x \rightarrow x. 
00100  * \f]
00101  */
00102 class RemoveOneFromProduct : public ProductTransformation
00103 {
00104 public:
00105   /** */
00106   RemoveOneFromProduct() : ProductTransformation() {;}
00107 
00108   /** */
00109   virtual ~RemoveOneFromProduct(){;}
00110 
00111   /** */
00112   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00113     const RCP<ScalarExpr>& right,
00114     RCP<ScalarExpr>& rtn) const ;
00115 };
00116 
00117 /** 
00118  * Transform a product by removing multiplication by -1.0: 
00119  * \f[
00120  * x \times (-1.0) \rightarrow -x. 
00121  * \f]
00122  * \f[
00123  * -1.0 \times x \rightarrow -x. 
00124  * \f]
00125  */
00126 class RemoveMinusOneFromProduct : public ProductTransformation
00127 {
00128 public:
00129   /** */
00130   RemoveMinusOneFromProduct() : ProductTransformation() {;}
00131 
00132   /** */
00133   virtual ~RemoveMinusOneFromProduct(){;}
00134 
00135   /** */
00136   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00137     const RCP<ScalarExpr>& right,
00138     RCP<ScalarExpr>& rtn) const ;
00139 };
00140 
00141 /** 
00142  * Multiply two constant exprs without transformation 
00143  */
00144 class MultiplyConstants : public ProductTransformation
00145 {
00146 public:
00147   /** */
00148   MultiplyConstants() : ProductTransformation() {;}
00149 
00150   /** */
00151   virtual ~MultiplyConstants(){;}
00152 
00153   /** */
00154   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00155     const RCP<ScalarExpr>& right,
00156     RCP<ScalarExpr>& rtn) const ;
00157 };
00158 
00159 /** 
00160  * Transform a product by moving any constants to the left:
00161  * \f[
00162  * x \times a \rightarrow a \times x
00163  * \f]
00164  **/
00165 class MoveConstantsToLeftOfProduct : public ProductTransformation
00166 {
00167 public:
00168   /** */
00169   MoveConstantsToLeftOfProduct() : ProductTransformation() {;}
00170 
00171   /** */
00172   virtual ~MoveConstantsToLeftOfProduct(){;}
00173 
00174   /** */
00175   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00176     const RCP<ScalarExpr>& right,
00177     RCP<ScalarExpr>& rtn) const ;
00178 };
00179 
00180 /** 
00181  * Transform a product by any unary minus operations outside the
00182  * product
00183  * \f[
00184  * (-x) \times y \rightarrow -(x \times y)
00185  * \f]
00186  * \f[
00187  * x \times (-y) \rightarrow -(x \times y)
00188  * \f]
00189  * \f[
00190  * )-x) \times (-y) \rightarrow x \times y
00191  * \f]
00192  **/
00193 class MoveUnaryMinusOutsideProduct : public ProductTransformation
00194 {
00195 public:
00196   /** */
00197   MoveUnaryMinusOutsideProduct() : ProductTransformation() {;}
00198 
00199   /** */
00200   virtual ~MoveUnaryMinusOutsideProduct(){;}
00201 
00202   /** */
00203   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00204     const RCP<ScalarExpr>& right,
00205     RCP<ScalarExpr>& rtn) const ;
00206 };
00207 
00208 /**
00209  * Transform a product by associating any hungry diff op in the
00210  * left operand with the right operand:
00211  * \f[
00212  * (u D_x) v \rightarrow u D_x u
00213  * \f]
00214  */
00215 class AssociateHungryDiffOpWithOperand : public ProductTransformation
00216 {
00217 public:
00218   /** */
00219   AssociateHungryDiffOpWithOperand() : ProductTransformation() {;}
00220 
00221   /** */
00222   virtual ~AssociateHungryDiffOpWithOperand(){;}
00223 
00224   /** */
00225   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00226     const RCP<ScalarExpr>& right,
00227     RCP<ScalarExpr>& rtn) const ;
00228 };
00229 
00230 /**
00231  * Kill a diff op acting on a constant
00232  * \f[
00233  * D_x \alpha \rightarrow 0
00234  * \f]
00235  * \f[
00236  * D_x (\alpha + u) \rightarrow D_x u
00237  * \f]
00238  */
00239 class KillDiffOpOnConstant : public ProductTransformation
00240 {
00241 public:
00242   /** */
00243   KillDiffOpOnConstant() : ProductTransformation() {;}
00244 
00245   /** */
00246   virtual ~KillDiffOpOnConstant(){;}
00247 
00248   /** */
00249   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00250     const RCP<ScalarExpr>& right,
00251     RCP<ScalarExpr>& rtn) const ;
00252 };
00253 
00254 /**
00255  * Bring a constant outside a diff op
00256  * \f[
00257  * D_x (\alpha u) \rightarrow \alpha D_x u
00258  * \f]
00259  */
00260 class BringConstantOutsideDiffOp : public ProductTransformation
00261 {
00262 public:
00263   /** */
00264   BringConstantOutsideDiffOp() : ProductTransformation() {;}
00265 
00266   /** */
00267   virtual ~BringConstantOutsideDiffOp(){;}
00268 
00269   /** */
00270   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00271     const RCP<ScalarExpr>& right,
00272     RCP<ScalarExpr>& rtn) const ;
00273 };
00274     
00275 /**
00276  * Distribute a sum of diff ops over their operand
00277  * \f[
00278  * (D_1 + D_2) u \rightarrow D_1 u + D_2 u
00279  * \f]
00280  */
00281 class DistributeSumOfDiffOps : public ProductTransformation
00282 {
00283 public:
00284   /** */
00285   DistributeSumOfDiffOps() : ProductTransformation() {;}
00286 
00287   /** */
00288   virtual ~DistributeSumOfDiffOps(){;}
00289 
00290   /** */
00291   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00292     const RCP<ScalarExpr>& right,
00293     RCP<ScalarExpr>& rtn) const ;
00294 };
00295 
00296 /**
00297  * Apply a simple diff op
00298  */
00299 class ApplySimpleDiffOp : public ProductTransformation
00300 {
00301 public:
00302   /** */
00303   ApplySimpleDiffOp() : ProductTransformation() {;}
00304 
00305   /** */
00306   virtual ~ApplySimpleDiffOp(){;}
00307 
00308   /** */
00309   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00310     const RCP<ScalarExpr>& right,
00311     RCP<ScalarExpr>& rtn) const ;
00312 };
00313 
00314 /** 
00315  * Rearrange a product whose right operand is 
00316  * a product including a constant
00317  * such that constants are grouped on the left:
00318  * \f[
00319  * \alpha (\beta u) \rightarrow (\alpha\beta) u
00320  * \f]
00321  * \f[
00322  * u (\alpha v) \rightarrow \alpha (u v)
00323  * \f]
00324  **/
00325 class RearrangeRightProductWithConstant : public ProductTransformation
00326 {
00327 public:
00328   /** */
00329   RearrangeRightProductWithConstant() : ProductTransformation() {;}
00330 
00331   /** */
00332   virtual ~RearrangeRightProductWithConstant(){;}
00333 
00334   /** */
00335   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00336     const RCP<ScalarExpr>& right,
00337     RCP<ScalarExpr>& rtn) const ;
00338 };
00339 
00340 /** 
00341  * Rearrange a product whose left operand is a product including a constant
00342  * such that constants are grouped on the left:
00343  * \f[
00344  * (\alpha u)\beta \rightarrow \alpha\beta u
00345  * \f]
00346  * \f[
00347  * (\alpha u)v \rightarrow \alpha (u v)
00348  * \f]
00349  **/
00350 class RearrangeLeftProductWithConstant : public ProductTransformation
00351 {
00352 public:
00353   /** */
00354   RearrangeLeftProductWithConstant() : ProductTransformation() {;}
00355 
00356   /** */
00357   virtual ~RearrangeLeftProductWithConstant(){;}
00358 
00359   /** */
00360   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00361     const RCP<ScalarExpr>& right,
00362     RCP<ScalarExpr>& rtn) const ;
00363 };
00364 
00365 /** 
00366  * Rearrange a product of a constant and an integral so that
00367  * the constant is under the integral sign:
00368  * \f[
00369  * \alpha \int u \rightarrow \int \alpha u
00370  * \f]
00371  **/
00372 class TakeConstantUnderIntegralSign : public ProductTransformation
00373 {
00374 public:
00375   /** */
00376   TakeConstantUnderIntegralSign() : ProductTransformation() {;}
00377 
00378   /** */
00379   virtual ~TakeConstantUnderIntegralSign(){;}
00380 
00381   /** */
00382   virtual bool doTransform(const RCP<ScalarExpr>& left, 
00383     const RCP<ScalarExpr>& right,
00384     RCP<ScalarExpr>& rtn) const ;
00385 };
00386 }
00387 
00388 #endif

Site Contact