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 //
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_MULTI_VECTOR_BASE_HPP
43 #define THYRA_MULTI_VECTOR_BASE_HPP
44 
45 #include "Thyra_MultiVectorBase_decl.hpp"
46 #include "Thyra_LinearOpBase.hpp"
47 #include "Thyra_VectorSpaceBase.hpp"
48 
49 #include "Thyra_VectorBase.hpp"
50 #include "Thyra_VectorStdOps_decl.hpp"
51 
52 namespace Thyra {
53 
54 
55 // Provide access to the columns as VectorBase objects
56 
57 
58 template<class Scalar>
59 RCP<const VectorBase<Scalar> >
61 {
62  return const_cast<MultiVectorBase*>(this)->nonconstColImpl(j);
63 }
64 
65 
66 // Overridden methods from LinearOpBase
67 
68 
69 template<class Scalar>
72 {
73  return this->clone_mv();
74 }
75 
76 // Overridden methods from RowStatLinearOpBase
77 
78 template<class Scalar>
80 rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
81 {
82  switch (rowStat) {
83  case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
84  case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
85  case RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM:
86  case RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM:
87  return true;
88  default:
90  }
91 
93 }
94 
95 template<class Scalar>
97 getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat,
98  const Ptr<VectorBase<Scalar> > &rowStatVec) const
99 {
100  switch (rowStat) {
101  case RowStatLinearOpBaseUtils::ROW_STAT_INV_ROW_SUM:
102  absRowSum(rowStatVec);
103  ::Thyra::reciprocal<Scalar>(*rowStatVec,rowStatVec.ptr());
104  break;
105  case RowStatLinearOpBaseUtils::ROW_STAT_ROW_SUM:
106  // compute absolute row sum
107  absRowSum(rowStatVec);
108  break;
109  case RowStatLinearOpBaseUtils::ROW_STAT_INV_COL_SUM:
110  absColSum(rowStatVec);
111  ::Thyra::reciprocal<Scalar>(*rowStatVec,rowStatVec.ptr());
112  break;
113  case RowStatLinearOpBaseUtils::ROW_STAT_COL_SUM:
114  // compute absolute row sum
115  absColSum(rowStatVec);
116  break;
117  default:
119  }
120 }
121 
122 // Overridden methods from ScaledLinearOpBase
123 
124 template<class Scalar>
127 {
128  return true;
129 }
130 
131 template<class Scalar>
134 {
135  return true;
136 }
137 
138 template<class Scalar>
141 {
142  // loop over each column applying the row scaling
143  for(Ordinal i=0;i<this->domain()->dim();i++)
144  ::Thyra::ele_wise_scale<Scalar>(row_scaling,this->col(i).ptr());
145 }
146 
147 template<class Scalar>
150 {
151  // this is probably incorrect if the domain is distrbuted
152  // but if it is on every processor its probably fine...
153 
155  col_scaling.acquireDetachedView(Thyra::Range1D(),&view);
156 
157  Teuchos::ArrayRCP<const Scalar> col_scaling_vec = view.values();
158 
159  // check to make sure things match up
160  TEUCHOS_ASSERT(this->domain()->dim()==col_scaling_vec.size());
161 
162  for(Ordinal i=0;i<this->domain()->dim();i++)
163  ::Thyra::scale<Scalar>(col_scaling_vec[i],this->col(i).ptr());
164 }
165 
166 // helper methods
167 
168 template<class Scalar>
171 {
172  using Teuchos::RCP;
173  using Teuchos::ptrFromRef;
174  using Teuchos::tuple;
175 
176  // compute absolute value of multi-vector
177  RCP<MultiVectorBase<Scalar> > abs_mv = createMembers(this->range(),this->domain());
178  for (Ordinal i = 0; i < abs_mv->domain()->dim(); ++i)
179  abs_mv->col(i)->abs(*this->col(i));
180 
181  // compute sum over all rows
182  RCP<VectorBase<Scalar> > ones = Thyra::createMember(this->domain());
183  ::Thyra::put_scalar<Scalar>(Teuchos::ScalarTraits<Scalar>::one(),ones.ptr());
184  ::Thyra::apply<Scalar>(*abs_mv,Thyra::NOTRANS,*ones,output);
185 }
186 
187 template<class Scalar>
190 {
191  using Teuchos::tuple;
192  using Teuchos::ptrInArg;
193  using Teuchos::null;
194  using Teuchos::Array;
195  using Teuchos::ArrayView;
196 
198  output->acquireDetachedView(Thyra::Range1D(),&view);
200  this->norms_1(norms());
201  for (Ordinal i = 0; i < norms.size(); ++i)
202  view[i] = Teuchos::as<Scalar>(norms[i]);
203  output->commitDetachedView(&view);
204 }
205 
206 
207 } // end namespace Thyra
208 
209 
210 #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)