Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Digital.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_Digital.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Dave Shirley, PSSI
33 //
34 // Creation Date : 01/05/06
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.62 $
40 //
41 // Revision Date : $Date: 2014/08/06 14:54:05 $
42 //
43 // Current Owner : $Author: peshola $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Digital_h
47 #define Xyce_N_DEV_Digital_h
48 
49 // ---------- Xyce Includes ----------
50 //Genie 110812
51 #include <N_DEV_Configuration.h>
52 #include <N_DEV_DeviceMaster.h>
53 #include <N_DEV_DeviceBlock.h>
54 #include <N_DEV_DeviceInstance.h>
55 #include <N_DEV_DeviceModel.h>
56 
57 namespace Xyce {
58 namespace Device {
59 namespace Digital {
60 
61 class Model;
62 class Instance; //Genie 110812
63 
64 struct Traits : public DeviceTraits<Model, Instance>
65 {
66  static const char *name() {return "Behavioral Digital";}
67  static const char *deviceTypeName() {return "Digital level 1";}
68  static int numNodes() {return 2;}
69  static int numOptionalNodes() {return 20;}
70  static bool modelRequired() {return true;}
71  static bool isLinearDevice() {return true;}
72 
73  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
74  static void loadModelParameters(ParametricData<Model> &model_parameters);
75  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
76 };
77 
78 //-----------------------------------------------------------------------------
79 // Class : Instance
80 // Purpose : This class refers to a single instance of a digital
81 // device. It contains indicies into the matrix equation.
82 // See the comments for the ResistorInstance class for
83 // more details.
84 //
85 // Special Notes :
86 // Creator : Dave Shirley, PSSI
87 // Creation Date : 01/05/06
88 //-----------------------------------------------------------------------------
89 
90 class Instance : public DeviceInstance
91 {
92  friend class ParametricData<Instance>;
93  friend class Model;
94  friend class Traits;
95  friend class Master;
96 
97  // NOT is deprecated now, and replaced by INV.
98  enum gType {INV, NOT, AND, NAND, OR, NOR, ADD, XOR, NXOR, DFF, DLTCH, BUF};
99 
100 public:
101 
102  Instance(
103  const Configuration & configuration,
104  const InstanceBlock & instance_block,
105  Model & model,
106  const FactoryBlock & factory_block);
107 
108 
109  ~Instance();
110 
111 private:
112  Instance(const Instance &);
113  Instance &operator=(const Instance &);
114 
115 public:
116  // Additional Public Declarations
117  void registerLIDs( const std::vector<int> & intLIDVecRef,
118  const std::vector<int> & extLIDVecRef );
119  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
120 
121  std::map<int,std::string> & getIntNameMap ();
122 
123  const std::vector< std::vector<int> > & jacobianStamp() const;
124  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
125 
126  bool processParams ();
127 
128  bool updateIntermediateVars () { return true; };
129  bool updatePrimaryState ();
130  bool updateSecondaryState ();
131  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &);
132 
133  // load functions, residual:
134  bool loadDAEQVector ();
135  bool loadDAEFVector ();
136 
137  // load functions, Jacobian:
138  bool loadDAEdQdx ();
139  bool loadDAEdFdx ();
140 
141  // added for debug. Allows tracking of digital device transitions since
142  // acceptStep() is only executed after a time-step is accepted by time integration
143  void acceptStep();
144 
145 public:
146  // iterator reference to the model which owns this instance.
147  // Getters and setters
149  return model_;
150  }
151 
152 private:
153 
154  Model & model_; //< Owning model
155 
156  // Data Members for Class Attributes
157  // For more explanation of these attributes
158  // see the resistor classes.
159 
160  // state variables:
161 
162  std::vector<double> qlo; // charge in the capacitor
163  std::vector<double> ilo; // current throught the capacitor
164  std::vector<double> vcaplo; // voltage drop across capacitor
165  std::vector<double> qhi;
166  std::vector<double> ihi;
167  std::vector<double> vcaphi;
168  std::vector<double> qref;
169  std::vector<double> iref;
170  std::vector<double> vcapref;
171 
172  std::vector<double> rilo;
173  std::vector<double> rihi;
174  std::vector<double> riref;
175  std::vector<double> currentOut;
176  std::vector<double> currentIn;
177 
178  std::vector<double> glo;
179  std::vector<double> ghi;
180 
181  std::vector<double> qInp; // charge in the capacitor
182  std::vector<double> iInp; // current throught the capacitor
183  std::vector<double> vcapInp; // voltage drop across capacitor
184 
185  std::vector<double> currentInp;
186 
187  // input params:
188 
189  bool ic1;
190  bool ic2;
191  bool ic3;
192 
193  int numInput; // Number of input leads
194  int numOutput; // Number of output leads
195  enum gType gate;
196 
197  //local id's (offsets)
198  int li_Lo;
199  int li_Hi;
200  int li_Ref;
201  std::vector<int> li_Inp;
202  std::vector<int> li_Out;
203 
204  // Input state vars
205  std::vector<int> li_currentStateInp;
206  std::vector<int> li_transitionTimeInp;
207  std::vector<int> li_QinpState;
208  std::vector<int> li_IinpState;
209 
210  // Output state vars
211  std::vector<int> li_currentStateOut;
212  std::vector<int> li_transitionTimeOut;
213  std::vector<int> li_QloState;
214  std::vector<int> li_IloState;
215  std::vector<int> li_QhiState;
216  std::vector<int> li_IhiState;
217 
218  std::vector<bool> inpL;
219  std::vector<double> iTime;
220  std::vector<bool> outL;
221  std::vector<double> oTime;
222 
223  double breakTime;
224 
225  // Offsets for Jacobian
226  int row_Lo;
227  int row_Hi;
228  int row_Ref;
229  std::vector< std::vector<int> > li_jac_Ref;
230  std::vector< std::vector<int> > li_jac_Lo;
231  std::vector< std::vector<int> > li_jac_Hi;
232 
233  std::vector< std::vector<int> > jacStamp;
234 
235  // added for debug purposes. Allows for tracking of input state changes
238 
239  //Genie 110812. change state var
240  //std::vector<bool> changeState;
241 };
242 
243 //-----------------------------------------------------------------------------
244 // Class : Model
245 // Purpose :
246 // Special Notes :
247 // Creator : Dave Shirley, PSSI
248 // Creation Date : 01/05/06
249 //-----------------------------------------------------------------------------
250 class Model : public DeviceModel
251 {
252  typedef std::vector<Instance *> InstanceVector;
253 
254  friend class ParametricData<Model>;
255  friend class Instance;
256  friend class Traits;friend class Master;
257 
258 public:
259  Model(
260  const Configuration & configuration,
261  const ModelBlock & MB,
262  const FactoryBlock & factory_block);
263  ~Model ();
264 
265 private:
266  Model();
267  Model(const Model &);
268  Model &operator=(const Model &);
269 
270 public:
271  bool processParams ();
272  bool processInstanceParams ();
273  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
274 
275  virtual std::ostream &printOutInstances(std::ostream &os) const;
276 
277 public:
278  void addInstance(Instance *instance) {
279  instanceContainer.push_back(instance);
280  }
281 
282 private:
283  std::vector<Instance*> instanceContainer;
284 
285 private:
286 
287  // Input Parameters
288  double vlo;
289  double vhi;
290  double vref;
291  double clo;
292  double chi;
293  double cload;
294  double rload;
295  double s0rlo;
296  double s0rhi;
297  double s0tsw;
298  double s0vlo;
299  double s0vhi;
300  double s1rlo;
301  double s1rhi;
302  double s1tsw;
303  double s1vlo;
304  double s1vhi;
305  double delay;
306 
307  // Dependent Parameters
308 
309  double gload;
310 };
311 
312 
313 //-----------------------------------------------------------------------------
314 // Class : Master
315 // Purpose :
316 // Special Notes :
317 // Creator : Genie Hsieh, SNL, Parallel Computational Sciences
318 // Creation Date : 10/23/12
319 //-----------------------------------------------------------------------------
320 class Master : public DeviceMaster<Traits>
321 {
322  friend class Instance;
323  friend class Model;
324 
325  public:
327  std::vector< std::pair<std::string,double> > & parNames,
328  const Configuration & configuration,
329  const FactoryBlock & factory_block,
330  const SolverState & ss1,
331  const DeviceOptions & do1)
332  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
333  {}
334 
335  // Genie 110812. For now override nothing and use the template functions of the following
336  // from DeviceMaster.h
337  /*virtual bool updateState (double * solVec, double * staVec) ;
338  virtual bool updateSecondaryState (double * staDeriv);
339 
340  // load functions:
341  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
342  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
343  */
344 
345 };
346 
347 void registerDevice();
348 
349 } // namespace Digital
350 } // namespace Device
351 } // namespace Xyce
352 
356 
357 #endif