MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_MultiVectorMutable.cpp
Go to the documentation of this file.
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 
45 #include "RTOp_TOp_assign_scalar.h"
47 #include "RTOp_TOp_scale_vector.h"
48 #include "RTOpPack_RTOpC.hpp"
49 #include "Teuchos_Workspace.hpp"
50 #include "Teuchos_dyn_cast.hpp"
51 
52 namespace {
53 
54 // vector scalar assignment operator
55 RTOpPack::RTOpC& assign_scalar_op()
56 {
57  static RTOpPack::RTOpC assign_scalar_op_;
58  return(assign_scalar_op_);
59 }
60 // vector assignment operator
61 static RTOpPack::RTOpC assign_vec_op;
62 // scale vector
63 static RTOpPack::RTOpC scale_vector_op;
64 
65 // Simple class for an object that will initialize the operator objects
66 class init_rtop_server_t {
67 public:
68  init_rtop_server_t() {
69  // Vector scalar assignment operator
70  TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_construct(0.0,&assign_scalar_op().op()));
71  // Vector assignment operator
73  // Operator scale_vector
75  }
76 };
77 
78 // When the program starts, this object will be created and the RTOp_Server object will
79 // be initialized before main() gets underway!
80 init_rtop_server_t init_rtop_server;
81 
82 } // end namespace
83 
84 namespace AbstractLinAlgPack {
85 
86 // Clone
87 
90 {
92  new_mv = this->space_cols().create_members(this->cols());
93  const MultiVector* multi_vecs[] = { this };
94  MultiVectorMutable* targ_multi_vecs[] = { new_mv.get() };
95  AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_vec_op,1,multi_vecs,1,targ_multi_vecs,NULL);
96  return new_mv;
97 }
98 
99 // Sub-view methods
100 
102 MultiVectorMutable::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng)
103 {
104  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: return a MultiVectorMutableSubView object.
105  // Note that the MultiVectorMutableSubView class should derive from
106  // MultiVectorSubView.
107  return Teuchos::null;
108 }
109 
110 // Overridden from MatrixOp
111 
113 {
114  TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_set_alpha(0.0,&assign_scalar_op().op()));
115  MultiVectorMutable* targ_multi_vecs[] = { this };
116  AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_scalar_op(),0,NULL,1,targ_multi_vecs,NULL);
117 }
118 
120 {
121  if( alpha == 0.0 ) {
122  TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_assign_scalar_set_alpha(alpha,&assign_scalar_op().op()));
123  MultiVectorMutable* targ_multi_vecs[] = { this };
124  AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_scalar_op(),0,NULL,1,targ_multi_vecs,NULL);
125  }
126  else if( alpha != 1.0 ) {
127  TEUCHOS_TEST_FOR_EXCEPT(0!=RTOp_TOp_scale_vector_set_alpha(alpha,&scale_vector_op.op()));
128  MultiVectorMutable* targ_multi_vecs[] = { this };
129  AbstractLinAlgPack::apply_op(APPLY_BY_COL,scale_vector_op,0,NULL,1,targ_multi_vecs,NULL);
130  }
131 }
132 
134 {
135  const MultiVector *mv_rhs = dynamic_cast<const MultiVector*>(&mwo_rhs);
136  if(mv_rhs) {
137  const MultiVector* multi_vecs[] = { mv_rhs };
138  MultiVectorMutable* targ_multi_vecs[] = { this };
139  AbstractLinAlgPack::apply_op(APPLY_BY_COL,assign_vec_op,1,multi_vecs,1,targ_multi_vecs,NULL);
140  }
141  else {
142  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Get column by column or row by row
143  }
144  return *this;
145 }
146 
147 MatrixOp::mat_mut_ptr_t
149 {
150  return this->mv_clone();
151 }
152 
154  MatrixOp* mwo_lhs, value_type alpha
155  ,BLAS_Cpp::Transp trans_rhs
156  ) const
157 {
158  return false; // ToDo: Specialize!
159 }
160 
162  value_type alpha,const MatrixOp& M_rhs, BLAS_Cpp::Transp trans_rhs
163  )
164 {
165  return false; // ToDo: Specialize!
166 }
167 
168 // Overridden form MultiVector
169 
171 {
172  return const_cast<MultiVectorMutable*>(this)->mv_clone();
173 }
174 
176 {
177  return const_cast<MultiVectorMutable*>(this)->col(j);
178 }
179 
181 {
182  return const_cast<MultiVectorMutable*>(this)->row(i);
183 }
184 
186 {
187  return const_cast<MultiVectorMutable*>(this)->diag(k);
188 }
189 
191 MultiVectorMutable::mv_sub_view(const Range1D& row_rng, const Range1D& col_rng) const
192 {
193  return const_cast<MultiVectorMutable*>(this)->mv_sub_view(row_rng,col_rng);
194 }
195 
196 } // end namespace AbstractLinAlgPack
int RTOp_TOp_assign_scalar_set_alpha(RTOp_value_type alpha, struct RTOp_RTOp *op)
Adapter subclass that uses a RTOp_RTOp object.
int RTOp_TOp_assign_scalar_construct(RTOp_value_type alpha, struct RTOp_RTOp *op)
int RTOp_TOp_scale_vector_set_alpha(RTOp_value_type alpha, struct RTOp_RTOp *op)
T * get() const
virtual multi_vec_mut_ptr_t mv_sub_view(const Range1D &row_rng, const Range1D &col_rng)
Returns a mutable sub-view of the multi vector.
int RTOp_TOp_assign_vectors_construct(struct RTOp_RTOp *op)
virtual multi_vec_mut_ptr_t mv_clone()
Clone the non-const multi-vector object.
virtual size_type cols() const
Return the number of columns in the matrix.
. One-based subregion index range class.
bool Mp_StM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs) const
RTOp_RTOp & op()
virtual vec_mut_ptr_t diag(int k)=0
Get a mutable diagonal vector.
Base class for all matrices that support basic matrix operations.
Interface for a collection of non-mutable vectors (multi-vector, matrix).
virtual vec_mut_ptr_t row(index_type i)=0
Get a mutable row vector.
Interface for a collection of mutable vectors (multi-vector, matrix).
virtual const VectorSpace & space_cols() const =0
Vector space for vectors that are compatible with the columns of the matrix.
void apply_op(EApplyBy apply_by, const RTOpPack::RTOp &primary_op, const size_t num_multi_vecs, const MultiVector *multi_vecs[], const size_t num_targ_multi_vecs, MultiVectorMutable *targ_multi_vecs[], RTOpPack::ReductTarget *reduct_objs[]=NULL, const index_type primary_first_ele=1, const index_type primary_sub_dim=0, const index_type primary_global_offset=0, const index_type secondary_first_ele=1, const index_type secondary_sub_dim=0)
Apply a reduction/transformation operator column by column and return an array of the reduction objec...
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.
virtual vec_mut_ptr_t col(index_type j)=0
Get a mutable column vector.
Transp
TRANS.
int RTOp_TOp_scale_vector_construct(RTOp_value_type alpha, struct RTOp_RTOp *op)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)