Thyra_SUNDIALS_Ops.hpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //      Thyra: Interfaces and Support Code for the Interoperability 
00005 //                  of Abstract Numerical Algorithms 
00006 //                 Copyright (2004) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
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 Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 
00030 #ifndef THYRA_SUNDIALS_OPS_HPP
00031 #define THYRA_SUNDIALS_OPS_HPP
00032 
00033 
00034 
00035 #include "Thyra_VectorBase.hpp"
00036 #include "RTOpPack_SUNDIALS_Ops.hpp"
00037 
00038 namespace Thyra
00039 { 
00041   template<class Scalar> inline
00042   void VProd(const VectorBase<Scalar>& x, 
00043              const VectorBase<Scalar>& y,
00044              VectorBase<Scalar>* z)
00045   {
00046     RTOpPack::SUNDIALS_VProd<Scalar> op;
00047     const VectorBase<Scalar>* vecs[]      = { &x, &y };
00048     VectorBase<Scalar>*       targ_vecs[] = { z };
00049     applyOp<Scalar>(op,2,vecs,1,targ_vecs,(RTOpPack::ReductTarget*)NULL);
00050   }  
00051 
00052 
00053 
00054   
00056   template<class Scalar> inline
00057   void VDiv(const VectorBase<Scalar>& x, 
00058             const VectorBase<Scalar>& y,
00059             VectorBase<Scalar>* z)
00060   {
00061     RTOpPack::SUNDIALS_VDiv<Scalar> op;
00062     const VectorBase<Scalar>* vecs[]      = { &x, &y };
00063     VectorBase<Scalar>*       targ_vecs[] = { z };
00064     applyOp<Scalar>(op,2,vecs,1,targ_vecs,(RTOpPack::ReductTarget*)NULL);
00065   }
00066 
00067 
00068 
00070   template<class Scalar> inline
00071   void VScale(const Scalar& c,
00072               const VectorBase<Scalar>& x, 
00073               VectorBase<Scalar>* z)
00074   {
00075     RTOpPack::SUNDIALS_VScale<Scalar> op(c);
00076     const VectorBase<Scalar>* vecs[]      = { &x };
00077     VectorBase<Scalar>*       targ_vecs[] = { z };
00078     applyOp<Scalar>(op,1,vecs,1,targ_vecs,(RTOpPack::ReductTarget*)NULL);
00079   }
00080 
00081 
00082 
00084   template<class Scalar> inline
00085   void VAddConst(const Scalar& c,
00086                  const VectorBase<Scalar>& x, 
00087                  VectorBase<Scalar>* z)
00088   {
00089     RTOpPack::SUNDIALS_VAddConst<Scalar> op(c);
00090     const VectorBase<Scalar>* vecs[]      = { &x };
00091     VectorBase<Scalar>*       targ_vecs[] = { z };
00092     applyOp<Scalar>(op,1,vecs,1,targ_vecs,(RTOpPack::ReductTarget*)NULL);
00093   }
00094 
00095   
00097   template<class Scalar> inline
00098   Scalar VWL2Norm(const VectorBase<Scalar>& x, 
00099                   const VectorBase<Scalar>& w)
00100   {
00101     RTOpPack::SUNDIALS_VWL2Norm<Scalar> op;
00102     Teuchos::RefCountPtr<RTOpPack::ReductTarget> red_targ 
00103       = op.reduct_obj_create();
00104 
00105     const VectorBase<Scalar>* vecs[]      = { &x, &w };
00106     
00107     applyOp<Scalar>(op,2,vecs,0,(VectorBase<Scalar>**)NULL,&*red_targ);
00108     return sqrt(op(*red_targ));
00109   }
00110 
00111 
00113   template<class Scalar> inline
00114   Scalar VWrmsNorm(const VectorBase<Scalar>& x, 
00115                    const VectorBase<Scalar>& w)
00116   {
00117     return VWL2Norm(x,w)/sqrt(x.space()->dim());
00118   }
00119 
00120 
00121 
00123   template<class Scalar> inline
00124   Scalar VWrmsMaskNorm(const VectorBase<Scalar>& x, 
00125                        const VectorBase<Scalar>& w, 
00126                        const VectorBase<Scalar>& id)
00127   {
00128     RTOpPack::SUNDIALS_VWrmsMaskNorm<Scalar> op;
00129     Teuchos::RefCountPtr<RTOpPack::ReductTarget> red_targ 
00130       = op.reduct_obj_create();
00131 
00132     const VectorBase<Scalar>* vecs[]      = { &x, &w, &id };
00133     
00134     applyOp<Scalar>(op,3,vecs,0,(VectorBase<Scalar>**)NULL,&*red_targ);
00135     return sqrt(op(*red_targ));
00136   }
00137   
00139   template<class Scalar> inline
00140   Scalar VMinQuotient(const VectorBase<Scalar>& num, 
00141                       const VectorBase<Scalar>& denom)
00142   {
00143     RTOpPack::SUNDIALS_VMinQuotient<Scalar> op;
00144     Teuchos::RefCountPtr<RTOpPack::ReductTarget> red_targ 
00145       = op.reduct_obj_create();
00146 
00147     const VectorBase<Scalar>* vecs[]      = { &num, &denom };
00148     
00149     applyOp<Scalar>(op,2,vecs,0,(VectorBase<Scalar>**)NULL,&*red_targ);
00150     return op(*red_targ);
00151   }
00152 
00153 
00155   template<class Scalar> inline
00156   bool VConstrMask(const VectorBase<Scalar>& x, 
00157                    const VectorBase<Scalar>& constraint, 
00158                    VectorBase<Scalar>* mask)
00159   {
00160     RTOpPack::SUNDIALS_VConstrMask<Scalar> op;
00161     Teuchos::RefCountPtr<RTOpPack::ReductTarget> red_targ 
00162       = op.reduct_obj_create();
00163 
00164     const VectorBase<Scalar>* vecs[]      = { &x, &constraint };
00165     VectorBase<Scalar>*       targ_vecs[] = { mask  };
00166     
00167     applyOp<Scalar>(op,2,vecs,1,targ_vecs,&*red_targ);
00168     return op(*red_targ);
00169   }
00170 
00172   template<class Scalar> inline
00173   bool VInvTest(const VectorBase<Scalar>& v_rhs, 
00174                 VectorBase<Scalar>* v_lhs)
00175   {
00176     RTOpPack::SUNDIALS_VInvTest<Scalar> op;
00177     Teuchos::RefCountPtr<RTOpPack::ReductTarget> red_targ 
00178       = op.reduct_obj_create();
00179 
00180     const VectorBase<Scalar>* vecs[]      = { &v_rhs };
00181     VectorBase<Scalar>*       targ_vecs[] = { v_lhs  };
00182     
00183     applyOp<Scalar>(op,1,vecs,1,targ_vecs,&*red_targ);
00184     return op(*red_targ);
00185   }
00186   
00188   template<class Scalar> inline
00189   void VCompare(const Scalar& alpha,
00190                 const VectorBase<Scalar>& x,
00191                 VectorBase<Scalar>* y)
00192   {
00193     TEST_FOR_EXCEPTION(y==NULL,std::logic_error,
00194                        "compareToScalar(...), Error!");
00195     RTOpPack::SUNDIALS_VCompare<Scalar> op(alpha);
00196     const VectorBase<Scalar>* vecs[]      = { &x };
00197     VectorBase<Scalar>* targ_vecs[] = {y };
00198     applyOp<Scalar>(op,1,vecs,1,targ_vecs,(RTOpPack::ReductTarget*)NULL);
00199   }
00200 } 
00201 
00202 #endif 

Generated on Thu Sep 18 12:33:03 2008 for Thyra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1