Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_ProductEpetraVector.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "EpetraExt_BlockUtility.h"
12 #include "Epetra_Map.h"
13 
17 {
18 }
19 
23 {
24 }
25 
28  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
29  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
30  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
31  ProductContainer<Epetra_Vector>(block_map),
32  coeff_map(coeff_map_),
33  product_comm(product_comm_),
34  product_map(Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,*block_map, *product_comm))),
35  bv(Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map)))
36 {
37  for (int i=0; i<this->size(); i++)
38  this->setCoeffPtr(i, bv->GetBlock(i));
39 }
40 
43  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
44  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
45  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
46  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
47  ProductContainer<Epetra_Vector>(block_map),
48  coeff_map(coeff_map_),
49  product_comm(product_comm_),
50  product_map(product_map_),
51  bv(Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map)))
52 {
53  for (int i=0; i<this->size(); i++)
54  this->setCoeffPtr(i, bv->GetBlock(i));
55 }
56 
59  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
60  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
61  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
62  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
64  const Epetra_Vector& block_vector) :
65  ProductContainer<Epetra_Vector>(block_map),
66  coeff_map(coeff_map_),
67  product_comm(product_comm_),
68  product_map(product_map_),
69  bv(Teuchos::rcp(new EpetraExt::BlockVector(CV, *coeff_map, block_vector)))
70 {
71  for (int i=0; i<this->size(); i++)
72  this->setCoeffPtr(i, bv->GetBlock(i));
73 }
74 
78  coeff_map(v.coeff_map),
79  product_comm(v.product_comm),
80  product_map(v.product_map),
81  bv(v.bv)
82 {
83 }
84 
87 
92  coeff_map = v.coeff_map;
93  product_comm = v.product_comm;
94  product_map = v.product_map;
95  bv = v.bv; // Note this is a shallow copy, which is consistent with above
96  return *this;
97 }
98 
102  if (this->size() > 0) {
103  if (bv != Teuchos::null)
104  bv->Update(1.0, v, 0.0);
105  else {
106  EpetraExt::BlockVector block_v(View, *coeff_map, v);
107  for (int i=0; i<this->size(); i++)
108  *(coeff_[i]) = *(block_v.GetBlock(i));
109  }
110  }
111  return *this;
112 }
113 
114 void
117 {
118  if (this->size() > 0) {
119  if (bv != Teuchos::null)
120  v.Update(1.0, *bv, 0.0);
121  else {
122  EpetraExt::BlockVector block_v(View, *coeff_map, v);
123  for (int i=0; i<this->size(); i++)
124  *(block_v.GetBlock(i)) = *(coeff_[i]);
125  }
126  }
127 }
128 
129 void
132 {
133  if (this->size() > 0) {
134  if (bv != Teuchos::null)
135  bv->Update(1.0, v, 0.0);
136  else {
137  EpetraExt::BlockVector block_v(View, *coeff_map, v);
138  for (int i=0; i<this->size(); i++)
139  *(coeff_[i]) = *(block_v.GetBlock(i));
140  }
141  }
142 }
143 
146 coefficientMap() const {
147  return coeff_map;
148 }
149 
152 productMap() const {
153  return product_map;
154 }
155 
158 productComm() const {
159  return product_comm;
160 }
161 
162 void
165  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
166  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_)
167 {
169  coeff_map = coeff_map_;
170  product_comm = product_comm_;
171  product_map =
172  Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,
173  *block_map,
174  *product_comm));
175  bv = Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map));
176  for (int i=0; i<this->size(); i++)
177  this->setCoeffPtr(i, bv->GetBlock(i));
178 }
179 
180 void
183  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
184  const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
185  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_)
186 {
188  coeff_map = coeff_map_;
189  product_comm = product_comm_;
190  product_map = product_map_;
191  bv = Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map));
192  for (int i=0; i<this->size(); i++)
193  this->setCoeffPtr(i, bv->GetBlock(i));
194 }
195 
196 void
199  const Epetra_Vector& block_vector)
200 {
201  bv = Teuchos::rcp(new EpetraExt::BlockVector(CV, *coeff_map, block_vector));
202  for (int i=0; i<this->size(); i++)
203  this->setCoeffPtr(i, bv->GetBlock(i));
204 }
205 
209 {
210  return bv;
211 }
212 
216 {
217  return bv;
218 }
219 
220 void
223 {
224  bv = block_vec;
225  for (int i=0; i<this->size(); i++)
226  this->setCoeffPtr(i, bv->GetBlock(i));
227 }
228 
229 void
232 {
233  Epetra_Vector v(*coeff_map);
234  int sz = this->size();
235  for (int i=0; i<sz; i++) {
236  v.Scale(1.0, *(this->coeff_[i]));
237  this->map_->Comm().SumAll(v.Values(),
238  this->coeff_[i]->Values(),
239  this->coeff_[i]->MyLength());
240  }
241 }
void setCoeffPtr(ordinal_type i, const Teuchos::RCP< Epetra_Vector > &c)
Set coefficient i to c.
ProductContainer & operator=(const ProductContainer &)
Assignment.
Teuchos::RCP< const Epetra_BlockMap > productMap() const
Get product map.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
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)
Reset to a new size.
Teuchos::RCP< EpetraExt::BlockVector > bv
Block vector storing coefficients.
Teuchos::RCP< const Epetra_BlockMap > product_map
Product map of block vector.
Teuchos::RCP< const EpetraExt::MultiComm > productComm() const
Get product comm.
void assignToBlockVector(Epetra_Vector &v) const
Assignment.
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)
void setBlockVector(const Teuchos::RCP< EpetraExt::BlockVector > &block_vec)
Set block vector.
ProductEpetraVector & operator=(const ProductEpetraVector &v)
Assignment.
Teuchos::RCP< const EpetraExt::MultiComm > product_comm
Product multi-level communicator.
A container class for products of Epetra_Vector&#39;s.
void resetCoefficients(Epetra_DataAccess CV, const Epetra_Vector &block_vector)
Reset vector cofficients.
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 > coeff_map
Product map of block vector.
Teuchos::RCP< const Epetra_BlockMap > coefficientMap() const
Get coefficient map.
void assignFromBlockVector(const Epetra_Vector &v)
Assignment.
Epetra_DataAccess
ordinal_type size() const
Return size.
void sumAll()
Sum coefficients across processors, storing result in this.