Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
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 
62 class twoD_diffusion_ME : public EpetraExt::ModelEvaluator {
63 public:
64 
67  const Teuchos::RCP<const Epetra_Comm>& comm, int n, int d,
68  double s = 0.1, double mu = 0.2,
71  bool log_normal = false,
72  bool eliminate_bcs = false,
74 
77 
80 
83 
86 
89 
92 
95  get_p_names(int l) const;
96 
99 
102 
105 
108 
110  InArgs createInArgs() const;
111 
113  OutArgs createOutArgs() const;
114 
116  void evalModel(const InArgs& inArgs, const OutArgs& outArgs) const;
117 
119 
122 
123 protected:
124 
126  template <typename FuncT>
127  void fillMatrices(const FuncT& func, int sz);
128 
129 protected:
130 
131  double h;
132  struct MeshPoint {
133  MeshPoint() : up(-1), down(-1), left(-1), right(-1), boundary(false) {}
134  double x, y;
135  int up, down, left, right;
136  bool boundary;
137  };
140 
144 
147 
150 
153 
156 
159 
162 
165 
168 
171 
174 
177 
180 
183 
186 
189 
190 };
191 
192 template <typename FuncT>
193 void
195 fillMatrices(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++) {
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
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
Teuchos::Array< int > bcIndices
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
int MyGlobalElements(int *MyGlobalElementList) const
Teuchos::RCP< Epetra_CrsMatrix > get_mean() const
Get mean matrix.
Teuchos::Array< Teuchos::RCP< Epetra_CrsMatrix > > A_k
KL coefficients of operator.
Teuchos::RCP< Epetra_Vector > x_init
Initial guess.
Teuchos::RCP< Epetra_Map > p_map
Parameter vector map.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
int NumMyElements() const
Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > precFactory
Teuchos::RCP< Epetra_CrsGraph > graph
Jacobian graph.
ModelEvaluator for a linear 2-D diffusion problem.
Teuchos::Array< MeshPoint > mesh
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< Teuchos::ParameterList > precParams
Teuchos::Array< double > basis_vals
Array to store values of basis at a point.
void resize(size_type new_size, const value_type &x=value_type())
~twoD_diffusion_ME()
Destructor.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const
Return response function map.
Teuchos::RCP< Epetra_Map > x_map
Solution vector map.
Teuchos::RCP< Epetra_CrsMatrix > A
Matrix to store deterministic operator.
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_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
expr val()
InArgs createInArgs() const
Create InArgs.
OutArgs createOutArgs() const
Create OutArgs.
Teuchos::RCP< Epetra_Vector > p_init
Initial parameters.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner for W.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< Epetra_Vector > b
Deterministic RHS.
Teuchos::RCP< Teuchos::Array< std::string > > p_names
Parameter names.
Teuchos::Array< double > point
Array to store a point for basis evaluation.
void fillMatrices(const FuncT &func, int sz)
Fill coefficient matrix given function to evaluate diffusion coefficient.
int n
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Teuchos::RCP< Epetra_Map > g_map
Response vector map.
Teuchos::RCP< Epetra_Import > importer
Importer to overlapped distribution.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > basis
Teuchos::Array< Teuchos::RCP< Epetra_Vector > > sg_kx_vec_all
Vectors to store matrix-vector products in SG residual calculation.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.