Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
twoD_diffusion_ME.hpp
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
42#ifndef TWOD_DIFFUSION_ME_HPP
43#define TWOD_DIFFUSION_ME_HPP
44
45#include "Teuchos_RCP.hpp"
46#include "Teuchos_Array.hpp"
47#include "Teuchos_ParameterList.hpp"
48
49#include "EpetraExt_ModelEvaluator.h"
50
51#include "Epetra_Map.h"
52#include "Epetra_LocalMap.h"
53#include "Epetra_Import.h"
54#include "Epetra_CrsGraph.h"
55#include "Epetra_CrsMatrix.h"
56
57#include "Stokhos.hpp"
58#include "Stokhos_Epetra.hpp"
60
62class twoD_diffusion_ME : public EpetraExt::ModelEvaluator {
63public:
64
67 const Teuchos::RCP<const Epetra_Comm>& comm, int n, int d,
68 double s = 0.1, double mu = 0.2,
69 const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& basis =
70 Teuchos::null,
71 bool log_normal = false,
72 bool eliminate_bcs = false,
73 const Teuchos::RCP<Teuchos::ParameterList>& precParams = Teuchos::null);
74
77
80
82 Teuchos::RCP<const Epetra_Map> get_x_map() const;
83
85 Teuchos::RCP<const Epetra_Map> get_f_map() const;
86
88 Teuchos::RCP<const Epetra_Map> get_p_map(int l) const;
89
91 Teuchos::RCP<const Epetra_Map> get_g_map(int j) const;
92
94 Teuchos::RCP<const Teuchos::Array<std::string> >
95 get_p_names(int l) const;
96
98 Teuchos::RCP<const Epetra_Vector> get_x_init() const;
99
101 Teuchos::RCP<const Epetra_Vector> get_p_init(int l) const;
102
104 Teuchos::RCP<Epetra_Operator> create_W() const;
105
107 Teuchos::RCP<EpetraExt::ModelEvaluator::Preconditioner> create_WPrec() const;
108
110 InArgs createInArgs() const;
111
113 OutArgs createOutArgs() const;
114
116 void evalModel(const InArgs& inArgs, const OutArgs& outArgs) const;
117
119
121 Teuchos::RCP<Epetra_CrsMatrix> get_mean() const { return A_k[0]; }
122
123protected:
124
126 template <typename FuncT>
127 void fillMatrices(const FuncT& func, int sz);
128
129protected:
130
131 double h;
132 struct MeshPoint {
133 MeshPoint() : up(-1), down(-1), left(-1), right(-1), boundary(false) {}
134 double x, y;
137 };
138 Teuchos::Array<MeshPoint> mesh;
139 Teuchos::Array<int> bcIndices;
140
141 Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> > basis;
144
145 Teuchos::RCP<Teuchos::ParameterList> precParams;
146 Teuchos::RCP<Stokhos::AbstractPreconditionerFactory> precFactory;
147
149 Teuchos::RCP<Epetra_Map> x_map;
150
152 Teuchos::RCP<Epetra_Import> importer;
153
155 Teuchos::RCP<Epetra_Vector> x_init;
156
158 Teuchos::RCP<Epetra_Map> p_map;
159
161 Teuchos::RCP<Epetra_Map> g_map;
162
164 Teuchos::RCP<Epetra_Vector> p_init;
165
167 Teuchos::RCP< Teuchos::Array<std::string> > p_names;
168
170 Teuchos::RCP<Epetra_CrsGraph> graph;
171
173 Teuchos::Array<Teuchos::RCP<Epetra_CrsMatrix> > A_k;
174
176 Teuchos::RCP<Epetra_Vector> b;
177
179 mutable Teuchos::Array< Teuchos::RCP<Epetra_Vector> > sg_kx_vec_all;
180
182 Teuchos::RCP<Epetra_CrsMatrix> A;
183
185 mutable Teuchos::Array<double> point;
186
188 mutable Teuchos::Array<double> basis_vals;
189
190};
191
192template <typename FuncT>
193void
195fillMatrices(const FuncT& func, int sz)
196{
197 int NumMyElements = x_map->NumMyElements();
198 int *MyGlobalElements = x_map->MyGlobalElements();
199 double h2 = h*h;
200 double val;
201
202 A_k.resize(sz);
203 for (int k=0; k<sz; k++) {
204 A_k[k] = Teuchos::rcp(new Epetra_CrsMatrix(Copy, *graph));
205 for( int i=0 ; i<NumMyElements; ++i ) {
206
207 // Center
208 int global_idx = MyGlobalElements[i];
209 if (mesh[global_idx].boundary) {
210 if (k == 0)
211 val = 1.0; //Enforce BC in mean matrix
212 else
213 val = 0.0;
214 A_k[k]->ReplaceGlobalValues(global_idx, 1, &val, &global_idx);
215 }
216 else {
217 double a_down =
218 -func(mesh[global_idx].x, mesh[global_idx].y-h/2.0, k)/h2;
219 double a_left =
220 -func(mesh[global_idx].x-h/2.0, mesh[global_idx].y, k)/h2;
221 double a_right =
222 -func(mesh[global_idx].x+h/2.0, mesh[global_idx].y, k)/h2;
223 double a_up =
224 -func(mesh[global_idx].x, mesh[global_idx].y+h/2.0, k)/h2;
225
226 // Center
227 val = -(a_down + a_left + a_right + a_up);
228 A_k[k]->ReplaceGlobalValues(global_idx, 1, &val, &global_idx);
229
230 // Down
231 if (!(eliminate_bcs && mesh[mesh[global_idx].down].boundary))
232 A_k[k]->ReplaceGlobalValues(global_idx, 1, &a_down,
233 &mesh[global_idx].down);
234
235 // Left
236 if (!(eliminate_bcs && mesh[mesh[global_idx].left].boundary))
237 A_k[k]->ReplaceGlobalValues(global_idx, 1, &a_left,
238 &mesh[global_idx].left);
239
240 // Right
241 if (!(eliminate_bcs && mesh[mesh[global_idx].right].boundary))
242 A_k[k]->ReplaceGlobalValues(global_idx, 1, &a_right,
243 &mesh[global_idx].right);
244
245 // Up
246 if (!(eliminate_bcs && mesh[mesh[global_idx].up].boundary))
247 A_k[k]->ReplaceGlobalValues(global_idx, 1, &a_up,
248 &mesh[global_idx].up);
249 }
250 }
251 A_k[k]->FillComplete();
252 A_k[k]->OptimizeStorage();
253 }
254}
255
256#endif // TWOD_DIFFUSION_ME_HPP
Copy
expr val()
Abstract base class for multivariate orthogonal polynomials.
ModelEvaluator for a linear 2-D diffusion problem.
Teuchos::RCP< Epetra_Vector > p_init
Initial parameters.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
InArgs createInArgs() const
Create InArgs.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Teuchos::RCP< Epetra_Import > importer
Importer to overlapped distribution.
Teuchos::Array< MeshPoint > mesh
Teuchos::Array< double > point
Array to store a point for basis evaluation.
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
OutArgs createOutArgs() const
Create OutArgs.
twoD_diffusion_ME(const Teuchos::RCP< const Epetra_Comm > &comm, int n, int d, double s=0.1, double mu=0.2, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &basis=Teuchos::null, bool log_normal=false, bool eliminate_bcs=false, const Teuchos::RCP< Teuchos::ParameterList > &precParams=Teuchos::null)
Constructor.
Teuchos::RCP< Epetra_CrsMatrix > A
Matrix to store deterministic operator.
Teuchos::Array< Teuchos::RCP< Epetra_CrsMatrix > > A_k
KL coefficients of operator
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Teuchos::Array< int > bcIndices
Teuchos::RCP< Epetra_CrsMatrix > get_mean() const
Get mean matrix.
Teuchos::RCP< Epetra_Map > x_map
Solution vector map.
~twoD_diffusion_ME()
Destructor.
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const
Return response function map.
Teuchos::RCP< Epetra_Map > g_map
Response vector map.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
Teuchos::RCP< Epetra_Map > p_map
Parameter vector map.
Teuchos::RCP< Epetra_Vector > x_init
Initial guess.
Teuchos::Array< Teuchos::RCP< Epetra_Vector > > sg_kx_vec_all
Vectors to store matrix-vector products in SG residual calculation.
Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > precFactory
Teuchos::RCP< Teuchos::ParameterList > precParams
Teuchos::RCP< Epetra_CrsGraph > graph
Jacobian graph.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner for W.
void fillMatrices(const FuncT &func, int sz)
Fill coefficient matrix given function to evaluate diffusion coefficient.
Teuchos::RCP< Teuchos::Array< std::string > > p_names
Parameter names.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Teuchos::Array< double > basis_vals
Array to store values of basis at a point.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< Epetra_Vector > b
Deterministic RHS.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > basis