Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_EpetraVectorOrthogPoly.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 
49 {
50 }
51 
54  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& basis,
55  const Teuchos::RCP<const Epetra_BlockMap>& block_map) :
56  ProductContainer<Epetra_Vector>(block_map),
57  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
58  ProductEpetraVector(block_map)
59 {
60 }
61 
64  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& basis,
65  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
66  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
67  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm) :
68  ProductContainer<Epetra_Vector>(block_map),
69  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
70  ProductEpetraVector(block_map, coeff_map, product_comm)
71 {
72 }
73 
76  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& basis,
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  ProductContainer<Epetra_Vector>(block_map),
82  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
83  ProductEpetraVector(block_map, coeff_map, product_map, product_comm)
84 {
85 }
86 
89  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& basis,
90  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
91  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
92  const Teuchos::RCP<const Epetra_BlockMap>& product_map,
93  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm,
95  const Epetra_Vector& block_vector) :
96  ProductContainer<Epetra_Vector>(block_map),
97  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
98  ProductEpetraVector(block_map, coeff_map, product_map, product_comm, CV,
99  block_vector)
100 {
101 }
102 
108 {
109 }
110 
113 
118  this->basis_ = v.basis_;
119  return *this;
120 }
121 
122 void
125  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& new_basis,
126  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
127  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
128  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm)
129 {
130  ProductEpetraVector::reset(block_map, coeff_map, product_comm);
131  this->basis_ = new_basis;
132 }
133 
134 void
137  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& new_basis,
138  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
139  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
140  const Teuchos::RCP<const Epetra_BlockMap>& product_map,
141  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm)
142 {
143  ProductEpetraVector::reset(block_map, coeff_map, product_map, product_comm);
144  this->basis_ = new_basis;
145 }
146 
147 void
150 {
151  if (this->map_->Comm().NumProc() == 1 || !this->map_->DistributedGlobal()) {
152  v.Scale(1.0, *(this->coeff_[0]));
153  return;
154  }
155 
156  int root = -1;
157  int gid = 0;
158  int lid = -1;
159  this->map_->RemoteIDList(1, &gid, &root, &lid);
160  if (this->map_->Comm().MyPID() == root) {
161  v.Scale(1.0, *(this->coeff_[lid]));
162  }
163  this->map_->Comm().Broadcast(v.Values(), v.MyLength(), root);
164 }
165 
166 void
169 {
170  Epetra_Vector *v_local = NULL;
171  bool is_parallel = (this->map_->Comm().NumProc() > 1) &&
172  this->map_->DistributedGlobal();
173  if (is_parallel)
174  v_local = new Epetra_Vector(v.Map());
175  else
176  v_local = &v;
177 
178  // Compute partial variance with terms on this processor
179  const Teuchos::Array<double>& nrm2 = this->basis_->norm_squared();
180  v_local->PutScalar(0.0);
181  int i_gid;
182  for (int i=0; i<this->size(); i++) {
183  i_gid = this->map_->GID(i);
184  if (i_gid != 0)
185  v_local->Multiply(nrm2[i_gid], *(this->coeff_[i]), *(this->coeff_[i]),
186  1.0);
187  }
188 
189  // Compute total variance by summing across all processors
190  if (is_parallel)
191  this->map_->Comm().SumAll(v_local->Values(), v.Values(), v.MyLength());
192 }
193 
194 void
197 {
198  // Compute variance
199  computeVariance(v);
200 
201  // Compute standard deviation
202  for (int i=0; i<v.MyLength(); i++)
203  v[i] = std::sqrt(v[i]);
204 }
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
double * Values() const
const Epetra_BlockMap & Map() const
int MyLength() const
int PutScalar(double ScalarConstant)
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.
EpetraVectorOrthogPoly()
Constructor with no basis.
void computeMean(Epetra_Vector &v) const
Compute mean.
int Scale(double ScalarValue)
ProductEpetraVector & operator=(const ProductEpetraVector &v)
Assignment.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
A container class for products of Epetra_Vector&#39;s.
EpetraVectorOrthogPoly & operator=(const EpetraVectorOrthogPoly &v)
Assignment.
void computeStandardDeviation(Epetra_Vector &v) const
Compute standard deviation.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< ordinal_type, value_type > > basis_
Basis.
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.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_MultiVector &A, const Epetra_MultiVector &B, double ScalarThis)
void computeVariance(Epetra_Vector &v) const
Compute variance.
Epetra_DataAccess
bool DistributedGlobal() const
void reset(const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &basis, 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 basis.