Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_NOX_SharedSystem.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_NOX_SharedSystem.h,v $
27 //
28 // Purpose : Interface to let multiple N_NLS::NOX::Group's
29 // share a single system of RHS Vector, Jacobian
30 // matrix, Newton vector, and gradient vector.
31 // Closely related to the NOX::Epetra::SharedSystem
32 // class.
33 //
34 // Special Notes :
35 //
36 // Creator : Tammy Kolda, NLS, 8950
37 //
38 // Creation Date : 01/31/02
39 //
40 // Revision Information:
41 // ---------------------
42 //
43 // Revision Number: $Revision: 1.25 $
44 //
45 // Revision Date : $Date: 2014/05/08 16:40:44 $
46 //
47 // Current Owner : $Author: erkeite $
48 //-------------------------------------------------------------------------
49 
50 #ifndef Xyce_N_NLS_NOX_SharedSystem_h
51 #define Xyce_N_NLS_NOX_SharedSystem_h
52 
53 // ---------- Standard Includes ----------
54 
55 // ---------- Xyce Includes ----------
56 
57 // ---------- NOX Includes ----------
58 
59 #include "N_NLS_NOX_Vector.h"
60 #include "N_NLS_NOX_Group.h"
61 
62 // ---------- Forward Declarations ----------
63 
64 class N_LAS_Vector;
65 class N_LAS_Matrix;
66 class Ifpack_IlukGraph;
67 class Ifpack_CrsRiluk;
68 
69 namespace N_NLS_NOX {
70  class Interface;
71 }
72 
73 namespace NOX {
74  namespace Parameter {
75  class List;
76  }
77 }
78 
79 //-----------------------------------------------------------------------------
80 // Class : N_NLS::NOX::SharedSystem
81 //
82 // Purpose :
83 //
84 // Interface to let multiple N_NLS::NOX::Group's share the
85 // vectors and matrices in the Xyce nonlinear solver.
86 //
87 // Closely related conceptually to the
88 // NOX::Epetra::SharedJacobian class.
89 //
90 // Creator : Tammy Kolda, SNL, 8950
91 //
92 // Creation Date : 1/31/02
93 //-----------------------------------------------------------------------------
94 
95 namespace N_NLS_NOX {
96 class SharedSystem {
97 
98 public:
99 
100  SharedSystem(N_LAS_Vector& x,
101  N_LAS_Vector& f,
102  N_LAS_Matrix& jacobian,
103  N_LAS_Vector& newton,
104  N_LAS_Vector& gradient,
105  N_LAS_System& lasSys,
106  N_NLS_NOX::Interface& interface);
107 
108  ~SharedSystem();
109 
110 
111  void reset(N_LAS_Vector& x,
112  N_LAS_Vector& f,
113  N_LAS_Matrix& jacobian,
114  N_LAS_Vector& newton,
115  N_LAS_Vector& gradient,
116  N_LAS_System& lasSys,
117  N_NLS_NOX::Interface& interface);
118 
119  //---------------------------------------------------------------------------
120  // Function : isJacobianOwner
121  // Purpose : Verify that the group pointed to by grp is owner of the
122  // Jacobian matrix.
123  //---------------------------------------------------------------------------
124  inline bool isJacobianOwner(const Group* grp) const
125  {
126  return (grp == ownerOfJacobian_);
127  };
128 
129  //---------------------------------------------------------------------------
130  // Function : areStateVectors
131  // Purpose : To compute a Jacobian, the state vectors must be
132  // updated with respect to the solution in the group.
133  // However, the state vectors are updated ONLY during
134  // calls to compute the residual. This method checks
135  // to see if the state vectors still correspond to this
136  // group. Returns true if state vectors are correct.
137  //---------------------------------------------------------------------------
138  inline bool areStateVectors(const Group* grp) const
139  {
140  return (grp == ownerOfStateVectors_);
141  };
142 
143  bool computeF(const Vector& solution, Vector& F, const Group* grp);
144 
145  bool computeJacobian(Group* grp);
146 
147  bool computeNewton(const Vector& F, Vector& Newton,
148  Teuchos::ParameterList& params);
149 
150  bool computeGradient(const Vector& F, Vector& Gradient);
151 
152  bool applyJacobian(const Vector& input, Vector& result) const;
153 
154  bool applyJacobianTranspose(const Vector& input, Vector& result) const;
155 
157 
158  // Take ownership of const Jacobian.
159  const N_LAS_Matrix& getJacobian() const;
160 
161  // Take ownership of Jacobian and get a reference to it.
162  N_LAS_Matrix& getJacobian(const Group* grp);
163 
164  // Take ownership of the state vectors.
165  void getStateVectors(const Group* grp);
166 
167  // Get a pointer to the N_LAS_System object
168  N_LAS_System* getLasSystem();
169 
170 #ifdef Xyce_DEBUG_NONLINEAR
171  // Use for debugging (corresponding to the ones in N_NLS_NonLinearSolver).
172  void debugOutput1 (N_LAS_Matrix & jacobian, N_LAS_Vector & rhs);
173  void debugOutput3 (N_LAS_Vector & dxVector, N_LAS_Vector & xVector);
174 #endif
175 
176  // Preconditioning objects for the Group::applyRightPreconditioning method
177  bool computePreconditioner();
178  bool deletePreconditioner();
179  bool applyRightPreconditioning(bool useTranspose,
180  Teuchos::ParameterList& params,
181  const Vector& input,
182  Vector& result);
183 
184  // This is used to construct vectors in the group. We used to
185  // clone a time integrator vector but when the DC Op point fails,
186  // somewhere (I have no idea where) it decides to delete vectors
187  // before the Nonlinear solver can delete theirs. This causes
188  // a seg fault.
189  //
191 
192  // Take ownership of const newton vector
193  const N_NLS_NOX::Vector & getNewtonVector() const;
194 
195  void printSoln(std::ostream &os) {xyceSolnPtr_->print(os);}
196  void printRes(std::ostream &os) {xyceFPtr_->print(os);}
197 
198 private:
199 
200  // Views of xyce objects used in the fill
201  Vector* xyceSolnPtr_; // Solution vector
202  Vector* xyceFPtr_; // Residual Vector
203  N_LAS_Matrix* xyceJacobianPtr_; // Jacobian matrix
204  Vector* xyceNewtonPtr_; // Newton Vector
205  Vector* xyceGradientPtr_; // gradient Vector
206  N_LAS_System* xyceLasSysPtr_; // LAS System
207  N_NLS_NOX::Interface* xyceInterfacePtr_; // Nonlinear Solver Interface
208 
209  // Flag for Matrix Free Loads tscoffe/tmei 07/29/08
211 
214 
215  // Ifpack preconditioning objects for applyRightPreconditioning method
216  mutable Ifpack_IlukGraph* ifpackGraphPtr_;
217  mutable Ifpack_CrsRiluk* ifpackPreconditionerPtr_;
218 
219 }; // class SharedSystem
220 } // namespace N_NLS_NOX
221 
222 #endif // Xyce_N_NLS_NOX_SharedSystem_h
223