Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
twoD_diffusion_problem_tpetra.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_PROBLEM_TPETRA_HPP
43 #define TWOD_DIFFUSION_PROBLEM_TPETRA_HPP
44 
45 #include "Teuchos_RCP.hpp"
46 #include "Teuchos_Array.hpp"
47 #include "Teuchos_Comm.hpp"
48 
49 #include "Tpetra_Map.hpp"
50 #include "Tpetra_Vector.hpp"
51 #include "Tpetra_Import.hpp"
52 #include "Tpetra_CrsGraph.hpp"
53 #include "Tpetra_CrsMatrix.hpp"
54 
55 #include "Stokhos.hpp"
57 //#include "Stokhos_Epetra.hpp"
58 
60 template <typename Scalar,
61  typename MeshScalar,
62  typename BasisScalar,
63  typename LocalOrdinal,
64  typename GlobalOrdinal,
65  typename Node>
67 public:
68 
69  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Map;
70  typedef Tpetra::Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Vector;
71  typedef Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_Operator;
72  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsMatrix;
73  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> Tpetra_CrsGraph;
74  typedef Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> Tpetra_Import;
75 
78  const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
80  BasisScalar s = 0.1, BasisScalar mu = 0.2,
81  bool log_normal = false,
82  bool eliminate_bcs = false);
83 
86 
89 
92 
95 
98 
101  get_p_names(LocalOrdinal l) const;
102 
105 
108 
111 
113  void computeResidual(const Tpetra_Vector& x,
114  const Tpetra_Vector& p,
115  Tpetra_Vector& f);
116 
118  void computeJacobian(const Tpetra_Vector& x,
119  const Tpetra_Vector& p,
120  Tpetra_CrsMatrix& J);
121 
123  void computeResponse(const Tpetra_Vector& x,
124  const Tpetra_Vector& p,
125  Tpetra_Vector& g);
126 
128 
129 protected:
130 
132  template <typename FuncT>
133  void computeA(const FuncT& func, const Tpetra_Vector& p,
134  Tpetra_CrsMatrix& jac);
135 
136 protected:
137 
138  // Mesh
139  MeshScalar h;
140  struct MeshPoint {
141  MeshPoint() : up(-1), down(-1), left(-1), right(-1), boundary(false) {}
142  MeshScalar x, y;
144  bool boundary;
145  };
148  bool log_normal;
149  bool eliminate_bcs;
150 
153 
156 
159 
162 
165 
168 
171 
174 
177 
180 
181  // Functor representing a diffusion function given by a KL expansion
185  KL_Diffusion_Func(MeshScalar xyLeft, MeshScalar xyRight,
186  BasisScalar mean, BasisScalar std_dev,
187  MeshScalar L, LocalOrdinal num_KL);
188  Scalar operator() (MeshScalar x, MeshScalar y,
189  const Teuchos::Array<Scalar>& rv) const;
190  };
191 
192  // Functor representing a diffusion function given by a log-normal
193  // PC expansion
194  template <typename DiffusionFunc>
196  const DiffusionFunc& func;
197  LogNormal_Diffusion_Func(const DiffusionFunc& func_) : func(func_) {}
198  Scalar operator() (MeshScalar x, MeshScalar y,
199  const Teuchos::Array<Scalar>& rv) const {
200  return std::exp(func(x,y,rv));
201  }
202  };
203 
206 
207 };
208 
210 
211 #endif // TWOD_DIFFUSION_ME_HPP
twoD_diffusion_problem
A linear 2-D diffusion problem.
Definition: twoD_diffusion_problem.hpp:58
twoD_diffusion_problem::get_p_init
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Definition: twoD_diffusion_problem.cpp:374
twoD_diffusion_problem::Tpetra_CrsMatrix
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Tpetra_CrsMatrix
Definition: twoD_diffusion_problem_tpetra.hpp:72
g
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
Definition: gram_schmidt_example3.cpp:109
twoD_diffusion_problem::p_names
Teuchos::RCP< Teuchos::Array< std::string > > p_names
Parameter names.
Definition: twoD_diffusion_problem.hpp:178
twoD_diffusion_problem::MeshPoint::x
double x
Definition: twoD_diffusion_problem.hpp:148
twoD_diffusion_problem::MeshPoint::right
int right
Definition: twoD_diffusion_problem.hpp:149
Stokhos_KL_ExponentialRandomField.hpp
Teuchos_RCP.hpp
twoD_diffusion_problem::KL_Diffusion_Func::rf
Teuchos::RCP< Stokhos::KL::ExponentialRandomField< MeshScalar > > rf
Definition: twoD_diffusion_problem_tpetra.hpp:184
twoD_diffusion_problem::computeA
void computeA(const FuncT &func, const Tpetra_Vector &p, Tpetra_CrsMatrix &jac)
Fill coefficient matrix given function to evaluate diffusion coefficient.
Definition: twoD_diffusion_problem_tpetra_def.hpp:368
twoD_diffusion_problem::Tpetra_Operator
Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > Tpetra_Operator
Definition: twoD_diffusion_problem_tpetra.hpp:71
twoD_diffusion_problem::graph
Teuchos::RCP< Tpetra_CrsGraph > graph
Jacobian graph.
Definition: twoD_diffusion_problem_tpetra.hpp:173
twoD_diffusion_problem::computeResponse
void computeResponse(const Epetra_Vector &x, const Epetra_Vector &p, Epetra_Vector &g)
Compute response.
Definition: twoD_diffusion_problem.cpp:424
twoD_diffusion_problem::MeshPoint::left
int left
Definition: twoD_diffusion_problem.hpp:149
twoD_diffusion_problem::computeJacobian
void computeJacobian(const Epetra_Vector &x, const Epetra_Vector &p, Epetra_Operator &J)
Compute Jacobian.
Definition: twoD_diffusion_problem.cpp:410
twoD_diffusion_problem_tpetra_def.hpp
twoD_diffusion_problem::MeshPoint::down
int down
Definition: twoD_diffusion_problem.hpp:149
twoD_diffusion_problem::get_p_map
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Definition: twoD_diffusion_problem.cpp:328
Sacado::UQ::exp
KOKKOS_INLINE_FUNCTION PCE< Storage > exp(const PCE< Storage > &a)
Definition: Sacado_UQ_PCE_Imp.hpp:827
Stokhos.hpp
twoD_diffusion_problem::g_map
Teuchos::RCP< const Tpetra_Map > g_map
Response vector map.
Definition: twoD_diffusion_problem_tpetra.hpp:164
twoD_diffusion_problem::Tpetra_Import
Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > Tpetra_Import
Definition: twoD_diffusion_problem_tpetra.hpp:74
twoD_diffusion_problem::mesh
Teuchos::Array< MeshPoint > mesh
Definition: twoD_diffusion_problem.hpp:152
twoD_diffusion_problem::get_x_init
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
Definition: twoD_diffusion_problem.cpp:367
twoD_diffusion_problem::h
MeshScalar h
Definition: twoD_diffusion_problem_tpetra.hpp:139
twoD_diffusion_problem::KL_Diffusion_Func
Definition: twoD_diffusion_problem_tpetra.hpp:182
twoD_diffusion_problem::Tpetra_CrsGraph
Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > Tpetra_CrsGraph
Definition: twoD_diffusion_problem_tpetra.hpp:73
Teuchos_Array.hpp
twoD_diffusion_problem::MeshPoint::MeshPoint
MeshPoint()
Definition: twoD_diffusion_problem_tpetra.hpp:141
twoD_diffusion_problem::LogNormal_Diffusion_Func
Definition: twoD_diffusion_problem_tpetra.hpp:195
twoD_diffusion_problem::p_map
Teuchos::RCP< const Tpetra_Map > p_map
Parameter vector map.
Definition: twoD_diffusion_problem_tpetra.hpp:161
Teuchos::RCP
Node
KokkosClassic::DefaultNode::DefaultNodeType Node
Definition: experimental/linear2d_diffusion_pce.cpp:79
Teuchos::Array
twoD_diffusion_problem::KL_Diffusion_Func::point
Teuchos::Array< MeshScalar > point
Definition: twoD_diffusion_problem_tpetra.hpp:183
twoD_diffusion_problem::LogNormal_Diffusion_Func::func
const DiffusionFunc & func
Definition: twoD_diffusion_problem_tpetra.hpp:196
twoD_diffusion_problem::lnFunc
Teuchos::RCP< LogNormal_Diffusion_Func< KL_Diffusion_Func > > lnFunc
Definition: twoD_diffusion_problem_tpetra.hpp:205
twoD_diffusion_problem::computeResidual
void computeResidual(const Epetra_Vector &x, const Epetra_Vector &p, Epetra_Vector &f)
Compute residual.
Definition: twoD_diffusion_problem.cpp:398
twoD_diffusion_problem::bcIndices
Teuchos::Array< GlobalOrdinal > bcIndices
Definition: twoD_diffusion_problem_tpetra.hpp:147
twoD_diffusion_problem::A
Teuchos::RCP< Tpetra_CrsMatrix > A
Matrix to store operator.
Definition: twoD_diffusion_problem_tpetra.hpp:179
twoD_diffusion_problem::LogNormal_Diffusion_Func::LogNormal_Diffusion_Func
LogNormal_Diffusion_Func(const DiffusionFunc &func_)
Definition: twoD_diffusion_problem_tpetra.hpp:197
twoD_diffusion_problem::importer
Teuchos::RCP< Tpetra_Import > importer
Importer to overlapped distribution.
Definition: twoD_diffusion_problem_tpetra.hpp:155
twoD_diffusion_problem::x_init
Teuchos::RCP< Tpetra_Vector > x_init
Initial guess.
Definition: twoD_diffusion_problem_tpetra.hpp:158
twoD_diffusion_problem::b
Teuchos::RCP< Tpetra_Vector > b
RHS.
Definition: twoD_diffusion_problem_tpetra.hpp:176
twoD_diffusion_problem::MeshPoint::boundary
bool boundary
Definition: twoD_diffusion_problem.hpp:150
twoD_diffusion_problem::get_p_names
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Definition: twoD_diffusion_problem.cpp:354
j
j
Definition: Sacado_Fad_Exp_MP_Vector.hpp:527
LocalOrdinal
int LocalOrdinal
Definition: ifpack2_pce_instantiations.cpp:47
twoD_diffusion_problem::get_f_map
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Definition: twoD_diffusion_problem.cpp:321
twoD_diffusion_problem::KL_Diffusion_Func::KL_Diffusion_Func
KL_Diffusion_Func(MeshScalar xyLeft, MeshScalar xyRight, BasisScalar mean, BasisScalar std_dev, MeshScalar L, LocalOrdinal num_KL)
Definition: twoD_diffusion_problem_tpetra_def.hpp:440
f
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
Definition: gram_schmidt_example3.cpp:98
twoD_diffusion_problem::LogNormal_Diffusion_Func::operator()
Scalar operator()(MeshScalar x, MeshScalar y, const Teuchos::Array< Scalar > &rv) const
Definition: twoD_diffusion_problem_tpetra.hpp:198
twoD_diffusion_problem::MeshPoint::y
MeshScalar y
Definition: twoD_diffusion_problem_tpetra.hpp:142
twoD_diffusion_problem::x_map
Teuchos::RCP< const Tpetra_Map > x_map
Solution vector map.
Definition: twoD_diffusion_problem_tpetra.hpp:152
twoD_diffusion_problem::klFunc
Teuchos::RCP< KL_Diffusion_Func > klFunc
Definition: twoD_diffusion_problem_tpetra.hpp:204
cusp::detail::device::x
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
twoD_diffusion_problem::p_init
Teuchos::RCP< Tpetra_Vector > p_init
Initial parameters.
Definition: twoD_diffusion_problem_tpetra.hpp:167
twoD_diffusion_problem::MeshPoint::up
int up
Definition: twoD_diffusion_problem.hpp:149
twoD_diffusion_problem::create_W
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Definition: twoD_diffusion_problem.cpp:387
twoD_diffusion_problem::get_x_map
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Definition: twoD_diffusion_problem.cpp:314
twoD_diffusion_problem::eliminate_bcs
bool eliminate_bcs
Definition: twoD_diffusion_problem.hpp:157
twoD_diffusion_problem::log_normal
bool log_normal
Definition: twoD_diffusion_problem.hpp:156
twoD_diffusion_problem::twoD_diffusion_problem
twoD_diffusion_problem(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)
Constructor.
Definition: twoD_diffusion_problem.cpp:160
Teuchos::Comm< int >
twoD_diffusion_problem::Tpetra_Map
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > Tpetra_Map
Definition: twoD_diffusion_problem_tpetra.hpp:69
Teuchos_Comm.hpp
twoD_diffusion_problem::Tpetra_Vector
Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > Tpetra_Vector
Definition: twoD_diffusion_problem_tpetra.hpp:70
twoD_diffusion_problem::MeshPoint
Definition: twoD_diffusion_problem.hpp:146
twoD_diffusion_problem::get_g_map
Teuchos::RCP< const Epetra_Map > get_g_map(int j) const
Return response function map.
Definition: twoD_diffusion_problem.cpp:341
GlobalOrdinal
int GlobalOrdinal
Definition: ifpack2_pce_instantiations.cpp:48
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_problem::KL_Diffusion_Func::operator()
Scalar operator()(MeshScalar x, MeshScalar y, const Teuchos::Array< Scalar > &rv) const
Definition: twoD_diffusion_problem_tpetra_def.hpp:469
Sacado::PCE::OrthogPoly< double, Storage >
Scalar
pce_type Scalar
Definition: ifpack2_pce_instantiations.cpp:46
twoD_diffusion_problem::MeshPoint::up
LocalOrdinal up
Definition: twoD_diffusion_problem_tpetra.hpp:143