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

Site Contact