Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_PCECovarianceOp.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
44#include "Epetra_LocalMap.h"
45#include "Epetra_Map.h"
46#include "Epetra_MultiVector.h"
47
50 : label("Stokhos::PCECovarianceOp"),
51 X(),
52 s(X_poly.basis()->norm_squared()),
53 useTranspose(false),
54 tmp_map(),
55 tmp()
56{
57 const Epetra_BlockMap& base_map = X_poly[0].Map();
58 int sz = X_poly.size();
59 Teuchos::RCP<Epetra_MultiVector> XX =
60 Teuchos::rcp(new Epetra_MultiVector(base_map, sz-1));
61 for (int i=0; i<sz-1; i++)
62 (*XX)(i)->Scale(1.0, X_poly[i+1]);
63 X = XX;
64 tmp_map =
65 Teuchos::rcp(new Epetra_LocalMap(X->NumVectors(), 0, X->Map().Comm()));
66}
67
69PCECovarianceOp(const Teuchos::RCP<const EpetraExt::BlockVector>& X_bv,
71 : label("Stokhos::PCECovarianceOp"),
72 X(),
73 s(basis.norm_squared()),
74 useTranspose(false),
75 tmp_map(),
76 tmp()
77{
78 const Epetra_BlockMap& base_map = X_bv->GetBaseMap();
79 int N = base_map.NumMyElements();
80 int sz = basis.size();
81 X = Teuchos::rcp(new Epetra_MultiVector(View, base_map, X_bv->Values()+N,
82 N, sz-1));
83 tmp_map =
84 Teuchos::rcp(new Epetra_LocalMap(X->NumVectors(), 0, X->Map().Comm()));
85}
86
88PCECovarianceOp(const Teuchos::RCP<const Epetra_MultiVector>& X_,
90 : label("Stokhos::PCECovarianceOp"),
91 X(X_),
92 s(basis.norm_squared()),
93 useTranspose(false),
94 tmp_map(),
95 tmp()
96{
97 tmp_map =
98 Teuchos::rcp(new Epetra_LocalMap(X->NumVectors(), 0, X->Map().Comm()));
99}
100
102{
103}
104
105int
107{
108 useTranspose = UseTheTranspose;
109 return 0;
110}
111
112int
114 Epetra_MultiVector& Result) const
115{
116 // Allocate temporary storage
117 int m = Input.NumVectors();
118 if (tmp == Teuchos::null || tmp->NumVectors() != m)
119 tmp = Teuchos::rcp(new Epetra_MultiVector(*tmp_map, m));
120
121 // Compute X^T*Input
122 tmp->Multiply('T', 'N', 1.0, *X, Input, 0.0);
123
124 // Compute S*tmp
125 for (int j=0; j<m; j++)
126 for (int i=0; i<X->NumVectors(); i++)
127 (*tmp)[j][i] *= s[i+1];
128
129 // Compute X*tmp
130 Result.Multiply('N', 'N', 1.0, *X, *tmp, 0.0);
131
132 return 0;
133}
134
135int
137 Epetra_MultiVector& Result) const
138{
139 throw "PCECovarianceOp::ApplyInverse not defined!";
140 return -1;
141}
142
143double
145{
146 return 1.0;
147}
148
149
150const char*
152{
153 return const_cast<char*>(label.c_str());
154}
155
156bool
158{
159 return useTranspose;
160}
161
162bool
164{
165 return false;
166}
167
168const Epetra_Comm &
170{
171 return X->Map().Comm();
172}
173const Epetra_Map&
175{
176 return dynamic_cast<const Epetra_Map&>(X->Map());
177}
178
179const Epetra_Map&
181{
182 return dynamic_cast<const Epetra_Map&>(X->Map());
183}
184
185const Epetra_BlockMap&
187{
188 return X->Map();
189}
int NumMyElements() const
int NumVectors() const
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_MultiVector &A, const Epetra_MultiVector &B, double ScalarThis)
Abstract base class for multivariate orthogonal polynomials.
virtual ordinal_type size() const =0
Return total size of basis.
virtual int Apply(const Epetra_MultiVector &Input, Epetra_MultiVector &Result) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector Input in Result as described ...
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Teuchos::RCP< const Epetra_MultiVector > X
Multivector X defining A = X*S*X^T.
PCECovarianceOp(const Stokhos::VectorOrthogPoly< Epetra_Vector > &X_poly)
Constructor with polynomial X.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of the inverse of the operator applied to a Epetra_MultiVector Input in Result as ...
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
Teuchos::RCP< Epetra_Map > tmp_map
Map needed for temporary vector.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator.
virtual ~PCECovarianceOp()
Destructor.
virtual const char * Label() const
Returns a character std::string describing the operator.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
const Epetra_BlockMap & CoeffMap() const
Returns PCE coefficient map.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
ordinal_type size() const
Return size.
A container class storing an orthogonal polynomial whose coefficients are vectors,...