Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_MultiVectorBase_def.hpp
1 // @HEADER
2 // *****************************************************************************
3 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
4 //
5 // Copyright 2004 NTESS and the Thyra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef THYRA_MULTI_VECTOR_BASE_HPP
11 #define THYRA_MULTI_VECTOR_BASE_HPP
12 
13 #include "Thyra_MultiVectorBase_decl.hpp"
14 #include "Thyra_LinearOpBase.hpp"
15 #include "Thyra_VectorSpaceBase.hpp"
16 
17 #include "Thyra_VectorBase.hpp"
18 #include "Thyra_VectorStdOps_decl.hpp"
19 
20 namespace Thyra {
21 
22 
23 // Provide access to the columns as VectorBase objects
24 
25 
26 template<class Scalar>
27 RCP<const VectorBase<Scalar> >
29 {
30  return const_cast<MultiVectorBase*>(this)->nonconstColImpl(j);
31 }
32 
33 
34 // Overridden methods from LinearOpBase
35 
36 
37 template<class Scalar>
40 {
41  return this->clone_mv();
42 }
43 
44 // Overridden methods from RowStatLinearOpBase
45 
46 template<class Scalar>
48 rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
49 {
50  switch (rowStat) {
51  case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
52  case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
53  case RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM:
54  case RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM:
55  return true;
56  default:
58  }
59 
61 }
62 
63 template<class Scalar>
65 getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat,
66  const Ptr<VectorBase<Scalar> > &rowStatVec) const
67 {
68  switch (rowStat) {
69  case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
70  absRowSum(rowStatVec);
71  ::Thyra::reciprocal<Scalar>(*rowStatVec,rowStatVec.ptr());
72  break;
73  case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
74  // compute absolute row sum
75  absRowSum(rowStatVec);
76  break;
77  case RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM:
78  absColSum(rowStatVec);
79  ::Thyra::reciprocal<Scalar>(*rowStatVec,rowStatVec.ptr());
80  break;
81  case RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM:
82  // compute absolute row sum
83  absColSum(rowStatVec);
84  break;
85  default:
87  }
88 }
89 
90 // Overridden methods from ScaledLinearOpBase
91 
92 template<class Scalar>
95 {
96  return true;
97 }
98 
99 template<class Scalar>
102 {
103  return true;
104 }
105 
106 template<class Scalar>
109 {
110  // loop over each column applying the row scaling
111  for(Ordinal i=0;i<this->domain()->dim();i++)
112  ::Thyra::ele_wise_scale<Scalar>(row_scaling,this->col(i).ptr());
113 }
114 
115 template<class Scalar>
118 {
119  // this is probably incorrect if the domain is distrbuted
120  // but if it is on every processor its probably fine...
121 
123  col_scaling.acquireDetachedView(Thyra::Range1D(),&view);
124 
125  Teuchos::ArrayRCP<const Scalar> col_scaling_vec = view.values();
126 
127  // check to make sure things match up
128  TEUCHOS_ASSERT(this->domain()->dim()==col_scaling_vec.size());
129 
130  for(Ordinal i=0;i<this->domain()->dim();i++)
131  ::Thyra::scale<Scalar>(col_scaling_vec[i],this->col(i).ptr());
132 }
133 
134 // helper methods
135 
136 template<class Scalar>
139 {
140  using Teuchos::RCP;
141  using Teuchos::ptrFromRef;
142  using Teuchos::tuple;
143 
144  // compute absolute value of multi-vector
145  RCP<MultiVectorBase<Scalar> > abs_mv = createMembers(this->range(),this->domain());
146  for (Ordinal i = 0; i < abs_mv->domain()->dim(); ++i)
147  abs_mv->col(i)->abs(*this->col(i));
148 
149  // compute sum over all rows
150  RCP<VectorBase<Scalar> > ones = Thyra::createMember(this->domain());
151  ::Thyra::put_scalar<Scalar>(Teuchos::ScalarTraits<Scalar>::one(),ones.ptr());
152  ::Thyra::apply<Scalar>(*abs_mv,Thyra::NOTRANS,*ones,output);
153 }
154 
155 template<class Scalar>
158 {
159  using Teuchos::tuple;
160  using Teuchos::ptrInArg;
161  using Teuchos::null;
162  using Teuchos::Array;
163  using Teuchos::ArrayView;
164 
166  output->acquireDetachedView(Thyra::Range1D(),&view);
168  this->norms_1(norms());
169  for (Ordinal i = 0; i < norms.size(); ++i)
170  view[i] = Teuchos::as<Scalar>(norms[i]);
171  output->commitDetachedView(&view);
172 }
173 
174 
175 } // end namespace Thyra
176 
177 
178 #endif // THYRA_MULTI_VECTOR_BASE_HPP
virtual RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
Return a non-changeable view of a constituent column vector.
virtual bool supportsScaleLeftImpl() const
Use the non-transposed operator.
virtual bool supportsScaleRightImpl() const
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling)
size_type size() const
const ArrayRCP< Scalar > values() const
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
RCP< const LinearOpBase< Scalar > > clone() const
This function is simply overridden to return this-&gt;clone_mv().
Ptr< T > ptr() const
Abstract interface for finite-dimensional dense vectors.
void acquireDetachedView(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls acquireDetachedVectorViewImpl().
void absRowSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling)
#define TEUCHOS_ASSERT(assertion_test)
void absColSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)