10 #ifndef THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_DEF_HPP
11 #define THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_DEF_HPP
13 #include "Thyra_DefaultMultipliedLinearOp_decl.hpp"
14 #include "Thyra_AssertOp.hpp"
23 template<
class Scalar>
25 void DefaultMultipliedLinearOp<Scalar>::assertInitialized()
const
33 template<
class Scalar>
35 std::string DefaultMultipliedLinearOp<Scalar>::getClassName()
const
41 template<
class Scalar>
43 Ordinal DefaultMultipliedLinearOp<Scalar>::getRangeDim()
const
45 return (numOps() > 0 ? this->range()->dim() : 0);
49 template<
class Scalar>
51 Ordinal DefaultMultipliedLinearOp<Scalar>::getDomainDim()
const
53 return (numOps() > 0 ? this->domain()->dim() : 0);
60 template<
class Scalar>
65 template<
class Scalar>
69 const int nOps = Ops.size();
71 for(
int k = 0; k < nOps; ++k )
74 setupDefaultObjectLabel();
78 template<
class Scalar>
82 const int nOps = Ops.size();
84 for(
int k = 0; k < nOps; ++k )
87 setupDefaultObjectLabel();
91 template<
class Scalar>
95 setupDefaultObjectLabel();
102 template<
class Scalar>
109 template<
class Scalar>
115 return Ops_[k].isConst();
119 template<
class Scalar>
126 return Ops_[k].getNonconstObj();
130 template<
class Scalar>
144 template<
class Scalar>
149 return getOp(0)->range();
151 return Teuchos::null;
155 template<
class Scalar>
160 return getOp(numOps()-1)->domain();
162 return Teuchos::null;
166 template<
class Scalar>
170 return Teuchos::null;
177 template<
class Scalar>
180 std::ostringstream oss;
181 oss << getClassName() <<
"{numOps="<<numOps()
182 <<
",rangeDim=" << getRangeDim()
183 <<
",domainDim="<< getDomainDim() <<
"}";
187 template<
class Scalar>
197 const int nOps = Ops_.size();
201 *out << this->description() << std::endl;
207 *out << this->description() << std::endl;
210 <<
"Constituent LinearOpBase objects for M = Op[0]*...*Op[numOps-1]:\n";
212 for(
int k = 0; k < nOps; ++k ) {
213 *out <<
"Op["<<k<<
"] = " << Teuchos::describe(*getOp(k),verbLevel);
229 template<
class Scalar>
232 bool overallOpSupported =
true;
233 for(
int k = 0; k < static_cast<int>(Ops_.size()); ++k )
234 if(!Thyra::opSupported(*getOp(k),M_trans)) overallOpSupported =
false;
235 return overallOpSupported;
240 template<
class Scalar>
249 using Teuchos::rcpFromPtr;
250 using Teuchos::rcpFromRef;
253 getClassName()+
"::apply(...)", *
this, M_trans, X, &*Y
255 #endif // TEUCHOS_DEBUG
256 const int nOps = Ops_.size();
265 for(
int k = nOps-1; k >= 0; --k ) {
268 if(k==0) Y_k = rcpFromPtr(Y);
else Y_k = T_k = createMembers(getOp(k)->range(), m);
269 if(k==nOps-1) X_k = rcpFromRef(X);
else X_k = T_kp1;
271 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr());
273 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr(), alpha, beta);
284 for(
int k = 0; k <= nOps-1; ++k ) {
287 if(k==nOps-1) Y_k = rcpFromPtr(Y);
else Y_k = T_k = createMembers(getOp(k)->domain(), m);
288 if(k==0) X_k = rcpFromRef(X);
else X_k = T_km1;
290 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr());
292 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr(), alpha, beta);
302 template<
class Scalar>
308 const int nOps = Ops_.size();
309 for(
int k = 0; k < nOps; ++k ) {
313 getClassName()+
"::initialize(...)"
328 template<
class Scalar>
329 void DefaultMultipliedLinearOp<Scalar>::setupDefaultObjectLabel()
331 std::ostringstream label;
332 const int nOps = Ops_.size();
333 for(
int k = 0; k < nOps; ++k ) {
334 std::string Op_k_label = Ops_[k]->getObjectLabel();
335 if (Op_k_label.length() == 0)
339 label <<
"("<<Op_k_label<<
")";
341 this->setObjectLabel(label.str());
353 template<
class Scalar>
355 Thyra::nonconstMultiply(
356 const RCP<LinearOpBase<Scalar> > &A,
357 const RCP<LinearOpBase<Scalar> > &B,
358 const std::string &M_label
361 using Teuchos::tuple;
362 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
363 defaultMultipliedLinearOp<Scalar>(tuple(A, B)());
365 multOp->setObjectLabel(M_label);
370 template<
class Scalar>
373 const RCP<
const LinearOpBase<Scalar> > &A,
374 const RCP<
const LinearOpBase<Scalar> > &B,
375 const std::string &M_label
378 using Teuchos::tuple;
379 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
380 defaultMultipliedLinearOp<Scalar>(tuple(A, B)());
382 multOp->setObjectLabel(M_label);
387 template<
class Scalar>
390 const RCP<
const LinearOpBase<Scalar> > &A,
391 const RCP<
const LinearOpBase<Scalar> > &B,
392 const RCP<
const LinearOpBase<Scalar> > &C,
393 const std::string &M_label
396 using Teuchos::tuple;
397 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
398 defaultMultipliedLinearOp<Scalar>(tuple(A, B, C)());
400 multOp->setObjectLabel(M_label);
412 #define THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_INSTANT(SCALAR) \
414 template class DefaultMultipliedLinearOp<SCALAR >; \
416 template RCP<LinearOpBase<SCALAR > > \
418 const RCP<LinearOpBase<SCALAR > > &A, \
419 const RCP<LinearOpBase<SCALAR > > &B, \
420 const std::string &M_label \
423 template RCP<const LinearOpBase<SCALAR > > \
425 const RCP<const LinearOpBase<SCALAR > > &A, \
426 const RCP<const LinearOpBase<SCALAR > > &B, \
427 const std::string &M_label \
430 template RCP<const LinearOpBase<SCALAR > > \
432 const RCP<const LinearOpBase<SCALAR > > &A, \
433 const RCP<const LinearOpBase<SCALAR > > &B, \
434 const RCP<const LinearOpBase<SCALAR > > &C, \
435 const std::string &M_label \
439 #endif // THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_DEF_HPP
void initialize(int *argc, char ***argv)
#define THYRA_ASSERT_LINEAR_OP_TIMES_LINEAR_OP_SPACES_NAMES(FUNC_NAME, M1, M1_T, M1_N, M2, M2_T, M2_N)
Assert that a linear operator multiplication matches up.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
basic_OSTab< char > OSTab
#define THYRA_ASSERT_LINEAR_OP_MULTIVEC_APPLY_SPACES(FUNC_NAME, M, M_T, X, Y)
This is a very useful macro that should be used to validate that the spaces for the multi-vector vers...
DefaultMultipliedLinearOp()
Constructs to uninitialized.
bool opIsConst(const int k) const
basic_FancyOStream< char > FancyOStream
Use the non-transposed operator.
EOpTransp real_trans(EOpTransp transp)
Return NOTRANS or TRANS for real scalar valued operators and this also is used for determining struct...
void uninitialize()
Set to uninitialized.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent linear operators.
void initialize(const ArrayView< const RCP< LinearOpBase< Scalar > > > &Ops)
Initialize given a list of non-const linear operators.
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< const LinearOpBase< Scalar > > clone() const
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
Concrete composite LinearOpBase subclass that creates an implicitly multiplied linear operator out of...
virtual std::string description() const
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
Base class for all linear operators.
std::string description() const
Prints just the name DefaultMultipliedLinearOp along with the overall dimensions and the number of co...
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
RCP< const LinearOpBase< Scalar > > getOp(const int k) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise...
std::string toString(const T &t)