Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_EpetraVectorOrthogPoly.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 
17 {
18 }
19 
23  const Teuchos::RCP<const Epetra_BlockMap>& block_map) :
24  ProductContainer<Epetra_Vector>(block_map),
25  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
26  ProductEpetraVector(block_map)
27 {
28 }
29 
33  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
34  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
35  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm) :
36  ProductContainer<Epetra_Vector>(block_map),
37  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
38  ProductEpetraVector(block_map, coeff_map, product_comm)
39 {
40 }
41 
45  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
46  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
47  const Teuchos::RCP<const Epetra_BlockMap>& product_map,
48  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm) :
49  ProductContainer<Epetra_Vector>(block_map),
50  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
51  ProductEpetraVector(block_map, coeff_map, product_map, product_comm)
52 {
53 }
54 
58  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
59  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
60  const Teuchos::RCP<const Epetra_BlockMap>& product_map,
61  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm,
63  const Epetra_Vector& block_vector) :
64  ProductContainer<Epetra_Vector>(block_map),
65  VectorOrthogPoly<Epetra_Vector>(basis, block_map),
66  ProductEpetraVector(block_map, coeff_map, product_map, product_comm, CV,
67  block_vector)
68 {
69 }
70 
76 {
77 }
78 
81 
86  this->basis_ = v.basis_;
87  return *this;
88 }
89 
90 void
93  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& new_basis,
94  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
95  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
96  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm)
97 {
98  ProductEpetraVector::reset(block_map, coeff_map, product_comm);
99  this->basis_ = new_basis;
100 }
101 
102 void
105  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> >& new_basis,
106  const Teuchos::RCP<const Epetra_BlockMap>& block_map,
107  const Teuchos::RCP<const Epetra_BlockMap>& coeff_map,
108  const Teuchos::RCP<const Epetra_BlockMap>& product_map,
109  const Teuchos::RCP<const EpetraExt::MultiComm>& product_comm)
110 {
111  ProductEpetraVector::reset(block_map, coeff_map, product_map, product_comm);
112  this->basis_ = new_basis;
113 }
114 
115 void
118 {
119  if (this->map_->Comm().NumProc() == 1 || !this->map_->DistributedGlobal()) {
120  v.Scale(1.0, *(this->coeff_[0]));
121  return;
122  }
123 
124  int root = -1;
125  int gid = 0;
126  int lid = -1;
127  this->map_->RemoteIDList(1, &gid, &root, &lid);
128  if (this->map_->Comm().MyPID() == root) {
129  v.Scale(1.0, *(this->coeff_[lid]));
130  }
131  this->map_->Comm().Broadcast(v.Values(), v.MyLength(), root);
132 }
133 
134 void
137 {
138  Epetra_Vector *v_local = NULL;
139  bool is_parallel = (this->map_->Comm().NumProc() > 1) &&
140  this->map_->DistributedGlobal();
141  if (is_parallel)
142  v_local = new Epetra_Vector(v.Map());
143  else
144  v_local = &v;
145 
146  // Compute partial variance with terms on this processor
147  const Teuchos::Array<double>& nrm2 = this->basis_->norm_squared();
148  v_local->PutScalar(0.0);
149  int i_gid;
150  for (int i=0; i<this->size(); i++) {
151  i_gid = this->map_->GID(i);
152  if (i_gid != 0)
153  v_local->Multiply(nrm2[i_gid], *(this->coeff_[i]), *(this->coeff_[i]),
154  1.0);
155  }
156 
157  // Compute total variance by summing across all processors
158  if (is_parallel)
159  this->map_->Comm().SumAll(v_local->Values(), v.Values(), v.MyLength());
160 }
161 
162 void
165 {
166  // Compute variance
167  computeVariance(v);
168 
169  // Compute standard deviation
170  for (int i=0; i<v.MyLength(); i++)
171  v[i] = std::sqrt(v[i]);
172 }
KOKKOS_INLINE_FUNCTION PCE< Storage > sqrt(const PCE< Storage > &a)
void computeVariance(Epetra_Vector &v) const
Compute variance.
void computeStandardDeviation(Epetra_Vector &v) const
Compute standard deviation.
void computeMean(Epetra_Vector &v) const
Compute mean.
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.
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.
virtual const Epetra_BlockMap & Map() const =0
A container class for products of Epetra_Vector&#39;s.
EpetraVectorOrthogPoly & operator=(const EpetraVectorOrthogPoly &v)
Assignment.
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.
Epetra_DataAccess
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.