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 62 TEUCHOS_TEST_FOR_EXCEPT( !( numOps() > 0 ) );
67 template<
class Scalar>
69 std::string DefaultAddedLinearOp<Scalar>::getClassName()
const 71 return Teuchos::Describable::description();
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>
163 TEUCHOS_TEST_FOR_EXCEPT( !( 0 <= k && k < numOps() ) );
165 return Ops_[k].isConst();
169 template<
class Scalar>
170 Teuchos::RCP<LinearOpBase<Scalar> >
174 TEUCHOS_TEST_FOR_EXCEPT( !( 0 <= k && k < numOps() ) );
176 return Ops_[k].getNonconstObj();
180 template<
class Scalar>
181 Teuchos::RCP<const LinearOpBase<Scalar> >
185 TEUCHOS_TEST_FOR_EXCEPT( !( 0 <= k && k < numOps() ) );
194 template<
class Scalar>
195 Teuchos::RCP< const VectorSpaceBase<Scalar> >
199 return getOp(0)->range();
201 return Teuchos::null;
205 template<
class Scalar>
206 Teuchos::RCP< const VectorSpaceBase<Scalar> >
210 return getOp(numOps()-1)->domain();
212 return Teuchos::null;
216 template<
class Scalar>
217 Teuchos::RCP<const LinearOpBase<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>
240 Teuchos::FancyOStream &out_arg
241 ,
const Teuchos::EVerbosityLevel verbLevel
245 using Teuchos::FancyOStream;
246 using Teuchos::OSTab;
247 RCP<FancyOStream> out = rcp(&out_arg,
false);
249 const int l_numOps = Ops_.size();
251 case Teuchos::VERB_DEFAULT:
252 case Teuchos::VERB_LOW:
253 *out << this->description() << std::endl;
255 case Teuchos::VERB_MEDIUM:
256 case Teuchos::VERB_HIGH:
257 case Teuchos::VERB_EXTREME:
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);
270 TEUCHOS_TEST_FOR_EXCEPT(
true);
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>
301 typedef Teuchos::ScalarTraits<Scalar> ST;
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 ) {
331 TEUCHOS_TEST_FOR_EXCEPT( Ops_[k]().
get() == NULL );
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>
371 Teuchos::RCP<Thyra::LinearOpBase<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>
390 Teuchos::RCP<const Thyra::LinearOpBase<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>
409 Teuchos::RCP<Thyra::LinearOpBase<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>
430 Teuchos::RCP<const Thyra::LinearOpBase<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 opIsConst(const int k) const
RCP< const LinearOpBase< Scalar > > getOp(const int k) const
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
#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...
RCP< const LinearOpBase< Scalar > > clone() const
#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.
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
Use the non-transposed operator.
Concrete composite LinearOpBase subclass that creates an implicitly added linear operator out of one ...
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise...
DefaultAddedLinearOp()
Constructs to uninitialized.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
void initialize(const ArrayView< const RCP< LinearOpBase< Scalar > > > &Ops)
Initialize given a list of non-const linear operators.
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
void uninitialize()
Set to uninitialized.
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
Base class for all linear operators.
const char * toString(EConj conj)
Return a string name for a EOpTransp value. `*.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent linear operators.
std::string description() const
Prints just the name DefaultAddedLinearOp along with the overall dimensions and the number of constit...