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.56.2.3 $
40 //
41 // Revision Date : $Date: 2014/03/12 16:50:27 $
42 //
43 // Current Owner : $Author: dgbaur $
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 const int numNodes() {return 2;}
69  static const int numOptionalNodes() {return 20;}
70  static const bool modelRequired() {return true;}
71  static const 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 & IB,
105  Model & Diter,
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  // Used to support U vs. Y syntax
142  std::string getDeviceLetter ();
143 
144 public:
145  // iterator reference to the model which owns this instance.
146  // Getters and setters
148  return model_;
149  }
150 
151 private:
152 
153  Model & model_; //< Owning model
154 
155  // Data Members for Class Attributes
156  // For more explanation of these attributes
157  // see the resistor classes.
158 
159  // state variables:
160 
161  std::vector<double> qlo; // charge in the capacitor
162  std::vector<double> ilo; // current throught the capacitor
163  std::vector<double> vcaplo; // voltage drop across capacitor
164  std::vector<double> qhi;
165  std::vector<double> ihi;
166  std::vector<double> vcaphi;
167  std::vector<double> qref;
168  std::vector<double> iref;
169  std::vector<double> vcapref;
170 
171  std::vector<double> rilo;
172  std::vector<double> rihi;
173  std::vector<double> riref;
174  std::vector<double> currentOut;
175  std::vector<double> currentIn;
176 
177  std::vector<double> glo;
178  std::vector<double> ghi;
179 
180  std::vector<double> qInp; // charge in the capacitor
181  std::vector<double> iInp; // current throught the capacitor
182  std::vector<double> vcapInp; // voltage drop across capacitor
183 
184  std::vector<double> currentInp;
185 
186  // input params:
187 
188  bool ic1;
189  bool ic2;
190  bool ic3;
191 
192  int numInput; // Number of input leads
193  int numOutput; // Number of output leads
194  enum gType gate;
195 
196  //local id's (offsets)
197  int li_Lo;
198  int li_Hi;
199  int li_Ref;
200  std::vector<int> li_Inp;
201  std::vector<int> li_Out;
202 
203  // Input state vars
204  std::vector<int> li_currentStateInp;
205  std::vector<int> li_transitionTimeInp;
206  std::vector<int> li_QinpState;
207  std::vector<int> li_IinpState;
208 
209  // Output state vars
210  std::vector<int> li_currentStateOut;
211  std::vector<int> li_transitionTimeOut;
212  std::vector<int> li_QloState;
213  std::vector<int> li_IloState;
214  std::vector<int> li_QhiState;
215  std::vector<int> li_IhiState;
216 
217  std::vector<bool> inpL;
218  std::vector<double> iTime;
219  std::vector<bool> outL;
220  std::vector<double> oTime;
221 
222  double breakTime;
223 
224  // Offsets for Jacobian
225  int row_Lo;
226  int row_Hi;
227  int row_Ref;
228  std::vector< std::vector<int> > li_jac_Ref;
229  std::vector< std::vector<int> > li_jac_Lo;
230  std::vector< std::vector<int> > li_jac_Hi;
231 
232  std::vector< std::vector<int> > jacStamp;
233 
234  //Genie 110812. change state var
235  //std::vector<bool> changeState;
236 };
237 
238 //-----------------------------------------------------------------------------
239 // Class : Model
240 // Purpose :
241 // Special Notes :
242 // Creator : Dave Shirley, PSSI
243 // Creation Date : 01/05/06
244 //-----------------------------------------------------------------------------
245 class Model : public DeviceModel
246 {
247  typedef std::vector<Instance *> InstanceVector;
248 
249  friend class ParametricData<Model>;
250  friend class Instance;
251  friend class Traits;friend class Master;
252 
253 public:
254  Model(
255  const Configuration & configuration,
256  const ModelBlock & MB,
257  const FactoryBlock & factory_block);
258  ~Model ();
259 
260 private:
261  Model();
262  Model(const Model &);
263  Model &operator=(const Model &);
264 
265 public:
266  bool processParams ();
267  bool processInstanceParams ();
268  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
269 
270  virtual std::ostream &printOutInstances(std::ostream &os) const;
271 
272 public:
273  void addInstance(Instance *instance) {
274  instanceContainer.push_back(instance);
275  }
276 
278  return instanceContainer;
279  }
280 
282  return instanceContainer;
283  }
284 
285 private:
286  std::vector<Instance*> instanceContainer;
287 
288 private:
289 
290  // Input Parameters
291  double vlo;
292  double vhi;
293  double vref;
294  double clo;
295  double chi;
296  double cload;
297  double rload;
298  double s0rlo;
299  double s0rhi;
300  double s0tsw;
301  double s0vlo;
302  double s0vhi;
303  double s1rlo;
304  double s1rhi;
305  double s1tsw;
306  double s1vlo;
307  double s1vhi;
308  double delay;
309 
310  // Dependent Parameters
311 
312  double gload;
313 };
314 
315 
316 //-----------------------------------------------------------------------------
317 // Class : Master
318 // Purpose :
319 // Special Notes :
320 // Creator : Genie Hsieh, SNL, Parallel Computational Sciences
321 // Creation Date : 10/23/12
322 //-----------------------------------------------------------------------------
323 class Master : public DeviceMaster<Traits>
324 {
325  friend class Instance;
326  friend class Model;
327 
328  public:
330  std::vector< std::pair<std::string,double> > & parNames,
331  const Configuration & configuration,
332  const FactoryBlock & factory_block,
333  const SolverState & ss1,
334  const DeviceOptions & do1)
335  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
336  {}
337 
338  // Genie 110812. For now override nothing and use the template functions of the following
339  // from DeviceMaster.h
340  /*virtual bool updateState (double * solVec, double * staVec) ;
341  virtual bool updateSecondaryState (double * staDeriv);
342 
343  // load functions:
344  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
345  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
346  */
347 
348 };
349 
350 void registerDevice();
351 
352 } // namespace Digital
353 } // namespace Device
354 } // namespace Xyce
355 
359 
360 #endif