10 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
16 LocalOrdinal n, LocalOrdinal d,
17 BasisScalar s, BasisScalar mu,
19 bool eliminate_bcs_) :
21 log_normal(log_normal_),
22 eliminate_bcs(eliminate_bcs_)
26 using Teuchos::arrayView;
30 using Tpetra::global_size_t;
41 MeshScalar xyLeft = -.5;
42 MeshScalar xyRight = .5;
43 h = (xyRight - xyLeft)/((MeshScalar)(n-1));
44 Array<GlobalOrdinal> global_dof_indices;
45 for (GlobalOrdinal
j=0;
j<n;
j++) {
46 MeshScalar y = xyLeft +
j*
h;
47 for (GlobalOrdinal i=0; i<n; i++) {
48 MeshScalar x = xyLeft + i*
h;
49 GlobalOrdinal idx =
j*n+i;
52 if (i == 0 || i == n-1 ||
j == 0 ||
j == n-1)
53 mesh[idx].boundary =
true;
55 mesh[idx].left = idx-1;
57 mesh[idx].right = idx+1;
59 mesh[idx].down = idx-n;
63 global_dof_indices.push_back(idx);
68 global_size_t n_global_dof = global_dof_indices.size();
69 int n_proc = comm->getSize();
70 int proc_id = comm->getRank();
71 size_t n_my_dof = n_global_dof / n_proc;
72 if (proc_id == n_proc-1)
73 n_my_dof += n_global_dof % n_proc;
74 ArrayView<GlobalOrdinal> my_dof =
75 global_dof_indices.view(proc_id*(n_global_dof / n_proc), n_my_dof);
76 x_map = Tpetra::createNonContigMap<LocalOrdinal,GlobalOrdinal>(my_dof, comm);
79 x_init = Tpetra::createVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
x_map);
80 x_init->putScalar(0.0);
83 p_map = Tpetra::createLocalMap<LocalOrdinal,GlobalOrdinal>(d, comm);
86 g_map = Tpetra::createLocalMap<LocalOrdinal,GlobalOrdinal>(1, comm);
89 p_init = Tpetra::createVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
p_map);
90 p_init->putScalar(0.0);
94 for (LocalOrdinal i=0;i<d;i++) {
96 ss <<
"KL Random Variable " << i+1;
97 (*p_names)[i] = ss.str();
101 size_t NumMyElements =
x_map->getLocalNumElements();
102 ArrayView<const GlobalOrdinal> MyGlobalElements =
103 x_map->getLocalElementList ();
105 for (
size_t i=0; i<NumMyElements; ++i ) {
108 GlobalOrdinal global_idx = MyGlobalElements[i];
109 graph->insertGlobalIndices(global_idx, arrayView(&global_idx, 1));
111 if (!
mesh[global_idx].boundary) {
114 graph->insertGlobalIndices(global_idx,
115 arrayView(&
mesh[global_idx].down,1));
119 graph->insertGlobalIndices(global_idx,
120 arrayView(&
mesh[global_idx].left,1));
124 graph->insertGlobalIndices(global_idx,
125 arrayView(&
mesh[global_idx].right,1));
129 graph->insertGlobalIndices(global_idx,
130 arrayView(&
mesh[global_idx].up,1));
133 graph->fillComplete();
139 b = Tpetra::createVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>(
x_map);
140 ArrayRCP<Scalar> b_view =
b->get1dViewNonConst();
141 for(
size_t i=0; i<NumMyElements; ++i) {
142 GlobalOrdinal global_idx = MyGlobalElements[i];
143 if (
mesh[global_idx].boundary)
155 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
168 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
181 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
189 get_p_map(LocalOrdinal l)
const
194 "Error! twoD_diffusion_problem::get_p_map(): " <<
195 "Invalid parameter index l = " << l << std::endl);
200 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
208 get_g_map(LocalOrdinal l)
const
213 "Error! twoD_diffusion_problem::get_g_map(): " <<
214 "Invalid parameter index l = " << l << std::endl);
219 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
224 get_p_names(LocalOrdinal l)
const
229 "Error! twoD_diffusion_problem::get_p_names(): " <<
230 "Invalid parameter index l = " << l << std::endl);
235 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
248 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
256 get_p_init(LocalOrdinal l)
const
261 "Error! twoD_diffusion_problem::get_p_init(): " <<
262 "Invalid parameter index l = " << l << std::endl);
267 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
282 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
293 computeA(*lnFunc, p, *
A);
295 computeA(*klFunc, p, *
A);
297 f.update(-1.0, *b, 1.0);
300 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
310 computeA(*lnFunc, p, jac);
312 computeA(*klFunc, p, jac);
315 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
326 x.meanValue(g_view());
327 g_view[0] *=
Scalar(x.getGlobalLength()) /
Scalar(mesh.size());
330 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
332 template <
typename FuncT>
339 using Teuchos::arrayView;
342 jac.setAllToScalar(0.0);
346 size_t NumMyElements = x_map->getLocalNumElements();
347 ArrayView<const GlobalOrdinal> MyGlobalElements =
348 x_map->getLocalElementList ();
352 for(
size_t i=0 ; i<NumMyElements; ++i ) {
355 GlobalOrdinal global_idx = MyGlobalElements[i];
356 if (mesh[global_idx].boundary) {
358 jac.replaceGlobalValues(global_idx, arrayView(&global_idx,1),
363 -func(mesh[global_idx].x, mesh[global_idx].y-h/2.0, rv)/h2;
365 -func(mesh[global_idx].x-h/2.0, mesh[global_idx].y, rv)/h2;
367 -func(mesh[global_idx].x+h/2.0, mesh[global_idx].y, rv)/h2;
369 -func(mesh[global_idx].x, mesh[global_idx].y+h/2.0, rv)/h2;
372 val = -(a_down + a_left + a_right + a_up);
373 jac.replaceGlobalValues(global_idx, arrayView(&global_idx,1),
377 if (!(eliminate_bcs && mesh[mesh[global_idx].down].boundary))
378 jac.replaceGlobalValues(global_idx,
379 arrayView(&mesh[global_idx].down,1),
380 arrayView(&a_down,1));
383 if (!(eliminate_bcs && mesh[mesh[global_idx].left].boundary))
384 jac.replaceGlobalValues(global_idx,
385 arrayView(&mesh[global_idx].left,1),
386 arrayView(&a_left,1));
389 if (!(eliminate_bcs && mesh[mesh[global_idx].right].boundary))
390 jac.replaceGlobalValues(global_idx,
391 arrayView(&mesh[global_idx].right,1),
392 arrayView(&a_right,1));
395 if (!(eliminate_bcs && mesh[mesh[global_idx].up].boundary))
396 jac.replaceGlobalValues(global_idx,
397 arrayView(&mesh[global_idx].up,1),
404 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
407 Node>::KL_Diffusion_Func::
408 KL_Diffusion_Func(MeshScalar xyLeft, MeshScalar xyRight,
409 BasisScalar mean, BasisScalar std_dev,
410 MeshScalar L, LocalOrdinal num_KL) : point(2)
413 rfParams.
set(
"Number of KL Terms", num_KL);
414 rfParams.
set(
"Mean", mean);
415 rfParams.
set(
"Standard Deviation", std_dev);
416 LocalOrdinal ndim = 2;
418 correlation_length(ndim);
419 for (LocalOrdinal i=0; i<ndim; i++) {
420 domain_upper[i] = xyRight;
421 domain_lower[i] = xyLeft;
422 correlation_length[i] = L;
424 rfParams.
set(
"Domain Upper Bounds", domain_upper);
425 rfParams.
set(
"Domain Lower Bounds", domain_lower);
426 rfParams.
set(
"Correlation Lengths", correlation_length);
432 template <
typename Scalar,
typename MeshScalar,
typename BasisScalar,
436 Node>::KL_Diffusion_Func::
441 return rf->evaluate(
point, rv);
Teuchos::RCP< Epetra_Map > x_map
Solution vector map.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< LogNormal_Diffusion_Func< KL_Diffusion_Func > > lnFunc
Teuchos::RCP< Epetra_Map > g_map
Response vector map.
Teuchos::RCP< Epetra_Map > p_map
Parameter vector map.
Teuchos::RCP< Epetra_Vector > p_init
Initial parameters.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Array< MeshPoint > mesh
Teuchos::RCP< Stokhos::KL::ExponentialRandomField< MeshScalar > > rf
Teuchos::RCP< KL_Diffusion_Func > klFunc
Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > Tpetra_CrsGraph
Teuchos::RCP< Epetra_Vector > x_init
Initial guess.
Tpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > Tpetra_Vector
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
Teuchos::Array< double > point
Array to store a point for basis evaluation.
Teuchos::RCP< Epetra_Vector > b
Deterministic RHS.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Tpetra_CrsMatrix
Teuchos::RCP< Teuchos::Array< std::string > > p_names
Parameter names.
Teuchos::RCP< Epetra_CrsGraph > graph
Jacobian graph.
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
A linear 2-D diffusion problem.