Xyce  6.1
N_DEV_Resistor3.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_Resistor3.h,v $
27 //
28 // Purpose : Resistor with zero resistance.
29 //
30 // Special Notes : This is a special case of the resistor device when it is
31 // specified with zero resistance. It will then behave like
32 // a voltage source with zero voltage difference so that a
33 // branch current is calculated.
34 //
35 // Creator : Richard Schiek, Electrical and Microsystems Modeling.
36 //
37 // Creation Date : 02/01/10
38 //
39 // Revision Information:
40 // ---------------------
41 //
42 // Revision Number: $Revision: 1.41 $
43 //
44 // Revision Date : $Date: 2015/04/08 19:18:24 $
45 //
46 // Current Owner : $Author: tvrusso $
47 //-----------------------------------------------------------------------------
48 
49 #ifndef Xyce_N_DEV_Resistor3_h
50 #define Xyce_N_DEV_Resistor3_h
51 
52 // ---------- Xyce Includes ----------
53 #include <N_DEV_Configuration.h>
54 #include <N_DEV_DeviceMaster.h>
55 #include <N_DEV_DeviceBlock.h>
56 #include <N_DEV_DeviceInstance.h>
57 #include <N_DEV_DeviceModel.h>
58 
59 #include <N_DEV_Resistor.h>
60 
61 namespace Xyce {
62 namespace Device {
63 namespace Resistor3 {
64 
65 // ---------- Forward Declarations ----------
66 class Model;
67 class Instance;
68 
69 struct Traits : public DeviceTraits<Model, Instance, Resistor::Traits>
70 {
71  static const char *name() {return "Resistor";}
72  static const char *deviceTypeName() {return "R level 3";}
73  static int numNodes() {return 2;}
74  static const char *primaryParameter() {return "R";}
75  static bool isLinearDevice() {return true;}
76 
77  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
78  static void loadModelParameters(ParametricData<Model> &model_parameters);
79  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
80 };
81 
82 //-----------------------------------------------------------------------------
83 // Class : Instance
84 // Purpose :
85 // Special Notes :
86 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
87 // Creation Date : 04/06/00
88 //-----------------------------------------------------------------------------
89 class Instance : public DeviceInstance
90 {
91  friend class ParametricData<Instance>;
92  friend class Model;
93  friend class Traits;
94  friend class Master;
95 
96 public:
97  Instance(
98  const Configuration & configuration,
99  const InstanceBlock & IB,
100  Model & Viter,
101  const FactoryBlock & factory_block);
102 
103  ~Instance();
104 
105 private:
106  Instance(const Instance &);
107  Instance &operator=(const Instance &);
108 
109 public:
110  bool isLinearDevice() const { return true; }
111 
112  void registerLIDs( const std::vector<int> & intLIDVecRef,
113  const std::vector<int> & extLIDVecRef );
114  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
115 
116  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
117 
118  const std::vector< std::vector<int> > & jacobianStamp() const;
119  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
120 
121  bool processParams ();
122 
123  bool updateIntermediateVars ();
124  bool updatePrimaryState ();
125 
126  // load functions, residual:
127  bool loadDAEQVector () { return true; }
128  bool loadDAEFVector ();
129 
130  // load functions, Jacobian:
131  bool loadDAEdQdx () { return true; }
132  bool loadDAEdFdx ();
133 
134  void setupPointers ();
135 
136  double getMaxTimeStepSize ();
137 
138  void varTypes( std::vector<char> & varTypeVec );
139 
140  void getLIDs(int & lpos, int & lneg,int & lbra)
141  {lpos = li_Pos; lneg = li_Neg; lbra = li_Bra;}
142 
143 public:
144  // iterator reference to the vsrc model which owns this instance.
145  // Getters and setters
147  {
148  return model_;
149  }
150 
151 private:
152  static std::vector< std::vector<int> > jacStamp;
153  static std::vector< std::vector<int> > jacStampPDE;
155 
156  Model & model_; //< Owning model
157 
158  // state variables:
159  double srcCurrent;
160  double srcVoltage;
161  double srcDrop;
162  double srcBC;
163 
164  // scale factor
165  double scale;
166  int nlstep;
167 
168  // Parameters
169  // user-specified paramters:
170  double R; // resistance (ohms)
171  // these are for the semiconductor resistor
172  double length; // resistor length.
173  double width; // resistor width.
174  double temp; // temperature of this instance
175  // temperature dependence parameters
176  // these can override values specified in the model
177  double tempCoeff1; // first order temperature coeff.
178  double tempCoeff2; // second order temperature coeff.
179  double dtemp; // externally specified device temperature. This parameter
180  // is NOT used and is only here for compatibility in parsing
181  // netlist from simulators that do support it.
182  // flags used to tell if the user has specified one of these values
183  // on the command line.
187 
188  // load variables
189  double source, v_pos, v_neg, i_bra;
190 
191  // indices into state vector:
192  int istate_I; // index for i0;
193 
194  // Matrix equation index variables:
195 
196  //local indices (offsets)
197  int li_Pos;
198  int li_Neg;
199  int li_Bra;
200 
201  // Jacobian matrix indices:
202  //Locally indexed offsets for jacobian
203  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
204  // branch current equ.
205 
206  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
207  // branch current equ.
208 
209  int APosEquBraVarOffset; // Offset, branch current variable
210  // contribution, KCL equation of the pos node
211 
212  int ANegEquBraVarOffset; // Offset, branch current variable
213  // contribution, KCL equation of the neg node
214 
215  // The following jacobian offsets are only neccessary
216  // for 2-level newton.
217  int APosEquPosNodeOffset; // Offset, positive node variable
218  // contribution, positive node KCL.
219 
220  int ANegEquNegNodeOffset; // Offset, negative node variable
221  // contribution, negative node KCL.
222 
223  int ABraEquBraVarOffset; // Offset, branch current variable
224  // contribution, branch current equation.
225 
226 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
227  // Jacobian matrix pointers:
232 
233  // The following jacobian pointers are only neccessary for 2-level newton.
237 #endif
238 };
239 
240 //-----------------------------------------------------------------------------
241 // Class : Model
242 // Purpose :
243 // Special Notes :
244 // Creator : Richard Schiek, Electrical and Microsystems Modeling
245 // Creation Date : 04/06/00
246 //-----------------------------------------------------------------------------
247 class Model : public DeviceModel
248 {
249  friend class ParametricData<Model>;
250  friend class Instance;
251  friend class Traits;
252  friend class Master;
253 
254  typedef std::vector<Instance *> InstanceVector;
255 
256 public:
257  Model(
258  const Configuration & configuration,
259  const ModelBlock & MB,
260  const FactoryBlock & factory_block);
261  ~Model ();
262 
263 private:
264  Model();
265  Model(const Model &);
266  Model &operator=(const Model &);
267 
268 public:
269  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
270 
271  virtual std::ostream &printOutInstances(std::ostream &os) const;
272  virtual bool processParams()
273  {
274  return true;
275  }
276 
277  virtual bool processInstanceParams()
278  {
279  return true;
280  }
281 
282 public:
283  void addInstance(Instance *instance)
284  {
285  instanceContainer.push_back(instance);
286  }
287 
288 private:
289  std::vector<Instance*> instanceContainer;
290 
291 private:
292 
293  // This is the dc and transient analysis value of the source.
294  double DC_TRAN;
295 };
296 
297 //-----------------------------------------------------------------------------
298 // Class : Master
299 // Purpose :
300 // Special Notes :
301 // Creator : Richard Schiek, Electrical and Microsystems Modeling
302 // Creation Date : 11/26/08
303 //-----------------------------------------------------------------------------
304 class Master : public DeviceMaster<Traits>
305 {
306  friend class Instance;
307  friend class Model;
308 
309 public:
311  const Configuration & configuration,
312  const FactoryBlock & factory_block,
313  const SolverState & ss1,
314  const DeviceOptions & do1)
315  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
316  {}
317 
318  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
319 
320  // load functions:
321  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
322  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
323 };
324 
325 void registerDevice();
326 
327 } // namespace Resistor3
328 } // namespace Device
329 } // namespace Xyce
330 
331 #endif
static Device * factory(const Configuration &configuration, const FactoryBlock &factory_block)
virtual bool processInstanceParams()
processInstanceParams
const std::vector< std::vector< int > > & jacobianStamp() const
void getLIDs(int &lpos, int &lneg, int &lbra)
Pure virtual class to augment a linear system.
Master(const Configuration &configuration, const FactoryBlock &factory_block, const SolverState &ss1, const DeviceOptions &do1)
static std::vector< std::vector< int > > jacStampPDE
virtual bool updateState(double *solVec, double *staVec, double *stoVec)
Updates the devices state information.
void varTypes(std::vector< char > &varTypeVec)
Instance(const Configuration &configuration, const InstanceBlock &IB, Model &Viter, const FactoryBlock &factory_block)
static void loadInstanceParameters(ParametricData< Instance > &instance_parameters)
virtual bool processParams()
processParams
DeviceMaster instantiates a device as described by the device traits T.
void registerLIDs(const std::vector< int > &intLIDVecRef, const std::vector< int > &extLIDVecRef)
The FactoryBlock contains parameters needed by the device, instance and model creation functions...
virtual void forEachInstance(DeviceInstanceOp &op) const
Apply a device instance "op" to all instances associated with this model.
void addInstance(Instance *instance)
Instance & operator=(const Instance &)
void registerStateLIDs(const std::vector< int > &staLIDVecRef)
The Device class is an interface for device implementations.
Definition: N_DEV_Device.h:101
void registerJacLIDs(const std::vector< std::vector< int > > &jacLIDVec)
std::vector< Instance * > InstanceVector
Class Configuration contains device configuration data.
static const char * primaryParameter()
std::vector< Instance * > instanceContainer
virtual bool loadDAEMatrices(Linear::Matrix &dFdx, Linear::Matrix &dQdx)
Populates the device's Jacobian object with these pointers.
Model & operator=(const Model &)
static const char * name()
ModelBlock represents a .MODEL line from the netlist.
The DeviceTraits template describes the configuration of a device.
virtual std::ostream & printOutInstances(std::ostream &os) const
Manages parameter binding for class C.
Definition: N_DEV_Pars.h:214
InstanceBlock represent a device instance line from the netlist.
static void loadModelParameters(ParametricData< Model > &model_parameters)
void loadNodeSymbols(Util::SymbolTable &symbol_table) const
Populates and returns the store name map.
static const char * deviceTypeName()
static std::vector< std::vector< int > > jacStamp
static ParametricData< Instance > parMap_
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.