Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_ANP_HB.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_HB.h,v $
27 //
28 // Purpose : HB analysis class
29 //
30 // Special Notes : Specify any "hidden" or subtle details of the class here.
31 // Portability details, error handling information, etc.
32 //
33 // Creator : Todd Coffey, 1414, Ting Mei 1437
34 //
35 // Creation Date : 07/23/08
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.41.2.1 $
41 // Revision Date : $Date: 2014/08/28 21:00:43 $
42 // Current Owner : $Author: dgbaur $
43 //-----------------------------------------------------------------------------
44 
45 #ifndef Xyce_N_ANP_HB_h
46 #define Xyce_N_ANP_HB_h
47 
48 #include <vector>
49 
50 #include <N_ANP_fwd.h>
51 #include <N_LOA_fwd.h>
52 #include <N_LAS_fwd.h>
53 #include <N_ANP_AnalysisBase.h>
54 #include <N_ANP_StepEvent.h>
55 #include <N_MPDE_State.h>
56 
57 #include <N_UTL_DFTInterfaceDecl.hpp>
58 #include <N_UTL_FFTInterface.hpp>
59 #include <N_UTL_Listener.h>
60 
61 class N_MPDE_Discretization;
62 
63 namespace Xyce {
64 namespace Analysis {
65 
66 //-------------------------------------------------------------------------
67 // Class : HB
68 // Purpose : HB analysis class
69 // Special Notes :
70 // Creator : Richard Schiek, SNL, Electrical and Microsystem Modeling
71 // Creation Date : 01/24/08
72 //-------------------------------------------------------------------------
73 class HB : public AnalysisBase, public Util::ListenerAutoSubscribe<StepEvent>
74 {
75 public:
76  HB( AnalysisManager &anaManagerPtr );
77  virtual ~HB();
78 
79  void notify(const StepEvent &event);
80 
81  // Method to set HB options
82  bool setHBOptions(const N_UTL_OptionBlock & OB);
83 
84  // Method to set HB linear solver / preconditioning options
85  bool setHBLinSol(const N_UTL_OptionBlock & OB);
86 
87  // Method to set non-HB linear solver / preconditioning options (needed for .STEP)
88  bool setLinSol(const N_UTL_OptionBlock & OB);
89 
90  // Override these methods using the current analysisObject_.
91  int getStepNumber ();
92  void setStepNumber (int step);
93  void setBeginningIntegrationFlag(bool bif);
95  void setIntegrationMethod (int im);
96  unsigned int getIntegrationMethod ();
97 
98  int getDoubleDCOPStep();
99 
100  bool getDCOPFlag();
101 
102  bool run();
103  bool init();
104  bool loopProcess();
105  bool processSuccessfulDCOP();
106  bool processFailedDCOP();
107  bool processSuccessfulStep();
108  bool processFailedStep();
109  bool finish();
110  bool handlePredictor();
111 
112  bool finalVerboseOutput();
113 
114  // Utility function for AnalysisManager to determine if a complex analysis type (like HB)
115  // is performing another type of analysis under the hood. This is necessary for populating
116  // the N_TIA_TimeIntInfo struct. For straightforward analysis types, this method is not
117  // needed because the AnalysisManager already knows which analysis is being performed.
118  bool isAnalysis( int analysis_type );
119 
120  // Transform the current solution vector for time domain and frequency domain output
121  void prepareHBOutput(N_LAS_Vector & solnVecPtr,
122  std::vector<double> & timePoints,
123  std::vector<double> & freqPoints,
124  Teuchos::RCP<N_LAS_BlockVector> & timeDomainSolnVec,
125  Teuchos::RCP<N_LAS_BlockVector> & freqDomainSolnVecReal,
126  Teuchos::RCP<N_LAS_BlockVector> & freqDomainSolnVecImaginary,
127  Teuchos::RCP<N_LAS_BlockVector> & timeDomainStoreVec,
128  Teuchos::RCP<N_LAS_BlockVector> & freqDomainStoreVecReal,
129  Teuchos::RCP<N_LAS_BlockVector> & freqDomainStoreVecImaginary) const;
130 
132 
133 private:
134 
135  // Add in solver info and timing info from current analysisObject_
136  void accumulateStatistics_();
137 
138  bool runTol_();
139  bool runStartupPeriods_();
140  bool runTransientIC_();
141  bool interpolateIC_();
142 
143  bool setFreqPoints_();
144 
145  bool setInitialGuess_();
146 
147  bool setTimePoints_();
148 
149  bool createFT_();
150 
151  // Flag to indicate of the simulation is paused
152  bool isPaused;
153 
154  // Timing/loop count info
155  double startDCOPtime, endTRANtime; // startTRANtime
156 
158  N_LOA_NonlinearEquationLoader * nonlinearEquationLoaderPtr_;
159  N_LAS_Builder * appBuilderPtr_;
160  N_PDS_Manager * pdsMgrPtr_;
161  Teuchos::RCP<AnalysisBase> analysisObject_;
162 
163  // Current analysis state flags.
165 
166  //Testing Flag
167  bool test_;
168 
169  // Problem Size
170  int size_;
171 
172  std::vector<int> numPosFreqs;
173  std::vector<int> numFreqs_;
174 
175  // Periodicity Information
176  double period_;
177 
178  // Number of fast time periods to integrate over and IGNORE before
179  // getting initial conditions for HB. Default is zero.
182 
185 
186  // Stored copy of transient TIAParams
188 
189  // Transient assisted HB.
190  int taHB_;
191 
194  std::string method_;
195 
197 
198  // HB loader, builder, system, and DFT
199  N_LOA_HBLoader * hbLoaderPtr_;
200  Teuchos::RCP<N_LAS_HBBuilder> hbBuilderPtr_;
201  Teuchos::RCP<N_LAS_System> lasHBSysPtr_;
202  Teuchos::RCP<N_UTL_FFTInterface<std::vector<double> > > ftInterface_;
203  std::vector<double> ftInData_, ftOutData_, iftInData_, iftOutData_;
204 
205  // Time discretization
208  std::vector<double> fastTimes_;
209  std::vector<double> timeSteps_;
210  std::vector<double> freqPoints_;
211  Teuchos::RCP<N_MPDE_Discretization> mpdeDiscPtr_;
212  N_MPDE_State mpdeState_;
213 
214  // Fourier matrices
215 
216  Teuchos::RCP<N_UTL_DFTInterfaceDecl<std::vector<double> > > dftInterface_;
217  Teuchos::SerialDenseMatrix<int,double> idftMatrix_, dftMatrix_;
218 
219  // Linear solver and nonlinear solver options
220  N_UTL_OptionBlock saved_lsHBOB_;
221  N_UTL_OptionBlock saved_lsOB_;
222  N_UTL_OptionBlock saved_nlHBOB_;
223 
224  // An analysis-dependent preconditioner factory.
225  Teuchos::RCP<N_LAS_PrecondFactory> precFactory_;
226 
227  // Local storage vectors
228  Teuchos::RCP<N_LAS_Vector> dcOpSolVecPtr_;
229  Teuchos::RCP<N_LAS_Vector> dcOpStateVecPtr_;
230  Teuchos::RCP<N_LAS_Vector> dcOpQVecPtr_;
231  Teuchos::RCP<N_LAS_Vector> dcOpStoreVecPtr_;
232 
233  std::vector<double> goodTimePoints_;
234  std::vector<Teuchos::RCP<N_LAS_Vector> > goodSolutionVec_;
235  std::vector<Teuchos::RCP<N_LAS_Vector> > goodStateVec_;
236  std::vector<Teuchos::RCP<N_LAS_Vector> > goodQVec_;
237  std::vector<Teuchos::RCP<N_LAS_Vector> > goodStoreVec_;
238 
239  // HB initial condition
240  Teuchos::RCP<N_LAS_BlockVector> HBICVectorPtr_;
241  Teuchos::RCP<N_LAS_BlockVector> HBICVectorFreqPtr_;
242 
243  // HB initial state condition
244  Teuchos::RCP<N_LAS_BlockVector> HBICStateVectorPtr_;
245 // Teuchos::RCP<N_LAS_BlockVector> HBICStateVectorFreqPtr_;
246 
247  // HB initial Q condition
248  Teuchos::RCP<N_LAS_BlockVector> HBICQVectorPtr_;
249  // Teuchos::RCP<N_LAS_BlockVector> HBICQVectorFreqPtr_;
250 
251  // HB initial store condition
252  Teuchos::RCP<N_LAS_BlockVector> HBICStoreVectorPtr_;
253 
254  // HB statistics
256 
257  // int hbTotalNumberSuccessfulStepsTaken_;
258  // int hbTotalNumberFailedStepsAttempted_;
259  // int hbTotalNumberJacobiansEvaluated_;
260  // int hbTotalNumberIterationMatrixFactorizations_;
261  // int hbTotalNumberLinearSolves_;
262  // int hbTotalNumberFailedLinearSolves_;
263  // int hbTotalNumberLinearIters_;
264  // int hbTotalNumberResidualEvaluations_;
265  // int hbTotalNonlinearConvergenceFailures_;
266  // double hbTotalResidualLoadTime_;
267  // double hbTotalJacobianLoadTime_;
268  // double hbTotalLinearSolutionTime_;
269 
271 };
272 
273 } // namespace Analysis
274 } // namespace Xyce
275 
277 
278 #endif // Xyce_N_ANP_HB_h
279