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