Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_NLS_Manager.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_Manager.h,v $
27 //
28 // Purpose : Defines N_NLS_Manager class.
29 //
30 // Special Notes :
31 //
32 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 04/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.110 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:24 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_NLS_Manager_h
47 #define Xyce_N_NLS_Manager_h
48 
49 // ---------- Standard Includes ----------
50 #include <map>
51 #include <vector>
52 
53 #include <Teuchos_RefCountPtr.hpp>
54 using Teuchos::RefCountPtr;
55 using Teuchos::rcp;
56 
57 #include <N_IO_fwd.h>
58 #include <N_TOP_fwd.h>
59 #include <N_UTL_OptionBlock.h>
60 #include <N_NLS_ReturnCodes.h>
61 
62 #include <N_ANP_fwd.h>
63 #include <N_IO_PkgOptionsMgr.h>
64 
65 // Nonlinear solver
67 
68 // Loader for RHS and Jacobian
69 class N_LOA_Loader;
70 
71 // Linear Algebra Support
72 class N_LAS_Matrix;
73 class N_LAS_Vector;
74 class N_LAS_System;
75 class N_LAS_PrecondFactory;
76 
78 
79 class N_NLS_Sensitivity;
81 class N_NLS_NonLinInfo;
82 
83 class N_PDS_Manager;
84 
85 // ---------- Enum Definitions ----------
86 
87 //-----------------------------------------------------------------------------
88 // Enum : AnalysisMode
89 // Description : These anlysis modes influence the choice of parameters for
90 // the nonlinear solver. The mode is set by the
91 // setAnalysisMode() function in the N_NLS_Manager class.
92 //-----------------------------------------------------------------------------
94 {
100 };
101 
102 //-----------------------------------------------------------------------------
103 // Class : N_NLS_Manager
104 // Purpose : Interface to the nonlinear solvers (NLS). All communication
105 // between Xyce and the nonlinear solver should be via this
106 // interface.
107 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
108 // Creation Date : 5/01/00
109 //-----------------------------------------------------------------------------
110 
112 {
113 public:
114 
115  N_NLS_Manager(N_IO_CmdParse & cp);
116  ~N_NLS_Manager();
117 
118  bool setOptions(const N_UTL_OptionBlock& OB );
119  bool setTimeOptions(const N_UTL_OptionBlock& OB );
120  bool setTranOptions(const N_UTL_OptionBlock& OB );
121  bool setHBOptions(const N_UTL_OptionBlock& OB );
122  bool getHBOptions(N_UTL_OptionBlock& HBOB);
123  bool setTwoLevelOptions (const N_UTL_OptionBlock & OB);
124  bool setTwoLevelTranOptions (const N_UTL_OptionBlock & OB);
125  bool setSensOptions (const N_UTL_OptionBlock & OB);
126  bool setSensitivityOptions (const N_UTL_OptionBlock & OB);
127  bool setLinSolOptions(const N_UTL_OptionBlock& OB );
128  bool setLocaOptions(const N_UTL_OptionBlock& OB );
129  bool setTwoLevelLocaOptions(const N_UTL_OptionBlock& OB );
130  bool setDCOPRestartOptions (const N_UTL_OptionBlock& OB );
131  bool setICOptions (const N_UTL_OptionBlock& OB );
132  bool setNodeSetOptions (const N_UTL_OptionBlock& OB );
133  bool registerLoader(N_LOA_Loader* ptr);
134  bool registerOutputMgr(N_IO_OutputMgr * outputPtr);
135  bool registerRHSVector(N_LAS_Vector* ptr);
136  bool registerLinearSystem(N_LAS_System* ptr);
137  bool registerPrecondFactory( const RCP<N_LAS_PrecondFactory>& ptr);
138 
140  bool registerTopology(N_TOP_Topology * topPtr);
141  bool registerPkgOptionsMgr( N_IO_PkgOptionsMgr *pkgOptPtr );
142  bool registerParallelMgr(N_PDS_Manager * pdsMgrPtr);
143  void setReturnCodes (const N_NLS_ReturnCodes & retCodeTmp);
145 
146  bool initializeAll();
147  int solve();
149  bool isFirstSolveComplete();
150  int getContinuationStep ();
151  bool getLocaFlag ();
152  int getNumIterations();
153  int getNumResidualLoads();
154  int getNumJacobianLoads();
155  int getNumLinearSolves();
158  unsigned int getTotalNumLinearIters();
159  double getTotalLinearSolveTime();
160  double getTotalResidualLoadTime();
161  double getTotalJacobianLoadTime();
162  void setAnalysisMode(AnalysisMode mode);
163 
164  // This is a more extensive version of setAnalysisMode.
165  // It makes it like we are starting over.
166  void resetAll(AnalysisMode mode);
167 
168  int getCouplingMode ();
169 
170  bool getTwoLevelSolveFlag ();
171 
172  void getNonLinInfo (N_NLS_NonLinInfo & nlInfo);
173 
174  bool enableSensitivity ();
175  bool calcSensitivity (
176  std::vector<double> & objectiveVec,
177  std::vector<double> & dOdpVec, std::vector<double> & dOdpAdjVec,
178  std::vector<double> & scaled_dOdpVec, std::vector<double> & scaled_dOdpAdjVec);
179 
180  bool obtainConductances (
181  const std::map<std::string,double> & inputMap,
182  std::vector<double> & outputVector,
183  std::vector< std::vector<double> > & jacobian );
184 
185  bool obtainConductances (
186  const std::string & isoName,
187  std::vector< std::vector<double> > & jacobian );
188 
189  void setMatrixFreeFlag(bool matrixFreeFlag);
190  void allocateTranSolver();
191 
192  // get the norm of F form last solve
193  double getMaxNormF() const;
194 
195  // get the vector index associated with the max norm.
196  int getMaxNormFindex () const;
197 
198 protected:
199 private:
200  bool allocateSolver_ ();
201  void usingNox_ ();
203 
204  bool setupSensitivity_ ();
205 
206  struct N_NLS_Manager_OptionsReg : public N_IO_PkgOptionsReg
207  {
209  : Mgr(mgr)
210  {}
211 
212  bool operator()( const N_UTL_OptionBlock & options )
213  { return Mgr->setOptions( options ); }
214 
216  };
217 
218  struct N_NLS_Manager_TranOptionsReg : public N_IO_PkgOptionsReg
219  {
221  : Mgr(mgr)
222  {}
223 
224  bool operator()( const N_UTL_OptionBlock & options )
225  { return Mgr->setTranOptions( options ); }
226 
228  };
229 
230  struct N_NLS_Manager_HBOptionsReg : public N_IO_PkgOptionsReg
231  {
233  : Mgr(mgr)
234  {}
235 
236  bool operator()( const N_UTL_OptionBlock & options )
237  { return Mgr->setHBOptions( options ); }
238 
240  };
241 
242 
243  struct N_NLS_Manager_LSOptionsReg : public N_IO_PkgOptionsReg
244  {
246  : Mgr(mgr)
247  {}
248 
249  bool operator()( const N_UTL_OptionBlock & options )
250  { return Mgr->setLinSolOptions( options ); }
251 
253  };
254 
255  struct N_NLS_Manager_LocaOptionsReg : public N_IO_PkgOptionsReg
256  {
258  : Mgr(mgr)
259  {}
260 
261  bool operator()( const N_UTL_OptionBlock & options )
262  { return Mgr->setLocaOptions( options ); }
263 
265  };
266 
267  struct N_NLS_Manager_SensOptionsReg : public N_IO_PkgOptionsReg
268  {
270  : Mgr(mgr)
271  {}
272 
273  bool operator()( const N_UTL_OptionBlock & options )
274  { return Mgr->setSensOptions( options ); }
275 
277  };
278 
279  struct N_NLS_Manager_SensitivityOptionsReg : public N_IO_PkgOptionsReg
280  {
282  : Mgr(mgr)
283  {}
284 
285  bool operator()( const N_UTL_OptionBlock & options )
286  { return Mgr->setSensitivityOptions( options ); }
287 
289  };
290 
291  struct N_NLS_Manager_TwoLvlOptionsReg : public N_IO_PkgOptionsReg
292  {
294  : Mgr(mgr)
295  {}
296 
297  bool operator()( const N_UTL_OptionBlock & options )
298  { return Mgr->setTwoLevelOptions( options ); }
299 
301  };
302 
303  struct N_NLS_Manager_TwoLvlTranOptionsReg : public N_IO_PkgOptionsReg
304  {
306  : Mgr(mgr)
307  {}
308 
309  bool operator()( const N_UTL_OptionBlock & options )
310  { return Mgr->setTwoLevelTranOptions( options ); }
311 
313  };
314 
315  struct N_NLS_Manager_TimeOptionsReg : public N_IO_PkgOptionsReg
316  {
318  : Mgr(mgr)
319  {}
320 
321  bool operator()( const N_UTL_OptionBlock & options )
322  { return Mgr->setTimeOptions( options ); }
323 
325  };
326 
327  struct N_NLS_Manager_DCOPRestartOptionsReg : public N_IO_PkgOptionsReg
328  {
330  : Mgr(mgr)
331  {}
332 
333  bool operator()( const N_UTL_OptionBlock & options )
334  { return Mgr->setDCOPRestartOptions (options); }
335 
337  };
338 
339 
340  struct N_NLS_Manager_ICOptionsReg : public N_IO_PkgOptionsReg
341  {
343  : Mgr(mgr)
344  {}
345 
346  bool operator()( const N_UTL_OptionBlock & options )
347  { return Mgr->setICOptions (options); }
348 
350  };
351 
352 
353  struct N_NLS_Manager_NodeSetOptionsReg : public N_IO_PkgOptionsReg
354  {
356  : Mgr(mgr)
357  {}
358 
359  bool operator()( const N_UTL_OptionBlock & options )
360  { return Mgr->setNodeSetOptions (options); }
361 
363  };
364 
365 public:
366 protected:
367 
368 private:
369 
370  // Pointer to the nonlinear solver that is being used.
372 
375  N_TOP_Topology * topPtr_;
376 
378  N_LOA_Loader * loaderPtr_;
379  N_LAS_System * lasSysPtr_;
380  N_LAS_Vector * rhsVecPtr_;
381  N_IO_OutputMgr * outputPtr_;
382  N_PDS_Manager * pdsMgrPtr_;
383  RCP<N_LAS_PrecondFactory> lasPrecPtr_;
384 
385  N_IO_CmdParse & commandLine_;
386  // package options manager
387  N_IO_PkgOptionsMgr * pkgOptMgrPtr_;
388 
389  // Flag to determine if we are doing 2-level newton or not.
391 
392  // Flag to determine if NOX is the solver in use.
393  bool noxFlag_;
394  bool noxFlagInner_; //for 2-level newton, option for inner loop to use nox.
395  bool noxFlagTransient_; // Use nox in transient phase of calculation.
396 
397  // container to hold netlist option blocks until we know which
398  // solver to allocate.
399  std::map<std::string,N_UTL_OptionBlock> optionBlockMap_;
400 
402 
404 
405  // Return Codes.
407 
408  Teuchos::RefCountPtr<N_UTL_Expression> exprPtr;
409 };
410 
411 #endif