42#ifndef THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
43#define THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
45#include "Thyra_DefaultAddedLinearOp_decl.hpp"
46#include "Thyra_DefaultScaledAdjointLinearOp.hpp"
47#include "Thyra_AssertOp.hpp"
48#include "Teuchos_Utils.hpp"
59void DefaultAddedLinearOp<Scalar>::assertInitialized()
const
69std::string DefaultAddedLinearOp<Scalar>::getClassName()
const
77Ordinal DefaultAddedLinearOp<Scalar>::getRangeDim()
const
79 return (numOps() > 0 ? this->range()->dim() : 0);
85Ordinal DefaultAddedLinearOp<Scalar>::getDomainDim()
const
87 return (numOps() > 0 ? this->domain()->dim() : 0);
107template<
class Scalar>
115template<
class Scalar>
119 const int l_numOps = Ops.size();
120 Ops_.resize(l_numOps);
121 for(
int k = 0; k < l_numOps; ++k )
122 Ops_[k].initialize(Ops[k]);
124 setupDefaultObjectLabel();
128template<
class Scalar>
132 const int l_numOps = Ops.size();
133 Ops_.resize(l_numOps);
134 for(
int k = 0; k < l_numOps; ++k )
135 Ops_[k].initialize(Ops[k]);
137 setupDefaultObjectLabel();
141template<
class Scalar>
145 setupDefaultObjectLabel();
152template<
class Scalar>
159template<
class Scalar>
165 return Ops_[k].isConst();
169template<
class Scalar>
176 return Ops_[k].getNonconstObj();
180template<
class Scalar>
194template<
class Scalar>
199 return getOp(0)->range();
201 return Teuchos::null;
205template<
class Scalar>
210 return getOp(numOps()-1)->domain();
212 return Teuchos::null;
216template<
class Scalar>
220 return Teuchos::null;
227template<
class Scalar>
230 std::ostringstream oss;
231 oss << getClassName() <<
"{numOps="<<numOps()
232 <<
",rangeDim=" << getRangeDim()
233 <<
",domainDim="<< getDomainDim() <<
"}";
238template<
class Scalar>
249 const int l_numOps = Ops_.size();
253 *out << this->description() << std::endl;
259 *out << this->description() << std::endl;
262 <<
"Constituent LinearOpBase objects for M = Op[0]*...*Op[numOps-1]:\n";
264 for(
int k = 0; k < l_numOps; ++k ) {
265 *out <<
"Op["<<k<<
"] = " << Teuchos::describe(*getOp(k),verbLevel);
281template<
class Scalar>
284 bool isOpSupported =
true;
285 for(
int k = 0; k < static_cast<int>(Ops_.size()); ++k )
286 if(!Thyra::opSupported(*getOp(k),M_trans)) isOpSupported =
false;
287 return isOpSupported;
292template<
class Scalar>
304 getClassName()+
"::apply(...)", *
this, M_trans, X, &*Y
314 const int l_numOps = Ops_.size();
315 for(
int j = 0; j < l_numOps; ++j )
316 Thyra::apply(*getOp(j), M_trans, X, Y, alpha, j==0 ? beta : ST::one());
323template<
class Scalar>
329 const int l_numOps = Ops_.size();
330 for(
int k = 0; k < l_numOps; ++k ) {
334 getClassName()+
"::initialize(...)"
349template<
class Scalar>
350void DefaultAddedLinearOp<Scalar>::setupDefaultObjectLabel()
352 std::ostringstream label;
353 const int l_numOps = Ops_.size();
354 for(
int k = 0; k < l_numOps; ++k ) {
355 std::string Op_k_label = Ops_[k]->getObjectLabel();
356 if (Op_k_label.length() == 0)
360 label <<
"("<<Op_k_label<<
")";
362 this->setObjectLabel(label.str());
370template<
class Scalar>
373 const RCP<LinearOpBase<Scalar> > &A,
374 const RCP<LinearOpBase<Scalar> > &B,
375 const std::string &label
378 using Teuchos::tuple;
379 RCP<LinearOpBase<Scalar> > alo =
380 defaultAddedLinearOp<Scalar>(
381 tuple<RCP<LinearOpBase<Scalar> > >(A, B)()
384 alo->setObjectLabel(label);
389template<
class Scalar>
392 const RCP<
const LinearOpBase<Scalar> > &A,
393 const RCP<
const LinearOpBase<Scalar> > &B,
394 const std::string &label
397 using Teuchos::tuple;
398 RCP<LinearOpBase<Scalar> > alo =
399 defaultAddedLinearOp<Scalar>(
400 tuple<RCP<
const LinearOpBase<Scalar> > >(A, B)()
403 alo->setObjectLabel(label);
408template<
class Scalar>
410Thyra::nonconstSubtract(
411 const RCP<LinearOpBase<Scalar> > &A,
412 const RCP<LinearOpBase<Scalar> > &B,
413 const std::string &label
416 typedef ScalarTraits<Scalar> ST;
417 using Teuchos::tuple;
418 RCP<LinearOpBase<Scalar> > alo =
419 defaultAddedLinearOp<Scalar>(
420 tuple<RCP<LinearOpBase<Scalar> > >(
421 A, nonconstScale<Scalar>(-ST::one(),B) )()
424 alo->setObjectLabel(label);
429template<
class Scalar>
432 const RCP<
const LinearOpBase<Scalar> > &A,
433 const RCP<
const LinearOpBase<Scalar> > &B,
434 const std::string &label
437 typedef ScalarTraits<Scalar> ST;
438 using Teuchos::tuple;
439 RCP<LinearOpBase<Scalar> > alo =
440 defaultAddedLinearOp<Scalar>(
441 tuple<RCP<
const LinearOpBase<Scalar> > >(
442 A, scale<Scalar>(-ST::one(),B)
446 alo->setObjectLabel(label);
455#define THYRA_DEFAULT_ADDED_LINEAR_OP_INSTANT(SCALAR) \
456 template class DefaultAddedLinearOp<SCALAR >; \
458 template RCP<LinearOpBase<SCALAR > > \
460 const RCP<LinearOpBase<SCALAR > > &A, \
461 const RCP<LinearOpBase<SCALAR > > &B, \
462 const std::string &label \
465 template RCP<const LinearOpBase<SCALAR > > \
467 const RCP<const LinearOpBase<SCALAR > > &A, \
468 const RCP<const LinearOpBase<SCALAR > > &B, \
469 const std::string &label \
472 template RCP<LinearOpBase<SCALAR > > \
474 const RCP<LinearOpBase<SCALAR > > &A, \
475 const RCP<LinearOpBase<SCALAR > > &B, \
476 const std::string &label \
479 template RCP<const LinearOpBase<SCALAR > > \
481 const RCP<const LinearOpBase<SCALAR > > &A, \
482 const RCP<const LinearOpBase<SCALAR > > &B, \
483 const std::string &label \
virtual std::string description() const
Concrete composite LinearOpBase subclass that creates an implicitly added linear operator out of one ...
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
bool opIsConst(const int k) const
void uninitialize()
Set to uninitialized.
std::string description() const
Prints just the name DefaultAddedLinearOp along with the overall dimensions and the number of constit...
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent linear operators.
DefaultAddedLinearOp()
Constructs to uninitialized.
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.
RCP< const LinearOpBase< Scalar > > clone() const
RCP< const LinearOpBase< Scalar > > getOp(const int k) const
Base class for all linear operators.
Interface for a collection of column vectors called a multi-vector.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#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...
#define THYRA_ASSERT_LINEAR_OP_PLUS_LINEAR_OP_SPACES_NAMES(FUNC_NAME, M1, M1_T, M1_N, M2, M2_T, M2_N)
Assert that a linear operator addition matches up.
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. `*.
@ NOTRANS
Use the non-transposed operator.
std::string toString(const T &t)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)