Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
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,
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 
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
twoD_diffusion_ME::p_names
Teuchos::RCP< Teuchos::Array< std::string > > p_names
Parameter names.
Definition: twoD_diffusion_ME.hpp:167
twoD_diffusion_ME::MeshPoint
Definition: twoD_diffusion_ME.hpp:132
twoD_diffusion_ME::MeshPoint::down
int down
Definition: twoD_diffusion_ME.hpp:135
twoD_diffusion_ME::importer
Teuchos::RCP< Epetra_Import > importer
Importer to overlapped distribution.
Definition: twoD_diffusion_ME.hpp:152
Teuchos_ParameterList.hpp
Teuchos_RCP.hpp
Epetra_BlockMap::NumMyElements
int NumMyElements() const
twoD_diffusion_ME::get_x_map
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Definition: twoD_diffusion_ME.cpp:335
twoD_diffusion_ME::create_W
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Definition: twoD_diffusion_ME.cpp:408
twoD_diffusion_ME::p_map
Teuchos::RCP< Epetra_Map > p_map
Parameter vector map.
Definition: twoD_diffusion_ME.hpp:158
twoD_diffusion_ME::get_f_map
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Definition: twoD_diffusion_ME.cpp:342
twoD_diffusion_ME::~twoD_diffusion_ME
~twoD_diffusion_ME()
Destructor.
Definition: twoD_diffusion_ME.cpp:326
Teuchos::Array::resize
void resize(size_type new_size, const value_type &x=value_type())
twoD_diffusion_ME::eliminate_bcs
bool eliminate_bcs
Definition: twoD_diffusion_ME.hpp:143
twoD_diffusion_ME::twoD_diffusion_ME
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.
Definition: twoD_diffusion_ME.cpp:163
twoD_diffusion_ME::MeshPoint::right
int right
Definition: twoD_diffusion_ME.hpp:135
twoD_diffusion_ME::get_p_names
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Definition: twoD_diffusion_ME.cpp:375
Stokhos_AbstractPreconditionerFactory.hpp
twoD_diffusion_ME::create_WPrec
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner for W.
Definition: twoD_diffusion_ME.cpp:419
twoD_diffusion_ME::MeshPoint::x
double x
Definition: twoD_diffusion_ME.hpp:134
twoD_diffusion_ME::sg_kx_vec_all
Teuchos::Array< Teuchos::RCP< Epetra_Vector > > sg_kx_vec_all
Vectors to store matrix-vector products in SG residual calculation.
Definition: twoD_diffusion_ME.hpp:179
twoD_diffusion_ME::precParams
Teuchos::RCP< Teuchos::ParameterList > precParams
Definition: twoD_diffusion_ME.hpp:145
Epetra_LocalMap.h
Stokhos_Epetra.hpp
Stokhos.hpp
twoD_diffusion_ME::MeshPoint::left
int left
Definition: twoD_diffusion_ME.hpp:135
twoD_diffusion_ME::MeshPoint::y
double y
Definition: twoD_diffusion_ME.hpp:134
Epetra_CrsMatrix.h
twoD_diffusion_ME::fillMatrices
void fillMatrices(const FuncT &func, int sz)
Fill coefficient matrix given function to evaluate diffusion coefficient.
Definition: twoD_diffusion_ME.hpp:195
twoD_diffusion_ME::precFactory
Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > precFactory
Definition: twoD_diffusion_ME.hpp:146
Teuchos::rcp
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
twoD_diffusion_ME::x_map
Teuchos::RCP< Epetra_Map > x_map
Solution vector map.
Definition: twoD_diffusion_ME.hpp:149
Teuchos_Array.hpp
twoD_diffusion_ME::basis_vals
Teuchos::Array< double > basis_vals
Array to store values of basis at a point.
Definition: twoD_diffusion_ME.hpp:188
twoD_diffusion_ME::MeshPoint::MeshPoint
MeshPoint()
Definition: twoD_diffusion_ME.hpp:133
twoD_diffusion_ME::evalModel
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
Definition: twoD_diffusion_ME.cpp:484
twoD_diffusion_ME::bcIndices
Teuchos::Array< int > bcIndices
Definition: twoD_diffusion_ME.hpp:139
Teuchos::RCP< const Epetra_Comm >
Epetra_CrsMatrix
Teuchos::Array
twoD_diffusion_ME::x_init
Teuchos::RCP< Epetra_Vector > x_init
Initial guess.
Definition: twoD_diffusion_ME.hpp:155
val
expr val()
twoD_diffusion_ME::createInArgs
InArgs createInArgs() const
Create InArgs.
Definition: twoD_diffusion_ME.cpp:432
twoD_diffusion_ME::graph
Teuchos::RCP< Epetra_CrsGraph > graph
Jacobian graph.
Definition: twoD_diffusion_ME.hpp:170
twoD_diffusion_ME::get_p_init
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Definition: twoD_diffusion_ME.cpp:395
twoD_diffusion_ME::mesh
Teuchos::Array< MeshPoint > mesh
Definition: twoD_diffusion_ME.hpp:138
Epetra_BlockMap::MyGlobalElements
int MyGlobalElements(int *MyGlobalElementList) const
twoD_diffusion_ME::basis
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > basis
Definition: twoD_diffusion_ME.hpp:141
j
j
Definition: Sacado_Fad_Exp_MP_Vector.hpp:527
Epetra_Import.h
cusp::detail::device::x
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
twoD_diffusion_ME::A
Teuchos::RCP< Epetra_CrsMatrix > A
Matrix to store deterministic operator.
Definition: twoD_diffusion_ME.hpp:182
twoD_diffusion_ME::createOutArgs
OutArgs createOutArgs() const
Create OutArgs.
Definition: twoD_diffusion_ME.cpp:457
twoD_diffusion_ME::log_normal
bool log_normal
Definition: twoD_diffusion_ME.hpp:142
twoD_diffusion_ME::h
double h
Definition: twoD_diffusion_ME.hpp:131
twoD_diffusion_ME::b
Teuchos::RCP< Epetra_Vector > b
Deterministic RHS.
Definition: twoD_diffusion_ME.hpp:176
Epetra_CrsGraph.h
twoD_diffusion_ME::get_mean
Teuchos::RCP< Epetra_CrsMatrix > get_mean() const
Get mean matrix.
Definition: twoD_diffusion_ME.hpp:121
twoD_diffusion_ME
ModelEvaluator for a linear 2-D diffusion problem.
Definition: twoD_diffusion_ME.hpp:62
twoD_diffusion_ME::A_k
Teuchos::Array< Teuchos::RCP< Epetra_CrsMatrix > > A_k
KL coefficients of operator
Definition: twoD_diffusion_ME.hpp:173
Epetra_Map.h
twoD_diffusion_ME::point
Teuchos::Array< double > point
Array to store a point for basis evaluation.
Definition: twoD_diffusion_ME.hpp:185
twoD_diffusion_ME::get_x_init
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
Definition: twoD_diffusion_ME.cpp:388
n
int n
cusp::detail::device::y
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType ValueType * y
Definition: csr_vector.h:267
twoD_diffusion_ME::get_g_map
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const
Return response function map.
Definition: twoD_diffusion_ME.cpp:362
Copy
Copy
twoD_diffusion_ME::MeshPoint::boundary
bool boundary
Definition: twoD_diffusion_ME.hpp:136
Stokhos::OrthogPolyBasis< int, double >
twoD_diffusion_ME::get_p_map
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Definition: twoD_diffusion_ME.cpp:349
twoD_diffusion_ME::p_init
Teuchos::RCP< Epetra_Vector > p_init
Initial parameters.
Definition: twoD_diffusion_ME.hpp:164
twoD_diffusion_ME::MeshPoint::up
int up
Definition: twoD_diffusion_ME.hpp:135
twoD_diffusion_ME::g_map
Teuchos::RCP< Epetra_Map > g_map
Response vector map.
Definition: twoD_diffusion_ME.hpp:161