Xyce  6.1
N_LOA_HBLoader.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-2015 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_LOA_HBLoader.h,v $
27 //
28 // Purpose : HB Specific Loader
29 //
30 // Special Notes :
31 //
32 // Creator : Todd Coffey, Ting Mei
33 //
34 // Creation Date : 07/28/08
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.47 $
40 //
41 // Revision Date : $Date: 2015/08/31 20:12:23 $
42 //
43 // Current Owner : $Author: tmei $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_LOA_HBLoader_H
47 #define Xyce_LOA_HBLoader_H
48 
49 #include <vector>
50 
51 #include <Teuchos_RCP.hpp>
52 
53 #include <N_DEV_fwd.h>
54 #include <N_LAS_fwd.h>
55 #include <N_PDS_fwd.h>
56 
57 #include <N_UTL_DFTInterfaceDecl.hpp>
58 #include <N_LOA_CktLoader.h>
59 
60 // ---------- Forward declarations --------
61 
62 class N_MPDE_Discretization;
63 
64 namespace Xyce {
65 namespace Loader {
66 
67 //-----------------------------------------------------------------------------
68 // Class : HBLoader
69 // Purpose : HB specific CktLoader interface
70 // Special Notes :
71 // Creator : Todd Coffey, Ting Mei, Rich Schiek
72 // Creation Date : 07/29/08
73 //-----------------------------------------------------------------------------
74 class HBLoader : public CktLoader
75 {
76 public:
77  HBLoader(
78  const Teuchos::RCP<const N_MPDE_Discretization> discPtr,
79  Device::DeviceMgr & device_manager,
80  Linear::Builder & builder);
81 
83  {}
84 
85  // Method which is called to load the new-DAE contributions
86  bool loadDAEMatrices( Linear::Vector * X,
87  Linear::Vector * S,
88  Linear::Vector * dSdt,
89  Linear::Vector * Store,
90  Linear::Matrix * dQdx,
91  Linear::Matrix * dFdx );
92 
93  // Method which is called to load the time-dependent HB Matrices
94  bool loadTimeDepDAEMatrices( Linear::Vector * X,
95  Linear::Vector * S,
96  Linear::Vector * dSdt,
97  Linear::Vector * Store,
98  Linear::Matrix * dQdx,
99  Linear::Matrix * dFdx );
100 
101  // Method for matrix-free
102  bool applyDAEMatrices( Linear::Vector * X,
103  Linear::Vector * S,
104  Linear::Vector * dSdt,
105  Linear::Vector * Store,
106  const Linear::Vector & V,
107  Linear::Vector * dQdxV,
108  Linear::Vector * dFdxV );
109 
110  // Method is called to load the mask to be used in calculating error norms.
111  bool loadDeviceErrorWeightMask(Linear::Vector * deviceMask) const;
112 
113  // Method which is called to load the new-DAE vectors
114  bool loadDAEVectors( Linear::Vector * X,
115  Linear::Vector * currX,
116  Linear::Vector * lastX,
117  Linear::Vector * S,
118  Linear::Vector * currS,
119  Linear::Vector * lastS,
120  Linear::Vector * dSdt,
121  Linear::Vector * Store,
122  Linear::Vector * currStore,
123  Linear::Vector * lastStore,
124  Linear::Vector * storeLeadCurrQ,
125  Linear::Vector * nextLeadFVectorPtr,
126  Linear::Vector * currLeadFVectorPtr,
127  Linear::Vector * lastLeadFVectorPtr,
128  Linear::Vector * nextLeadQVectorPtr,
129  Linear::Vector * nextJunctionVVectorPtr,
130  Linear::Vector * currJunctionVVectorPtr,
131  Linear::Vector * lastJunctionVVectorPtr,
132  Linear::Vector * Q,
133  Linear::Vector * F,
134  Linear::Vector * B,
135  Linear::Vector * dFdxdVp,
136  Linear::Vector * dQdxdVp );
137 
138  bool updateState( Linear::Vector * nextSolVectorPtr,
139  Linear::Vector * currSolVectorPtr,
140  Linear::Vector * lastSolVectorPtr,
141  Linear::Vector * nextStaVectorPtr,
142  Linear::Vector * currStaVectorPtr,
143  Linear::Vector * lastStaVectorPtr,
144  Linear::Vector * nextStoVectorPtr,
145  Linear::Vector * currStoVectorPtr,
146  Linear::Vector * lastStoVectorPtr
147  );
148 
149  // Virtual method which initializes the nonlinear problem.
150  virtual bool initializeProblem( Linear::Vector * nextSolVectorPtr,
151  Linear::Vector * currSolVectorPtr,
152  Linear::Vector * lastSolVectorPtr,
153  Linear::Vector * nextStaVectorPtr,
154  Linear::Vector * currStaVectorPtr,
155  Linear::Vector * lastStaVectorPtr,
156  Linear::Vector * StateDerivVectorPtr,
157  Linear::Vector * nextStoVectorPtr,
158  Linear::Vector * currStoVectorPtr,
159  Linear::Vector * lastStoVectorPtr,
160  Linear::Vector * QVectorPtr,
161  Linear::Vector * FVectorPtr,
162  Linear::Vector * BVectorPtr,
163  Linear::Vector * dFdxdVpVectorPtr,
164  Linear::Vector * dQdxdVpVectorPtr) const
165  {
166  return false;
167  }
168 
169  // Get the voltage limiter flag:
170  bool getLimiterFlag () { return HBLoader::appLoaderPtr_->getLimiterFlag (); }
171 
172  // Get the stored time-domain Jacobians from the HB loader.
173  Teuchos::RCP<Linear::Matrix>& getStoreLindQdx() { return linAppdQdxPtr_; }
174  Teuchos::RCP<Linear::Matrix>& getStoreLindFdx() { return linAppdFdxPtr_; }
175  std::vector<Teuchos::RCP<Linear::Matrix> >& getStoreNLdQdx() { return vecNLAppdQdxPtr_; }
176  std::vector<Teuchos::RCP<Linear::Matrix> >& getStoreNLdFdx() { return vecNLAppdFdxPtr_; }
177 
178  bool applyLinearMatrices( const Linear::BlockVector & bVf,
179  Linear::BlockVector & permlindQdxV,
180  Linear::BlockVector & permlindFdxV );
181 
182  // New functions for LOA_HBLoader
183  // Assumption: xt is in the block format:
184  // xt.block(i) = { x_n(t_i) }_{n=0..N} N = number of solution components, t_i = time point i
185  // P takes xt's block format and converts it to:
186  // (P*xt).block(n) = { x_n(t_i) }_{i=0..T} T = number of time points in block vector.
187 
188 
189  void setFastTimes( const std::vector<double> & times );
190 
191  void setHBFreqs( const std::vector<double> & freqs);
192  Teuchos::RCP<Linear::BlockVector> & getStoreVecFreqPtr() { return bStoreVecFreqPtr_;}
193  Teuchos::RCP<Linear::BlockVector> & getLeadCurrentVecFreqPtr() { return bLeadCurrentVecFreqPtr_;}
194 
195  // Is the problem being applied as a matrix free operator.
196  void setMatrixFreeFlag(bool matrixFreeFlag)
197  {
198  matrixFreeFlag_ = matrixFreeFlag;
199  }
200 
201  // xf = D*P*xt, xf has the same block format as (P*xt).
202  void permutedFFT(const Linear::BlockVector & xt, Linear::BlockVector * xf); // Reference for input, pointer for output
203  // xt = P^{-1}D^{-1}*xf
204  void permutedIFT(const Linear::BlockVector & xf, Linear::BlockVector * xt, int numTimePts_= 0);
205 
206  // Registration method for the device packaage
207  void registerAppLoader( Teuchos::RCP<Loader> appLoaderPtr )
208  { appLoaderPtr_ = appLoaderPtr; }
209 
210  void registerHBBuilder(Teuchos::RCP<Linear::HBBuilder> hbBuilderPtr);
211 
212  void registerDFTInterface( const Teuchos::RCP<N_UTL_DFTInterfaceDecl<std::vector<double> > >& dftInterface )
213  { dftInterface_ = dftInterface; }
214 
215  virtual bool analyticSensitivitiesAvailable (std::string & name) { return false; }
217  std::string & name,
218  std::vector<double> & dfdpVec,
219  std::vector<double> & dqdpVec,
220  std::vector<double> & dbdpVec,
221  std::vector<int> & FindicesVec,
222  std::vector<int> & QindicesVec,
223  std::vector<int> & BindicesVec) const
224  {}
225 
226  virtual bool setParam (std::string & name, double val, bool overrideOriginal=false) { return false; }
227  virtual double getParamAndReduce(Parallel::Machine comm, const std::string & name) const { return 0.0; }
228 
229  // voltage limiter toggle functions
230  virtual bool getVoltageLimiterStatus();
231  virtual void setVoltageLimiterStatus(bool voltageLimterStatus);
232 
233 private:
234  // discretization
235  Teuchos::RCP<const N_MPDE_Discretization> fastTimeDiscPtr_;
236 
237  //Fast Time Scale Points
238  std::vector<double> times_;
240  std::vector<double> periodicTimes_;
241  double period_;
242 
243  // Matrix free flag, operator is being applied not loaded
245 
246  std::vector<double> freqs_ ;
247  // Base Application loader
248  Teuchos::RCP<Loader> appLoaderPtr_; ///< Actually a CktLoader
250 
251  // Application Linear Objects
252  Teuchos::RCP<Linear::Vector> appVecPtr_;
253  Teuchos::RCP<Linear::Vector> appNextStaVecPtr_;
254  Teuchos::RCP<Linear::Vector> appCurrStaVecPtr_;
255  Teuchos::RCP<Linear::Vector> appLastStaVecPtr_;
256 
257  Teuchos::RCP<Linear::Matrix> appdQdxPtr_;
258  Teuchos::RCP<Linear::Matrix> appdFdxPtr_;
259 
260  Teuchos::RCP<Linear::Matrix> linAppdQdxPtr_;
261  std::vector<Teuchos::RCP<Linear::Matrix> > vecNLAppdQdxPtr_;
262  Teuchos::RCP<Linear::Matrix> linAppdFdxPtr_;
263  std::vector<Teuchos::RCP<Linear::Matrix> > vecNLAppdFdxPtr_;
264 
265  Teuchos::RCP<Linear::Vector> appNextStoVecPtr_;
266  Teuchos::RCP<Linear::Vector> appCurrStoVecPtr_;
267  Teuchos::RCP<Linear::Vector> appLastStoVecPtr_;
268  Teuchos::RCP<Linear::Vector> appStoLeadCurrQVecPtr_;
269 
270  Teuchos::RCP<Linear::Vector> appNextLeadFVecPtr_;
271  Teuchos::RCP<Linear::Vector> appCurrLeadFVecPtr_;
272  Teuchos::RCP<Linear::Vector> appLastLeadFVecPtr_;
273  Teuchos::RCP<Linear::Vector> appLeadQVecPtr_;
274  Teuchos::RCP<Linear::Vector> appNextJunctionVVecPtr_;
275  Teuchos::RCP<Linear::Vector> appCurrJunctionVVecPtr_;
276  Teuchos::RCP<Linear::Vector> appLastJunctionVVecPtr_;
277 
278  // Tmp storage block matrices
279  Teuchos::RCP<Linear::BlockMatrix> bmdQdxPtr_;
280  Teuchos::RCP<Linear::BlockMatrix> bmdFdxPtr_;
281 
282  // HB Builder: (needed to convert AztecOO created Linear::Vectors into Linear::BlockVectors
283  Teuchos::RCP<Linear::HBBuilder> hbBuilderPtr_;
284 
285  // App Builder: (needed to load time domain vectors and matrices)
286  Linear::Builder & builder_;
287 
288  Teuchos::RCP<Linear::BlockVector> bXtPtr_;
289  Teuchos::RCP<Linear::BlockVector> bVtPtr_;
290 
291  Teuchos::RCP<Linear::BlockVector> bStoreVecFreqPtr_;
292  Teuchos::RCP<Linear::BlockVector> bStoreLeadCurrQVecFreqPtr_;
293  Teuchos::RCP<Linear::BlockVector> bLeadCurrentVecFreqPtr_;
294  Teuchos::RCP<Linear::BlockVector> bLeadCurrentQVecFreqPtr_;
295 
296  // DFT Interface
297  Teuchos::RCP<N_UTL_DFTInterfaceDecl<std::vector<double> > > dftInterface_;
298 };
299 
300 } // namespace Loader
301 } // namespace Xyce
302 
303 #endif // Xyce_LOA_HBLoader_H
HBLoader(const Teuchos::RCP< const N_MPDE_Discretization > discPtr, Device::DeviceMgr &device_manager, Linear::Builder &builder)
Teuchos::RCP< Linear::Vector > appLastStaVecPtr_
virtual void setVoltageLimiterStatus(bool voltageLimterStatus)
virtual bool analyticSensitivitiesAvailable(std::string &name)
Teuchos::RCP< Linear::Vector > appCurrStoVecPtr_
Teuchos::RCP< Linear::BlockMatrix > bmdFdxPtr_
Linear::Builder & builder_
Teuchos::RCP< Linear::Matrix > & getStoreLindQdx()
std::vector< double > periodicTimes_
virtual bool initializeProblem(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *StateDerivVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr, Linear::Vector *QVectorPtr, Linear::Vector *FVectorPtr, Linear::Vector *BVectorPtr, Linear::Vector *dFdxdVpVectorPtr, Linear::Vector *dQdxdVpVectorPtr) const
Pure virtual class to augment a linear system.
void registerDFTInterface(const Teuchos::RCP< N_UTL_DFTInterfaceDecl< std::vector< double > > > &dftInterface)
void setFastTimes(const std::vector< double > &times)
bool updateState(Linear::Vector *nextSolVectorPtr, Linear::Vector *currSolVectorPtr, Linear::Vector *lastSolVectorPtr, Linear::Vector *nextStaVectorPtr, Linear::Vector *currStaVectorPtr, Linear::Vector *lastStaVectorPtr, Linear::Vector *nextStoVectorPtr, Linear::Vector *currStoVectorPtr, Linear::Vector *lastStoVectorPtr)
Device::DeviceMgr & deviceManager_
void permutedIFT(const Linear::BlockVector &xf, Linear::BlockVector *xt, int numTimePts_=0)
bool loadDAEMatrices(Linear::Vector *X, Linear::Vector *S, Linear::Vector *dSdt, Linear::Vector *Store, Linear::Matrix *dQdx, Linear::Matrix *dFdx)
Teuchos::RCP< Loader > appLoaderPtr_
Actually a CktLoader.
Teuchos::RCP< const N_MPDE_Discretization > fastTimeDiscPtr_
Teuchos::RCP< Linear::Matrix > appdQdxPtr_
Teuchos::RCP< Linear::Vector > appStoLeadCurrQVecPtr_
std::vector< Teuchos::RCP< Linear::Matrix > > & getStoreNLdFdx()
void permutedFFT(const Linear::BlockVector &xt, Linear::BlockVector *xf)
Teuchos::RCP< Linear::Vector > appCurrStaVecPtr_
Teuchos::RCP< Linear::HBBuilder > hbBuilderPtr_
virtual void getAnalyticSensitivities(std::string &name, std::vector< double > &dfdpVec, std::vector< double > &dqdpVec, std::vector< double > &dbdpVec, std::vector< int > &FindicesVec, std::vector< int > &QindicesVec, std::vector< int > &BindicesVec) const
void setMatrixFreeFlag(bool matrixFreeFlag)
Teuchos::RCP< Linear::Matrix > linAppdFdxPtr_
Teuchos::RCP< Linear::Vector > appCurrLeadFVecPtr_
Teuchos::RCP< Linear::BlockVector > bXtPtr_
Teuchos::RCP< Linear::Matrix > & getStoreLindFdx()
Teuchos::RCP< Linear::BlockVector > bLeadCurrentVecFreqPtr_
Teuchos::RCP< Linear::BlockVector > & getLeadCurrentVecFreqPtr()
Teuchos::RCP< Linear::BlockVector > bStoreVecFreqPtr_
Teuchos::RCP< Linear::BlockVector > bVtPtr_
Teuchos::RCP< Linear::Vector > appNextJunctionVVecPtr_
virtual double getParamAndReduce(Parallel::Machine comm, const std::string &name) const
Teuchos::RCP< Linear::BlockVector > bStoreLeadCurrQVecFreqPtr_
Teuchos::RCP< Linear::BlockMatrix > bmdQdxPtr_
bool applyLinearMatrices(const Linear::BlockVector &bVf, Linear::BlockVector &permlindQdxV, Linear::BlockVector &permlindFdxV)
void setHBFreqs(const std::vector< double > &freqs)
void registerHBBuilder(Teuchos::RCP< Linear::HBBuilder > hbBuilderPtr)
virtual bool getVoltageLimiterStatus()
Teuchos::RCP< N_UTL_DFTInterfaceDecl< std::vector< double > > > dftInterface_
Teuchos::RCP< Linear::Vector > appLeadQVecPtr_
std::vector< Teuchos::RCP< Linear::Matrix > > vecNLAppdQdxPtr_
Teuchos::RCP< Linear::BlockVector > & getStoreVecFreqPtr()
Teuchos::RCP< Linear::Vector > appLastLeadFVecPtr_
bool loadTimeDepDAEMatrices(Linear::Vector *X, Linear::Vector *S, Linear::Vector *dSdt, Linear::Vector *Store, Linear::Matrix *dQdx, Linear::Matrix *dFdx)
Teuchos::RCP< Linear::Matrix > appdFdxPtr_
bool applyDAEMatrices(Linear::Vector *X, Linear::Vector *S, Linear::Vector *dSdt, Linear::Vector *Store, const Linear::Vector &V, Linear::Vector *dQdxV, Linear::Vector *dFdxV)
std::vector< double > times_
Teuchos::RCP< Linear::Vector > appLastStoVecPtr_
std::vector< Teuchos::RCP< Linear::Matrix > > & getStoreNLdQdx()
std::vector< Teuchos::RCP< Linear::Matrix > > vecNLAppdFdxPtr_
Teuchos::RCP< Linear::BlockVector > bLeadCurrentQVecFreqPtr_
Teuchos::RCP< Linear::Vector > appNextLeadFVecPtr_
virtual bool setParam(std::string &name, double val, bool overrideOriginal=false)
Teuchos::RCP< Linear::Vector > appLastJunctionVVecPtr_
std::vector< double > freqs_
Teuchos::RCP< Linear::Vector > appVecPtr_
Teuchos::RCP< Linear::Matrix > linAppdQdxPtr_
bool loadDAEVectors(Linear::Vector *X, Linear::Vector *currX, Linear::Vector *lastX, Linear::Vector *S, Linear::Vector *currS, Linear::Vector *lastS, Linear::Vector *dSdt, Linear::Vector *Store, Linear::Vector *currStore, Linear::Vector *lastStore, Linear::Vector *storeLeadCurrQ, Linear::Vector *nextLeadFVectorPtr, Linear::Vector *currLeadFVectorPtr, Linear::Vector *lastLeadFVectorPtr, Linear::Vector *nextLeadQVectorPtr, Linear::Vector *nextJunctionVVectorPtr, Linear::Vector *currJunctionVVectorPtr, Linear::Vector *lastJunctionVVectorPtr, Linear::Vector *Q, Linear::Vector *F, Linear::Vector *B, Linear::Vector *dFdxdVp, Linear::Vector *dQdxdVp)
Teuchos::RCP< Linear::Vector > appCurrJunctionVVecPtr_
Teuchos::RCP< Linear::Vector > appNextStoVecPtr_
void registerAppLoader(Teuchos::RCP< Loader > appLoaderPtr)
Teuchos::RCP< Linear::Vector > appNextStaVecPtr_
bool loadDeviceErrorWeightMask(Linear::Vector *deviceMask) const