AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_VectorSpace.cpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) 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 (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "AbstractLinAlgPack_VectorSpace.hpp"
43 #include "AbstractLinAlgPack_VectorSpaceSubSpace.hpp"
44 #include "AbstractLinAlgPack_VectorSpaceFactory.hpp"
45 #include "AbstractLinAlgPack_VectorMutable.hpp"
46 #include "AbstractLinAlgPack_MultiVectorMutable.hpp"
47 #include "AbstractLinAlgPack_InnerProductDot.hpp"
48 #include "AbstractLinAlgPack_GenPermMatrixSlice.hpp"
49 #include "Teuchos_Assert.hpp"
50 
51 namespace AbstractLinAlgPack {
52 
53 // Constructors / initializers
54 
56 {
57  this->inner_prod(inner_prod);
58 }
59 
60 void VectorSpace::inner_prod( const inner_prod_ptr_t& inner_prod )
61 {
62  if(inner_prod.get()) {
63  inner_prod_ = inner_prod;
64  } else {
65  inner_prod_ = Teuchos::rcp(new InnerProductDot());
66  }
67 }
68 
71 {
72  return inner_prod_;
73 }
74 
75 // Virtual functions with default implementations
76 
78 {
79  return false;
80 }
81 
84 {
85  return Teuchos::null;
86 }
87 
89 VectorSpace::create_member(const value_type& alpha) const
90 {
91  namespace mmp = MemMngPack;
92  vec_mut_ptr_t vec = this->create_member();
93  *vec = alpha;
94  return vec;
95 }
96 
98 VectorSpace::create_members(size_type num_vecs) const
99 {
100  return Teuchos::null;
101 }
102 
104 VectorSpace::sub_space(const Range1D& rng_in) const
105 {
106  namespace mmp = MemMngPack;
107  const index_type dim = this->dim();
108  const Range1D rng = rng_in.full_range() ? Range1D(1,dim) : rng_in;
109 #ifdef TEUCHOS_DEBUG
111  rng.ubound() > dim, std::out_of_range
112  ,"VectorSpace::sub_space(rng): Error, rng = ["<<rng.lbound()<<","<<rng.ubound()<<"] "
113  "is not in the range [1,this->dim()] = [1,"<<dim<<"]" );
114 #endif
115  if( rng.lbound() == 1 && rng.ubound() == dim )
116  return space_ptr_t( this, false );
117  return Teuchos::rcp(
119  Teuchos::rcp( this, false )
120  ,rng ) );
121 }
122 
125  const GenPermMatrixSlice &P
126  ,BLAS_Cpp::Transp P_trans
127  ) const
128 {
129  const index_type
130  dim = BLAS_Cpp::rows( P.rows(), P.cols(), P_trans );
131  space_fcty_ptr_t vec_spc_fcty = this->small_vec_spc_fcty();
132  if(vec_spc_fcty.get())
133  return vec_spc_fcty->create_vec_spc(dim);
134  return Teuchos::null;
135 }
136 
137 // Overridden from AbstractFactory<>
138 
139 VectorSpace::obj_ptr_t VectorSpace::create() const
140 {
141  return this->create_member();
142 }
143 
144 } // end namespace AbstractLinAlgPack
Concrete subclass for a default sub-space of a vector.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Index ubound() const
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
virtual space_ptr_t space(const GenPermMatrixSlice &P, BLAS_Cpp::Transp P_trans) const
Create a vector space for vector to gather the elements into.
virtual bool is_in_core() const
Returns true if the vectors are in core.
virtual space_ptr_t sub_space(const Range1D &rng) const
Create a transient sub-space of the current vector space.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const VectorSpace > space_ptr_t
obj_ptr_t create() const
Just calls this->create_member() by default!
virtual const inner_prod_ptr_t inner_prod() const
Return the smart pointer to the inner product strategy object.
bool full_range() const
virtual index_type dim() const =0
Return the dimmension of the vector space.
Index lbound() const
Teuchos::RCP< const InnerProduct > inner_prod_ptr_t
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
virtual multi_vec_mut_ptr_t create_members(size_type num_vecs) const
Create a set of vector members (a MultiVectorMutable) from the vector space.
VectorSpace(const inner_prod_ptr_t &inner_prod=Teuchos::null)
Calls inner_prod()
Transp
virtual space_fcty_ptr_t small_vec_spc_fcty() const
Return a VectorSpaceFactory object for the creation of vector spaces with a small dimension...
Concrete matrix type to represent general permutation (mapping) matrices.