Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_ANP_AnalysisInterface.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_ANP_AnalysisInterface.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
33 //
34 // Creation Date : 01/21/08
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.47 $
40 //
41 // Revision Date : $Date: 2014/02/24 23:49:12 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_ANALYSIS_INTERFACE_H
47 #define Xyce_ANALYSIS_INTERFACE_H
48 
49 // ---------- Standard Includes ----------
50 
51 #include <list>
52 #include <vector>
53 
54 #include <Teuchos_RefCountPtr.hpp>
55 using Teuchos::RefCountPtr;
56 using Teuchos::rcp;
57 
58 // ---------- Xyce Includes ----------
59 
60 #include <N_DEV_fwd.h>
61 #include <N_UTL_fwd.h>
62 #include <N_ANP_fwd.h>
63 
64 #include <N_UTL_Xyce.h>
65 #include <N_UTL_Misc.h>
66 #include <N_UTL_Timer.h>
67 #include <N_NLS_Manager.h>
68 
69 #include <N_IO_fwd.h>
70 #include <N_PDS_fwd.h>
71 #include <N_IO_PkgOptionsMgr.h>
72 
73 // ---------- Forward Declarations ----------
74 class N_MPDE_Manager;
75 
76 class N_TIA_TIAParams;
77 class N_TIA_TimeIntInfo;
79 
80 class N_NLS_Manager;
81 
82 class N_LAS_System;
83 
84 class N_LOA_Loader;
85 
86 class N_PDS_Manager;
88 
89 class N_LOA_NonlinearEquationLoader;
90 class N_LAS_Builder;
91 
92 namespace Xyce {
93 namespace Analysis {
94 
95 // ---------- Enum Definitions ----------
97 {
101 };
102 
104 {
114 };
115 
116 //-----------------------------------------------------------------------------
117 // Class :
118 // Purpose : This function converts between N_NLS_Manager.h AnalysisMode
119 // : and AnalysisInterface.h ANP_Analysis_Mode
120 // Special Notes :
121 // Creator : Todd Coffey, 1414
122 // Creation Date : 07/23/08
123 //-----------------------------------------------------------------------------
125 
126 //-----------------------------------------------------------------------------
127 // Class : AnalysisInterface
128 // Purpose :
129 // Special Notes :
130 // Creator : Eric R. Keiter, 9233, Computational Sciences
131 // Creation Date : 11/09/00
132 //-----------------------------------------------------------------------------
134 {
135 public:
136 
137  // Default donstructor
138  AnalysisInterface(N_IO_CmdParse & cp);
139 
140  // Destructor
142 
143 
144  // Execution functions:
145  void resetAll();
146 
147  // Execute the control loop for the set analysis type.
148  bool run();
149 
150  // Method to register the TIA parameters object.
151  bool registerTIAParams(const N_TIA_TIAParams & tiaParams_tmp);
152 
153  // Method to register the linear system object pointer.
154  bool registerLinearSystem(N_LAS_System * lasSysPtr);
155 
156  // Method to register the nonlinear solver manager pointer.
157  bool registerNLSManager(N_NLS_Manager * nlsMgrPtr);
158 
159  // Method to register the nonlinear loader object pointer.
160  bool registerLoader(N_LOA_Loader * loaderPtr);
161 
162  // Method to register the ?DAE? Loader pointer
163  bool registerNonlinearEquationLoader( N_LOA_NonlinearEquationLoader * nonlinearEquationLoaderPtr );
164 
165  // Method to register the output manager pointer.
166  bool registerOutputMgr(N_IO_OutputMgr * outputPtr);
167 
168  // Method to register the restart manager pointer.
169  bool registerRestartMgr(N_IO_RestartMgr * restartPtr);
170 
171  // Method to register the Device inerfaace pointer
172  bool registerDeviceInterface ( N_DEV_DeviceInterface * devInterfacePtr );
173 
174  // Method to register the Parallel Services Manager pointer
175  bool registerParallelManager( N_PDS_Manager * pdsMgrPtr );
176 
177  // Method to register the Topology pointer
178  bool registerTopology( N_TOP_Topology * topoMgrPtr );
179 
180  // Method to register the Application Builder pointer
181  bool registerApplicationBuilder( N_LAS_Builder * appBuilderPtr );
182 
183  // Method to register the package options manager
184  bool registerPkgOptionsMgr( N_IO_PkgOptionsMgr * pkgOptPtr );
185 
186  // Method to set the transient solution parameters.
187  bool setTranAnalysisParams(const N_UTL_OptionBlock & tiaParamBlock);
188 
189  // Method to set the DC sweep solution parameters.
190  bool setDCAnalysisParams(const N_UTL_OptionBlock & tiaParamBlock);
191 
192  // Method to handle OP statements.
193  bool setOPAnalysisParams(const N_UTL_OptionBlock & tiaParamBlock);
194 
195  // Method to set the STEP solution parameters.
196  bool setSTEPAnalysisParams(const N_UTL_OptionBlock & tiaParamBlock);
197 
198  // Method to handle SAVE statements
199  bool setSaveOptions(const N_UTL_OptionBlock & tiaParamBlock);
200 
201  // Method to handle DCOP restart statements
202  bool setDCOPRestartParams(const N_UTL_OptionBlock & tiaParamBlock);
203 
204  // Method to set a pause time (goes down to AnalysisManager)
205  void setPauseTime(const double pauseTime);
206 
207  // Method to get a pause time (goes down to AnalysisManager)
208  double getPauseTime();
209 
210  // Method to check if a simulation is currently paused
211  bool isPaused();
212 
213  // Method to signal that simulation is resuming
214  void resumeSimulation();
215 
216  // Method to register the AC Analysis options.
217  bool setACAnalysisParams(const N_UTL_OptionBlock & OB);
218 
219  // Method to register the MOR Analysis options.
220  bool setMORAnalysisParams(const N_UTL_OptionBlock & OB);
221 
222  // Method to register the utility options.
223  bool setMOROptions(const N_UTL_OptionBlock & OB);
224 
225  // Method to register the utility options.
226  bool setTranOptions(const N_UTL_OptionBlock & OB);
227 
228  // Method to register the MPDE Analysis options.
229  bool setMPDEAnalysisParams(const N_UTL_OptionBlock & OB);
230 
231  // Method to register the MPDE utility options.
232  bool setMPDEOptions(const N_UTL_OptionBlock & OB);
233 
234  // Method to register the MPDE utility options.
235  bool setTRANMPDEOptions(const N_UTL_OptionBlock & OB);
236 
237  // Method to register the HB Analysis options.
238  bool setHBAnalysisParams(const N_UTL_OptionBlock & OB);
239 
240  // Method to register the HBINT options.
241  bool setHBOptions(const N_UTL_OptionBlock & OB);
242 
243  // Method to register the LINSOL options.
244  bool setLinSol(const N_UTL_OptionBlock & OB);
245 
246  // Method to register the HB-LINSOL options.
247  bool setHBLinSol(const N_UTL_OptionBlock & OB);
248 
249  // Method to register the sensitivity options.
250  bool setSensOptions(const N_UTL_OptionBlock & OB);
251 
252  // Method to register the sensitivity parameter list options.
253  bool setSensParamsOptions(const N_UTL_OptionBlock & OB);
254 
255  // Method to register the elapsed time timer
256  bool registerElapsedTimer (N_UTL_Timer *);
257 
258  // Gets flag for MPDE or HB block analysis
259  bool getBlockAnalysisFlag() const;
260 
261  // Gets flag for transient analysis
262  bool getTransientFlag() const;
263 
264  // This function performs the final initializations. Mainly, it initializes
265  // the two data container classes, DataStore and StepErrorControl. It also
266  // registers the neccessary vectors with the LAS system class.
267  bool initializeAll();
268 
269  // Gets the next time value.
270  double getTime() const;
271 
272  // Gets the next time value.
273  double getCurrentTime() const;
274 
275  // Gets the final time value.
276  double getFinalTime() const;
277 
278  // Gets the initial time value.
279  double getInitialTime() const;
280 
281  // Updates the divided difference values.
282  bool updateDivDiffs();
283 
284  // Calls the time int. method to update the corrector derivatives.
285  bool updateDerivs();
286 
287  // updates state vectors after initial step of starting with a previous OP
288  bool completeOPStartStep();
289 
290  // updates the State vectors. This function is called from the LOCA interface.
292  ( const std::vector<std::string> & paramNames,
293  const std::vector<double> & paramVals,
294  N_LAS_Vector * solnVecPtr );
295 
296  // Called from the LOCA interface:
297  bool failHomotopyStep ();
298 
299  bool startTimeStep (const N_TIA_TimeIntInfo & tiInfo);
300 
301  // This function equates the 6 temporary vectors with their "next" vector
302  // equivalents. This function is neccessary for the nonlinear solver damping
303  // loop.
304  bool equateTmpVectors();
305 
306  bool updateDerivsBlock(const std::list< index_pair > & solGIDList,
307  const std::list< index_pair > & staGIDlist);
308 
309  // Gets the size of the restart data (bytes?).
310  int restartDataSize( bool pack = true );
311 
312  // Dumps the restart data to a file.
313  bool dumpRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack = true );
314 
315  // Restores the restart data from a file.
316  bool restoreRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack = true );
317 
318  // Gets the solution variable data.
319  bool getSolnVarData(const int & gid, std::vector< double > & varData);
320 
321  // Gets the state variable data.
322  bool getStateVarData(const int & gid, std::vector< double > & varData);
323 
324  // Gets the store variable data.
325  bool getStoreVarData(const int & gid, std::vector< double > & varData);
326 
327  // Sets the solution variable data.
328  bool setSolnVarData(const int & gid, const std::vector< double > & varData);
329 
330  // Sets the state variable data.
331  bool setStateVarData(const int & gid, const std::vector< double > & varData);
332 
333  // Sets the store variable data.
334  bool setStoreVarData(const int & gid, const std::vector< double > & varData);
335 
336  // set begining integration to true
337  void setBeginningIntegrationFlag(bool bif);
338 
339  // Outputs summary information for time-integration function.
340  bool outputSummary();
341 
342  // Registers the pointer to the Parallel Distribution Manager.
343  bool registerParallelServices(N_PDS_Manager * pds);
344 
345  // Accessor so that an outsider can use a different solution vector.
346  bool setNextSolVectorPtr (N_LAS_Vector * solVecPtr);
347 
348  // Accessor to the N_TIA_TIAParams object.
350 
351  // .TRAN
352  struct AnalysisInterface_TransAnalysisReg : public N_IO_PkgOptionsReg
353  {
355  : Mgr(mgr)
356  {}
357 
358  bool operator()( const N_UTL_OptionBlock & options )
359  { return Mgr->setTranAnalysisParams( options ); }
360 
362  };
363 
364  // .options TIMEINT
365  struct AnalysisInterface_TranOptionsReg : public N_IO_PkgOptionsReg
366  {
368  : Mgr(mgr)
369  {}
370 
371  bool operator()( const N_UTL_OptionBlock & options )
372  { return Mgr->setTranOptions( options ); }
373 
375  };
376 
377  // .DC
378  struct AnalysisInterface_DCAnalysisReg : public N_IO_PkgOptionsReg
379  {
381  : Mgr(mgr)
382  {}
383 
384  bool operator()( const N_UTL_OptionBlock & options )
385  { return Mgr->setDCAnalysisParams( options ); }
386 
388  };
389 
390  // .options OP_IO
391  struct AnalysisInterface_DCOPOptionsReg : public N_IO_PkgOptionsReg
392  {
394  : Mgr(mgr)
395  {}
396 
397  bool operator()( const N_UTL_OptionBlock & options )
398  { return Mgr->setDCOPRestartParams( options ); }
399 
401  };
402 
403 
404  // .OP
405  struct AnalysisInterface_OPAnalysisReg : public N_IO_PkgOptionsReg
406  {
408  : Mgr(mgr)
409  {}
410 
411  bool operator()( const N_UTL_OptionBlock & options )
412  { return Mgr->setOPAnalysisParams( options ); }
413 
415  };
416 
417  // .STEP
418  struct AnalysisInterface_STEPAnalysisReg : public N_IO_PkgOptionsReg
419  {
421  : Mgr(mgr)
422  {}
423 
424  bool operator()( const N_UTL_OptionBlock & options )
425  { return Mgr->setSTEPAnalysisParams( options ); }
426 
428  };
429 
430  // .options SAVE
431  struct AnalysisInterface_SaveOptionsReg : public N_IO_PkgOptionsReg
432  {
434  : Mgr(mgr)
435  {}
436 
437  bool operator()( const N_UTL_OptionBlock & options )
438  { return Mgr->setSaveOptions( options ); }
439 
441  };
442 
443  // .MPDE
444  struct AnalysisInterface_MPDE_AnalysisReg : public N_IO_PkgOptionsReg
445  {
447  : anpInt_(anpInt)
448  {}
449 
450  bool operator()( const N_UTL_OptionBlock & options )
451  { return anpInt_->setMPDEAnalysisParams( options ); }
452 
454  };
455 
456  // .HB
457  struct AnalysisInterface_HB_AnalysisReg : public N_IO_PkgOptionsReg
458  {
460  : anpInt_(anpInt)
461  {}
462 
463  bool operator()( const N_UTL_OptionBlock & options )
464  { return anpInt_->setHBAnalysisParams( options ); }
465 
467  };
468 
469  // .options HBINT
470  struct AnalysisInterface_HB_OptionsReg : public N_IO_PkgOptionsReg
471  {
473  : anpInt_(anpInt)
474  {}
475 
476  bool operator()( const N_UTL_OptionBlock & options )
477  { return anpInt_->setHBOptions( options ); }
478 
480  };
481 
482  // .options LINSOL
483  struct AnalysisInterface_LinSolReg : public N_IO_PkgOptionsReg
484  {
486  : anpInt_(anpInt)
487  {}
488 
489  bool operator()( const N_UTL_OptionBlock & options )
490  { return anpInt_->setLinSol( options ); }
491 
493  };
494 
495  // .options LINSOL-HB
496  struct AnalysisInterface_HB_LinSolReg : public N_IO_PkgOptionsReg
497  {
499  : anpInt_(anpInt)
500  {}
501 
502  bool operator()( const N_UTL_OptionBlock & options )
503  { return anpInt_->setHBLinSol( options ); }
504 
506  };
507 
508  // .options MPDEINT
509  struct AnalysisInterface_MPDE_OptionsReg : public N_IO_PkgOptionsReg
510  {
512  : anpInt_(anpInt)
513  {}
514 
515  bool operator()( const N_UTL_OptionBlock & options )
516  { return anpInt_->setMPDEOptions( options ); }
517 
519  };
520 
521  // .options TIMEINT-MPDE
522  struct AnalysisInterface_MPDE_TranMPDEOptionsReg : public N_IO_PkgOptionsReg
523  {
525  : anpInt_(anpInt)
526  {}
527 
528  bool operator()( const N_UTL_OptionBlock & options )
529  { return anpInt_->setTRANMPDEOptions( options ); }
530 
532  };
533 
534  // .AC
535  struct AnalysisInterface_AC_AnalysisReg : public N_IO_PkgOptionsReg
536  {
538  : anpInt_(anpInt)
539  {}
540 
541  bool operator()( const N_UTL_OptionBlock & options )
542  { return anpInt_->setACAnalysisParams( options ); }
543 
545  };
546 
547  // .MOR
548  struct AnalysisInterface_MOR_AnalysisReg : public N_IO_PkgOptionsReg
549  {
551  : anpInt_(anpInt)
552  {}
553 
554  bool operator()( const N_UTL_OptionBlock & options )
555  { return anpInt_->setMORAnalysisParams( options ); }
556 
558  };
559 
560  // .options MOR_OPTS
561  struct AnalysisInterface_MOR_OptionsReg : public N_IO_PkgOptionsReg
562  {
564  : anpInt_(anpInt)
565  {}
566 
567  bool operator()( const N_UTL_OptionBlock & options )
568  { return anpInt_->setMOROptions( options ); }
569 
571  };
572 
573 
574  // .options SENS
575  struct AnalysisInterface_SensOptionsReg : public N_IO_PkgOptionsReg
576  {
578  : anpInt_(anpInt)
579  {}
580 
581  bool operator()( const N_UTL_OptionBlock & options )
582  { return anpInt_->setSensOptions( options ); }
583 
585  };
586 
587  // Function calls relating to residual and jacobian assembly
588  // These all come from the NonlinearEquationLoader class.
589  bool loadRHS ();
590  bool loadJacobian ();
591  bool applyJacobian (const N_LAS_Vector& input, N_LAS_Vector& result); // for HB Only (matrix free)
592  double getResidualTime();
593  double getJacobianTime();
594  // End of NonlinearEquationLoader function calls.
595 
596  bool simulationComplete();
597 
598  // Execute the control loop for the
599  // set analysis type, for a set number of steps.
600  bool runStep
601  (const N_TIA_TimeIntInfo & tiInfo, N_TIA_TwoLevelError & tlError);
602 
603  void condutanceTest ();
604  bool startupSolvers ();
605  bool finishSolvers ();
606 
607  bool provisionalStep (double maxTimeStep, double &currTimeStep);
608 
609  void acceptProvisionalStep ();
610  void rejectProvisionalStep ();
611 
613  ( const std::vector<std::string> & paramNames,
614  const std::vector<double> & paramVals);
615 
616  void homotopyStepFailure ();
617 
618  void stepSuccess (int analysis);
619  void stepFailure (int analysis);
621  bool getBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
622 
623 #ifdef Xyce_Dakota
624  // routines to get/set Dakota run flags and actually run a Dakota iteration
625  // calles underlying ControlAlgorithm functions
626  bool getDakotaRunFlag();
627  void setDakotaRunFlag( bool flag );
628  int getDakotaIteration();
629  void setDakotaIteration( int iterNumber );
630 #endif
631 
632  // Get all the various solver info:
633  void getTimeIntInfo(N_TIA_TimeIntInfo & tiInfo);
634 
635  // manage verbosity of "Percent Progress" printing
636  void silenceProgress();
637  void enableProgress();
638 
640 
642  bool evalTransientModel(
643  double t,
644  N_LAS_Vector * SolVectorPtr,
645  N_LAS_Vector * CurrSolVectorPtr,
646  N_LAS_Vector * LastSolVectorPtr,
647  N_LAS_Vector * StateVectorPtr,
648  N_LAS_Vector * CurrStateVectorPtr,
649  N_LAS_Vector * LastStateVectorPtr,
650  N_LAS_Vector * StateDerivVectorPtr,
651  N_LAS_Vector * StoreVectorPtr,
652  N_LAS_Vector * CurrStoreVectorPtr,
653  N_LAS_Vector * LastStoreVectorPtr,
654  N_LAS_Vector * stoLeadCurrQCompVectorPtr,
655  N_LAS_Vector * QVectorPtr,
656  N_LAS_Vector * FVectorPtr,
657  N_LAS_Vector * dFdxdVpVectorPtr,
658  N_LAS_Vector * dQdxdVpVectorPtr,
659  N_LAS_Matrix * dQdxMatrixPtr,
660  N_LAS_Matrix * dFdxMatrixPtr
661  );
663  double t,
664  N_LAS_Vector * SolVectorPtr,
665  N_LAS_Vector * StaVectorPtr ,
666  N_LAS_Vector * StoVectorPtr
667  );
668 
669 private :
670 
671  // Pointer to the TIA AnalysisManager.
672  RefCountPtr<AnalysisManager> anaManagerPtr_;
673 
674  // commandline object
675  N_IO_CmdParse & commandLine_;
676 
677  // package options manager
678  N_IO_PkgOptionsMgr *pkgOptMgrPtr_;
679 
680 };
681 
682 } // namespace Analysis
683 } // namespace Xyce
684 
686 
687 #endif //_TIME_MANAGER_H
688