Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_TpetraLinearObjContainer.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef __Panzer_TpetraLinearObjContainer_hpp__
12 #define __Panzer_TpetraLinearObjContainer_hpp__
13 
14 #include "PanzerDiscFE_config.hpp"
15 
16 #include <map>
17 
18 // Tpetra includes
19 #include "Tpetra_Vector.hpp"
20 #include "Tpetra_CrsMatrix.hpp"
21 
22 #include "Thyra_TpetraThyraWrappers.hpp"
23 
26 #include "Panzer_NodeType.hpp"
27 
28 #include "Teuchos_RCP.hpp"
29 
30 namespace panzer {
31 
32 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT=panzer::TpetraNodeType>
34  , public ThyraObjContainer<ScalarT> {
36 
37 public:
39 
40  typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType;
41  typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType;
42  typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType;
43  typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType;
44  typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType;
45  typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType;
46 
47  TpetraLinearObjContainer(const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> > & domain,
48  const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> > & range)
49  {
50  domainSpace = Thyra::createVectorSpace<ScalarT>(domain);
51  rangeSpace = Thyra::createVectorSpace<ScalarT>(range);
52  }
53 
54  virtual void initialize()
55  {
56  if(get_x()!=Teuchos::null) get_x()->putScalar(0.0);
57  if(get_dxdt()!=Teuchos::null) get_dxdt()->putScalar(0.0);
58  if(get_f()!=Teuchos::null) get_f()->putScalar(0.0);
59  if(get_A()!=Teuchos::null) {
61  mat->setAllToScalar(0.0);
62  }
63  }
64 
66  void clear()
67  {
68  set_x(Teuchos::null);
69  set_dxdt(Teuchos::null);
70  set_f(Teuchos::null);
71  set_A(Teuchos::null);
72  }
73 
74  inline void set_x(const Teuchos::RCP<VectorType> & in) { x = in; }
75  inline const Teuchos::RCP<VectorType> get_x() const { return x; }
76 
77  inline void set_dxdt(const Teuchos::RCP<VectorType> & in) { dxdt = in; }
78  inline const Teuchos::RCP<VectorType> get_dxdt() const { return dxdt; }
79 
80  inline void set_f(const Teuchos::RCP<VectorType> & in) { f = in; }
81  inline const Teuchos::RCP<VectorType> get_f() const { return f; }
82 
83  inline void set_A(const Teuchos::RCP<CrsMatrixType> & in) { A = in; }
84  inline const Teuchos::RCP<CrsMatrixType> get_A() const { return A; }
85 
86  void initializeMatrix(ScalarT value)
87  {
88  A->setAllToScalar(value);
89  }
90 
91  virtual void set_x_th(const Teuchos::RCP<Thyra::VectorBase<ScalarT> > & in)
92  {
93  if(in==Teuchos::null) { x = Teuchos::null; return; }
94 
96  = TOE::getConstTpetraVector(in);
97  x = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(x_const);
98  }
100  { return (x==Teuchos::null) ? Teuchos::null : Thyra::createVector(x,domainSpace); }
101 
103  {
104  if(in==Teuchos::null) { dxdt = Teuchos::null; return; }
105 
107  = TOE::getConstTpetraVector(in);
108  dxdt = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(dxdt_const);
109  }
111  { return (dxdt==Teuchos::null) ? Teuchos::null : Thyra::createVector(dxdt,domainSpace); }
112 
114  { f = (in==Teuchos::null) ? Teuchos::null : TOE::getTpetraVector(in); }
116  { return (f==Teuchos::null) ? Teuchos::null : Thyra::createVector(f,rangeSpace); }
117 
119  { A = (in==Teuchos::null) ? Teuchos::null : Teuchos::rcp_dynamic_cast<CrsMatrixType>(TOE::getTpetraOperator(in),true); }
121  { return (A==Teuchos::null) ? Teuchos::null : Thyra::createLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(A,rangeSpace,domainSpace); }
122 
123 private:
124  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
125 
128 
131 };
132 
133 }
134 
135 #endif
TpetraLinearObjContainer(const Teuchos::RCP< const Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > &domain, const Teuchos::RCP< const Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > > &range)
const Teuchos::RCP< CrsMatrixType > get_A() const
const Teuchos::RCP< VectorType > get_x() const
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > f
Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > VectorType
Teuchos::RCP< Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > A
Tpetra::Map< LocalOrdinalT, GlobalOrdinalT, NodeT > MapType
virtual void set_A_th(const Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > &in)
const Teuchos::RCP< VectorType > get_dxdt() const
virtual Teuchos::RCP< Thyra::VectorBase< ScalarT > > get_x_th() const
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > domainSpace
Tpetra::Export< LocalOrdinalT, GlobalOrdinalT, NodeT > ExportType
Tpetra::CrsMatrix< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > CrsMatrixType
virtual Teuchos::RCP< Thyra::VectorBase< ScalarT > > get_dxdt_th() const
void set_x(const Teuchos::RCP< VectorType > &in)
virtual void set_dxdt_th(const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &in)
Tpetra::CrsGraph< LocalOrdinalT, GlobalOrdinalT, NodeT > CrsGraphType
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > x
Tpetra::Import< LocalOrdinalT, GlobalOrdinalT, NodeT > ImportType
void set_dxdt(const Teuchos::RCP< VectorType > &in)
Teuchos::RCP< Tpetra::Vector< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > > dxdt
virtual void set_f_th(const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &in)
virtual Teuchos::RCP< Thyra::LinearOpBase< ScalarT > > get_A_th() const
void set_A(const Teuchos::RCP< CrsMatrixType > &in)
Teuchos::RCP< const Thyra::VectorSpaceBase< ScalarT > > rangeSpace
void set_f(const Teuchos::RCP< VectorType > &in)
Thyra::TpetraOperatorVectorExtraction< ScalarT, LocalOrdinalT, GlobalOrdinalT, NodeT > TOE
virtual void set_x_th(const Teuchos::RCP< Thyra::VectorBase< ScalarT > > &in)
const Teuchos::RCP< VectorType > get_f() const
void initializeMatrix(ScalarT value)
Put a particular scalar in the matrix.
virtual Teuchos::RCP< Thyra::VectorBase< ScalarT > > get_f_th() const