Xyce  6.1
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-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_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.126 $
40 //
41 // Revision Date : $Date: 2015/04/08 19:18:24 $
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  /// Destroys this instance
142 
143 private:
144  Instance(const Instance &);
145  Instance &operator=(const Instance &);
146 
147 public:
148 
149  bool isLinearDevice() const { return true; }
150 
151  /// Gets the resistor model that owns this instance.
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 registerBranchDataLIDs(const std::vector<int> & branchLIDVecRef) /* override */;
158  virtual void registerJacLIDs(const std::vector< std::vector<int> > & jacLIDVec) /* override */;
159 
160  virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
161 
162  virtual bool processParams() /* override */;
163  virtual bool updateTemperature(const double & temp_tmp) /* override */;
164  virtual bool updateIntermediateVars() /* override */;
165  virtual bool updatePrimaryState() /* override */;
166 
167  int getNumNoiseSources () const { return 1; }
168  void setupNoiseSources (Xyce::Analysis::NoiseData & noiseData);
169  void getNoiseSources (Xyce::Analysis::NoiseData & noiseData);
170 
171  /// Return Jacobian stamp that informs topology of the layout of the
172  /// resistor jacobian.
173  virtual const std::vector< std::vector<int> > &jacobianStamp() const /* override */ {
174  return jacStamp;
175  }
176 
177  virtual bool loadDAEFVector() /* override */;
178  virtual bool loadDAEdFdx() /* override */;
179 
180  /// Load Q vector
181  /// Since the Resistor does no charge storage, this is a no-op.
182  virtual bool loadDAEQVector() /* override */
183  {
184  return true;
185  }
186 
187  /// Load derivative of Q vector with respect to solution vector
188  /// Since the Resistor does no charge storage, this is a no-op.
189  virtual bool loadDAEdQdx() /* override */
190  {
191  return true;
192  }
193 
194  virtual void setupPointers() /* override */;
195 
196 private:
197  static std::vector< std::vector<int> > jacStamp; ///< All Resistor instances have a common Jacobian Stamp
198  static void initializeJacobianStamp();
199 
200  Model & model_; ///< Owning model
201 
202  // User-specified parameters:
203  double R; ///< Resistance (ohms)
204 
205  // These are for the semiconductor resistor
206  double length; ///< Resistor length.
207  double width; ///< Resistor width.
208  double temp; ///< Temperature of this instance
209 
210  // Temperature dependence parameters, these can override values specified in the model
211  double tempCoeff1; ///< First order temperature coeff.
212  double tempCoeff2; ///< Second order temperature coeff.
213  double dtemp; ///< Externally specified device temperature.
214  ///< NOT used, only here for compatibility in parsing
215  ///< netlist from simulators that support it
216 
217  // Flags used to tell if the user has specified one of these values on the command line.
218  bool tempCoeff1Given; ///< First order temperation value was given in netlist
219  bool tempCoeff2Given; ///< Second order temperature coeff was given in netlist
220  bool dtempGiven; ///< Externally specified device temperature was given in netlist
221 
222  // Derived parameters:
223  double G; ///< Conductance(1.0/ohms)
224  double i0; ///< Current(ohms)
225 
226  int li_Pos; ///< Index for Positive Node
227  int li_Neg; ///< Index for Negative Node
228  int li_store_dev_i; ///< Index for Lead Current
229  int li_branch_data; ///< Index for Lead Current and junction voltage (for power calculations)
230 
231  // Offset variables corresponding to the above declared indices.
232  int APosEquPosNodeOffset; ///< Column index into force matrix of Pos/Pos conductance
233  int APosEquNegNodeOffset; ///< Column index into force matrix of Pos/Neg conductance
234  int ANegEquPosNodeOffset; ///< Column index into force matrix of Neg/Pos conductance
235  int ANegEquNegNodeOffset; ///< Column index into force matrix of Neg/Neg conductance
236 
237 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
238  // Pointers for Jacobian
243 #endif
244 
245 };
246 
247 
248 //-----------------------------------------------------------------------------
249 // Class : Xyce::Device::Resistor::Model
250 // Purpose :
251 // Special Notes :
252 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
253 // Creation Date : 3/16/00
254 //-----------------------------------------------------------------------------
255 ///
256 /// Resistor model class
257 ///
258 class Model : public DeviceModel
259 {
260  friend class ParametricData<Model>; ///< Allow ParametricData to changes member values
261  friend class Instance; ///< Don't force a lot of pointless getters
262  friend class Traits;
263  friend class Master; ///< Don't force a lot of pointless getters
264 
265 public:
266  typedef std::vector<Instance *> InstanceVector;
267 
268  Model(
269  const Configuration & configuration,
270  const ModelBlock & model_block,
271  const FactoryBlock & factory_block);
272  ~Model();
273 
274 private:
275  Model();
276  Model(const Model &);
277  Model &operator=(const Model &);
278 
279 public:
280 
281  //---------------------------------------------------------------------------
282  // Function : Xyce::Device::Resistor::Model::addInstance
283  // Purpose :
284  // Special Notes :
285  // Scope : public
286  // Creator : David Baur
287  // Creation Date : 8/12/2013
288  //---------------------------------------------------------------------------
289  ///
290  /// Add an instance to the list of instances associated with this model
291  ///
292  /// @author David G. Baur Raytheon Sandia National Laboratories 1355
293  /// @date 8/12/2013
294  void addInstance(Instance *instance)
295  {
296  instanceContainer.push_back(instance);
297  }
298 
299  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
300 
301  virtual std::ostream &printOutInstances(std::ostream &os) const;
302 
303  virtual bool processParams() /* override */;
304  virtual bool processInstanceParams() /* override */;
305 
306 private:
307  InstanceVector instanceContainer; ///< List of owned resistor instances
308 
309  // Semiconductor resistor parameters
310  double tempCoeff1; ///< First order temperature coefficient
311  double tempCoeff2; ///< Second order temperature coefficient
312  double sheetRes; ///< Sheet resistance
313  double resistanceMultiplier; ///< resistance multiplier
314  double defWidth; ///< Default width
315  double narrow; ///< Narrowing due to side etching
316  double tnom; ///< Parameter measurement temperature
317 };
318 
319 
320 //-----------------------------------------------------------------------------
321 // Class : Xyce::Device::Resistor::Master
322 // Purpose :
323 // Special Notes :
324 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
325 // Creation Date : 11/26/08
326 //-----------------------------------------------------------------------------
327 ///
328 /// Resistor master
329 ///
330 /// The "master" class is the one that contains the updateState, loadDAEVectors
331 /// and loadDAEMatrices methods that are actually called when it is time to
332 /// compute and load device contributions.
333 ///
334 /// The default implementations of these methods in the DeviceMaster
335 /// template class simply loops over all instances and calls their
336 /// updatePrimaryState, loadDAEFVector/loadDAEQVector, and
337 /// loadDAEdFdx/loadDAEdQdx methods, respectively.
338 ///
339 /// For efficiency, the Resistor class reimplements these methods to do the
340 /// work directly, instead of calling instance-level functions.
341 ///
342 class Master : public DeviceMaster<Traits>
343 {
344  friend class Instance; ///< Don't force a lot of pointless getters
345  friend class Model; ///< Don't force a lot of pointless getters
346 
347 public:
348 
349  //---------------------------------------------------------------------------
350  // Function : Xyce::Device::Resistor::Master::Master
351  // Purpose :
352  // Special Notes :
353  // Scope : public
354  // Creator : Eric Keiter
355  // Creation Date : 11/26/08
356  //---------------------------------------------------------------------------
357  ///
358  /// Construct a Resistor Device.
359  ///
360  /// @param configuration
361  /// @param factory_block
362  /// @param solver_state
363  /// @param device_options
365  const Configuration & configuration,
366  const FactoryBlock & factory_block,
367  const SolverState & solver_state,
368  const DeviceOptions & device_options)
369  : DeviceMaster<Traits>(configuration, factory_block, solver_state, device_options)
370  {}
371 
372  virtual bool updateState(double * solVec, double * staVec, double * stoVec);
373  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
374  virtual bool loadDAEMatrices(Linear::Matrix & dFdx, Linear::Matrix & dQdx);
375 };
376 
377 void registerDevice();
378 
379 } // namespace Resistor
380 } // namespace Device
381 } // namespace Xyce
382 
383 #endif // Xyce_N_DEV_Resistor_h
static void loadModelParameters(ParametricData< Model > &p)
Loads the parameter definition into the model parameter map.
Instance & operator=(const Instance &)
virtual bool updatePrimaryState()
Update the state variables.
int li_Pos
Index for Positive Node.
int ANegEquNegNodeOffset
Column index into force matrix of Neg/Neg conductance.
virtual void setupPointers()
Setup direct access pointer to solution matrix and vectors.
double sheetRes
Sheet resistance.
int li_branch_data
Index for Lead Current and junction voltage (for power calculations)
InstanceVector instanceContainer
List of owned resistor instances.
double length
Resistor length.
Resistor model class.
Pure virtual class to augment a linear system.
static resistorSensitivity resSens
static void initializeJacobianStamp()
Common Jacobian stamp initializer for all Resistor devices.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &solver_state, const DeviceOptions &device_options)
Construct a Resistor Device.
double tempCoeff2
Second order temperature coeff.
virtual void registerBranchDataLIDs(const std::vector< int > &branchLIDVecRef)
Register the local store IDs.
double resistanceMultiplier
resistance multiplier
int APosEquPosNodeOffset
Column index into force matrix of Pos/Pos conductance.
Base class for all parameters.
Definition: N_DEV_Pars.h:169
virtual bool processParams()
Process parameters.
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Update state for all resistor instances, regardless of model.
static void loadInstanceParameters(ParametricData< Instance > &p)
Loads the parameter definition into the instance parameter map.
virtual void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
virtual bool loadDAEVectors(double *solVec, double *fVec, double *qVec, double *bVec, double *storeLeadF, double *storeLeadQ, double *leadF, double *leadQ, double *junctionV)
Load DAE vectors of all resistor instances, regardless of model.
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
virtual bool loadDAEFVector()
Load the DAE F vector.
DeviceMaster instantiates a device as described by the device traits T.
double tempCoeff1
First order temperature coeff.
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
virtual void operator()(const ParameterBase &entity, const std::string &name, std::vector< double > &dfdp, std::vector< double > &dqdp, std::vector< double > &dbdp, std::vector< int > &Findices, std::vector< int > &Qindices, std::vector< int > &Bindices) const
void addInstance(Instance *instance)
Add an instance to the list of instances associated with this model.
static const char * name()
double temp
Temperature of this instance.
double dtemp
Externally specified device temperature.
int li_store_dev_i
Index for Lead Current.
virtual bool loadDAEQVector()
Load Q vector Since the Resistor does no charge storage, this is a no-op.
virtual void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
Register the Jacobian local IDs.
static const char * deviceTypeName()
bool tempCoeff2Given
Second order temperature coeff was given in netlist.
Resistor device instance class.
Model & operator=(const Model &)
double narrow
Narrowing due to side etching.
double R
Resistance (ohms)
~Instance()
Destroys this instance.
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
virtual bool processInstanceParams()
Process the instance parameters of instance owned by this model.
void setupNoiseSources(Xyce::Analysis::NoiseData &noiseData)
virtual void registerStateLIDs(const std::vector< int > &staLIDVecRef)
Register the local state IDs.
virtual const std::vector< std::vector< int > > & jacobianStamp() const
Return Jacobian stamp that informs topology of the layout of the resistor jacobian.
virtual std::ostream & printOutInstances(std::ostream &os) const
Print instances associated with this model.
virtual bool loadDAEdFdx()
Load the DAE the derivative of the F vector with respect to the solution vector x, dFdx.
Model & model_
Owning model.
Class Configuration contains device configuration data.
virtual void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
Register local IDs.
virtual bool loadDAEdQdx()
Load derivative of Q vector with respect to solution vector Since the Resistor does no charge storage...
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
Create a new instance of the Resistor device.
double width
Resistor width.
int ANegEquPosNodeOffset
Column index into force matrix of Neg/Pos conductance.
double G
Conductance(1.0/ohms)
virtual bool processParams()
Process model parameters.
static const char * instanceDefaultParameter()
double tempCoeff1
First order temperature coefficient.
double tempCoeff2
Second order temperature coefficient.
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Load DAE matrices for all resistor instances, regardless of model.
double defWidth
Default width.
virtual void registerStoreLIDs(const std::vector< int > &stoLIDVecRef)
Register the local store IDs.
Base sensitivity functor.
Definition: N_DEV_Pars.h:148
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
static const char * primaryParameter()
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
~Model()
Destroy this model.
int li_Neg
Index for Negative Node.
static std::vector< std::vector< int > > jacStamp
All Resistor instances have a common Jacobian Stamp.
InstanceBlock represent a device instance line from the netlist.
void registerDevice()
Define how to use the device in a netlist.
Instance(const Configuration &configuration, const InstanceBlock &instance_block, Model &model, const FactoryBlock &factory_block)
Construct a resistor instance.
virtual bool updateTemperature(const double &temp_tmp)
Update the parameters that depend on the temperature of the device.
int APosEquNegNodeOffset
Column index into force matrix of Pos/Neg conductance.
std::vector< Instance * > InstanceVector
void getNoiseSources(Xyce::Analysis::NoiseData &noiseData)
Model & getModel()
Gets the resistor model that owns this instance.
double tnom
Parameter measurement temperature.
bool tempCoeff1Given
First order temperation value was given in netlist.
virtual bool updateIntermediateVars()
Update the intermediate variables.
bool dtempGiven
Externally specified device temperature was given in netlist.