Xyce  6.1
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-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_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: 2015/04/02 18:20:10 $
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_UTL_fwd.h>
51 
52 #include <N_DEV_Configuration.h>
53 #include <N_DEV_DeviceBlock.h>
54 #include <N_DEV_DeviceInstance.h>
55 #include <N_DEV_DeviceMaster.h>
56 #include <N_DEV_DeviceModel.h>
57 #include <N_DEV_Param.h>
58 
59 namespace Xyce {
60 namespace Device {
61 namespace ADC {
62 
63 class Model;
64 class Instance;
65 
66 struct Traits : public DeviceTraits<Model, Instance>
67 {
68  static const char *name() {return "ADC";}
69  static const char *deviceTypeName() {return "YADC level 1 (Analog to Digital Interface)";};
70  static int numNodes() {return 2;}
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 the ADC device.
81 // It contains indices into the matrix equation. See comments
82 // for the ResistorInstance class for more details.
83 // Special Notes :
84 // Creator : Lon Waters
85 // Creation Date : 07/26/2002
86 //----------------------------------------------------------------------------
87 class Instance : public DeviceInstance
88 {
89  friend class ParametricData<Instance>;
90  friend class Model;
91  friend class Traits;
92  friend class Master;
93  friend class DeviceInstanceOp;
94 
95 public:
96  Instance(
97  const Configuration & configuration,
98  const InstanceBlock & instance_block,
99  Model & model,
100  const FactoryBlock & factory_block);
101 
102  Instance(const Instance &right);
103 
104  ~Instance();
105 
106  // Additional Public Declarations
107  void registerLIDs( const std::vector<int> & intLIDVecRef,
108  const std::vector<int> & extLIDVecRef );
109  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
110 
111  const std::vector< std::vector<int> > & jacobianStamp() const;
112  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
113 
114  virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
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<Util::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, double * leadF, double * leadQ, double * junctionV);
264  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
265 
266  bool getBreakPoints (std::vector<Util::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 
289 #endif
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Definition: N_DEV_ADC.C:121
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_ADC.h:158
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_ADC.C:268
static const char * name()
Definition: N_DEV_ADC.h:68
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_ADC.C:81
virtual void forEachInstance(DeviceInstanceOp &op) const
Definition: N_DEV_ADC.C:748
Pure virtual class to augment a linear system.
void getTVVEC(std::vector< std::pair< double, double > > &TVVVEC_Out)
Definition: N_DEV_ADC.C:343
void registerDevice()
Definition: N_DEV_ADC.C:866
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_ADC.C:604
static const char * deviceTypeName()
Definition: N_DEV_ADC.h:69
static int numNodes()
Definition: N_DEV_ADC.h:70
bool getInstanceBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_ADC.C:445
std::vector< Instance * > InstanceVector
Definition: N_DEV_ADC.h:201
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_ADC.C:74
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_ADC.C:860
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
Definition: N_DEV_ADC.h:251
bool getInstanceParamsMap(std::map< std::string, double > &paramsMap)
Definition: N_DEV_ADC.C:631
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_ADC.C:726
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_ADC.C:821
DeviceMaster instantiates a device as described by the device traits T.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
static bool isLinearDevice()
Definition: N_DEV_ADC.h:71
std::vector< std::pair< double, double > > TVVEC
Definition: N_DEV_ADC.h:169
void addInstance(Instance *instance)
Definition: N_DEV_ADC.h:229
std::vector< Instance * > instanceContainer
Definition: N_DEV_ADC.h:235
bool getBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_ADC.C:846
bool processParams()
processParams
Definition: N_DEV_ADC.C:591
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_ADC.C:255
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Definition: N_DEV_ADC.C:786
Class Configuration contains device configuration data.
bool setBitVectorWidth(int width)
Definition: N_DEV_ADC.C:650
void trimTVVEC(double earliestTime)
Definition: N_DEV_ADC.C:363
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_ADC.C:284
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_ADC.C:764
Model & operator=(const Model &)
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_ADC.C:242
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 registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_ADC.C:199
InstanceBlock represent a device instance line from the netlist.
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Populates the device's ExternData object with these pointers.
Definition: N_DEV_ADC.C:799