Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_ProductEpetraVector.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
51
53ProductEpetraVector(const Teuchos::RCP<const Epetra_BlockMap>& block_map) :
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_) :
64 coeff_map(coeff_map_),
65 product_comm(product_comm_),
66 product_map(Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,*block_map, *product_comm))),
67 bv(Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map)))
68{
69 for (int i=0; i<this->size(); i++)
70 this->setCoeffPtr(i, bv->GetBlock(i));
71}
72
75 const Teuchos::RCP<const Epetra_BlockMap>& block_map,
76 const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
77 const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
78 const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_) :
80 coeff_map(coeff_map_),
81 product_comm(product_comm_),
82 product_map(product_map_),
83 bv(Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map)))
84{
85 for (int i=0; i<this->size(); i++)
86 this->setCoeffPtr(i, bv->GetBlock(i));
87}
88
91 const Teuchos::RCP<const Epetra_BlockMap>& block_map,
92 const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
93 const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
94 const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_,
96 const Epetra_Vector& block_vector) :
98 coeff_map(coeff_map_),
99 product_comm(product_comm_),
100 product_map(product_map_),
101 bv(Teuchos::rcp(new EpetraExt::BlockVector(CV, *coeff_map, block_vector)))
102{
103 for (int i=0; i<this->size(); i++)
104 this->setCoeffPtr(i, bv->GetBlock(i));
105}
106
110 coeff_map(v.coeff_map),
111 product_comm(v.product_comm),
112 product_map(v.product_map),
113 bv(v.bv)
114{
115}
116
119
124 coeff_map = v.coeff_map;
125 product_comm = v.product_comm;
126 product_map = v.product_map;
127 bv = v.bv; // Note this is a shallow copy, which is consistent with above
128 return *this;
129}
130
133operator=(const Epetra_Vector& v) {
134 if (this->size() > 0) {
135 if (bv != Teuchos::null)
136 bv->Update(1.0, v, 0.0);
137 else {
138 EpetraExt::BlockVector block_v(View, *coeff_map, v);
139 for (int i=0; i<this->size(); i++)
140 *(coeff_[i]) = *(block_v.GetBlock(i));
141 }
142 }
143 return *this;
144}
145
146void
149{
150 if (this->size() > 0) {
151 if (bv != Teuchos::null)
152 v.Update(1.0, *bv, 0.0);
153 else {
154 EpetraExt::BlockVector block_v(View, *coeff_map, v);
155 for (int i=0; i<this->size(); i++)
156 *(block_v.GetBlock(i)) = *(coeff_[i]);
157 }
158 }
159}
160
161void
164{
165 if (this->size() > 0) {
166 if (bv != Teuchos::null)
167 bv->Update(1.0, v, 0.0);
168 else {
169 EpetraExt::BlockVector block_v(View, *coeff_map, v);
170 for (int i=0; i<this->size(); i++)
171 *(coeff_[i]) = *(block_v.GetBlock(i));
172 }
173 }
174}
175
176Teuchos::RCP<const Epetra_BlockMap>
178coefficientMap() const {
179 return coeff_map;
180}
181
182Teuchos::RCP<const Epetra_BlockMap>
184productMap() const {
185 return product_map;
186}
187
188Teuchos::RCP<const EpetraExt::MultiComm>
190productComm() const {
191 return product_comm;
192}
193
194void
196reset(const Teuchos::RCP<const Epetra_BlockMap>& block_map,
197 const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
198 const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_)
199{
201 coeff_map = coeff_map_;
202 product_comm = product_comm_;
203 product_map =
204 Teuchos::rcp(EpetraExt::BlockUtility::GenerateBlockMap(*coeff_map,
205 *block_map,
206 *product_comm));
207 bv = Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map));
208 for (int i=0; i<this->size(); i++)
209 this->setCoeffPtr(i, bv->GetBlock(i));
210}
211
212void
214reset(const Teuchos::RCP<const Epetra_BlockMap>& block_map,
215 const Teuchos::RCP<const Epetra_BlockMap>& coeff_map_,
216 const Teuchos::RCP<const Epetra_BlockMap>& product_map_,
217 const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm_)
218{
220 coeff_map = coeff_map_;
221 product_comm = product_comm_;
222 product_map = product_map_;
223 bv = Teuchos::rcp(new EpetraExt::BlockVector(*coeff_map, *product_map));
224 for (int i=0; i<this->size(); i++)
225 this->setCoeffPtr(i, bv->GetBlock(i));
226}
227
228void
231 const Epetra_Vector& block_vector)
232{
233 bv = Teuchos::rcp(new EpetraExt::BlockVector(CV, *coeff_map, block_vector));
234 for (int i=0; i<this->size(); i++)
235 this->setCoeffPtr(i, bv->GetBlock(i));
236}
237
238Teuchos::RCP<EpetraExt::BlockVector>
241{
242 return bv;
243}
244
245Teuchos::RCP<const EpetraExt::BlockVector>
247getBlockVector() const
248{
249 return bv;
250}
251
252void
254setBlockVector(const Teuchos::RCP<EpetraExt::BlockVector>& block_vec)
255{
256 bv = block_vec;
257 for (int i=0; i<this->size(); i++)
258 this->setCoeffPtr(i, bv->GetBlock(i));
259}
260
261void
263sumAll()
264{
265 Epetra_Vector v(*coeff_map);
266 int sz = this->size();
267 for (int i=0; i<sz; i++) {
268 v.Scale(1.0, *(this->coeff_[i]));
269 this->map_->Comm().SumAll(v.Values(),
270 this->coeff_[i]->Values(),
271 this->coeff_[i]->MyLength());
272 }
273}
Epetra_DataAccess
int Scale(double ScalarValue)
double * Values() const
int Update(double ScalarA, const Epetra_MultiVector &A, double ScalarThis)
A product (in the mathematical sense) container class whose coefficients are vectors,...
void reset(const Teuchos::RCP< const Epetra_BlockMap > &map)
Resize to new map map.
ProductContainer & operator=(const ProductContainer &)
Assignment.
void setCoeffPtr(ordinal_type i, const Teuchos::RCP< Epetra_Vector > &c)
Set coefficient i to c.
A container class for products of Epetra_Vector's.
Teuchos::RCP< const EpetraExt::MultiComm > product_comm
Product multi-level communicator.
void assignFromBlockVector(const Epetra_Vector &v)
Assignment.
Teuchos::RCP< const Epetra_BlockMap > productMap() const
Get product map.
void assignToBlockVector(Epetra_Vector &v) const
Assignment.
Teuchos::RCP< const Epetra_BlockMap > coefficientMap() const
Get coefficient map.
Teuchos::RCP< const Epetra_BlockMap > product_map
Product map of block vector.
Teuchos::RCP< const EpetraExt::MultiComm > productComm() const
Get product comm.
Teuchos::RCP< const Epetra_BlockMap > coeff_map
Product map of block vector.
void sumAll()
Sum coefficients across processors, storing result in this.
void resetCoefficients(Epetra_DataAccess CV, const Epetra_Vector &block_vector)
Reset vector cofficients.
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.
ProductEpetraVector & operator=(const ProductEpetraVector &v)
Assignment.
Teuchos::RCP< EpetraExt::BlockVector > getBlockVector()
Get block vector.
void setBlockVector(const Teuchos::RCP< EpetraExt::BlockVector > &block_vec)
Set block vector.