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->resumeFill();
94  mat->setAllToScalar(0.0);
95  mat->fillComplete();
96  }
97  }
98 
100  void clear()
101  {
102  set_x(Teuchos::null);
103  set_dxdt(Teuchos::null);
104  set_f(Teuchos::null);
105  set_A(Teuchos::null);
106  }
107 
108  inline void set_x(const Teuchos::RCP<VectorType> & in) { x = in; }
109  inline const Teuchos::RCP<VectorType> get_x() const { return x; }
110 
111  inline void set_dxdt(const Teuchos::RCP<VectorType> & in) { dxdt = in; }
112  inline const Teuchos::RCP<VectorType> get_dxdt() const { return dxdt; }
113 
114  inline void set_f(const Teuchos::RCP<VectorType> & in) { f = in; }
115  inline const Teuchos::RCP<VectorType> get_f() const { return f; }
116 
117  inline void set_A(const Teuchos::RCP<CrsMatrixType> & in) { A = in; }
118  inline const Teuchos::RCP<CrsMatrixType> get_A() const { return A; }
119 
120  void initializeMatrix(ScalarT value)
121  {
122  A->resumeFill();
123  A->setAllToScalar(value);
124  A->fillComplete();
125  }
126 
128  {
129  if(in==Teuchos::null) { x = Teuchos::null; return; }
130 
132  = TOE::getConstTpetraVector(in);
133  x = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(x_const);
134  }
136  { return (x==Teuchos::null) ? Teuchos::null : Thyra::createVector(x,domainSpace); }
137 
139  {
140  if(in==Teuchos::null) { dxdt = Teuchos::null; return; }
141 
143  = TOE::getConstTpetraVector(in);
144  dxdt = Teuchos::rcp_const_cast<Tpetra::Vector<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> >(dxdt_const);
145  }
147  { return (dxdt==Teuchos::null) ? Teuchos::null : Thyra::createVector(dxdt,domainSpace); }
148 
150  { f = (in==Teuchos::null) ? Teuchos::null : TOE::getTpetraVector(in); }
152  { return (f==Teuchos::null) ? Teuchos::null : Thyra::createVector(f,rangeSpace); }
153 
155  { A = (in==Teuchos::null) ? Teuchos::null : Teuchos::rcp_dynamic_cast<CrsMatrixType>(TOE::getTpetraOperator(in),true); }
157  { return (A==Teuchos::null) ? Teuchos::null : Thyra::createLinearOp<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT>(A,rangeSpace,domainSpace); }
158 
159 private:
160  typedef Thyra::TpetraOperatorVectorExtraction<ScalarT,LocalOrdinalT,GlobalOrdinalT,NodeT> TOE;
161 
164 
167 };
168 
169 }
170 
171 #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