Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Resistor.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_Resistor.h,v $
27 //
28 // Purpose :
29 //
30 // Special Notes :
31 //
32 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
33 //
34 // Creation Date : 02/28/00
35 //
36 // Revision Information:
37 // ---------------------
38 //
39 // Revision Number: $Revision: 1.111.2.5 $
40 //
41 // Revision Date : $Date: 2014/03/06 02:55:06 $
42 //
43 // Current Owner : $Author: tvrusso $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Resistor_h
47 #define Xyce_N_DEV_Resistor_h
48 
49 #include <N_DEV_fwd.h>
50 #include <N_DEV_Configuration.h>
51 #include <N_DEV_DeviceInstance.h>
52 #include <N_DEV_DeviceModel.h>
53 #include <N_DEV_DeviceMaster.h>
54 
55 namespace Xyce {
56 namespace Device {
57 namespace Resistor {
58 
59 class Model;
60 class Instance;
61 
62 struct Traits : public DeviceTraits<Model, Instance>
63 {
64  static const char *name() {return "Resistor";}
65  static const char *deviceTypeName() {return "R level 1";}
66  static const int numNodes() {return 2;}
67  static const char *primaryParameter() {return "R";}
68  static const char *instanceDefaultParameter() {return "R";}
69  static const bool isLinearDevice() {return true;}
70 
71  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
74 };
75 
76 //-----------------------------------------------------------------------------
77 // Class : Xyce::Device::Resistor::Instance
78 // Purpose :
79 // Special Notes :
80 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
81 // Creation Date : 3/16/00
82 //-----------------------------------------------------------------------------
83 ///
84 /// Resistor device instance class.
85 ///
86 /// An instance is created for each occurance of the device in the netlist.
87 ///
88 /// It contains "unique" resistor information - ie stuff that will be
89 /// true of only one resistor in the circuit, such as the nodes to
90 /// which it is connected. A resistor is connected to only two
91 /// circuit nodes.
92 ///
93 /// This class does not directly contain information about its node
94 /// indices. It contains indices into the 5 parts (dFdx, dQdx, dx, F,
95 /// and Q) of the matrix problem A*dx = b, and also the solution
96 /// vector x. A is the Jacobian matrix that will be formed from dFdx
97 /// and d(dQ/dt)dx, dx is the update to x, and b is right hand side
98 /// function vector that will be formed from F and dQ/dt. These
99 /// indices are global, and determined by topology during the
100 /// initialization stage of execution.
101 ///
102 class Instance : public DeviceInstance
103 {
104  friend class ParametricData<Instance>; ///< Allow ParametricData to changes member values
105  friend class Model;
106  friend class Traits;
107  friend class Master;
108 
109 public:
110  Instance(
111  const Configuration & configuration,
112  const InstanceBlock & instance_block,
113  Model & model,
114  const FactoryBlock & factory_block);
115 
116  //---------------------------------------------------------------------------
117  // Function : Xyce::Device::Resistor::Instance::~Instance
118  // Purpose : destructor
119  // Special Notes :
120  // Scope : public
121  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
122  // Creation Date : 3/16/00
123  //---------------------------------------------------------------------------
124  ///
125  /// Destroys this instance
126  ///
127  /// @author Eric Keiter, SNL
128  /// @date 3/16/00
130 
131 private:
132  Instance(const Instance &);
133  Instance &operator=(const Instance &);
134 
135 public:
136 
137  //---------------------------------------------------------------------------
138  // Function : Xyce::Device::Resistor::Instance::getModel
139  // Purpose : destructor
140  // Special Notes :
141  // Scope : public
142  // Creator : Eric Keiter, SNL, Parallel Computational Sciences
143  // Creation Date : 3/16/00
144  //---------------------------------------------------------------------------
145  ///
146  /// Gets the resistor model that owns this instance.
147  ///
148  /// @return reference to the owning Resistor::Model
149  ///
150  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
151  /// @date Mon Aug 12 08:36:37 2013
152  Model &getModel() { return model_; }
153 
154  virtual void registerLIDs(const std::vector<int> & intLIDVecRef, const std::vector<int> & extLIDVecRef) /* override */;
155  virtual void registerStateLIDs(const std::vector<int> & staLIDVecRef) /* override */;
156  virtual void registerStoreLIDs(const std::vector<int> & stoLIDVecRef) /* override */;
157  virtual void registerJacLIDs(const std::vector< std::vector<int> > & jacLIDVec) /* override */;
158  virtual std::map<int, std::string> &getStoreNameMap() /* override */;
159 
160  virtual bool processParams() /* override */;
161  virtual bool updateTemperature(const double & temp_tmp) /* override */;
162  virtual bool updateIntermediateVars() /* override */;
163  virtual bool updatePrimaryState() /* override */;
164 
165  //---------------------------------------------------------------------------
166  // Function : Xyce::Device::Resistor::Instance::jacobianStamp
167  // Purpose :
168  // Special Notes :
169  // Scope : public
170  // Creator : Robert Hoekstra, SNL, Parallel Computational Sciences
171  // Creation Date : 08/20/01
172  //---------------------------------------------------------------------------
173  ///
174  /// Return Jacobian stamp that informs topology of the layout of the
175  /// resistor jacobian.
176  ///
177  /// The Jacobian stamp describes the shape of the Jacobian to the
178  /// Topology subsystem. The Topology subsystem, in turn, returns
179  /// the offsets into the matrix and solution vectors where this
180  /// instance data is located.
181  ///
182  /// @return const reference to a std::vector of std::vector of
183  /// integers describing Jacobian stamp shape
184  ///
185  /// @author Robert Hoekstra
186  /// @date 8/20/2001
187  virtual const std::vector< std::vector<int> > &jacobianStamp() const /* override */ {
188  return jacStamp;
189  }
190 
191  virtual bool loadDAEFVector() /* override */;
192  virtual bool loadDAEdFdx() /* override */;
193 
194  //---------------------------------------------------------------------------
195  // Function : Xyce::Device::Resistor::Instance::loadDAEQVector
196  // Purpose :
197  // Special Notes :
198  // Scope : public
199  // Creator : Eric Keiter
200  // Creation Date : 1/24/03
201  //---------------------------------------------------------------------------
202  ///
203  /// Load Q vector
204  ///
205  /// @return true on success
206  ///
207  /// Since the Resistor does no charge storage, this is a no-op.
208  ///
209  /// @author Eric Keiter
210  /// @date 1/24/03
211  virtual bool loadDAEQVector() /* override */
212  {
213  return true;
214  }
215 
216  //---------------------------------------------------------------------------
217  // Function : Xyce::Device::Resistor::Instance::loadDAEdQdx
218  // Purpose :
219  // Special Notes :
220  // Scope : public
221  // Creator : Eric Keiter
222  // Creation Date : 1/24/03
223  //---------------------------------------------------------------------------
224  ///
225  /// Load derivative of Q vector with respect to solution vector
226  ///
227  /// @return true on success
228  ///
229  /// Since the Resistor does no charge storage, this is a no-op.
230  ///
231  /// @author Eric Keiter
232  /// @date 1/24/03
233  virtual bool loadDAEdQdx() /* override */
234  {
235  return true;
236  }
237 
238  virtual void setupPointers() /* override */;
239 
240 private:
241  static std::vector< std::vector<int> > jacStamp; ///< All Resistor instances have a common Jacobian Stamp
242  static void initializeJacobianStamp();
243 
244  Model & model_; ///< Owning model
245 
246  // User-specified parameters:
247  double R; ///< Resistance (ohms)
248 
249  // These are for the semiconductor resistor
250  double length; ///< Resistor length.
251  double width; ///< Resistor width.
252  double temp; ///< Temperature of this instance
253 
254  // Temperature dependence parameters, these can override values specified in the model
255  double tempCoeff1; ///< First order temperature coeff.
256  double tempCoeff2; ///< Second order temperature coeff.
257  double dtemp; ///< Externally specified device temperature.
258  ///< NOT used, only here for compatibility in parsing
259  ///< netlist from simulators that support it
260 
261  // Flags used to tell if the user has specified one of these values on the command line.
262  bool tempCoeff1Given; ///< First order temperation value was given in netlist
263  bool tempCoeff2Given; ///< Second order temperature coeff was given in netlist
264  bool dtempGiven; ///< Externally specified device temperature was given in netlist
265 
266  // Derived parameters:
267  double G; ///< Conductance(1.0/ohms)
268  double i0; ///< Current(ohms)
269 
270  int li_Pos; ///< Index for Positive Node
271  int li_Neg; ///< Index for Negative Node
272  int li_store_dev_i; ///< Index for Lead Current
273 
274  // Offset variables corresponding to the above declared indices.
275  int APosEquPosNodeOffset; ///< Column index into force matrix of Pos/Pos conductance
276  int APosEquNegNodeOffset; ///< Column index into force matrix of Pos/Neg conductance
277  int ANegEquPosNodeOffset; ///< Column index into force matrix of Neg/Pos conductance
278  int ANegEquNegNodeOffset; ///< Column index into force matrix of Neg/Neg conductance
279 
280 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
281  // Pointers for Jacobian
286 #endif
287 };
288 
289 
290 //-----------------------------------------------------------------------------
291 // Class : Xyce::Device::Resistor::Model
292 // Purpose :
293 // Special Notes :
294 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
295 // Creation Date : 3/16/00
296 //-----------------------------------------------------------------------------
297 ///
298 /// Resistor model class
299 ///
300 class Model : public DeviceModel
301 {
302  friend class ParametricData<Model>; ///< Allow ParametricData to changes member values
303  friend class Instance; ///< Don't force a lot of pointless getters
304  friend class Traits;
305  friend class Master; ///< Don't force a lot of pointless getters
306 
307 public:
308  typedef std::vector<Instance *> InstanceVector;
309 
310  Model(
311  const Configuration & configuration,
312  const ModelBlock & model_block,
313  const FactoryBlock & factory_block);
314  ~Model();
315 
316 private:
317  Model();
318  Model(const Model &);
319  Model &operator=(const Model &);
320 
321 public:
322 
323  //---------------------------------------------------------------------------
324  // Function : Xyce::Device::Resistor::Model::addInstance
325  // Purpose :
326  // Special Notes :
327  // Scope : public
328  // Creator : David Baur
329  // Creation Date : 8/12/2013
330  //---------------------------------------------------------------------------
331  ///
332  /// Add an instance to the list of instances associated with this model
333  ///
334  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
335  /// @date 8/12/2013
336  void addInstance(Instance *instance)
337  {
338  instanceContainer.push_back(instance);
339  }
340 
341  //---------------------------------------------------------------------------
342  // Function : Xyce::Device::Resistor::Model::getInstanceVector
343  // Purpose :
344  // Special Notes :
345  // Scope : public
346  // Creator : David Baur
347  // Creation Date : 8/12/2013
348  //---------------------------------------------------------------------------
349  ///
350  /// Get a non-const reference to the vector for all resistor
351  /// instances owned by this model.
352  ///
353  /// @return reference to InstanceVector containing all resistors owned by this model
354  ///
355  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
356  /// @date 8/12/2013
358  {
359  return instanceContainer;
360  }
361 
362  //---------------------------------------------------------------------------
363  // Function : Xyce::Device::Resistor::Model::getInstanceVector
364  // Purpose :
365  // Special Notes :
366  // Scope : public
367  // Creator : David Baur
368  // Creation Date : 8/12/2013
369  //---------------------------------------------------------------------------
370  ///
371  /// Get a const reference to the instance vector for all resistors
372  /// owned by this model.
373  ///
374  /// @return const reference to InstanceVector containing all resistors owned by this model
375  ///
376  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
377  /// @date Mon Aug 12 09:10:00 2013
379  {
380  return instanceContainer;
381  }
382 
383  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
384 
385  virtual std::ostream &printOutInstances(std::ostream &os) const;
386 
387  virtual bool processParams() /* override */;
388  virtual bool processInstanceParams() /* override */;
389 
390 private:
391  InstanceVector instanceContainer; ///< List of owned resistor instances
392 
393  // Semiconductor resistor parameters
394  double tempCoeff1; ///< First order temperature coefficient
395  double tempCoeff2; ///< Second order temperature coefficient
396  double sheetRes; ///< Sheet resistance
397  double defWidth; ///< Default width
398  double narrow; ///< Narrowing due to side etching
399  double tnom; ///< Parameter measurement temperature
400 };
401 
402 
403 //-----------------------------------------------------------------------------
404 // Class : Xyce::Device::Resistor::Master
405 // Purpose :
406 // Special Notes :
407 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
408 // Creation Date : 11/26/08
409 //-----------------------------------------------------------------------------
410 ///
411 /// Resistor master
412 ///
413 /// The "master" class is the one that contains the updateState, loadDAEVectors
414 /// and loadDAEMatrices methods that are actually called when it is time to
415 /// compute and load device contributions.
416 ///
417 /// The default implementations of these methods in the DeviceMaster
418 /// template class simply loops over all instances and calls their
419 /// updatePrimaryState, loadDAEFVector/loadDAEQVector, and
420 /// loadDAEdFdx/loadDAEdQdx methods, respectively.
421 ///
422 /// For efficiency, the Resistor class reimplements these methods to do the
423 /// work directly, instead of calling instance-level functions.
424 ///
425 class Master : public DeviceMaster<Traits>
426 {
427  friend class Instance; ///< Don't force a lot of pointless getters
428  friend class Model; ///< Don't force a lot of pointless getters
429 
430 public:
431 
432  //---------------------------------------------------------------------------
433  // Function : Xyce::Device::Resistor::Master::Master
434  // Purpose :
435  // Special Notes :
436  // Scope : public
437  // Creator : Eric Keiter
438  // Creation Date : 11/26/08
439  //---------------------------------------------------------------------------
440  ///
441  /// Construct a Resistor Device.
442  ///
443  /// @param configuration
444  /// @param factory_block
445  /// @param solver_state
446  /// @param device_options
448  const Configuration & configuration,
449  const FactoryBlock & factory_block,
450  const SolverState & solver_state,
451  const DeviceOptions & device_options)
452  : DeviceMaster<Traits>(configuration, factory_block, solver_state, device_options)
453  {}
454 
455  virtual bool updateState(double * solVec, double * staVec, double * stoVec) /* override */;
456  virtual bool loadDAEVectors(double * solVec, double * fVec, double * qVec, double * storeLeadF, double * storeLeadQ) /* override */;
457  virtual bool loadDAEMatrices(N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx) /* override */;
458 };
459 
460 void registerDevice();
461 
462 } // namespace Resistor
463 } // namespace Device
464 } // namespace Xyce
465 
469 
470 #endif // Xyce_N_DEV_Resistor_h