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"
57 template<
class Scalar>
59 void DefaultAddedLinearOp<Scalar>::assertInitialized()
const
67 template<
class Scalar>
69 std::string DefaultAddedLinearOp<Scalar>::getClassName()
const
75 template<
class Scalar>
77 Ordinal DefaultAddedLinearOp<Scalar>::getRangeDim()
const
79 return (numOps() > 0 ? this->range()->dim() : 0);
83 template<
class Scalar>
85 Ordinal DefaultAddedLinearOp<Scalar>::getDomainDim()
const
87 return (numOps() > 0 ? this->domain()->dim() : 0);
94 template<
class Scalar>
99 template<
class Scalar>
107 template<
class Scalar>
115 template<
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();
128 template<
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();
141 template<
class Scalar>
145 setupDefaultObjectLabel();
152 template<
class Scalar>
159 template<
class Scalar>
165 return Ops_[k].isConst();
169 template<
class Scalar>
176 return Ops_[k].getNonconstObj();
180 template<
class Scalar>
194 template<
class Scalar>
199 return getOp(0)->range();
201 return Teuchos::null;
205 template<
class Scalar>
210 return getOp(numOps()-1)->domain();
212 return Teuchos::null;
216 template<
class Scalar>
220 return Teuchos::null;
227 template<
class Scalar>
230 std::ostringstream oss;
231 oss << getClassName() <<
"{numOps="<<numOps()
232 <<
",rangeDim=" << getRangeDim()
233 <<
",domainDim="<< getDomainDim() <<
"}";
238 template<
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);
281 template<
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;
292 template<
class Scalar>
304 getClassName()+
"::apply(...)", *
this, M_trans, X, &*Y
306 #endif // TEUCHOS_DEBUG
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());
323 template<
class Scalar>
329 const int l_numOps = Ops_.size();
330 for(
int k = 0; k < l_numOps; ++k ) {
334 getClassName()+
"::initialize(...)"
349 template<
class Scalar>
350 void 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());
370 template<
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);
389 template<
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);
408 template<
class Scalar>
410 Thyra::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);
429 template<
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 \
487 #endif // THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
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...
#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.
basic_FancyOStream< char > FancyOStream
Use the non-transposed operator.
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise...
RCP< const LinearOpBase< Scalar > > clone() const
bool opIsConst(const int k) const
Concrete composite LinearOpBase subclass that creates an implicitly added linear operator out of one ...
DefaultAddedLinearOp()
Constructs to uninitialized.
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.
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.
virtual std::string description() const
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
void uninitialize()
Set to uninitialized.
Base class for all linear operators.
std::string description() const
Prints just the name DefaultAddedLinearOp along with the overall dimensions and the number of constit...
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
std::string toString(const T &t)
RCP< const LinearOpBase< Scalar > > getOp(const int k) const