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 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.113.2.1 $
40 //
41 // Revision Date : $Date: 2014/08/19 16:28:07 $
42 //
43 // Current Owner : $Author: erkeite $
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_NLS_fwd.h>
64 #include <N_IO_PkgOptionsMgr.h>
65 
66 // Loader for RHS and Jacobian
67 class N_LOA_Loader;
68 
69 // Linear Algebra Support
70 class N_LAS_Matrix;
71 class N_LAS_Vector;
72 class N_LAS_System;
73 class N_LAS_PrecondFactory;
74 
75 class N_TIA_DataStore;
76 
77 class TwoLevelNewton;
78 
79 class N_PDS_Manager;
80 
81 namespace Xyce {
82 namespace Nonlinear {
83 
84 // ---------- Enum Definitions ----------
85 
86 //-----------------------------------------------------------------------------
87 // Class : Manager
88 // Purpose : Interface to the nonlinear solvers (NLS). All communication
89 // between Xyce and the nonlinear solver should be via this
90 // interface.
91 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
92 // Creation Date : 5/01/00
93 //-----------------------------------------------------------------------------
94 
95 class Manager
96 {
97 public:
98 
99  Manager(N_IO_CmdParse & cp);
100  ~Manager();
101 
102  bool setOptions(const N_UTL_OptionBlock& OB );
103  bool setTimeOptions(const N_UTL_OptionBlock& OB );
104  bool setTranOptions(const N_UTL_OptionBlock& OB );
105  bool setHBOptions(const N_UTL_OptionBlock& OB );
106  bool getHBOptions(N_UTL_OptionBlock& HBOB);
107  bool setTwoLevelOptions (const N_UTL_OptionBlock & OB);
108  bool setTwoLevelTranOptions (const N_UTL_OptionBlock & OB);
109  bool setSensOptions (const N_UTL_OptionBlock & OB);
110  bool setSensitivityOptions (const N_UTL_OptionBlock & OB);
111  bool setLinSolOptions(const N_UTL_OptionBlock& OB );
112  bool setLocaOptions(const N_UTL_OptionBlock& OB );
113  bool setTwoLevelLocaOptions(const N_UTL_OptionBlock& OB );
114  bool setDCOPRestartOptions (const N_UTL_OptionBlock& OB );
115  bool setICOptions (const N_UTL_OptionBlock& OB );
116  bool setNodeSetOptions (const N_UTL_OptionBlock& OB );
117  bool registerLoader(N_LOA_Loader* ptr);
118  bool registerOutputMgr(N_IO_OutputMgr * outputPtr);
119  bool registerRHSVector(N_LAS_Vector* ptr);
120  bool registerLinearSystem(N_LAS_System* ptr);
121  bool registerPrecondFactory( const RCP<N_LAS_PrecondFactory>& ptr);
122 
124  bool registerTopology(N_TOP_Topology * topPtr);
125  bool registerPkgOptionsMgr( N_IO_PkgOptionsMgr *pkgOptPtr );
126  bool registerParallelMgr(N_PDS_Manager * pdsMgrPtr);
127  bool registerTIADataStore(N_TIA_DataStore * tiaDSPtr);
128  void setReturnCodes (const ReturnCodes & retCodeTmp);
129  ReturnCodes getReturnCodes() const;
130 
131  bool initializeAll();
132  int solve();
134  bool isFirstSolveComplete();
135  int getContinuationStep ();
136  bool getLocaFlag ();
137  int getNumIterations();
138  int getNumResidualLoads();
139  int getNumJacobianLoads();
140  int getNumLinearSolves();
143  unsigned int getTotalNumLinearIters();
144  double getTotalLinearSolveTime();
145  double getTotalResidualLoadTime();
146  double getTotalJacobianLoadTime();
147  void setAnalysisMode(AnalysisMode mode);
148 
149  // This is a more extensive version of setAnalysisMode.
150  // It makes it like we are starting over.
151  void resetAll(AnalysisMode mode);
152 
153  int getCouplingMode ();
154 
155  bool getTwoLevelSolveFlag ();
156 
157  void getNonLinInfo (NonLinInfo & nlInfo);
158 
159  bool enableSensitivity ();
160  bool icSensitivity (
161  std::vector<double> & objectiveVec,
162  std::vector<double> & dOdpVec, std::vector<double> & dOdpAdjVec,
163  std::vector<double> & scaled_dOdpVec, std::vector<double> & scaled_dOdpAdjVec);
164  bool calcSensitivity (
165  std::vector<double> & objectiveVec,
166  std::vector<double> & dOdpVec, std::vector<double> & dOdpAdjVec,
167  std::vector<double> & scaled_dOdpVec, std::vector<double> & scaled_dOdpAdjVec);
168 
169  bool obtainConductances (
170  const std::map<std::string,double> & inputMap,
171  std::vector<double> & outputVector,
172  std::vector< std::vector<double> > & jacobian );
173 
174  bool obtainConductances (
175  const std::string & isoName,
176  std::vector< std::vector<double> > & jacobian );
177 
178  void setMatrixFreeFlag(bool matrixFreeFlag);
179  void allocateTranSolver();
180 
181  // get the norm of F form last solve
182  double getMaxNormF() const;
183 
184  // get the vector index associated with the max norm.
185  int getMaxNormFindex () const;
186 
187 protected:
188 private:
189  bool allocateSolver_ ();
190  void usingNox_ ();
192 
193  bool setupSensitivity_ ();
194 
195  struct Manager_OptionsReg : public N_IO_PkgOptionsReg
196  {
198  : Mgr(mgr)
199  {}
200 
201  bool operator()( const N_UTL_OptionBlock & options )
202  { return Mgr->setOptions( options ); }
203 
205  };
206 
207  struct Manager_TranOptionsReg : public N_IO_PkgOptionsReg
208  {
210  : Mgr(mgr)
211  {}
212 
213  bool operator()( const N_UTL_OptionBlock & options )
214  { return Mgr->setTranOptions( options ); }
215 
217  };
218 
219  struct Manager_HBOptionsReg : public N_IO_PkgOptionsReg
220  {
222  : Mgr(mgr)
223  {}
224 
225  bool operator()( const N_UTL_OptionBlock & options )
226  { return Mgr->setHBOptions( options ); }
227 
229  };
230 
231 
232  struct Manager_LSOptionsReg : public N_IO_PkgOptionsReg
233  {
235  : Mgr(mgr)
236  {}
237 
238  bool operator()( const N_UTL_OptionBlock & options )
239  { return Mgr->setLinSolOptions( options ); }
240 
242  };
243 
244  struct Manager_LocaOptionsReg : public N_IO_PkgOptionsReg
245  {
247  : Mgr(mgr)
248  {}
249 
250  bool operator()( const N_UTL_OptionBlock & options )
251  { return Mgr->setLocaOptions( options ); }
252 
254  };
255 
256  struct Manager_SensOptionsReg : public N_IO_PkgOptionsReg
257  {
259  : Mgr(mgr)
260  {}
261 
262  bool operator()( const N_UTL_OptionBlock & options )
263  { return Mgr->setSensOptions( options ); }
264 
266  };
267 
268  struct Manager_SensitivityOptionsReg : public N_IO_PkgOptionsReg
269  {
271  : Mgr(mgr)
272  {}
273 
274  bool operator()( const N_UTL_OptionBlock & options )
275  { return Mgr->setSensitivityOptions( options ); }
276 
278  };
279 
280  struct Manager_TwoLvlOptionsReg : public N_IO_PkgOptionsReg
281  {
283  : Mgr(mgr)
284  {}
285 
286  bool operator()( const N_UTL_OptionBlock & options )
287  { return Mgr->setTwoLevelOptions( options ); }
288 
290  };
291 
292  struct Manager_TwoLvlTranOptionsReg : public N_IO_PkgOptionsReg
293  {
295  : Mgr(mgr)
296  {}
297 
298  bool operator()( const N_UTL_OptionBlock & options )
299  { return Mgr->setTwoLevelTranOptions( options ); }
300 
302  };
303 
304  struct Manager_TimeOptionsReg : public N_IO_PkgOptionsReg
305  {
307  : Mgr(mgr)
308  {}
309 
310  bool operator()( const N_UTL_OptionBlock & options )
311  { return Mgr->setTimeOptions( options ); }
312 
314  };
315 
316  struct Manager_DCOPRestartOptionsReg : public N_IO_PkgOptionsReg
317  {
319  : Mgr(mgr)
320  {}
321 
322  bool operator()( const N_UTL_OptionBlock & options )
323  { return Mgr->setDCOPRestartOptions (options); }
324 
326  };
327 
328 
329  struct Manager_ICOptionsReg : public N_IO_PkgOptionsReg
330  {
332  : Mgr(mgr)
333  {}
334 
335  bool operator()( const N_UTL_OptionBlock & options )
336  { return Mgr->setICOptions (options); }
337 
339  };
340 
341 
342  struct Manager_NodeSetOptionsReg : public N_IO_PkgOptionsReg
343  {
345  : Mgr(mgr)
346  {}
347 
348  bool operator()( const N_UTL_OptionBlock & options )
349  { return Mgr->setNodeSetOptions (options); }
350 
352  };
353 
354 public:
355 protected:
356 
357 private:
358 
359  // Pointer to the nonlinear solver that is being used.
361 
364  N_TOP_Topology * topPtr_;
365 
367  N_LOA_Loader * loaderPtr_;
368  N_LAS_System * lasSysPtr_;
369  N_LAS_Vector * rhsVecPtr_;
370  N_IO_OutputMgr * outputPtr_;
371  N_PDS_Manager * pdsMgrPtr_;
372  RCP<N_LAS_PrecondFactory> lasPrecPtr_;
373 
374  N_IO_CmdParse & commandLine_;
375  // package options manager
376  N_IO_PkgOptionsMgr * pkgOptMgrPtr_;
377 
379 
380  // Flag to determine if we are doing 2-level newton or not.
382 
383  // Flag to determine if NOX is the solver in use.
384  bool noxFlag_;
385  bool noxFlagInner_; //for 2-level newton, option for inner loop to use nox.
386  bool noxFlagTransient_; // Use nox in transient phase of calculation.
387 
388  // container to hold netlist option blocks until we know which
389  // solver to allocate.
390  std::map<std::string,N_UTL_OptionBlock> optionBlockMap_;
391 
393 
395 
396  // Return Codes.
398 
399  Teuchos::RefCountPtr<N_UTL_Expression> exprPtr;
400 };
401 
402 } // namespace Nonlinear
403 } // namespace Xyce
404 
406 
407 #endif // Xyce_N_NLS_Manager_h