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