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.163.2.1 $
40 //
41 // Revision Date : $Date: 2014/08/25 20:12:49 $
42 //
43 // Current Owner : $Author: dgbaur $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_DeviceInterface_h
47 #define Xyce_N_DEV_DeviceInterface_h
48 
49 #include <map>
50 #include <set>
51 #include <string>
52 #include <vector>
53 
54 #include <N_DEV_fwd.h>
55 #include <N_IO_fwd.h>
56 #include <N_PDS_fwd.h>
57 #include <N_UTL_fwd.h>
58 #include <N_ANP_fwd.h>
59 #include <N_NLS_fwd.h>
60 
61 class N_LAS_Matrix;
62 class N_LAS_System;
63 class N_LAS_Vector;
65 
66 namespace Xyce {
67 namespace Device {
68 
69 //-----------------------------------------------------------------------------
70 // Class : N_DEV_DeviceInterface
71 // Purpose :
72 // Special Notes :
73 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
74 // Creation Date : 3/05/02
75 //-----------------------------------------------------------------------------
76 
78 {
79  // functions:
80 public:
81  static DeviceInterface * factory(N_IO_CmdParse & cp);
82 
84 
85  // registration functions:
86  bool registerLinearSystem(N_LAS_System * tmp_system_ptr);
87 
88  bool registerAnalysisManager (N_ANP_AnalysisManager * tmp_anaIntPtr);
89 
90  bool registerOutputMgr(N_IO_OutputMgr * tmp_outputMgrPtr);
91  bool registerMeasureMgr(N_IO_MeasureMgr * tmp_outputMgrPtr);
92  bool registerParallelMgr(N_PDS_Manager * tmp_pdsMgrPtr);
93 
94  bool registerNonlinearSolver (Nonlinear::Manager * tmp_nlsMgrPtr);
95 
96  bool registerOptions(const Util::OptionBlock & OB);
97 
98  bool registerSensParams (const Util::OptionBlock & OB);
99 
100  bool registerICLoads( std::vector<std::pair<int,double> > * icLoads );
101 
102  bool registerPkgOptionsMgr( N_IO_PkgOptionsMgr *pkgOptPtr );
103 
104  // this function is called from the output manager to inform the
105  // device package of the devices for which lead currents have been requested.
106  // The device manager will take care of doing isolated F and Q loads
107  // for these devices so the lead currents can be calculated
108  bool setLeadCurrentRequests( const std::set<std::string> & deviceNames );
109 
110  // MPDE registrations
111  std::vector<double> getFastSourcePeriod (std::vector<std::string>& sourceNames);
112  std::vector<double> registerFastSources (std::vector<std::string> & sourceNames);
113  void deRegisterFastSources (std::vector<std::string> & sourceNames);
114  void deactivateSlowSources();
115  void activateSlowSources();
116 
117  void setMPDEFlag( bool flagVal );
118  void setBlockAnalysisFlag( bool flagVal );
119  void setFastTime( double timeVal );
120 
121  // Initialization function, to be called after all registrations are
122  // finished, and the linear system class is completely set up.
123  bool initializeAll();
124 
125  // Device accessor functions:
126  bool addDeviceModel(const ModelBlock & MB);
127 
129 
131 
132  bool deleteDeviceInstance (const std::string & name);
133 
134  const std::map<std::string,int> & getDeviceCountMap ();
135  void addDeviceToCount(const std::string & device_name, int num_devs = 1);
136  void addDevicesToCount(const std::map<std::string,int> & device_map);
137 
138  // void printOutLists();
139 
140  bool output ();
141  bool finishOutput ();
142 
143  void dotOpOutput ();
144 
145  // needed for parallel only:
146  void setGlobalFlags ();
147 
148  // Load functions:
149  bool loadDeviceMask();
150  bool setInitialGuess (N_LAS_Vector * solVectorPtr);
151 
153  std::string & name,
154  std::vector<double> & dfdpVec,
155  std::vector<double> & dqdpVec,
156  std::vector<double> & dbdpVec,
157  std::vector<int> & FindicesVec,
158  std::vector<int> & QindicesVec,
159  std::vector<int> & BindicesVec
160  );
161 
162  bool analyticSensitivitiesAvailable (std::string & name);
163  bool setParam(std::string & name, double val);
164  double getParamAndReduce(const std::string & name);
165  bool getParamAndReduce(const std::string & name, double & val);
166  double getParamNoReduce(const std::string & name) const;
167  bool findParam(const std::string & name) const;
168 
169  bool updateSources();
170 
171  DeviceEntity *getDeviceEntity(const std::string &full_param_name) const;
172  EntityTypeId getModelGroup(const std::string &model_type_name);
173 
174  bool getLinearSystemFlag ();
175  bool getVoltageLimiterFlag ();
176  bool getPDESystemFlag ();
177 
178  // setup initial conditions on devices
179  bool setICs (N_LAS_Vector * tmpSolVectorPtr,
180  N_LAS_Vector * tmpCurrSolVectorPtr,
181  N_LAS_Vector * tmpLastSolVectorPtr,
182  N_LAS_Vector * tmpStaVectorPtr,
183  N_LAS_Vector * tmpCurrStaVectorPtr,
184  N_LAS_Vector * tmpLasStaVectorPtr,
185  N_LAS_Vector * tmpStaDerivVectorPtr,
186  N_LAS_Vector * tmpStoVectorPtr,
187  N_LAS_Vector * tmpCurrStoVectorPtr,
188  N_LAS_Vector * tmpLasStoVectorPtr,
189  N_LAS_Vector * tmpQVectorPtr,
190  N_LAS_Vector * tmpFVectorPtr,
191  N_LAS_Vector * tmpBVectorPtr,
192  N_LAS_Vector * tmpdFdxdVpVectorPtr,
193  N_LAS_Vector * tmpdQdxdVpVectorPtr);
194 
195  // time integration stuff:
196  bool getBreakPoints ( std::vector<N_UTL_BreakPoint> & breakPointTimes );
197  double getMaxTimeStepSize ();
198 
199  // Generic API calls (currently used only by Xygra)
200  Device *getDevice(EntityTypeId model_type_id);
201 
202  // Two-level Newton and PDE-Continuation
203  int enablePDEContinuation ();
204  bool disablePDEContinuation ();
205  void getNumInterfaceNodes (std::vector<int> & numINodes);
206  bool loadCouplingRHS (int iPDEDevice, int iElectrode, N_LAS_Vector * dfdvPtr);
207  bool calcCouplingTerms (int iSubProblem, int iElectrode, const N_LAS_Vector * dxdvPtr);
208  bool raiseDebugLevel (int increment);
209 
210  // load functions:
211  bool loadDAEMatrices (N_LAS_Vector * tmpSolVectorPtr,
212  N_LAS_Vector * tmpStaVectorPtr,
213  N_LAS_Vector * tmpStaDerivVectorPtr,
214  N_LAS_Vector * tmpStoVectorPtr,
215  N_LAS_Matrix * tmpdQdxMatrixPtr,
216  N_LAS_Matrix * tmpdFdxMatrixPtr);
217 
218  bool loadDAEVectors (N_LAS_Vector * tmpSolVectorPtr,
219  N_LAS_Vector * tmpCurrSolVectorPtr,
220  N_LAS_Vector * tmpLastSolVectorPtr,
221  N_LAS_Vector * tmpStaVectorPtr,
222  N_LAS_Vector * tmpCurrStaVectorPtr,
223  N_LAS_Vector * tmpLasStaVectorPtr,
224  N_LAS_Vector * tmpStaDerivVectorPtr,
225  N_LAS_Vector * tmpStoVectorPtr,
226  N_LAS_Vector * tmpCurrStoVectorPtr,
227  N_LAS_Vector * tmpLasStoVectorPtr,
228  N_LAS_Vector * tmpStoLeadCurrQCompVectorPtr,
229  N_LAS_Vector * tmpQVectorPtr,
230  N_LAS_Vector * tmpFVectorPtr,
231  N_LAS_Vector * tmpBVectorPtr,
232  N_LAS_Vector * tmpdFdxdVpVectorPtr,
233  N_LAS_Vector * tmpdQdxdVpVectorPtr);
234 
235  bool updateState
236  (N_LAS_Vector * nextSolVectorPtr,
237  N_LAS_Vector * currSolVectorPtr,
238  N_LAS_Vector * lastSolVectorPtr,
239  N_LAS_Vector * nextStaVectorPtr,
240  N_LAS_Vector * currStaVectorPtr,
241  N_LAS_Vector * lastStaVectorPtr,
242  N_LAS_Vector * nextStoVectorPtr,
243  N_LAS_Vector * currStoVectorPtr,
244  N_LAS_Vector * lastStoVectorPtr
245  );
246 
247  bool loadBVectorsforAC (N_LAS_Vector * bVecRealPtr,
248  N_LAS_Vector * bVecImagPtr);
249 
250  bool getBMatrixEntriesforMOR(std::vector<int>& bMatEntriesVec, std::vector<int>& bMatPosEntriesVec);
251 
252  // voltlim doesn't work with MPDE, but does work for DCOP and the
253  // various initial conditions used in MPDE. Hence the need for these
254  // functions.
255  // void setVoltageLimiterFlag ();
256  void unsetVoltageLimiterFlag ();
257 
258  void setVoltageLimiterFlag (bool flagVal);
259 
260  int getHomotopyBlockSize() const;
261 
262  void addGlobalPar (const Util::Param &);
263  const double *findGlobalPar( const std::string & parName) const;
264  double getGlobalPar( const std::string & parName ) const;
265 
266  // For convergence testing
267  bool allDevsConverged();
268 
269  // For 2-level, need inner "solve" convergence.
270  bool innerDevsConverged();
271 
272  // Functions needed for power node (2-level) algorithm):
273  void setupExternalDevices();
274 
276  (const std::vector<std::string> & paramNames,
277  const std::vector<double> & paramVals);
278 
279  void homotopyStepFailure ();
280 
281  void stepSuccess(Analysis::CurrentMode analysis);
282  void stepFailure(Analysis::CurrentMode analysis);
283 
284  void acceptStep();
285 
286  bool getInitialQnorm (std::vector<N_TIA_TwoLevelError> & tleVec );
287  bool getInnerLoopErrorSums (std::vector <N_TIA_TwoLevelError> & tleVec);
288 
289  bool updateStateArrays();
290  bool startTimeStep ();
291  void setExternalSolverState (const SolverState & ss);
292 
293  void updateSolverState ();
294 
295  int restartDataSize(bool pack);
296 
297  // Output restart data.
298  bool dumpRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack );
299 
300  // Load restart data.
301  bool restoreRestartData(char * buf, int bsize, int & pos, N_PDS_Comm * comm, bool pack );
302 
303 protected:
304 
305 private:
306  DeviceInterface(N_IO_CmdParse & cp);
307  DeviceInterface(const DeviceInterface &right);
308 
309 
310 public:
311 
312 protected:
313 
314 private:
316 };
317 
318 } // namespace Device
319 } // namespace Xyce
320 
322 
323 #endif
324