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_MP_Vector.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_MP_VECTOR_HPP
11 #define AMESOS2_SOLVER_MP_VECTOR_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>
22  const Teuchos::RCP<const Tpetra::CrsMatrix<Sacado::MP::Vector<S>, LO, GO, NO > >& A = Teuchos::null,
23  const Teuchos::RCP<Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, NO > >& X = Teuchos::null,
24  const Teuchos::RCP<const Tpetra::MultiVector<Sacado::MP::Vector<S>, LO, GO, NO > >& B = Teuchos::null)
25  {
26  if (A != Teuchos::null) {
27  return Kokkos::dimension_scalar(A->getLocalValuesDevice(Tpetra::Access::ReadOnly));
28  }
29  else if (X != Teuchos::null) {
30  return Kokkos::dimension_scalar(X->getLocalViewDevice(Tpetra::Access::ReadOnly));
31  }
32  else if (B != Teuchos::null) {
33  return Kokkos::dimension_scalar(B->getLocalViewDevice(Tpetra::Access::ReadOnly));
34  }
35  return 0;
36  }
37 
44  template <class Storage, class LocalOrdinal, class GlobalOrdinal, class Node,
45  template<class,class> class ConcreteSolver>
47  public Solver< Tpetra::CrsMatrix<Sacado::MP::Vector<Storage>,
48  LocalOrdinal,
49  GlobalOrdinal,
50  Node>,
51  Tpetra::MultiVector<Sacado::MP::Vector<Storage>,
52  LocalOrdinal,
53  GlobalOrdinal,
54  Node>
55  >
56  {
57  public:
58 
60  typedef Tpetra::CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> Matrix;
61  typedef Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> Vector;
62 
63  typedef typename Scalar::value_type BaseScalar;
64  typedef Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> Map;
65  typedef Tpetra::CrsGraph<LocalOrdinal,GlobalOrdinal,Node> FlatGraph;
66  typedef Tpetra::CrsMatrix<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatMatrix;
67  typedef Tpetra::MultiVector<BaseScalar,LocalOrdinal,GlobalOrdinal,Node> FlatVector;
68  typedef ConcreteSolver<FlatMatrix,FlatVector> FlatConcreteSolver;
69  typedef Solver<FlatMatrix,FlatVector> FlatSolver;
70 
71  typedef Solver<Matrix,Vector> solver_type;
72  typedef typename solver_type::type type;
73 
77  const Teuchos::RCP<Vector>& X_,
78  const Teuchos::RCP<const Vector>& B_) :
79  A(A_), X(X_), B(B_) {
80  const LocalOrdinal mp_size = get_mp_vector_size(A, X, B);
81  flat_graph = Stokhos::create_flat_mp_graph(*(A->getCrsGraph()),
82  flat_X_map,
83  flat_B_map,
84  mp_size);
85  if (A != Teuchos::null)
87  if (X != Teuchos::null)
89  if (B != Teuchos::null)
91  flat_solver =
92  create_solver_with_supported_type<ConcreteSolver,FlatMatrix,FlatVector>::apply(flat_A, flat_X, flat_B);
93  }
94 
96 
97 
105  virtual type& preOrdering( void ) {
106  flat_solver->preOrdering();
107  return *this;
108  }
109 
110 
116  virtual type& symbolicFactorization( void ) {
117  flat_solver->symbolicFactorization();
118  return *this;
119  }
120 
121 
134  virtual type& numericFactorization( void ) {
135  flat_solver->numericFactorization();
136  return *this;
137  }
138 
139 
152  virtual void solve( void ) {
153  flat_solver->solve();
154  }
155 
156 
174  virtual void solve(const Teuchos::Ptr<Vector> XX,
175  const Teuchos::Ptr<const Vector> BB) const {
176  flat_solver->solve(
179  }
180 
181 
199  virtual void solve(Vector* XX, const Vector* BB) const {
200  flat_solver->solve(
203  }
204 
206 
207 
224  virtual type& setParameters(
225  const Teuchos::RCP<Teuchos::ParameterList> & parameterList ) {
226  flat_solver->setParameters(parameterList);
227  return *this;
228  }
229 
230 
236  getValidParameters( void ) const {
237  return flat_solver->getValidParameters();
238  }
239 
241 
242 
266  virtual void setA( const Teuchos::RCP<const Matrix> a,
267  EPhase keep_phase = CLEAN ) {
268  A = a;
269 
270  // Rebuild flat matrix/graph
271  const LocalOrdinal mp_size = get_mp_vector_size(A);
272  if (keep_phase <= CLEAN) {
276  flat_graph = Stokhos::create_flat_mp_graph(*(A->getCrsGraph()),
277  flat_X_map,
278  flat_B_map,
279  mp_size);
280  }
281  if (keep_phase <= SYMBFACT) // should this by NUMFACT???
283 
284  flat_solver->setA(flat_A, keep_phase);
285  }
286 
306  virtual void setA( const Matrix* a, EPhase keep_phase = CLEAN ) {
307  this->setA(Teuchos::rcp(a,false), keep_phase);
308  }
309 
310 
312  virtual bool matrixShapeOK( void ) {
313  return flat_solver->matrixShapeOK();
314  }
315 
316 
318  virtual void setX( const Teuchos::RCP<Vector> x ) {
319  X = x;
320  if (x != Teuchos::null)
322  else
324  flat_solver->setX(flat_X);
325  }
326 
327 
329  virtual void setX( Vector* x ) {
330  if (x != 0) {
331  X = Teuchos::rcp(x, false);
333  }
334  else {
335  X = Teuchos::null;
337  }
338  flat_solver->setX(flat_X);
339  }
340 
341 
343  virtual const Teuchos::RCP<Vector> getX( void ) {
344  return X;
345  }
346 
347 
349  virtual Vector* getXRaw( void ) {
350  return X.get();
351  }
352 
353 
355  virtual void setB( const Teuchos::RCP<const Vector> b ) {
356  B = b;
357  if (b != Teuchos::null)
359  else
361  flat_solver->setB(flat_B);
362  }
363 
364 
366  virtual void setB( const Vector* b ) {
367  if (b != 0) {
368  B = Teuchos::rcp(b, false);
370  }
371  else {
372  B = Teuchos::null;
374  }
375  flat_solver->setB(flat_B);
376  }
377 
378 
380  virtual const Teuchos::RCP<const Vector> getB( void ) {
381  return B;
382  }
383 
384 
386  virtual const Vector* getBRaw( void ) {
387  return B.get();
388  }
389 
390 
393  return flat_solver->getComm();
394  }
395 
396 
398  virtual Status& getStatus() const {
399  return flat_solver->getStatus();
400  }
401 
402 
404  virtual std::string name( void ) const {
405  return flat_solver->name();
406  }
407 
409 
410 
415  virtual std::string description( void ) const {
417  return flat_solver->description();
418  }
419 
420 
423  virtual void describe( Teuchos::FancyOStream &out,
425  flat_solver->describe(out, verbLevel);
426  }
427 
429 
430 
435  virtual void printTiming( Teuchos::FancyOStream &out,
438  flat_solver->printTiming(out, verbLevel);
439  }
440 
441 
450  virtual void getTiming( Teuchos::ParameterList& timingParameterList ) const{
451  flat_solver->getTiming(timingParameterList);
452  }
453 
455 
456  protected:
457 
467 
468  };
469 
470  template < template <class,class> class ConcreteSolver,
471  class ST, class LO, class GO, class NO >
474  typedef Tpetra::CrsMatrix<SC,LO,GO,NO> Matrix;
475  typedef Tpetra::MultiVector<SC,LO,GO,NO> Vector;
480  ctassert<
481  std::is_same_v<
482  typename MatrixTraits<Matrix>::scalar_t,
483  typename MultiVecAdapter<Vector>::scalar_t
484  >
485  > same_scalar_assertion;
486  (void)same_scalar_assertion; // This stops the compiler from warning about unused declared variables
487 
488  // If our assertion did not fail, then create and return a new solver
490  }
491  };
492 
493  // Specialization of create_solver_with_supported_type for
494  // Sacado::MP::Vector where we create MPVectorSolverAdapter wrapping
495  // each solver
496  template < template <class,class> class ConcreteSolver,
497  class ST, class LO, class GO, class NO >
498  struct create_solver_with_supported_type<
499  ConcreteSolver,
500  Tpetra::CrsMatrix<Sacado::MP::Vector<ST>,LO,GO,NO>,
501  Tpetra::MultiVector<Sacado::MP::Vector<ST>,LO,GO,NO> > :
502  public create_mp_vector_solver_impl<ConcreteSolver, ST, LO, GO, NO> {};
503 
504  // Specialization for solver_supports_scalar for Sacado::MP::Vector<Storage>
505  // value == true if and only if
506  // solver_supprts_scalar<ConcreteSolver,Storage::value_type> == true
507  template <template <class,class> class ConcreteSolver,
508  typename Storage>
509  struct solver_supports_scalar<ConcreteSolver, Sacado::MP::Vector<Storage> > {
511  typedef typename Scalar::value_type BaseScalar;
512  typedef typename solver_traits<ConcreteSolver>::supported_scalars supported_scalars;
513  static const bool value =
514  std::conditional_t<std::is_same_v<supported_scalars, Meta::nil_t>,
515  std::true_type,
516  Meta::type_list_contains<supported_scalars,
517  BaseScalar> >::value;
518  };
519 
520 } // namespace Amesos2
521 
522 #endif // AMESOS2_SOLVER_MP_VECTOR_HPP
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 void setX(Vector *x)
Sets the LHS vector X using a raw pointer.
Stokhos::StandardStorage< int, double > Storage
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
virtual std::string description(void) const
Returns a short description of this Solver.
virtual std::string name(void) const
Return the name of this solver.
virtual void setA(const Teuchos::RCP< const Matrix > a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
virtual void solve(void)
Solves (or )
virtual type & preOrdering(void)
Pre-orders the matrix.
virtual const Teuchos::RCP< Vector > getX(void)
Returns the vector that is the LHS of the linear system.
virtual const Vector * getBRaw(void)
Returns a raw pointer to the RHS of the linear system.
virtual void setB(const Vector *b)
Sets the RHS vector B using a raw pointer.
Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > FlatGraph
Solver< FlatMatrix, FlatVector > FlatSolver
virtual void solve(Vector *XX, const Vector *BB) const
Solve using the given XX and BB (multi)vectors.
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)
Teuchos::RCP< const FlatGraph > flat_graph
T * get() const
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< View< T, P...> >::value, unsigned >::type dimension_scalar(const View< T, P...> &view)
Teuchos::RCP< FlatSolver > flat_solver
virtual type & symbolicFactorization(void)
Performs symbolic factorization on the matrix.
virtual Status & getStatus() const
Returns a reference to this solver&#39;s internal status object.
virtual void getTiming(Teuchos::ParameterList &timingParameterList) const
Extracts timing information from the current solver.
static Teuchos::RCP< Solver< Matrix, Vector > > apply(Teuchos::RCP< const Matrix > A, Teuchos::RCP< Vector > X, Teuchos::RCP< const Vector > B)
Teuchos::RCP< const FlatMatrix > flat_A
Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ConcreteSolver< FlatMatrix, FlatVector > FlatConcreteSolver
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 setX(const Teuchos::RCP< Vector > x)
Sets the LHS vector X.
Teuchos::RCP< Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > create_flat_mp_graph(const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > &graph, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_domain_map, Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &flat_range_map, const LocalOrdinal block_size)
virtual void printTiming(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Prints timing information about the current solver.
Tpetra::MultiVector< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatVector
virtual void setA(const Matrix *a, EPhase keep_phase=CLEAN)
Sets the matrix A of this solver.
virtual bool matrixShapeOK(void)
Returns true if the solver can handle the matrix shape.
static const EVerbosityLevel verbLevel_default
virtual void setB(const Teuchos::RCP< const Vector > b)
Sets the RHS vector B.
LO get_mp_vector_size(const Teuchos::RCP< const Tpetra::CrsMatrix< Sacado::MP::Vector< S >, LO, GO, NO > > &A=Teuchos::null, const Teuchos::RCP< Tpetra::MultiVector< Sacado::MP::Vector< S >, LO, GO, NO > > &X=Teuchos::null, const Teuchos::RCP< const Tpetra::MultiVector< Sacado::MP::Vector< S >, LO, GO, NO > > &B=Teuchos::null)
Tpetra::MultiVector< SC, LO, GO, NO > Vector
MPVectorSolverAdapter(const Teuchos::RCP< const Matrix > &A_, const Teuchos::RCP< Vector > &X_, const Teuchos::RCP< const Vector > &B_)
Constructor.
virtual void solve(const Teuchos::Ptr< Vector > XX, const Teuchos::Ptr< const Vector > BB) const
Solve using the given XX and BB (multi)vectors.
Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > Vector
Tpetra::CrsMatrix< SC, LO, GO, NO > Matrix
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node
Amesos2 solver adapter for MP::Vector scalar type.
virtual type & setParameters(const Teuchos::RCP< Teuchos::ParameterList > &parameterList)
Set/update internal variables and solver options.
Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > Map
Teuchos::RCP< const FlatVector > flat_B
virtual type & numericFactorization(void)
Performs numeric factorization on the matrix.
virtual Teuchos::RCP< const Teuchos::Comm< int > > getComm(void) const
Returns a pointer to the Teuchos::Comm communicator with this matrix.
Tpetra::CrsMatrix< BaseScalar, LocalOrdinal, GlobalOrdinal, Node > FlatMatrix
virtual Vector * getXRaw(void)
Returns a raw pointer to the LHS of the linear system.
virtual const Teuchos::RCP< const Vector > getB(void)
Returns the vector that is the RHS of the linear system.
Sacado::MP::Vector< Storage > Scalar