Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_ADC.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_ADC.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Lon Waters
33 //
34 // Creation Date : 07/26/2002
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revsion$
40 //
41 // Revsion Date : $Date: 2014/05/22 17:40:28 $
42 //
43 // Current Owner : $Author: erkeite $
44 //----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_ADC_h
47 #define Xyce_N_DEV_ADC_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 
53 #include <N_DEV_DeviceBlock.h>
54 #include <N_DEV_DeviceInstance.h>
55 #include <N_DEV_DeviceModel.h>
56 
57 #include <N_DEV_Param.h>
58 #include <N_UTL_BreakPoint.h>
59 
60 
61 namespace Xyce {
62 namespace Device {
63 namespace ADC {
64 
65 class Model;
66 class Instance;
67 
68 struct Traits : public DeviceTraits<Model, Instance>
69 {
70  static const char *name() {return "ADC";}
71  static const char *deviceTypeName() {return "YADC level 1 (Analog to Digital Interface)";};
72  static int numNodes() {return 2;}
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 the ADC device.
83 // It contains indices into the matrix equation. See comments
84 // for the ResistorInstance class for more details.
85 // Special Notes :
86 // Creator : Lon Waters
87 // Creation Date : 07/26/2002
88 //----------------------------------------------------------------------------
89 class Instance : public DeviceInstance
90 {
91  friend class ParametricData<Instance>;
92  friend class Model;
93  friend class Traits;
94  friend class Master;
95  friend class DeviceInstanceOp;
96 
97 public:
98  Instance(
99  const Configuration & configuration,
100  const InstanceBlock & instance_block,
101  Model & model,
102  const FactoryBlock & factory_block);
103 
104  Instance(const Instance &right);
105 
106  ~Instance();
107 
108  // Additional Public Declarations
109  void registerLIDs( const std::vector<int> & intLIDVecRef,
110  const std::vector<int> & extLIDVecRef );
111  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
112 
113  const std::vector< std::vector<int> > & jacobianStamp() const;
114  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
115 
116  bool processParams ();
117 
118  bool updateIntermediateVars ();
119  bool updatePrimaryState ();
120  bool updateSecondaryState ();
121 
122  void getTVVEC(std::vector< std::pair<double, double> > & TVVVEC_Out);
123  void trimTVVEC(double earliestTime);
124  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
125  void acceptStep();
126 
127  bool getInstanceParamsMap(std::map<std::string,double>& paramsMap);
128  int getNumberQuantLevels();
129  bool setBitVectorWidth(int width);
130 
131  // iterator reference to the model which owns this instance.
132  // Getters and setters
134  {
135  return model_;
136  }
137 
138 private:
139  Model & model_; //< Owning model
140 
141 public:
142 
143  bool loadDAEQVector () {return true;};
144  bool loadDAEFVector ();
145 
146  bool loadDAEdQdx () {return true;};
147  bool loadDAEdFdx ();
148 
149  int getLIPos() const {
150  return li_Pos;
151  }
152 
153  int getLINeg() const {
154  return li_Neg;
155  }
156 
157 private:
158  static std::vector< std::vector<int> > jacStamp;
159 
160  // parameters:
161  double R;
162 
163  // derived parameters:
164  double G; // conductance (1.0/ohms)
165  double i0; // current (amps)
166  double v_pos, v_neg;
167 
168  // other variables:
169  std::vector< std::pair<double, double> > TVVEC;
170  int outputBitVectorWidth_; // number of bits on digital side
171  int nQuantLevels_; // 2^(outputBitVectorWidth_)
172  int lastOutputLevel_; // save last value, so we know when we're going to cause a change
173 
174  // Indices into the state vector:
175 
176  //local indices (offsets)
177  int li_Pos;
178  int li_Neg;
179 
180  //Locally indexed offsets for jacobian
185 };
186 
187 //----------------------------------------------------------------------------
188 // Function : Model
189 // Purpose :
190 // Special Notes :
191 // Creator : Lon Waters
192 // Creation Date : 07/26/2002
193 //----------------------------------------------------------------------------
194 class Model : public DeviceModel
195 {
196  friend class ParametricData<Model>;
197  friend class Instance;
198  friend class Traits;
199  friend class Master;
200 
201  typedef std::vector<Instance *> InstanceVector;
202 
203 public:
204  Model(
205  const Configuration & configuration,
206  const ModelBlock & model_block,
207  const FactoryBlock & factory_block);
208  ~Model();
209 
210 private:
211  Model();
212  Model(const Model &);
213  Model &operator=(const Model &);
214 
215 public:
216  bool processParams ();
217  bool processInstanceParams ();
218  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
219 
220  virtual std::ostream &printOutInstances(std::ostream &os) const;
221 
222 private:
223  // Model Parameters
227 
228 public:
229  void addInstance(Instance *instance)
230  {
231  instanceContainer.push_back(instance);
232  }
233 
234 private:
235  std::vector<Instance*> instanceContainer;
236 };
237 
238 //-----------------------------------------------------------------------------
239 // Class : Master
240 // Purpose :
241 // Special Notes :
242 // Creator : Richard Schiek, Electrical and Microsystems modeling
243 // Creation Date : 02/25/2009
244 //-----------------------------------------------------------------------------
245 class Master : public DeviceMaster<Traits>
246 {
247  friend class Instance;
248  friend class Model;
249 
250 public:
252  const Configuration & configuration,
253  const FactoryBlock & factory_block,
254  const SolverState & ss1,
255  const DeviceOptions & do1)
256  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
257  {}
258 
259  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
260  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
261 
262  // load functions:
263  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
264  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
265 
266  bool getBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
267 };
268 
269 //-----------------------------------------------------------------------------
270 // Function : Instance::getNumberQuantLevels
271 // Purpose : return number of possible quantization levels of an ADC
272 // Special Notes : Assumes that width has already been set!
273 // Scope : public
274 // Creator : Tom Russo, SNL, Component Information and Models
275 // Creation Date : 05/07/2004
276 //-----------------------------------------------------------------------------
277 
279 {
280  return nQuantLevels_;
281 }
282 
283 void registerDevice();
284 
285 } // namespace ADC
286 } // namespace Device
287 } // namespace Xyce
288 
292 
293 #endif