Xyce  6.1
N_NLS_MatrixFreeEpetraOperator.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // Copyright Notice
3 //
4 // Copyright 2002 Sandia Corporation. Under the terms
5 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
6 // Government retains certain rights in this software.
7 //
8 // Xyce(TM) Parallel Electrical Simulator
9 // Copyright (C) 2002-2015 Sandia Corporation
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 //-----------------------------------------------------------------------------
24 
25 //-------------------------------------------------------------------------
26 // Filename : $RCSfile: N_NLS_MatrixFreeEpetraOperator.h,v $
27 //
28 // Purpose : This is an HB specific class that derives off of
29 // Epetra_Operator and supports the matrix-free load method that we need for
30 // HB. It takes a pointer to the NonLinearSolver so that it can correctly do
31 // the apply function, which calls applyJacobian.
32 //
33 // Creator : Todd Coffey, 1414
34 //
35 // Creation Date : 09/04/08
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.13 $
41 //
42 // Revision Date : $Date: 2015/04/08 19:18:29 $
43 //
44 // Current Owner : $Author: tvrusso $
45 //-------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_NLS_MatrixFreeEpetraOperator_h
48 #define Xyce_N_NLS_MatrixFreeEpetraOperator_h
49 
50 // ---------- Standard Includes ----------
51 #include <Teuchos_RCP.hpp>
52 
53 // ---------- Trilinos Includes ----------
54 
55 #include <Epetra_Operator.h>
56 #include <Epetra_MultiVector.h>
57 #include <Epetra_Comm.h>
58 #include <Epetra_Map.h>
59 
60 // ---------- Xyce Includes ----------
61 
62 #include <N_LAS_MultiVector.h>
63 
64 // ---------- Using Declarations ------------
65 using Teuchos::RCP;
66 using Teuchos::rcp;
67 
68 namespace Xyce {
69 namespace Nonlinear {
70 
71 //-----------------------------------------------------------------------------
72 // Class : MatrixFreeEpetraOperator
73 // Purpose : Matrix Free Epetra Operator concrete class
74 // Special Notes :
75 // Creator : Todd Coffey, 1414
76 // Creation Date : 9/4/08
77 //-----------------------------------------------------------------------------
78 
79 class MatrixFreeEpetraOperator : virtual public Epetra_Operator
80 {
81 
82 public:
83 
85 
86  virtual ~MatrixFreeEpetraOperator();
87 
88  void initialize(
89  RCP<NonLinearSolver> nonlinearSolver,
90  RCP<Linear::Vector> solVector,
91  RCP<Linear::Vector> rhsVector,
92  RCP<const Epetra_Map> solutionMap
93  );
94 
95  //! If set true, transpose of this operator will be applied.
96  /*! This flag allows the transpose of the given operator to be used implicitly. Setting this flag
97  affects only the Apply() and ApplyInverse() methods. If the implementation of this interface
98  does not support transpose use, this method should return a value of -1.
99 
100  \param[in]
101  UseTranspose -If true, multiply by the transpose of operator, otherwise just use operator.
102 
103  \return Integer error code, set to 0 if successful. Set to -1 if this implementation does not support transpose.
104  */
105  int SetUseTranspose(bool UseTranspose);
106 
107  //! Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
108  /*
109  \param[in]
110  X - A Epetra_MultiVector of dimension NumVectors to multiply with matrix.
111  \param[out]
112  Y -A Epetra_MultiVector of dimension NumVectors containing result.
113 
114  \return Integer error code, set to 0 if successful.
115  */
116  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
117  int Apply(const Linear::MultiVector& X, Linear::MultiVector& Y) const;
118 
119  //! Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y.
120  /*
121  \param[in]
122  X - A Epetra_MultiVector of dimension NumVectors to solve for.
123  \param[out]
124  Y -A Epetra_MultiVector of dimension NumVectors containing result.
125 
126  \return Integer error code, set to 0 if successful.
127 
128  \warning In order to work with AztecOO, any implementation of this method must
129  support the case where X and Y are the same object.
130  */
131  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
132  int ApplyInverse(const Linear::MultiVector& X, Linear::MultiVector& Y) const;
133 
134  //! Returns the infinity norm of the global matrix.
135  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
136  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
137 
138  \warning This method must not be called unless HasNormInf() returns true.
139  */
140  double NormInf() const;
141 
142  //! Returns a character string describing the operator
143  const char * Label() const;
144 
145  //! Returns the current UseTranspose setting.
146  bool UseTranspose() const;
147 
148  //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
149  bool HasNormInf() const;
150 
151  //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
152  const Epetra_Comm & Comm() const;
153 
154  //! Returns the Epetra_Map object associated with the domain of this operator.
155  const Epetra_Map & OperatorDomainMap() const;
156 
157  //! Returns the Epetra_Map object associated with the range of this operator.
158  const Epetra_Map & OperatorRangeMap() const;
159 
160 private:
162  Teuchos::RCP<Linear::Vector> solVectorRCPtr_;
163  Teuchos::RCP<Linear::Vector> rhsVectorRCPtr_;
164  Teuchos::RCP<NonLinearSolver> nonlinearSolverRCPtr_;
165  Teuchos::RCP<const Epetra_Map> solutionMap_;
166 };
167 
168 // Non-member constructor
169 RCP<MatrixFreeEpetraOperator> matrixFreeEpetraOperator(
170  RCP<NonLinearSolver> nonlinearSolver,
171  RCP<Linear::Vector> solVector,
172  RCP<Linear::Vector> rhsVector,
173  RCP<const Epetra_Map> solutionMap
174  );
175 
176 } // namespace Nonlinear
177 } // namespace Xyce
178 
179 #endif // Xyce_N_NLS_MatrixFreeEpetraOperator_h
bool UseTranspose() const
Returns the current UseTranspose setting.
Pure virtual class to augment a linear system.
const char * Label() const
Returns a character string describing the operator.
int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y...
const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this operator.
const Epetra_Comm & Comm() const
Returns a pointer to the Epetra_Comm communicator associated with this operator.
int SetUseTranspose(bool UseTranspose)
If set true, transpose of this operator will be applied.
void initialize(RCP< NonLinearSolver > nonlinearSolver, RCP< Linear::Vector > solVector, RCP< Linear::Vector > rhsVector, RCP< const Epetra_Map > solutionMap)
bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
double NormInf() const
Returns the infinity norm of the global matrix.
const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this operator.
RCP< MatrixFreeEpetraOperator > matrixFreeEpetraOperator(RCP< NonLinearSolver > nonlinearSolver, RCP< Linear::Vector > solVector, RCP< Linear::Vector > rhsVector, RCP< const Epetra_Map > solutionMap)
int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.