42#ifndef THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_DEF_HPP
43#define THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_DEF_HPP
45#include "Thyra_DefaultMultipliedLinearOp_decl.hpp"
46#include "Thyra_AssertOp.hpp"
57void DefaultMultipliedLinearOp<Scalar>::assertInitialized()
const
67std::string DefaultMultipliedLinearOp<Scalar>::getClassName()
const
75Ordinal DefaultMultipliedLinearOp<Scalar>::getRangeDim()
const
77 return (numOps() > 0 ? this->range()->dim() : 0);
83Ordinal DefaultMultipliedLinearOp<Scalar>::getDomainDim()
const
85 return (numOps() > 0 ? this->domain()->dim() : 0);
101 const int nOps = Ops.size();
103 for(
int k = 0; k < nOps; ++k )
104 Ops_[k].initialize(Ops[k]);
106 setupDefaultObjectLabel();
110template<
class Scalar>
114 const int nOps = Ops.size();
116 for(
int k = 0; k < nOps; ++k )
117 Ops_[k].initialize(Ops[k]);
119 setupDefaultObjectLabel();
123template<
class Scalar>
127 setupDefaultObjectLabel();
134template<
class Scalar>
141template<
class Scalar>
147 return Ops_[k].isConst();
151template<
class Scalar>
158 return Ops_[k].getNonconstObj();
162template<
class Scalar>
176template<
class Scalar>
181 return getOp(0)->range();
187template<
class Scalar>
192 return getOp(numOps()-1)->domain();
198template<
class Scalar>
209template<
class Scalar>
212 std::ostringstream oss;
213 oss << getClassName() <<
"{numOps="<<numOps()
214 <<
",rangeDim=" << getRangeDim()
215 <<
",domainDim="<< getDomainDim() <<
"}";
219template<
class Scalar>
229 const int nOps = Ops_.size();
233 *out << this->description() << std::endl;
239 *out << this->description() << std::endl;
242 <<
"Constituent LinearOpBase objects for M = Op[0]*...*Op[numOps-1]:\n";
244 for(
int k = 0; k < nOps; ++k ) {
245 *out <<
"Op["<<k<<
"] = " << Teuchos::describe(*getOp(k),verbLevel);
261template<
class Scalar>
264 bool overallOpSupported =
true;
265 for(
int k = 0; k < static_cast<int>(Ops_.size()); ++k )
266 if(!Thyra::opSupported(*getOp(k),M_trans)) overallOpSupported =
false;
267 return overallOpSupported;
272template<
class Scalar>
281 using Teuchos::rcpFromPtr;
282 using Teuchos::rcpFromRef;
285 getClassName()+
"::apply(...)", *
this, M_trans, X, &*Y
288 const int nOps = Ops_.size();
297 for(
int k = nOps-1; k >= 0; --k ) {
300 if(k==0) Y_k = rcpFromPtr(Y);
else Y_k = T_k = createMembers(getOp(k)->range(), m);
301 if(k==nOps-1) X_k = rcpFromRef(X);
else X_k = T_kp1;
303 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr());
305 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr(), alpha, beta);
316 for(
int k = 0; k <= nOps-1; ++k ) {
319 if(k==nOps-1) Y_k = rcpFromPtr(Y);
else Y_k = T_k = createMembers(getOp(k)->domain(), m);
320 if(k==0) X_k = rcpFromRef(X);
else X_k = T_km1;
322 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr());
324 Thyra::apply(*getOp(k), M_trans, *X_k, Y_k.
ptr(), alpha, beta);
334template<
class Scalar>
340 const int nOps = Ops_.size();
341 for(
int k = 0; k < nOps; ++k ) {
345 getClassName()+
"::initialize(...)"
360template<
class Scalar>
361void DefaultMultipliedLinearOp<Scalar>::setupDefaultObjectLabel()
363 std::ostringstream label;
364 const int nOps = Ops_.size();
365 for(
int k = 0; k < nOps; ++k ) {
366 std::string Op_k_label = Ops_[k]->getObjectLabel();
367 if (Op_k_label.length() == 0)
371 label <<
"("<<Op_k_label<<
")";
373 this->setObjectLabel(label.str());
385template<
class Scalar>
387Thyra::nonconstMultiply(
388 const RCP<LinearOpBase<Scalar> > &A,
389 const RCP<LinearOpBase<Scalar> > &B,
390 const std::string &M_label
393 using Teuchos::tuple;
394 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
395 defaultMultipliedLinearOp<Scalar>(tuple(A, B)());
397 multOp->setObjectLabel(M_label);
402template<
class Scalar>
405 const RCP<
const LinearOpBase<Scalar> > &A,
406 const RCP<
const LinearOpBase<Scalar> > &B,
407 const std::string &M_label
410 using Teuchos::tuple;
411 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
412 defaultMultipliedLinearOp<Scalar>(tuple(A, B)());
414 multOp->setObjectLabel(M_label);
419template<
class Scalar>
422 const RCP<
const LinearOpBase<Scalar> > &A,
423 const RCP<
const LinearOpBase<Scalar> > &B,
424 const RCP<
const LinearOpBase<Scalar> > &C,
425 const std::string &M_label
428 using Teuchos::tuple;
429 RCP<DefaultMultipliedLinearOp<Scalar> > multOp =
430 defaultMultipliedLinearOp<Scalar>(tuple(A, B, C)());
432 multOp->setObjectLabel(M_label);
444#define THYRA_DEFAULT_MULTIPLIED_LINEAR_OP_INSTANT(SCALAR) \
446 template class DefaultMultipliedLinearOp<SCALAR >; \
448 template RCP<LinearOpBase<SCALAR > > \
450 const RCP<LinearOpBase<SCALAR > > &A, \
451 const RCP<LinearOpBase<SCALAR > > &B, \
452 const std::string &M_label \
455 template RCP<const LinearOpBase<SCALAR > > \
457 const RCP<const LinearOpBase<SCALAR > > &A, \
458 const RCP<const LinearOpBase<SCALAR > > &B, \
459 const std::string &M_label \
462 template RCP<const LinearOpBase<SCALAR > > \
464 const RCP<const LinearOpBase<SCALAR > > &A, \
465 const RCP<const LinearOpBase<SCALAR > > &B, \
466 const RCP<const LinearOpBase<SCALAR > > &C, \
467 const std::string &M_label \
virtual std::string description() const
Concrete composite LinearOpBase subclass that creates an implicitly multiplied linear operator out of...
bool opIsConst(const int k) const
RCP< const LinearOpBase< Scalar > > getOp(const int k) const
void uninitialize()
Set to uninitialized.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent linear operators.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise.
void initialize(const ArrayView< const RCP< LinearOpBase< Scalar > > > &Ops)
Initialize given a list of non-const linear operators.
DefaultMultipliedLinearOp()
Constructs to uninitialized.
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
std::string description() const
Prints just the name DefaultMultipliedLinearOp along with the overall dimensions and the number of co...
RCP< const LinearOpBase< Scalar > > clone() const
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Base class for all linear operators.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Interface for a collection of column vectors called a multi-vector.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#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.
#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...
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
const char * toString(EConj conj)
Return a string name for a EOpTransp value. `*.
EOpTransp real_trans(EOpTransp transp)
Return NOTRANS or TRANS for real scalar valued operators and this also is used for determining struct...
@ NOTRANS
Use the non-transposed operator.
T_To & dyn_cast(T_From &from)
std::string toString(const T &t)