Go to the documentation of this file.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 #ifndef TSFNONMEMBEROPHELPERS_IMPL_HPP
00030 #define TSFNONMEMBEROPHELPERS_IMPL_HPP
00031
00032
00033 #include "TSFMultiVectorOperator.hpp"
00034 #include "TSFCommonOperatorsDecl.hpp"
00035 #include "Thyra_DefaultZeroLinearOp.hpp"
00036 #include "Thyra_DefaultDiagonalLinearOp.hpp"
00037 #include "Thyra_DefaultAddedLinearOp.hpp"
00038 #include "Thyra_DefaultMultipliedLinearOp.hpp"
00039 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
00040 #include "Thyra_DefaultIdentityLinearOp.hpp"
00041 #include "SundanceOut.hpp"
00042
00043
00044 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00045 #include "TSFCommonOperatorsImpl.hpp"
00046 #include "TSFLinearOperatorImpl.hpp"
00047 #endif
00048
00049 namespace TSFExtended
00050 {
00051
00052 template <class Scalar> inline
00053 LinearOperator<Scalar> zeroOperator(
00054 const VectorSpace<Scalar>& domain,
00055 const VectorSpace<Scalar>& range)
00056 {
00057 RCP<LinearOpBase<Scalar> > op
00058 = rcp(new SimpleZeroOp<Scalar>(domain, range));
00059
00060 return op;
00061 }
00062
00063
00064 template <class Scalar> inline
00065 LinearOperator<Scalar> identityOperator(
00066 const VectorSpace<Scalar>& space)
00067 {
00068 RCP<LinearOpBase<Scalar> > op
00069 = rcp(new SimpleIdentityOp<Scalar>(space));
00070
00071 return op;
00072 }
00073
00074
00075 template <class Scalar> inline
00076 LinearOperator<Scalar> diagonalOperator(
00077 const Vector<Scalar>& vec)
00078 {
00079 RCP<LinearOpBase<Scalar> > op
00080 = rcp(new DefaultDiagonalLinearOp<Scalar>(vec.ptr()));
00081
00082 return op;
00083 }
00084
00085
00086
00087 template <class Scalar> inline
00088 LinearOperator<Scalar> composedOperator(
00089 const Array<LinearOperator<Scalar> >& ops)
00090 {
00091
00092
00093 Array<LinearOperator<Scalar> > strippedOps;
00094
00095 for (int i=0; i<ops.size(); i++)
00096 {
00097 LinearOperator<Scalar> op_i = ops[i];
00098
00099
00100
00101 const SimpleZeroOp<Scalar>* zPtr
00102 = dynamic_cast<const SimpleZeroOp<Scalar>*>(op_i.ptr().get());
00103
00104 if (zPtr != 0)
00105 {
00106 VectorSpace<Scalar> r = ops[0].range();
00107 VectorSpace<Scalar> d = ops[ops.size()-1].domain();
00108 return zeroOperator(d, r);
00109 }
00110
00111
00112 const SimpleIdentityOp<Scalar>* IPtr
00113 = dynamic_cast<const SimpleIdentityOp<Scalar>*>(op_i.ptr().get());
00114 if (IPtr != 0)
00115 {
00116 continue;
00117 }
00118
00119 strippedOps.append(op_i);
00120 }
00121
00122 TEST_FOR_EXCEPT(strippedOps.size() < 1);
00123 if (strippedOps.size()==1) return strippedOps[0];
00124
00125 RCP<LinearOpBase<Scalar> > op
00126 = rcp(new SimpleComposedOp<Scalar>(strippedOps));
00127 return op;
00128 }
00129
00130
00131
00132
00133
00134 template <class Scalar> inline
00135 LinearOperator<Scalar> addedOperator(
00136 const Array<LinearOperator<Scalar> >& ops)
00137 {
00138
00139 Array<LinearOperator<Scalar> > strippedOps;
00140
00141 for (int i=0; i<ops.size(); i++)
00142 {
00143 LinearOperator<Scalar> op_i = ops[i];
00144
00145
00146 const SimpleZeroOp<Scalar>* zPtr
00147 = dynamic_cast<const SimpleZeroOp<Scalar>*>(op_i.ptr().get());
00148
00149 if (zPtr != 0) continue;
00150
00151 strippedOps.append(op_i);
00152 }
00153
00154 TEST_FOR_EXCEPT(strippedOps.size() < 1);
00155 if (strippedOps.size()==1) return strippedOps[0];
00156
00157 RCP<LinearOpBase<Scalar> > op
00158 = rcp(new SimpleAddedOp<Scalar>(strippedOps));
00159
00160 return op;
00161 }
00162
00163
00164
00165 template <class Scalar> inline
00166 LinearOperator<Scalar> scaledOperator(
00167 const Scalar& scale,
00168 const LinearOperator<Scalar>& op)
00169 {
00170 RCP<LinearOpBase<Scalar> > A
00171 = rcp(new DefaultScaledAdjointLinearOp<Scalar>(scale, Thyra::NOTRANS, op.ptr()));
00172
00173 return A;
00174 }
00175
00176
00177
00178 template <class Scalar> inline
00179 LinearOperator<Scalar> scaledTransposedOperator(
00180 const Scalar& scale,
00181 const LinearOperator<Scalar>& op)
00182 {
00183 RCP<LinearOpBase<Scalar> > A
00184 = rcp(new DefaultScaledAdjointLinearOp<Scalar>(scale, Thyra::TRANS, op.ptr()));
00185
00186 return A;
00187 }
00188
00189
00190
00191 template <class Scalar> inline
00192 LinearOperator<Scalar> transposedOperator(
00193 const LinearOperator<Scalar>& op)
00194 {
00195
00196
00197 const SimpleTransposedOp<Scalar>* tPtr
00198 = dynamic_cast<const SimpleTransposedOp<Scalar>*>(op.ptr().get());
00199 if (tPtr)
00200 {
00201 return tPtr->op();
00202 }
00203
00204
00205 const SimpleZeroOp<Scalar>* zPtr
00206 = dynamic_cast<const SimpleZeroOp<Scalar>*>(op.ptr().get());
00207
00208 if (zPtr != 0)
00209 {
00210 VectorSpace<Scalar> r = op.range();
00211 VectorSpace<Scalar> d = op.domain();
00212 return zeroOperator(r, d);
00213 }
00214
00215
00216
00217 RCP<LinearOpBase<Scalar> > A
00218 = rcp(new SimpleTransposedOp<Scalar>(op));
00219
00220 return A;
00221 }
00222
00223
00224 template <class Scalar> inline
00225 LinearOperator<Scalar> multiVectorOperator(
00226 const Teuchos::Array<Vector<Scalar> >& cols,
00227 const VectorSpace<Scalar>& domain)
00228 {
00229 RCP<LinearOpBase<Scalar> > A
00230 = rcp(new MultiVectorOperator<Scalar>(cols, domain));
00231
00232 return A;
00233 }
00234
00235
00236
00237 }
00238
00239
00240 #endif