00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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