Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_ProductEpetraMultiVector.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) 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 Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
43 #include "EpetraExt_BlockUtility.h"
44 #include "Epetra_Map.h"
45 
49 {
50 }
51 
55 {
56 }
57 
60  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
61  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
62  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
63  int num_vectors) :
65  coeff_map(coeff_map_),
66  product_comm(product_comm_),
67  product_map(Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,*block_map, *product_comm))),
68  bv(Teuchos::rcp(new EpetraExt::BlockMultiVector(*coeff_map, *product_map,
69  num_vectors)))
70 {
71  for (int i=0; i<this->size(); i++)
72  this->setCoeffPtr(i, bv->GetBlock(i));
73 }
74 
77  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
78  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
79  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
80  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
81  int num_vectors) :
83  coeff_map(coeff_map_),
84  product_comm(product_comm_),
85  product_map(product_map_),
86  bv(Teuchos::rcp(new EpetraExt::BlockMultiVector(*coeff_map, *product_map,
87  num_vectors)))
88 {
89  for (int i=0; i<this->size(); i++)
90  this->setCoeffPtr(i, bv->GetBlock(i));
91 }
92 
95  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
96  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
97  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
98  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
100  const Epetra_MultiVector& block_vector) :
102  coeff_map(coeff_map_),
103  product_comm(product_comm_),
104  product_map(product_map_),
105  bv(Teuchos::rcp(new EpetraExt::BlockMultiVector(CV, *coeff_map,
106  block_vector)))
107 {
108  for (int i=0; i<this->size(); i++)
109  this->setCoeffPtr(i, bv->GetBlock(i));
110 }
111 
115  coeff_map(v.coeff_map),
116  product_comm(v.product_comm),
117  product_map(v.product_map),
118  bv(v.bv)
119 {
120 }
121 
124 
129  coeff_map = v.coeff_map;
130  product_comm = v.product_comm;
131  product_map = v.product_map;
132  bv = v.bv; // Note this is a shallow copy, which is consistent with above
133  return *this;
134 }
135 
139  if (this->size() > 0) {
140  if (bv != Teuchos::null)
141  bv->Update(1.0, v, 0.0);
142  else {
143  EpetraExt::BlockMultiVector block_v(View, *coeff_map, v);
144  for (int i=0; i<this->size(); i++)
145  *(coeff_[i]) = *(block_v.GetBlock(i));
146  }
147  }
148  return *this;
149 }
150 
151 void
154 {
155  if (this->size() > 0) {
156  if (bv != Teuchos::null)
157  v.Update(1.0, *bv, 0.0);
158  else {
159  EpetraExt::BlockMultiVector block_v(View, *coeff_map, v);
160  for (int i=0; i<this->size(); i++)
161  *(block_v.GetBlock(i)) = *(coeff_[i]);
162  }
163  }
164 }
165 
166 void
169 {
170  if (this->size() > 0) {
171  if (bv != Teuchos::null)
172  bv->Update(1.0, v, 0.0);
173  else {
174  EpetraExt::BlockMultiVector block_v(View, *coeff_map, v);
175  for (int i=0; i<this->size(); i++)
176  *(coeff_[i]) = *(block_v.GetBlock(i));
177  }
178  }
179 }
180 
183 coefficientMap() const {
184  return coeff_map;
185 }
186 
189 productMap() const {
190  return product_map;
191 }
192 
195 productComm() const {
196  return product_comm;
197 }
198 
199 int
201 numVectors() const {
202  if (bv != Teuchos::null)
203  return bv->NumVectors();
204  else if (this->size() > 0 && this->coeff_[0] != Teuchos::null)
205  return this->coeff_[0]->NumVectors();
206  return -1;
207 }
208 
209 void
212  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
213  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
214  int num_vectors)
215 {
217  coeff_map = coeff_map_;
218  product_comm = product_comm_;
219  product_map =
220  Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,
221  *block_map,
222  *product_comm));
223  bv = Teuchos::rcp(new EpetraExt::BlockMultiVector(*coeff_map, *product_map,
224  num_vectors));
225  for (int i=0; i<this->size(); i++)
226  this->setCoeffPtr(i, bv->GetBlock(i));
227 }
228 
229 void
232  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
233  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
234  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
235  int num_vectors)
236 {
238  coeff_map = coeff_map_;
239  product_comm = product_comm_;
240  product_map = product_map_;
241  bv = Teuchos::rcp(new EpetraExt::BlockMultiVector(*coeff_map, *product_map,
242  num_vectors));
243  for (int i=0; i<this->size(); i++)
244  this->setCoeffPtr(i, bv->GetBlock(i));
245 }
246 
247 void
250  const Epetra_MultiVector& block_vector)
251 {
252  bv =
253  Teuchos::rcp(new EpetraExt::BlockMultiVector(CV, *coeff_map, block_vector));
254  for (int i=0; i<this->size(); i++)
255  this->setCoeffPtr(i, bv->GetBlock(i));
256 }
257 
261 {
262  return bv;
263 }
264 
268 {
269  return bv;
270 }
271 
272 void
275 {
276  bv = block_vec;
277  for (int i=0; i<this->size(); i++)
278  this->setCoeffPtr(i, bv->GetBlock(i));
279 }
void setCoeffPtr(ordinal_type i, const Teuchos::RCP< Epetra_MultiVector > &c)
Set coefficient i to c.
Teuchos::RCP< const EpetraExt::MultiComm > product_comm
Product multi-level communicator.
int numVectors() const
Get number of vectors.
ProductContainer & operator=(const ProductContainer &)
Assignment.
void assignToBlockMultiVector(Epetra_MultiVector &v) const
Assignment.
Teuchos::RCP< EpetraExt::BlockMultiVector > bv
Block vector storing coefficients.
ProductEpetraMultiVector & operator=(const ProductEpetraMultiVector &v)
Assignment.
Teuchos::RCP< const EpetraExt::MultiComm > productComm() const
Get product comm.
void reset(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to new map map.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< const Epetra_BlockMap > coefficientMap() const
Get coefficient map.
void reset(const Teuchos::RCP< const Epetra_BlockMap > &block_map, const Teuchos::RCP< const Epetra_BlockMap > &coeff_map, const Teuchos::RCP< const EpetraExt::MultiComm > &product_comm, int num_vectors)
Reset to a new size.
A container class storing products of Epetra_MultiVector&#39;s.
Teuchos::RCP< EpetraExt::BlockMultiVector > getBlockMultiVector()
Get block vector.
A product (in the mathematical sense) container class whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
Teuchos::RCP< const Epetra_BlockMap > productMap() const
Get product map.
Teuchos::RCP< const Epetra_BlockMap > coeff_map
Product map of block vector.
void setBlockMultiVector(const Teuchos::RCP< EpetraExt::BlockMultiVector > &block_vec)
Set block vector.
void resetCoefficients(Epetra_DataAccess CV, const Epetra_MultiVector &block_vector)
Reset vector cofficients.
Teuchos::RCP< const Epetra_BlockMap > product_map
Product map of block vector.
void assignFromBlockMultiVector(const Epetra_MultiVector &v)
Assignment.
Epetra_DataAccess
ordinal_type size() const
Return size.