Thyra  Version of the Day
Thyra_DefaultAddedLinearOp_decl.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_DEFAULT_ADDED_LINEAR_OP_DECL_HPP
43 #define THYRA_DEFAULT_ADDED_LINEAR_OP_DECL_HPP
44 
45 
46 #include "Thyra_AddedLinearOpBase.hpp"
47 #include "Teuchos_ConstNonconstObjectContainer.hpp"
48 
49 
50 namespace Thyra {
51 
52 
84 template<class Scalar>
85 class DefaultAddedLinearOp : virtual public AddedLinearOpBase<Scalar>
86 {
87 public:
88 
91 
99 
106 
112  DefaultAddedLinearOp(const ArrayView<const RCP<const LinearOpBase<Scalar> > > &Ops);
113 
131  void initialize(const ArrayView<const RCP<LinearOpBase<Scalar> > > &Ops);
132 
152  void initialize(const ArrayView<const RCP<const LinearOpBase<Scalar> > > &Ops);
153 
160  void uninitialize();
161 
163 
166 
168  int numOps() const;
170  bool opIsConst(const int k) const;
174  RCP<const LinearOpBase<Scalar> > getOp(const int k) const;
175 
177 
180 
185 
190 
193 
195 
198 
202  std::string description() const;
203 
211  void describe(
213  const Teuchos::EVerbosityLevel verbLevel
214  ) const;
215 
217 
218 protected:
219 
222 
226  bool opSupportedImpl(EOpTransp M_trans) const;
227 
229  void applyImpl(
230  const EOpTransp M_trans,
231  const MultiVectorBase<Scalar> &X,
232  const Ptr<MultiVectorBase<Scalar> > &Y,
233  const Scalar alpha,
234  const Scalar beta
235  ) const;
236 
238 
239 private:
240 
241  std::vector<Teuchos::ConstNonconstObjectContainer<LinearOpBase<Scalar> > > Ops_;
242 
243  inline void assertInitialized() const;
244  inline std::string getClassName() const;
245  inline Ordinal getRangeDim() const;
246  inline Ordinal getDomainDim() const;
247 
248  void validateOps();
249  void setupDefaultObjectLabel();
250 
251  // Not defined and not to be called
253  DefaultAddedLinearOp& operator=(const DefaultAddedLinearOp&);
254 
255 };
256 
257 
259 template<class Scalar>
260 inline
262 defaultAddedLinearOp()
263 {
264  return Teuchos::rcp(new DefaultAddedLinearOp<Scalar>);
265 }
266 
267 
269 template<class Scalar>
270 inline
271 RCP<DefaultAddedLinearOp<Scalar> >
272 defaultAddedLinearOp(const ArrayView<const RCP<LinearOpBase<Scalar> > > &Ops)
273 {
274  return Teuchos::rcp(new DefaultAddedLinearOp<Scalar>(Ops));
275 }
276 
277 
279 template<class Scalar>
280 inline
281 RCP<DefaultAddedLinearOp<Scalar> >
282 defaultAddedLinearOp(const ArrayView<const RCP<const LinearOpBase<Scalar> > > &Ops)
283 {
284  return Teuchos::rcp(new DefaultAddedLinearOp<Scalar>(Ops));
285 }
286 
287 
292 template<class Scalar>
293 RCP<LinearOpBase<Scalar> >
294 nonconstAdd(
295  const RCP<LinearOpBase<Scalar> > &A,
296  const RCP<LinearOpBase<Scalar> > &B,
297  const std::string &label = ""
298  );
299 
300 
305 template<class Scalar>
306 RCP<const LinearOpBase<Scalar> >
307 add(
308  const RCP<const LinearOpBase<Scalar> > &A,
309  const RCP<const LinearOpBase<Scalar> > &B,
310  const std::string &label = ""
311  );
312 
313 
318 template<class Scalar>
319 RCP<LinearOpBase<Scalar> >
320 nonconstSubtract(
321  const RCP<LinearOpBase<Scalar> > &A,
322  const RCP<LinearOpBase<Scalar> > &B,
323  const std::string &label = ""
324  );
325 
326 
331 template<class Scalar>
332 RCP<const LinearOpBase<Scalar> >
333 subtract(
334  const RCP<const LinearOpBase<Scalar> > &A,
335  const RCP<const LinearOpBase<Scalar> > &B,
336  const std::string &label = ""
337  );
338 
339 
340 } // end namespace Thyra
341 
342 
343 #endif // THYRA_DEFAULT_ADDED_LINEAR_OP_DECL_HPP
Thyra::DefaultAddedLinearOp::getOp
RCP< const LinearOpBase< Scalar > > getOp(const int k) const
Definition: Thyra_DefaultAddedLinearOp_def.hpp:182
Thyra::DefaultAddedLinearOp::description
std::string description() const
Prints just the name DefaultAddedLinearOp along with the overall dimensions and the number of constit...
Definition: Thyra_DefaultAddedLinearOp_def.hpp:228
Thyra::DefaultAddedLinearOp::opIsConst
bool opIsConst(const int k) const
Definition: Thyra_DefaultAddedLinearOp_def.hpp:160
Thyra::EOpTransp
EOpTransp
Enumeration for determining how a linear operator is applied. `*.
Definition: Thyra_OperatorVectorTypes.hpp:160
Thyra::DefaultAddedLinearOp::domain
RCP< const VectorSpaceBase< Scalar > > domain() const
Returns this->getOp(this->numOps()-1).domain() if <t>this->numOps() > 0 and returns Teuchos::null oth...
Definition: Thyra_DefaultAddedLinearOp_def.hpp:207
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Thyra::DefaultAddedLinearOp::clone
RCP< const LinearOpBase< Scalar > > clone() const
Definition: Thyra_DefaultAddedLinearOp_def.hpp:218
Teuchos::EVerbosityLevel
EVerbosityLevel
Teuchos::ArrayView
Teuchos::RCP
Teuchos::Ptr
Thyra::Ordinal
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Definition: Thyra_OperatorVectorTypes.hpp:127
Thyra::DefaultAddedLinearOp::range
RCP< const VectorSpaceBase< Scalar > > range() const
Returns this->getOp(0).range() if <t>this->numOps() > 0 and returns Teuchos::null otherwise.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:196
Teuchos::basic_FancyOStream
Thyra::MultiVectorBase
Interface for a collection of column vectors called a multi-vector.
Definition: Thyra_MultiVectorBase_decl.hpp:493
Thyra::DefaultAddedLinearOp::uninitialize
void uninitialize()
Set to uninitialized.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:142
Thyra::DefaultAddedLinearOp::opSupportedImpl
bool opSupportedImpl(EOpTransp M_trans) const
Returns true only if all constituent operators support M_trans.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:282
Thyra::LinearOpBase
Base class for all linear operators.
Definition: Thyra_LinearOpBase_decl.hpp:191
Thyra::DefaultAddedLinearOp::DefaultAddedLinearOp
DefaultAddedLinearOp()
Constructs to uninitialized.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:95
Thyra::DefaultAddedLinearOp::numOps
int numOps() const
Definition: Thyra_DefaultAddedLinearOp_def.hpp:153
Thyra::DefaultAddedLinearOp::applyImpl
void applyImpl(const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha, const Scalar beta) const
Definition: Thyra_DefaultAddedLinearOp_def.hpp:293
Thyra::DefaultAddedLinearOp::initialize
void initialize(const ArrayView< const RCP< LinearOpBase< Scalar > > > &Ops)
Initialize given a list of non-const linear operators.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:116
Thyra::DefaultAddedLinearOp::getNonconstOp
RCP< LinearOpBase< Scalar > > getNonconstOp(const int k)
Definition: Thyra_DefaultAddedLinearOp_def.hpp:171
Thyra::DefaultAddedLinearOp
Concrete composite LinearOpBase subclass that creates an implicitly added linear operator out of one ...
Definition: Thyra_DefaultAddedLinearOp_decl.hpp:85
Thyra::DefaultAddedLinearOp::describe
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Prints the details about the constituent linear operators.
Definition: Thyra_DefaultAddedLinearOp_def.hpp:239
Thyra::AddedLinearOpBase
Interface class for implicitly added linear operators.
Definition: Thyra_AddedLinearOpBase.hpp:73