Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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-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_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: 2014/05/22 17:40:28 $
42 //
43 // Current Owner : $Author: erkeite $
44 //----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_DAC_h
47 #define Xyce_N_DEV_DAC_h
48 
49 // ---------- Xyce Includes ----------
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceMaster.h>
52 #include <N_DEV_DeviceBlock.h>
53 #include <N_DEV_DeviceInstance.h>
54 #include <N_DEV_DeviceModel.h>
55 
56 #include <N_DEV_Param.h>
57 #include <N_UTL_BreakPoint.h>
58 
59 // ---------- Forward Declarations ----------
60 
61 namespace Xyce {
62 namespace Device {
63 namespace DAC{
64 
65 class Model;
66 class Instance;
67 
68 struct Traits : public DeviceTraits<Model, Instance>
69 {
70  static const char *name() {return "DAC";}
71  static const char *deviceTypeName() {return "YDAC level 1 (Digital to Analog 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 DAC 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;friend class Master;
94 
95 public:
96 
97  Instance(
98  const Configuration & configuration,
99  const InstanceBlock & IB,
100  Model & DACiter,
101  const FactoryBlock & factory_block);
102 
103 
104  ~Instance();
105 
106 private:
107  Instance(const Instance &);
108  Instance &operator=(const Instance &);
109 
110 public:
111  // Additional Public Declarations
112  void registerLIDs( const std::vector<int> & intLIDVecRef,
113  const std::vector<int> & extLIDVecRef );
114  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
115  std::map<int,std::string> & getIntNameMap ();
116 
117  const std::vector< std::vector<int> > & jacobianStamp() const;
118  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
119 
120  bool processParams ();
121 
122  bool updateIntermediateVars ();
123  bool updatePrimaryState ();
124  bool updateSecondaryState ();
125 
126  bool updateTVVEC ( std::vector< std::pair<double, double> > const & newPairs );
127  bool getInstanceBreakPoints (std::vector<N_UTL_BreakPoint> &breakPointTimes);
128 
130  bool setInternalState( const DeviceState & state );
131 
132  // iterator reference to the model which owns this instance.
133  // Getters and setters
135  {
136  return model_;
137  }
138 
139 public:
140 
141  bool loadDAEQVector () {return true;};
142  bool loadDAEFVector ();
143 
144  bool loadDAEdQdx () {return true;};
145  bool loadDAEdFdx ();
146 
147  void varTypes( std::vector<char> & varTypeVec );
148 
149 private:
150 
151  bool updateVoltage(double);
152 
153 private:
154  static std::vector< std::vector<int> > jacStamp;
155 
156  Model & model_; //< Owning model
157 
158  // user-specified parameters:
159  std::string file; // User specified file containing DAC data as time and
160  //voltage pairs.
161 
162  std::vector< std::pair<double, double> > TVVEC; // vector of (time, voltage) pairs
163  // read in from "file".
164 
165  // state variables:
166 
167  // other variables:
168  int numTVpairs_; // number of (time, voltage) pairs in TVVEC
169  double v_pos;
170  double v_neg;
171  double i_bra;
172  double vDrop;
173  double voltage_;
174  int loc_;
175 
176  // Indices into the state vector:
177 
178 
179 
180  //local indices (offsets)
181  int li_Pos;
182  int li_Neg;
183  int li_Bra;
184 
185  //Locally indexed offsets for jacobian
186  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
187  // branch current equ.
188 
189  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
190  // branch current equ.
191 
192  int APosEquBraVarOffset; // Offset, branch current variable
193  // contribution, KCL equation of the pos node
194 
195  int ANegEquBraVarOffset; // Offset, branch current variable
196  // contribution, KCL equation of the neg node
197 };
198 
199 //----------------------------------------------------------------------------
200 // Function : Model
201 // Purpose :
202 // Special Notes :
203 // Creator : Lon Waters
204 // Creation Date : 07/26/2002
205 //----------------------------------------------------------------------------
206 class Model : public DeviceModel
207 {
208  typedef std::vector<Instance *> InstanceVector;
209 
210  friend class ParametricData<Model>;
211  friend class Instance;
212  friend class Traits;friend class Master;
213 
214 public:
215  Model(
216  const Configuration & configuration,
217  const ModelBlock & MB,
218  const FactoryBlock & factory_block);
219  ~Model();
220 
221 private:
222  Model();
223  Model(const Model &);
224  Model &operator=(const Model &);
225 
226 public:
227  bool processParams ();
228  bool processInstanceParams ();
229  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
230 
231  virtual std::ostream &printOutInstances(std::ostream &os) const;
232 
233 private:
234 
235  // Model Parameters
236  double riseTime;
237  double fallTime;
238  double R;
239  double L;
240  double C;
242 
243  // Data Members for Associations
244 
245 public:
246  void addInstance(Instance *instance)
247  {
248  instanceContainer.push_back(instance);
249  }
250 
251 private:
252  std::vector<Instance*> instanceContainer;
253 };
254 
255 //-----------------------------------------------------------------------------
256 // Class : Master
257 // Purpose :
258 // Special Notes :
259 // Creator : Richard Schiek, Electrical and Microsystems modeling
260 // Creation Date : 02/25/2009
261 //-----------------------------------------------------------------------------
262 class Master : public DeviceMaster<Traits>
263 {
264  friend class Instance;
265  friend class Model;
266  friend class Traits;
267 
268 public:
270  const Configuration & configuration,
271  const FactoryBlock & factory_block,
272  const SolverState & ss1,
273  const DeviceOptions & do1)
274  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
275  {}
276 
277  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
278  virtual bool updateSecondaryState (double * staDeriv, double * stoVec);
279 
280  // load functions:
281  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
282  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
283 };
284 
285 void registerDevice();
286 
287 } // namespace DAC
288 } // namespace Device
289 } // namespace Xyce
290 
294 
295 #endif