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