Thyra Version of the Day
Loading...
Searching...
No Matches
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
52namespace Thyra {
53
54
55// Provide access to the columns as VectorBase objects
56
57
58template<class Scalar>
61{
62 return const_cast<MultiVectorBase*>(this)->nonconstColImpl(j);
63}
64
65
66// Overridden methods from LinearOpBase
67
68
69template<class Scalar>
72{
73 return this->clone_mv();
74}
75
76// Overridden methods from RowStatLinearOpBase
77
78template<class Scalar>
80rowStatIsSupportedImpl(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
95template<class Scalar>
97getRowStatImpl(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
124template<class Scalar>
127{
128 return true;
129}
130
131template<class Scalar>
134{
135 return true;
136}
137
138template<class Scalar>
140scaleLeftImpl(const VectorBase< Scalar > &row_scaling)
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
147template<class Scalar>
149scaleRightImpl(const VectorBase< Scalar > &col_scaling)
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
168template<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
184 ::Thyra::apply<Scalar>(*abs_mv,Thyra::NOTRANS,*ones,output);
185}
186
187template<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
const ArrayRCP< Scalar > values() const
size_type size() const
Ptr< T > ptr() const
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
void apply(const LinearOpBase< Scalar > &M, const EOpTransp M_trans, const MultiVectorBase< Scalar > &X, const Ptr< MultiVectorBase< Scalar > > &Y, const Scalar alpha=static_cast< Scalar >(1.0), const Scalar beta=static_cast< Scalar >(0.0))
Non-member function call for M.apply(...).
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Interface for a collection of column vectors called a multi-vector.
virtual void scaleLeftImpl(const VectorBase< Scalar > &row_scaling)
virtual bool supportsScaleLeftImpl() const
virtual bool supportsScaleRightImpl() const
RCP< const VectorBase< Scalar > > col(Ordinal j) const
Calls colImpl().
virtual RCP< VectorBase< Scalar > > nonconstColImpl(Ordinal j)=0
Return a changeable view of a constituent column vector.
void norms(const MultiVectorBase< Scalar > &V, const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms)
Column-wise multi-vector natural norm.
virtual void scaleRightImpl(const VectorBase< Scalar > &col_scaling)
void absColSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
RCP< const LinearOpBase< Scalar > > clone() const
This function is simply overridden to return this->clone_mv().
virtual RCP< MultiVectorBase< Scalar > > clone_mv() const =0
Clone the multi-vector object (if supported).
virtual void getRowStatImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat, const Ptr< VectorBase< Scalar > > &rowStatVec) const
void absRowSum(const Teuchos::Ptr< Thyra::VectorBase< Scalar > > &output) const
virtual RCP< const VectorBase< Scalar > > colImpl(Ordinal j) const
Return a non-changeable view of a constituent column vector.
void norms_1(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Column-wise 1-norms.
virtual bool rowStatIsSupportedImpl(const RowStatLinearOpBaseUtils::ERowStat rowStat) const
Abstract interface for finite-dimensional dense vectors.
void ele_wise_scale(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise scaling: y(i) *= x(i), i = 0...y->space()->dim()-1.
void put_scalar(const Scalar &alpha, const Ptr< VectorBase< Scalar > > &y)
Assign all elements to a scalar: y(i) = alpha, i = 0...y->space()->dim()-1.
void reciprocal(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise reciprocal: y(i) = 1/x(i), i = 0...y->space()->dim()-1.
void acquireDetachedView(const Range1D &rng, RTOpPack::ConstSubVectorView< Scalar > *sub_vec) const
Calls acquireDetachedVectorViewImpl().
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
RCP< MultiVectorBase< Scalar > > createMembers(const RCP< const VectorSpaceBase< Scalar > > &vs, int numMembers, const std::string &label="")
Create a set of vector members (a MultiVectorBase) from the vector space.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
NOTRANS
Type for the dimension of a vector space. `**/ typedef Teuchos::Ordinal Ordinal;.
Teuchos::Range1D Range1D
TypeTo as(const TypeFrom &t)
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)