10 #ifndef THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
11 #define THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
13 #include "Thyra_DefaultAddedLinearOp_decl.hpp"
14 #include "Thyra_DefaultScaledAdjointLinearOp.hpp"
15 #include "Thyra_AssertOp.hpp"
16 #include "Teuchos_Utils.hpp"
25 template<
class Scalar>
27 void DefaultAddedLinearOp<Scalar>::assertInitialized()
const
35 template<
class Scalar>
37 std::string DefaultAddedLinearOp<Scalar>::getClassName()
const
43 template<
class Scalar>
45 Ordinal DefaultAddedLinearOp<Scalar>::getRangeDim()
const
47 return (numOps() > 0 ? this->range()->dim() : 0);
51 template<
class Scalar>
53 Ordinal DefaultAddedLinearOp<Scalar>::getDomainDim()
const
55 return (numOps() > 0 ? this->domain()->dim() : 0);
62 template<
class Scalar>
67 template<
class Scalar>
75 template<
class Scalar>
83 template<
class Scalar>
87 const int l_numOps = Ops.size();
88 Ops_.resize(l_numOps);
89 for(
int k = 0; k < l_numOps; ++k )
92 setupDefaultObjectLabel();
96 template<
class Scalar>
100 const int l_numOps = Ops.size();
101 Ops_.resize(l_numOps);
102 for(
int k = 0; k < l_numOps; ++k )
105 setupDefaultObjectLabel();
109 template<
class Scalar>
113 setupDefaultObjectLabel();
120 template<
class Scalar>
127 template<
class Scalar>
133 return Ops_[k].isConst();
137 template<
class Scalar>
144 return Ops_[k].getNonconstObj();
148 template<
class Scalar>
162 template<
class Scalar>
167 return getOp(0)->range();
169 return Teuchos::null;
173 template<
class Scalar>
178 return getOp(numOps()-1)->domain();
180 return Teuchos::null;
184 template<
class Scalar>
188 return Teuchos::null;
195 template<
class Scalar>
198 std::ostringstream oss;
199 oss << getClassName() <<
"{numOps="<<numOps()
200 <<
",rangeDim=" << getRangeDim()
201 <<
",domainDim="<< getDomainDim() <<
"}";
206 template<
class Scalar>
217 const int l_numOps = Ops_.size();
221 *out << this->description() << std::endl;
227 *out << this->description() << std::endl;
230 <<
"Constituent LinearOpBase objects for M = Op[0]*...*Op[numOps-1]:\n";
232 for(
int k = 0; k < l_numOps; ++k ) {
233 *out <<
"Op["<<k<<
"] = " << Teuchos::describe(*getOp(k),verbLevel);
249 template<
class Scalar>
252 bool isOpSupported =
true;
253 for(
int k = 0; k < static_cast<int>(Ops_.size()); ++k )
254 if(!Thyra::opSupported(*getOp(k),M_trans)) isOpSupported =
false;
255 return isOpSupported;
260 template<
class Scalar>
272 getClassName()+
"::apply(...)", *
this, M_trans, X, &*Y
274 #endif // TEUCHOS_DEBUG
282 const int l_numOps = Ops_.size();
283 for(
int j = 0; j < l_numOps; ++j )
284 Thyra::apply(*getOp(j), M_trans, X, Y, alpha, j==0 ? beta : ST::one());
291 template<
class Scalar>
297 const int l_numOps = Ops_.size();
298 for(
int k = 0; k < l_numOps; ++k ) {
302 getClassName()+
"::initialize(...)"
317 template<
class Scalar>
318 void DefaultAddedLinearOp<Scalar>::setupDefaultObjectLabel()
320 std::ostringstream label;
321 const int l_numOps = Ops_.size();
322 for(
int k = 0; k < l_numOps; ++k ) {
323 std::string Op_k_label = Ops_[k]->getObjectLabel();
324 if (Op_k_label.length() == 0)
328 label <<
"("<<Op_k_label<<
")";
330 this->setObjectLabel(label.str());
338 template<
class Scalar>
341 const RCP<LinearOpBase<Scalar> > &A,
342 const RCP<LinearOpBase<Scalar> > &B,
343 const std::string &label
346 using Teuchos::tuple;
347 RCP<LinearOpBase<Scalar> > alo =
348 defaultAddedLinearOp<Scalar>(
349 tuple<RCP<LinearOpBase<Scalar> > >(A, B)()
352 alo->setObjectLabel(label);
357 template<
class Scalar>
360 const RCP<
const LinearOpBase<Scalar> > &A,
361 const RCP<
const LinearOpBase<Scalar> > &B,
362 const std::string &label
365 using Teuchos::tuple;
366 RCP<LinearOpBase<Scalar> > alo =
367 defaultAddedLinearOp<Scalar>(
368 tuple<RCP<const LinearOpBase<Scalar> > >(A, B)()
371 alo->setObjectLabel(label);
376 template<
class Scalar>
378 Thyra::nonconstSubtract(
379 const RCP<LinearOpBase<Scalar> > &A,
380 const RCP<LinearOpBase<Scalar> > &B,
381 const std::string &label
384 typedef ScalarTraits<Scalar> ST;
385 using Teuchos::tuple;
386 RCP<LinearOpBase<Scalar> > alo =
387 defaultAddedLinearOp<Scalar>(
388 tuple<RCP<LinearOpBase<Scalar> > >(
389 A, nonconstScale<Scalar>(-ST::one(),B) )()
392 alo->setObjectLabel(label);
397 template<
class Scalar>
400 const RCP<
const LinearOpBase<Scalar> > &A,
401 const RCP<
const LinearOpBase<Scalar> > &B,
402 const std::string &label
405 typedef ScalarTraits<Scalar> ST;
406 using Teuchos::tuple;
407 RCP<LinearOpBase<Scalar> > alo =
408 defaultAddedLinearOp<Scalar>(
409 tuple<RCP<const LinearOpBase<Scalar> > >(
410 A, scale<Scalar>(-ST::one(),B)
414 alo->setObjectLabel(label);
423 #define THYRA_DEFAULT_ADDED_LINEAR_OP_INSTANT(SCALAR) \
424 template class DefaultAddedLinearOp<SCALAR >; \
426 template RCP<LinearOpBase<SCALAR > > \
428 const RCP<LinearOpBase<SCALAR > > &A, \
429 const RCP<LinearOpBase<SCALAR > > &B, \
430 const std::string &label \
433 template RCP<const LinearOpBase<SCALAR > > \
435 const RCP<const LinearOpBase<SCALAR > > &A, \
436 const RCP<const LinearOpBase<SCALAR > > &B, \
437 const std::string &label \
440 template RCP<LinearOpBase<SCALAR > > \
442 const RCP<LinearOpBase<SCALAR > > &A, \
443 const RCP<LinearOpBase<SCALAR > > &B, \
444 const std::string &label \
447 template RCP<const LinearOpBase<SCALAR > > \
449 const RCP<const LinearOpBase<SCALAR > > &A, \
450 const RCP<const LinearOpBase<SCALAR > > &B, \
451 const std::string &label \
455 #endif // THYRA_DEFAULT_ADDED_LINEAR_OP_DEF_HPP
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
void initialize(int *argc, char ***argv)
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