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