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 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef __Panzer_TpetraLinearObjContainer_hpp__
44 #define __Panzer_TpetraLinearObjContainer_hpp__
45 
46 #include "PanzerDiscFE_config.hpp"
47 
48 #include <map>
49 
50 // Tpetra includes
51 #include "Tpetra_Vector.hpp"
52 #include "Tpetra_CrsMatrix.hpp"
53 
54 #include "Thyra_TpetraThyraWrappers.hpp"
55 
58 #include "Panzer_NodeType.hpp"
59 
60 #include "Teuchos_RCP.hpp"
61 
62 namespace panzer {
63 
64 template <typename ScalarT,typename LocalOrdinalT,typename GlobalOrdinalT,typename NodeT=panzer::TpetraNodeType>
66  , public ThyraObjContainer<ScalarT> {
68 
69 public:
71 
72  typedef Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> VectorType;
73  typedef Tpetra::CrsMatrix<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> CrsMatrixType;
74  typedef Tpetra::CrsGraph<LocalOrdinalT,GlobalOrdinalT,NodeT> CrsGraphType;
75  typedef Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> MapType;
76  typedef Tpetra::Import<LocalOrdinalT,GlobalOrdinalT,NodeT> ImportType;
77  typedef Tpetra::Export<LocalOrdinalT,GlobalOrdinalT,NodeT> ExportType;
78 
79  TpetraLinearObjContainer(const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> > & domain,
80  const Teuchos::RCP<const Tpetra::Map<LocalOrdinalT,GlobalOrdinalT,NodeT> > & range)
81  {
82  domainSpace = Thyra::createVectorSpace<ScalarT>(domain);
83  rangeSpace = Thyra::createVectorSpace<ScalarT>(range);
84  }
85 
86  virtual void initialize()
87  {
88  if(get_x()!=Teuchos::null) get_x()->putScalar(0.0);
89  if(get_dxdt()!=Teuchos::null) get_dxdt()->putScalar(0.0);
90  if(get_f()!=Teuchos::null) get_f()->putScalar(0.0);
91  if(get_A()!=Teuchos::null) {
93  mat->setAllToScalar(0.0);
94  }
95  }
96 
98  void clear()
99  {
100  set_x(Teuchos::null);
101  set_dxdt(Teuchos::null);
102  set_f(Teuchos::null);
103  set_A(Teuchos::null);
104  }
105 
106  inline void set_x(const Teuchos::RCP<VectorType> & in) { x = in; }
107  inline const Teuchos::RCP<VectorType> get_x() const { return x; }
108 
109  inline void set_dxdt(const Teuchos::RCP<VectorType> & in) { dxdt = in; }
110  inline const Teuchos::RCP<VectorType> get_dxdt() const { return dxdt; }
111 
112  inline void set_f(const Teuchos::RCP<VectorType> & in) { f = in; }
113  inline const Teuchos::RCP<VectorType> get_f() const { return f; }
114 
115  inline void set_A(const Teuchos::RCP<CrsMatrixType> & in) { A = in; }
116  inline const Teuchos::RCP<CrsMatrixType> get_A() const { return A; }
117 
118  void initializeMatrix(ScalarT value)
119  {
120  A->setAllToScalar(value);
121  }
122 
124  {
125  if(in==Teuchos::null) { x = Teuchos::null; return; }
126 
128  = TOE::getConstTpetraVector(in);
129  x = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(x_const);
130  }
132  { return (x==Teuchos::null) ? Teuchos::null : Thyra::createVector(x,domainSpace); }
133 
135  {
136  if(in==Teuchos::null) { dxdt = Teuchos::null; return; }
137 
139  = TOE::getConstTpetraVector(in);
140  dxdt = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(dxdt_const);
141  }
143  { return (dxdt==Teuchos::null) ? Teuchos::null : Thyra::createVector(dxdt,domainSpace); }
144 
146  { f = (in==Teuchos::null) ? Teuchos::null : TOE::getTpetraVector(in); }
148  { return (f==Teuchos::null) ? Teuchos::null : Thyra::createVector(f,rangeSpace); }
149 
151  { A = (in==Teuchos::null) ? Teuchos::null : Teuchos::rcp_dynamic_cast<CrsMatrixType>(TOE::getTpetraOperator(in),true); }
153  { return (A==Teuchos::null) ? Teuchos::null : Thyra::createLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(A,rangeSpace,domainSpace); }
154 
155 private:
156  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
157 
160 
163 };
164 
165 }
166 
167 #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