Xyce  6.1
N_DEV_DAC.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_DAC.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_DAC_h
47 #define Xyce_N_DEV_DAC_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 DAC{
62 
63 class Model;
64 class Instance;
65 
66 struct Traits : public DeviceTraits<Model, Instance>
67 {
68  static const char *name() {return "DAC";}
69  static const char *deviceTypeName() {return "YDAC level 1 (Digital to Analog 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 DAC 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;friend class Master;
92 
93 public:
94 
95  Instance(
96  const Configuration & configuration,
97  const InstanceBlock & IB,
98  Model & DACiter,
99  const FactoryBlock & factory_block);
100 
101 
102  ~Instance();
103 
104 private:
105  Instance(const Instance &);
106  Instance &operator=(const Instance &);
107 
108 public:
109  // Additional Public Declarations
110  void registerLIDs( const std::vector<int> & intLIDVecRef,
111  const std::vector<int> & extLIDVecRef );
112  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
113 
114  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
115 
116  const std::vector< std::vector<int> > & jacobianStamp() const;
117  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
118 
119  bool processParams ();
120 
121  bool updateIntermediateVars ();
122  bool updatePrimaryState ();
123  bool updateSecondaryState ();
124 
125  bool updateTVVEC ( std::vector< std::pair<double, double> > const & newPairs );
126  bool getInstanceBreakPoints (std::vector<Util::BreakPoint> &breakPointTimes);
127 
129  bool setInternalState( const DeviceState & state );
130 
131  // iterator reference to the model which owns this instance.
132  // Getters and setters
134  {
135  return model_;
136  }
137 
138 public:
139 
140  bool loadDAEQVector () {return true;};
141  bool loadDAEFVector ();
142 
143  bool loadDAEdQdx () {return true;};
144  bool loadDAEdFdx ();
145 
146  void varTypes( std::vector<char> & varTypeVec );
147 
148 private:
149 
150  bool updateVoltage(double);
151 
152 private:
153  static std::vector< std::vector<int> > jacStamp;
154 
155  Model & model_; //< Owning model
156 
157  // user-specified parameters:
158  std::string file; // User specified file containing DAC data as time and
159  //voltage pairs.
160 
161  std::vector< std::pair<double, double> > TVVEC; // vector of (time, voltage) pairs
162  // read in from "file".
163 
164  // state variables:
165 
166  // other variables:
167  int numTVpairs_; // number of (time, voltage) pairs in TVVEC
168  double v_pos;
169  double v_neg;
170  double i_bra;
171  double vDrop;
172  double voltage_;
173  int loc_;
174 
175  // Indices into the state vector:
176 
177 
178 
179  //local indices (offsets)
180  int li_Pos;
181  int li_Neg;
182  int li_Bra;
183 
184  //Locally indexed offsets for jacobian
185  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
186  // branch current equ.
187 
188  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
189  // branch current equ.
190 
191  int APosEquBraVarOffset; // Offset, branch current variable
192  // contribution, KCL equation of the pos node
193 
194  int ANegEquBraVarOffset; // Offset, branch current variable
195  // contribution, KCL equation of the neg node
196 };
197 
198 //----------------------------------------------------------------------------
199 // Function : Model
200 // Purpose :
201 // Special Notes :
202 // Creator : Lon Waters
203 // Creation Date : 07/26/2002
204 //----------------------------------------------------------------------------
205 class Model : public DeviceModel
206 {
207  typedef std::vector<Instance *> InstanceVector;
208 
209  friend class ParametricData<Model>;
210  friend class Instance;
211  friend class Traits;friend class Master;
212 
213 public:
214  Model(
215  const Configuration & configuration,
216  const ModelBlock & MB,
217  const FactoryBlock & factory_block);
218  ~Model();
219 
220 private:
221  Model();
222  Model(const Model &);
223  Model &operator=(const Model &);
224 
225 public:
226  bool processParams ();
227  bool processInstanceParams ();
228  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
229 
230  virtual std::ostream &printOutInstances(std::ostream &os) const;
231 
232 private:
233 
234  // Model Parameters
235  double riseTime;
236  double fallTime;
237  double R;
238  double L;
239  double C;
241 
242  // Data Members for Associations
243 
244 public:
245  void addInstance(Instance *instance)
246  {
247  instanceContainer.push_back(instance);
248  }
249 
250 private:
251  std::vector<Instance*> instanceContainer;
252 };
253 
254 //-----------------------------------------------------------------------------
255 // Class : Master
256 // Purpose :
257 // Special Notes :
258 // Creator : Richard Schiek, Electrical and Microsystems modeling
259 // Creation Date : 02/25/2009
260 //-----------------------------------------------------------------------------
261 class Master : public DeviceMaster<Traits>
262 {
263  friend class Instance;
264  friend class Model;
265  friend class Traits;
266 
267 public:
269  const Configuration & configuration,
270  const FactoryBlock & factory_block,
271  const SolverState & ss1,
272  const DeviceOptions & do1)
273  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
274  {}
275 
276  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
277  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
278 
279  // load functions:
280  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
281  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
282 };
283 
284 void registerDevice();
285 
286 } // namespace DAC
287 } // namespace Device
288 } // namespace Xyce
289 
290 #endif
static void loadModelParameters(ParametricData< Model > &model_parameters)
Definition: N_DEV_DAC.C:86
bool updateTVVEC(std::vector< std::pair< double, double > > const &newPairs)
Definition: N_DEV_DAC.C:377
bool updateVoltage(double)
Definition: N_DEV_DAC.C:508
std::vector< std::pair< double, double > > TVVEC
Definition: N_DEV_DAC.h:161
bool setInternalState(const DeviceState &state)
Definition: N_DEV_DAC.C:716
std::vector< Instance * > instanceContainer
Definition: N_DEV_DAC.h:251
bool processInstanceParams()
processInstanceParams
Definition: N_DEV_DAC.C:780
Pure virtual class to augment a linear system.
bool getInstanceBreakPoints(std::vector< Util::BreakPoint > &breakPointTimes)
Definition: N_DEV_DAC.C:629
static const char * deviceTypeName()
Definition: N_DEV_DAC.h:69
static std::vector< std::vector< int > > jacStamp
Definition: N_DEV_DAC.h:153
Instance & operator=(const Instance &)
virtual bool updateSecondaryState(double *staDeriv, double *stoVec)
Updates the devices secondary state information.
Definition: N_DEV_DAC.C:953
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
Definition: N_DEV_DAC.C:915
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Definition: N_DEV_DAC.C:267
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_DAC.C:966
DeviceMaster instantiates a device as described by the device traits T.
Model & operator=(const Model &)
bool processParams()
processParams
Definition: N_DEV_DAC.C:767
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
static int numNodes()
Definition: N_DEV_DAC.h:70
static const char * name()
Definition: N_DEV_DAC.h:68
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
Definition: N_DEV_DAC.C:897
std::vector< Instance * > InstanceVector
Definition: N_DEV_DAC.h:207
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &DACiter, const FactoryBlock &factory_block)
Definition: N_DEV_DAC.C:143
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Definition: N_DEV_DAC.C:1007
Class Configuration contains device configuration data.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
Definition: N_DEV_DAC.h:268
const std::vector< std::vector< int > > & jacobianStamp() const
Definition: N_DEV_DAC.C:293
static bool isLinearDevice()
Definition: N_DEV_DAC.h:71
DeviceState * getInternalState()
Definition: N_DEV_DAC.C:687
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
Definition: N_DEV_DAC.C:280
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
Definition: N_DEV_DAC.C:76
void addInstance(Instance *instance)
Definition: N_DEV_DAC.h:245
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Definition: N_DEV_DAC.C:219
void varTypes(std::vector< char > &varTypeVec)
Definition: N_DEV_DAC.C:753
ModelBlock represents a .MODEL line from the netlist.
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Definition: N_DEV_DAC.C:306
The DeviceTraits template describes the configuration of a device.
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Definition: N_DEV_DAC.C:990
virtual std::ostream & printOutInstances(std::ostream &os) const
Definition: N_DEV_DAC.C:860
void registerDevice()
Definition: N_DEV_DAC.C:1013