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/02/26 20:16:30 $
42 //
43 // Current Owner : $Author: tvrusso $
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 const int numNodes() {return 2;}
73  static const 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 //----------------------------------------------------------------------------
90 {
91  friend class ParametricData<Instance>;
92  friend class Model;
93  friend class Traits;friend class Master;
94 
95 public:
96 
97  Instance(
98  const Configuration & configuration,
99  const InstanceBlock & IB,
100  Model & ADCiter,
101  const FactoryBlock & factory_block);
102 
103  Instance(const Instance &right);
104 
105  ~Instance();
106 
107  // Additional Public Declarations
108  void registerLIDs( const std::vector<int> & intLIDVecRef,
109  const std::vector<int> & extLIDVecRef );
110  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
111 
112  const std::vector< std::vector<int> > & jacobianStamp() const;
113  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
114 
115  bool processParams ();
116 
117  bool updateIntermediateVars ();
118  bool updatePrimaryState ();
119  bool updateSecondaryState ();
120 
121  void getTVVEC(std::vector< std::pair<double, double> > & TVVVEC_Out);
122  void trimTVVEC(double earliestTime);
123  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
124  void acceptStep();
125 
126  bool getInstanceParamsMap(std::map<std::string,double>& paramsMap);
127  int getNumberQuantLevels();
128  bool setBitVectorWidth(int width);
129 
130  // iterator reference to the model which owns this instance.
131  // Getters and setters
133  {
134  return model_;
135  }
136 
137 private:
138  Model & model_; //< Owning model
139 
140 public:
141 
142  bool loadDAEQVector () {return true;};
143  bool loadDAEFVector ();
144 
145  bool loadDAEdQdx () {return true;};
146  bool loadDAEdFdx ();
147 
148 private:
149  static std::vector< std::vector<int> > jacStamp;
150 
151  // parameters:
152  double R;
153 
154  // derived parameters:
155  double G; // conductance (1.0/ohms)
156  double i0; // current (amps)
157  double v_pos, v_neg;
158 
159  // state variables:
160 
161  // other variables:
162  std::vector< std::pair<double, double> > TVVEC;
163  int outputBitVectorWidth_; // number of bits on digital side
164  int nQuantLevels_; // 2^(outputBitVectorWidth_)
165  int lastOutputLevel_; // save last value, so we know when we're going
166  // to cause a change
167 
168  // Indices into the state vector:
169 
170  //local indices (offsets)
171  int li_Pos;
172  int li_Neg;
173 
174  //Locally indexed offsets for jacobian
179 };
180 
181 //----------------------------------------------------------------------------
182 // Function : Model
183 // Purpose :
184 // Special Notes :
185 // Creator : Lon Waters
186 // Creation Date : 07/26/2002
187 //----------------------------------------------------------------------------
188 class Model : public DeviceModel
189 {
190  typedef std::vector<Instance *> InstanceVector;
191 
192  friend class ParametricData<Model>;
193  friend class Instance;
194  friend class Traits;friend class Master;
195 
196 public:
197  Model(
198  const Configuration & configuration,
199  const ModelBlock & MB,
200  const FactoryBlock & factory_block);
201  ~Model();
202 
203 private:
204  Model();
205  Model(const Model &);
206  Model &operator=(const Model &);
207 
208 public:
209  bool processParams ();
210  bool processInstanceParams ();
211  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
212 
213  virtual std::ostream &printOutInstances(std::ostream &os) const;
214 
215 private:
216  // Model Parameters
220 
221  // Data Members for Associations
222 
223 public:
224  void addInstance(Instance *instance)
225  {
226  instanceContainer.push_back(instance);
227  }
228 
230  {
231  return instanceContainer;
232  }
233 
235  {
236  return instanceContainer;
237  }
238 
239 private:
240  std::vector<Instance*> instanceContainer;
241 };
242 
243 //-----------------------------------------------------------------------------
244 // Class : Master
245 // Purpose :
246 // Special Notes :
247 // Creator : Richard Schiek, Electrical and Microsystems modeling
248 // Creation Date : 02/25/2009
249 //-----------------------------------------------------------------------------
250 class Master : public DeviceMaster<Traits>
251 {
252  friend class Instance;
253  friend class Model;
254 
255 public:
257  const Configuration & configuration,
258  const FactoryBlock & factory_block,
259  const SolverState & ss1,
260  const DeviceOptions & do1)
261  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
262  {}
263 
264  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
265  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
266 
267  // load functions:
268  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ);
269  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
270 
271  bool getBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
272  bool getADCMap(std::map<std::string,std::map<std::string,double> >& ADCMap);
273  bool getTimeVoltagePairs( std::map<std::string,std::vector<std::pair<double,double> > >& tvvmap);
274 };
275 
276 //-----------------------------------------------------------------------------
277 // Function : Instance::getNumberQuantLevels
278 // Purpose : return number of possible quantization levels of an ADC
279 // Special Notes : Assumes that width has already been set!
280 // Scope : public
281 // Creator : Tom Russo, SNL, Component Information and Models
282 // Creation Date : 05/07/2004
283 //-----------------------------------------------------------------------------
284 
286 {
287  return nQuantLevels_;
288 }
289 
290 void registerDevice();
291 
292 } // namespace ADC
293 } // namespace Device
294 } // namespace Xyce
295 
299 
300 #endif