Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-2014 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.8 $
41 //
42 // Revision Date : $Date: 2014/08/07 23:08:54 $
43 //
44 // Current Owner : $Author: dgbaur $
45 //-------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_NLS_MatrixFreeEpetraOperator_h
48 #define Xyce_N_NLS_MatrixFreeEpetraOperator_h
49 
50 // ---------- Standard Includes ----------
51 #include <Teuchos_RefCountPtr.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 // ---------- Forward Declarations ----------
65 class N_LAS_Vector;
66 
67 // ---------- Using Declarations ------------
68 using Teuchos::RefCountPtr;
69 using Teuchos::rcp;
70 
71 namespace Xyce {
72 namespace Nonlinear {
73 
74 //-----------------------------------------------------------------------------
75 // Class : MatrixFreeEpetraOperator
76 // Purpose : Matrix Free Epetra Operator concrete class
77 // Special Notes :
78 // Creator : Todd Coffey, 1414
79 // Creation Date : 9/4/08
80 //-----------------------------------------------------------------------------
81 
82 class MatrixFreeEpetraOperator : virtual public Epetra_Operator
83 {
84 
85 public:
86 
88 
89  virtual ~MatrixFreeEpetraOperator();
90 
91  void initialize(
92  RefCountPtr<NonLinearSolver> nonlinearSolver,
93  RefCountPtr<N_LAS_Vector> solVector,
94  RefCountPtr<N_LAS_Vector> rhsVector,
95  RefCountPtr<const Epetra_Map> solutionMap
96  );
97 
98  //! If set true, transpose of this operator will be applied.
99  /*! This flag allows the transpose of the given operator to be used implicitly. Setting this flag
100  affects only the Apply() and ApplyInverse() methods. If the implementation of this interface
101  does not support transpose use, this method should return a value of -1.
102 
103  \param[in]
104  UseTranspose -If true, multiply by the transpose of operator, otherwise just use operator.
105 
106  \return Integer error code, set to 0 if successful. Set to -1 if this implementation does not support transpose.
107  */
108  int SetUseTranspose(bool UseTranspose);
109 
110  //! Returns the result of a Epetra_Operator applied to a Epetra_MultiVector X in Y.
111  /*
112  \param[in]
113  X - A Epetra_MultiVector of dimension NumVectors to multiply with matrix.
114  \param[out]
115  Y -A Epetra_MultiVector of dimension NumVectors containing result.
116 
117  \return Integer error code, set to 0 if successful.
118  */
119  int Apply(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
120  int Apply(const N_LAS_MultiVector& X, N_LAS_MultiVector& Y) const;
121 
122  //! Returns the result of a Epetra_Operator inverse applied to an Epetra_MultiVector X in Y.
123  /*
124  \param[in]
125  X - A Epetra_MultiVector of dimension NumVectors to solve for.
126  \param[out]
127  Y -A Epetra_MultiVector of dimension NumVectors containing result.
128 
129  \return Integer error code, set to 0 if successful.
130 
131  \warning In order to work with AztecOO, any implementation of this method must
132  support the case where X and Y are the same object.
133  */
134  int ApplyInverse(const Epetra_MultiVector& X, Epetra_MultiVector& Y) const;
135  int ApplyInverse(const N_LAS_MultiVector& X, N_LAS_MultiVector& Y) const;
136 
137  //! Returns the infinity norm of the global matrix.
138  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
139  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
140 
141  \warning This method must not be called unless HasNormInf() returns true.
142  */
143  double NormInf() const;
144 
145  //! Returns a character string describing the operator
146  const char * Label() const;
147 
148  //! Returns the current UseTranspose setting.
149  bool UseTranspose() const;
150 
151  //! Returns true if the \e this object can provide an approximate Inf-norm, false otherwise.
152  bool HasNormInf() const;
153 
154  //! Returns a pointer to the Epetra_Comm communicator associated with this operator.
155  const Epetra_Comm & Comm() const;
156 
157  //! Returns the Epetra_Map object associated with the domain of this operator.
158  const Epetra_Map & OperatorDomainMap() const;
159 
160  //! Returns the Epetra_Map object associated with the range of this operator.
161  const Epetra_Map & OperatorRangeMap() const;
162 
163 private:
165  Teuchos::RefCountPtr<N_LAS_Vector> solVectorRCPtr_;
166  Teuchos::RefCountPtr<N_LAS_Vector> rhsVectorRCPtr_;
167  Teuchos::RefCountPtr<NonLinearSolver> nonlinearSolverRCPtr_;
168  Teuchos::RefCountPtr<const Epetra_Map> solutionMap_;
169 };
170 
171 // Non-member constructor
172 RefCountPtr<MatrixFreeEpetraOperator> matrixFreeEpetraOperator(
173  RefCountPtr<NonLinearSolver> nonlinearSolver,
174  RefCountPtr<N_LAS_Vector> solVector,
175  RefCountPtr<N_LAS_Vector> rhsVector,
176  RefCountPtr<const Epetra_Map> solutionMap
177  );
178 
179 } // namespace Nonlinear
180 } // namespace Xyce
181 
183 
184 #endif // Xyce_N_NLS_MatrixFreeEpetraOperator_h