Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Amesos2_Solver_UQ_PCE.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef AMESOS2_SOLVER_UQ_PCE_HPP
11 #define AMESOS2_SOLVER_UQ_PCE_HPP
12 
13 #include "Amesos2_Solver.hpp"
14 #include "Amesos2_Factory.hpp"
17 
18 namespace Amesos2 {
19 
20  template <class S, class LO, class GO, class NO>
23  const Teuchos::RCP<const Tpetra::CrsMatrix<Sacado::UQ::PCE<S>, LO, GO, NO > >& A = Teuchos::null,
24  const Teuchos::RCP<Tpetra::MultiVector<Sacado::UQ::PCE<S>, LO, GO, NO > >& X = Teuchos::null,
25  const Teuchos::RCP<const Tpetra::MultiVector<Sacado::UQ::PCE<S>, LO, GO, NO > >& B = Teuchos::null)
26  {
27  if (A != Teuchos::null) {
28  return Kokkos::cijk(A->getLocalValuesDevice(Tpetra::Access::ReadOnly));
29  }
30  else if (X != Teuchos::null) {
31  return Kokkos::cijk(X->getLocalViewDevice(Tpetra::Access::ReadOnly));
32  }
33  else if (B != Teuchos::null) {
34  return Kokkos::cijk(B->getLocalViewDevice(Tpetra::Access::ReadOnly));
35  }
36  return typename Sacado::UQ::PCE<S>::cijk_type();
37  }
38 
45  template <class Storage, class LocalOrdinal, class GlobalOrdinal,
46  class Node, template<class,class> class ConcreteSolver>
48  public Solver< Tpetra::CrsMatrix<Sacado::UQ::PCE<Storage>,
49  LocalOrdinal,
50  GlobalOrdinal,
51  Node >,
52  Tpetra::MultiVector<Sacado::UQ::PCE<Storage>,
53  LocalOrdinal,
54  GlobalOrdinal,
55  Node >
56  >
57  {
58  public:
59 
61  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix;
62  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Vector;
63 
64  typedef typename Scalar::value_type BaseScalar;
65  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Map;
66  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> FlatGraph;
67  typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatMatrix;
68  typedef Tpetra::MultiVector<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatVector;
69  typedef ConcreteSolver<FlatMatrix,FlatVector> FlatConcreteSolver;
70  typedef Solver<FlatMatrix,FlatVector> FlatSolver;
71 
72  typedef Solver<Matrix,Vector> solver_type;
73  typedef typename solver_type::type type;
74  typedef typename Scalar::cijk_type cijk_type;
75 
79  const Teuchos::RCP<Vector>& X_,
80  const Teuchos::RCP<const Vector>& B_) :
81  A(A_), X(X_), B(B_) {
82  cijk = get_pce_cijk(A, X, B);
83  const size_t pce_size =
84  Kokkos::dimension_scalar(A->getLocalMatrixDevice().values);
85  flat_graph =
86  Stokhos::create_flat_pce_graph(*(A->getCrsGraph()),
87  cijk,
88  flat_X_map,
89  flat_B_map,
90  cijk_graph,
91  pce_size);
92  if (A != Teuchos::null)
94  if (X != Teuchos::null)
96  if (B != Teuchos::null)
98  flat_solver =
99  create_solver_with_supported_type<ConcreteSolver,FlatMatrix,FlatVector>::apply(flat_A, flat_X, flat_B);
100  }
101 
103 
104 
112  virtual type& preOrdering( void ) {
113  flat_solver->preOrdering();
114  return *this;
115  }
116 
117 
123  virtual type& symbolicFactorization( void ) {
124  flat_solver->symbolicFactorization();
125  return *this;
126  }
127 
128 
141  virtual type& numericFactorization( void ) {
142  flat_solver->numericFactorization();
143  return *this;
144  }
145 
146 
159  virtual void solve( void ) {
160  flat_solver->solve();
161  }
162 
163 
178  virtual void solve(const Teuchos::Ptr<Vector> XX,
179  const Teuchos::Ptr<const Vector> BB) const {
180  flat_solver->solve(
183  }
184 
185 
200  virtual void solve(Vector* XX, const Vector* BB) const {
201  flat_solver->solve(
204  }
205 
207 
208 
225  virtual type& setParameters(
226  const Teuchos::RCP<Teuchos::ParameterList> & parameterList ) {
227  flat_solver->setParameters(parameterList);
228  return *this;
229  }
230 
231 
237  getValidParameters( void ) const {
238  return flat_solver->getValidParameters();
239  }
240 
242 
243 
267  virtual void setA( const Teuchos::RCP<const Matrix> a,
268  EPhase keep_phase = CLEAN ) {
269  A = a;
270 
271  // Rebuild flat matrix/graph
272  cijk = get_pce_cijk(A);
273  if (keep_phase <= CLEAN) {
277  flat_graph =
278  Stokhos::create_flat_pce_graph(*(A->getCrsGraph()),
279  cijk,
280  flat_X_map,
281  flat_B_map,
282  cijk_graph,
283  Kokkos::dimension_scalar(A->getLocalMatrixDevice().values));
284  }
285  if (keep_phase <= SYMBFACT) // should this by NUMFACT???
287 
288  flat_solver->setA(flat_A, keep_phase);
289  }
290 
310  virtual void setA( const Matrix* a, EPhase keep_phase = CLEAN ) {
311  this->setA(Teuchos::rcp(a,false), keep_phase);
312  }
313 
314 
316  virtual bool matrixShapeOK( void ) {
317  return flat_solver->matrixShapeOK();
318  }
319 
320 
322  virtual void setX( const Teuchos::RCP<Vector> x ) {
323  X = x;
324  if (x != Teuchos::null)
326  else
328  flat_solver->setX(flat_X);
329  }
330 
331 
333  virtual void setX( Vector* x ) {
334  if (x != 0) {
335  X = Teuchos::rcp(x, false);
337  }
338  else {
339  X = Teuchos::null;
341  }
342  flat_solver->setX(flat_X);
343  }
344 
345 
347  virtual const Teuchos::RCP<Vector> getX( void ) {
348  return X;
349  }
350 
351 
353  virtual Vector* getXRaw( void ) {
354  return X.get();
355  }
356 
357 
359  virtual void setB( const Teuchos::RCP<const Vector> b ) {
360  B = b;
361  if (b != Teuchos::null)
363  else
365  flat_solver->setB(flat_B);
366  }
367 
368 
370  virtual void setB( const Vector* b ) {
371  if (b != 0) {
372  B = Teuchos::rcp(b, false);
374  }
375  else {
376  B = Teuchos::null;
378  }
379  flat_solver->setB(flat_B);
380  }
381 
382 
384  virtual const Teuchos::RCP<const Vector> getB( void ) {
385  return B;
386  }
387 
388 
390  virtual const Vector* getBRaw( void ) {
391  return B.get();
392  }
393 
394 
397  return flat_solver->getComm();
398  }
399 
400 
402  virtual Status& getStatus() const {
403  return flat_solver->getStatus();
404  }
405 
406 
408  virtual std::string name( void ) const {
409  return flat_solver->name();
410  }
411 
413 
414 
419  virtual std::string description( void ) const {
421  return flat_solver->description();
422  }
423 
424 
427  virtual void describe( Teuchos::FancyOStream &out,
429  flat_solver->describe(out, verbLevel);
430  }
431 
433 
434 
439  virtual void printTiming( Teuchos::FancyOStream &out,
442  flat_solver->printTiming(out, verbLevel);
443  }
444 
445 
454  virtual void getTiming( Teuchos::ParameterList& timingParameterList ) const{
455  flat_solver->getTiming(timingParameterList);
456  }
457 
459 
460  protected:
461 
472 
473  };
474 
475  // Specialization of create_solver_with_supported_type for
476  // Sacado::UQ::PCE where we create PCESolverAdapter wrapping
477  // each solver
478  template < template <class,class> class ConcreteSolver,
479  class ST, class LO, class GO, class NO >
480  struct create_solver_with_supported_type<
481  ConcreteSolver,
482  Tpetra::CrsMatrix<Sacado::UQ::PCE<ST>,LO,GO,NO >,
483  Tpetra::MultiVector<Sacado::UQ::PCE<ST>,LO,GO,NO > > {
485  typedef Tpetra::CrsMatrix<SC,LO,GO,NO> Matrix;
486  typedef Tpetra::MultiVector<SC,LO,GO,NO> Vector;
491  {
492  ctassert<
493  std::is_same_v<
494  typename MatrixTraits<Matrix>::scalar_t,
495  typename MultiVecAdapter<Vector>::scalar_t
496  >
497  > same_scalar_assertion;
498  (void)same_scalar_assertion; // This stops the compiler from warning about unused declared variables
499 
500  // If our assertion did not fail, then create and return a new solver
502  }
503  };
504 
505  // Specialization for solver_supports_scalar for Sacado::UQ::PCE<Storage>
506  // value == true if and only if
507  // solver_supprts_scalar<ConcreteSolver,Storage::value_type> == true
508  template <template <class,class> class ConcreteSolver,
509  typename Storage>
510  struct solver_supports_scalar<ConcreteSolver, Sacado::UQ::PCE<Storage> > {
512  typedef typename Scalar::value_type BaseScalar;
513  typedef typename solver_traits<ConcreteSolver>::supported_scalars supported_scalars;
514  static const bool value =
515  std::conditional_t<std::is_same_v<supported_scalars, Meta::nil_t>,
516  std::true_type,
517  Meta::type_list_contains<supported_scalars,
518  BaseScalar> >::value;
519  };
520 
521 
522 } // namespace Amesos2
523 
524 #endif // AMESOS2_SOLVER_UQ_PCE_HPP
virtual void setX(const Teuchos::RCP< Vector > x)
Sets the LHS vector X.
Teuchos::RCP< Tpetra::CrsMatrix< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_matrix(const Tpetra::CrsMatrix< Sacado::UQ::PCE< Storage >, LocalOrdinal, GlobalOrdinal, Node > &mat, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &flat_graph, const Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &cijk_graph, const CijkType &cijk_dev)
virtual Vector * getXRaw(void)
Returns a raw pointer to the LHS of the linear system.
virtual Status & getStatus() const
Returns a reference to this solver&#39;s internal status object.
Stokhos::StandardStorage< int, double > Storage
virtual type & numericFactorization(void)
Performs numeric factorization on the matrix.
virtual const Vector * getBRaw(void)
Returns a raw pointer to the RHS of the linear system.
virtual std::string description(void) const
Returns a short description of this Solver.
Sacado::UQ::PCE< Storage > Scalar
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > Map
Teuchos::RCP< const Matrix > A
Solver< FlatMatrix, FlatVector > FlatSolver
virtual const Teuchos::RCP< Vector > getX(void)
Returns the vector that is the LHS of the linear system.
Teuchos::RCP< const Tpetra::MultiVector< typename Storage::value_type, LocalOrdinal, GlobalOrdinal, Node > > create_flat_vector_view(const Tpetra::MultiVector< Sacado::UQ::PCE< Storage >, LocalOrdinal, GlobalOrdinal, Node > &vec, const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_map)
virtual void setA(const Teuchos::RCP< const Matrix > a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
T * get() const
Teuchos::RCP< const Vector > B
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters(void) const
Return a const parameter list of all of the valid parameters that this-&gt;setParameterList(...) will accept.
virtual void printTiming(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Prints timing information about the current solver.
virtual void setA(const Matrix *a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
virtual void solve(const Teuchos::Ptr< Vector > XX, const Teuchos::Ptr< const Vector > BB) const
Solve using the given X and B vectors.
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > Vector
Amesos2 solver adapter for UQ::PCE scalar type.
virtual std::string name(void) const
Return the name of this solver.
virtual void setB(const Teuchos::RCP< const Vector > b)
Sets the RHS vector B.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
static Teuchos::RCP< Solver< Matrix, Vector > > apply(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
virtual void setX(Vector *x)
Sets the LHS vector X using a raw pointer.
virtual void solve(Vector *XX, const Vector *BB) const
Solve using the given X and B vectors.
Teuchos::RCP< const FlatGraph > flat_graph
ConcreteSolver< FlatMatrix, FlatVector > FlatConcreteSolver
Teuchos::RCP< FlatVector > flat_X
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm(void) const
Returns a pointer to the Teuchos::Comm communicator with this matrix.
Teuchos::RCP< const Map > flat_B_map
virtual bool matrixShapeOK(void)
Returns true if the solver can handle the matrix shape.
Tpetra::MultiVector< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatVector
static const EVerbosityLevel verbLevel_default
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Teuchos::RCP< const FlatMatrix > flat_A
Solver< Matrix, Vector > solver_type
virtual type & preOrdering(void)
Pre-orders the matrix.
virtual type & symbolicFactorization(void)
Performs symbolic factorization on the matrix.
Teuchos::RCP< const Map > flat_X_map
virtual void getTiming(Teuchos::ParameterList &timingParameterList) const
Extracts timing information from the current solver.
virtual const Teuchos::RCP< const Vector > getB(void)
Returns the vector that is the RHS of the linear system.
Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > FlatGraph
Teuchos::RCP< FlatSolver > flat_solver
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node
Teuchos::RCP< const FlatGraph > cijk_graph
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_pce_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, const CijkType &cijk, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, Teuchos::RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &cijk_graph, const size_t matrix_pce_size)
Teuchos::RCP< const FlatVector > flat_B
PCESolverAdapter(const Teuchos::RCP< const Matrix > &A_, const Teuchos::RCP< Vector > &X_, const Teuchos::RCP< const Vector > &B_)
Constructor.
Tpetra::CrsMatrix< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatMatrix
virtual void setB(const Vector *b)
Sets the RHS vector B using a raw pointer.
virtual type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Set/update internal variables and solver options.
Sacado::UQ::PCE< S >::cijk_type get_pce_cijk(const Teuchos::RCP< const Tpetra::CrsMatrix< Sacado::UQ::PCE< S >, LO, GO, NO > > &A=Teuchos::null, const Teuchos::RCP< Tpetra::MultiVector< Sacado::UQ::PCE< S >, LO, GO, NO > > &X=Teuchos::null, const Teuchos::RCP< const Tpetra::MultiVector< Sacado::UQ::PCE< S >, LO, GO, NO > > &B=Teuchos::null)
virtual void solve(void)
Solves (or )