Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_DeviceInterface.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_DEV_DeviceInterface.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 03/05/02
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.145.2.1 $
40 //
41 // Revision Date : $Date: 2014/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_DeviceInterface_h
47 #define Xyce_N_DEV_DeviceInterface_h
48 
49 // ---------- Standard Includes ----------
50 
51 #include <vector>
52 #include <map>
53 #include <string>
54 
55 #include <Teuchos_RefCountPtr.hpp>
56 using Teuchos::RefCountPtr;
57 using Teuchos::rcp;
58 
59 #include <N_DEV_fwd.h>
60 #include <N_IO_fwd.h>
61 #include <N_UTL_fwd.h>
62 #include <N_ANP_fwd.h>
63 
64 #include <N_UTL_Misc.h>
65 #include <N_UTL_BreakPoint.h>
66 #include <N_UTL_Param.h>
67 
68 #include <N_PDS_Manager.h>
69 
71 
72 class N_NLS_Manager;
73 
74 class N_LAS_System;
75 class N_LAS_Vector;
76 class N_LAS_Matrix;
77 
78 class N_MPDE_Manager;
79 
80 namespace Xyce {
81 namespace Device {
82 
83 //-----------------------------------------------------------------------------
84 // Class : N_DEV_DeviceInterface
85 // Purpose :
86 // Special Notes :
87 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
88 // Creation Date : 3/05/02
89 //-----------------------------------------------------------------------------
90 
92 {
93  // functions:
94 public:
95  static DeviceInterface * factory(N_IO_CmdParse & cp);
96 
98 
99  // registration functions:
100  bool registerLinearSystem(N_LAS_System * tmp_system_ptr);
101 
102  bool registerAnalysisInterface (N_ANP_AnalysisInterface * tmp_anaIntPtr);
103 
104  bool registerOutputMgr(N_IO_OutputMgr * tmp_outputMgrPtr);
105 
106  bool registerParallelMgr(N_PDS_Manager * tmp_pdsMgrPtr);
107 
108  bool registerNonlinearSolver (N_NLS_Manager * tmp_nlsMgrPtr);
109 
110  bool registerOptions(const Util::OptionBlock & OB);
111 
112  bool registerSensParams (const Util::OptionBlock & OB);
113 
114  bool registerICLoads( std::vector<std::pair<int,double> > * icLoads );
115 
116  bool registerPkgOptionsMgr( N_IO_PkgOptionsMgr *pkgOptPtr );
117 
118  const EntityTypeIdDeviceMap &getDeviceMap() const;
119 
120  // this function is called from the output manager to inform the
121  // device package of the devices for which lead currents have been requested.
122  // The device manager will take care of doing isolated F and Q loads
123  // for these devices so the lead currents can be calculated
124  bool setLeadCurrentRequests( const std::set<std::string> & deviceNames );
125 
126  // MPDE registrations
127  std::vector<double> getFastSourcePeriod (std::vector<std::string>& sourceNames);
128  std::vector<double> registerFastSources (std::vector<std::string> & sourceNames);
129  void deRegisterFastSources (std::vector<std::string> & sourceNames);
130  void deactivateSlowSources();
131  void activateSlowSources();
132 
133  void setMPDEFlag( bool flagVal );
134  void setBlockAnalysisFlag( bool flagVal );
135  void setFastTime( double timeVal );
136 
137  // Initialization function, to be called after all registrations are
138  // finished, and the linear system class is completely set up.
139  bool initializeAll();
140 
141  void resetForStepAnalysis ();
142 
143  // Device accessor functions:
144  bool addDeviceModel(const ModelBlock & MB);
145 
147 
149 
150  bool deleteDeviceInstance (const std::string & name);
151 
152  const std::map<std::string,int> & getDeviceCountMap ();
153  void addDeviceToCount(const std::string & device_name);
154 
155  // void printOutLists();
156 
157  bool output ();
158  bool finishOutput ();
159 
160  void dotOpOutput ();
161 
162  // needed for parallel only:
163  void setGlobalFlags ();
164 
165  // Load functions:
166  bool loadDeviceMask();
167  bool setInitialGuess (N_LAS_Vector * solVectorPtr);
168 
169  bool setParam(std::string & name, double val);
170  double getParamAndReduce(const std::string & name);
171  bool getParamAndReduce(const std::string & name, double & val);
172  double getParamNoReduce(const std::string & name) const;
173  bool findParam(const std::string & name) const;
174 
175  bool getVsrcLIDs(std::string & srcName, int & li_Pos, int & li_Neg, int & li_Bra);
176 
177  bool updateSources();
178 
180  DeviceEntity *getDeviceEntity(const std::string &param) const;
181 
182  bool getLinearSystemFlag ();
183  bool getVoltageLimiterFlag ();
184  bool getPDESystemFlag ();
185 
186  // setup initial conditions on devices
187  bool setICs (N_LAS_Vector * tmpSolVectorPtr,
188  N_LAS_Vector * tmpCurrSolVectorPtr,
189  N_LAS_Vector * tmpLastSolVectorPtr,
190  N_LAS_Vector * tmpStaVectorPtr,
191  N_LAS_Vector * tmpCurrStaVectorPtr,
192  N_LAS_Vector * tmpLasStaVectorPtr,
193  N_LAS_Vector * tmpStaDerivVectorPtr,
194  N_LAS_Vector * tmpStoVectorPtr,
195  N_LAS_Vector * tmpCurrStoVectorPtr,
196  N_LAS_Vector * tmpLasStoVectorPtr,
197  N_LAS_Vector * tmpQVectorPtr,
198  N_LAS_Vector * tmpFVectorPtr,
199  N_LAS_Vector * tmpdFdxdVpVectorPtr,
200  N_LAS_Vector * tmpdQdxdVpVectorPtr);
201 
202  // Testing functions
203  bool runParameterTests (std::string & deviceName);
204 
205  // time integration stuff:
206  bool getBreakPoints ( std::vector<N_UTL_BreakPoint> & breakPointTimes );
207  double getMaxTimeStepSize ();
208 
209  // Used by mixed signal:
210  bool getDACDeviceNames(std::vector<std::string> & dacNames);
211  bool getADCMap(std::map<std::string,std::map<std::string,double> >& ADCMap);
213  std::map<std::string,std::vector<std::pair<double,double> >* > const & timeVoltageUpdateMap);
214  bool getTimeVoltagePairs(
215  std::map<std::string,std::vector<std::pair<double,double> > > & timeVoltageUpdateMap);
216 
217  bool setADCWidths(std::map<std::string,int> const & ADCWidthMap);
218 
219  // Generic API calls (currently used only by Xygra)
220  bool getDeviceNames(const std::string & deviceType,
221  std::vector<std::string> & deviceNames);
222 
223  int xygraGetNumNodes (const std::string & deviceName);
224  int xygraGetNumWindings (const std::string & deviceName);
225  void xygraGetCoilWindings (const std::string & deviceName,
226  std::vector<int> & cW);
227  void xygraGetCoilNames (const std::string & deviceName,
228  std::vector<std::string> & cN);
229  bool xygraSetConductances (const std::string & deviceName,
230  const std::vector<std::vector<double> > & cM);
231  bool xygraSetK (const std::string & deviceName,
232  const std::vector<std::vector<double> > & kM,
233  const double t=0);
234  bool xygraSetSources (const std::string & deviceName,
235  const std::vector<double> & sV,
236  const double t=0);
237  bool xygraGetVoltages (const std::string & deviceName,
238  std::vector< double > & vN);
239 
240  // Two-level Newton and PDE-Continuation
241  int enablePDEContinuation ();
242  bool disablePDEContinuation ();
243  void getNumInterfaceNodes (std::vector<int> & numINodes);
244  bool loadCouplingRHS (int iPDEDevice, int iElectrode, N_LAS_Vector * dfdvPtr);
245  bool calcCouplingTerms (int iSubProblem, int iElectrode, const N_LAS_Vector * dxdvPtr);
246  bool raiseDebugLevel (int increment);
247 
248  // load functions:
249  bool loadDAEMatrices (N_LAS_Vector * tmpSolVectorPtr,
250  N_LAS_Vector * tmpStaVectorPtr,
251  N_LAS_Vector * tmpStaDerivVectorPtr,
252  N_LAS_Vector * tmpStoVectorPtr,
253  N_LAS_Matrix * tmpdQdxMatrixPtr,
254  N_LAS_Matrix * tmpdFdxMatrixPtr);
255 
256  bool loadDAEVectors (N_LAS_Vector * tmpSolVectorPtr,
257  N_LAS_Vector * tmpCurrSolVectorPtr,
258  N_LAS_Vector * tmpLastSolVectorPtr,
259  N_LAS_Vector * tmpStaVectorPtr,
260  N_LAS_Vector * tmpCurrStaVectorPtr,
261  N_LAS_Vector * tmpLasStaVectorPtr,
262  N_LAS_Vector * tmpStaDerivVectorPtr,
263  N_LAS_Vector * tmpStoVectorPtr,
264  N_LAS_Vector * tmpCurrStoVectorPtr,
265  N_LAS_Vector * tmpLasStoVectorPtr,
266  N_LAS_Vector * tmpStoLeadCurrQCompVectorPtr,
267  N_LAS_Vector * tmpQVectorPtr,
268  N_LAS_Vector * tmpFVectorPtr,
269  N_LAS_Vector * tmpdFdxdVpVectorPtr,
270  N_LAS_Vector * tmpdQdxdVpVectorPtr);
271 
272  bool updateState
273  (N_LAS_Vector * nextSolVectorPtr,
274  N_LAS_Vector * currSolVectorPtr,
275  N_LAS_Vector * lastSolVectorPtr,
276  N_LAS_Vector * nextStaVectorPtr,
277  N_LAS_Vector * currStaVectorPtr,
278  N_LAS_Vector * lastStaVectorPtr,
279  N_LAS_Vector * nextStoVectorPtr,
280  N_LAS_Vector * currStoVectorPtr,
281  N_LAS_Vector * lastStoVectorPtr
282  );
283 
284  bool loadBVectorsforAC (N_LAS_Vector * bVecRealPtr,
285  N_LAS_Vector * bVecImagPtr);
286 
287  bool getBMatrixEntriesforMOR(std::vector<int>& bMatEntriesVec, std::vector<int>& bMatPosEntriesVec);
288 
289  // voltlim doesn't work with MPDE, but does work for DCOP and the
290  // various initial conditions used in MPDE. Hence the need for these
291  // functions.
292  // void setVoltageLimiterFlag ();
293  void unsetVoltageLimiterFlag ();
294 
295  void setVoltageLimiterFlag (bool flagVal);
296 
297  int getHomotopyBlockSize() const;
298 
299  void addGlobalPar (Util::Param &);
300  const double *findGlobalPar( const std::string & parName) const;
301  double getGlobalPar( const std::string & parName ) const;
302 
303  // For convergence testing
304  bool allDevsConverged();
305 
306  // For 2-level, need inner "solve" convergence.
307  bool innerDevsConverged();
308 
309  // Functions needed for power node (2-level) algorithm):
310 #ifdef Xyce_EXTDEV
311  void setupExternalDevices();
312 #endif
313 
315  (const std::vector<std::string> & paramNames,
316  const std::vector<double> & paramVals);
317 
318  void homotopyStepFailure ();
319 
320  void stepSuccess (int analysis);
321  void stepFailure (int analysis);
322 
323  void acceptStep();
324 
325  bool getInitialQnorm (std::vector<N_TIA_TwoLevelError> & tleVec );
326  bool getInnerLoopErrorSums (std::vector <N_TIA_TwoLevelError> & tleVec);
327 
328  bool updateStateArrays();
329  bool startTimeStep ();
330  void setExternalSolverState (const SolverState & ss);
331 
332  void updateSolverState ();
333 
334  int restartDataSize(bool pack);
335 
336  // Output restart data.
337  bool dumpRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack );
338 
339  // Load restart data.
340  bool restoreRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack );
341 
342 protected:
343 
344 private:
345  DeviceInterface(N_IO_CmdParse & cp);
346  DeviceInterface(const DeviceInterface &right);
347 
348 
349 public:
350 
351 protected:
352 
353 private:
355 };
356 
357 } // namespace Device
358 } // namespace Xyce
359 
361 
362 #endif
363