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.39.2.1 $
43 //
44 // Revision Date : $Date: 2015/04/02 18:20:11 $
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  void registerLIDs( const std::vector<int> & intLIDVecRef,
111  const std::vector<int> & extLIDVecRef );
112  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
113 
114  void loadNodeSymbols(Util::SymbolTable &symbol_table) const; // override
115 
116  const std::vector< std::vector<int> > & jacobianStamp() const;
117  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
118 
119  bool processParams ();
120 
121  bool updateIntermediateVars ();
122  bool updatePrimaryState ();
123 
124  // load functions, residual:
125  bool loadDAEQVector () { return true; }
126  bool loadDAEFVector ();
127 
128  // load functions, Jacobian:
129  bool loadDAEdQdx () { return true; }
130  bool loadDAEdFdx ();
131 
132  void setupPointers ();
133 
134  double getMaxTimeStepSize ();
135 
136  void varTypes( std::vector<char> & varTypeVec );
137 
138  void getLIDs(int & lpos, int & lneg,int & lbra)
139  {lpos = li_Pos; lneg = li_Neg; lbra = li_Bra;}
140 
141 public:
142  // iterator reference to the vsrc model which owns this instance.
143  // Getters and setters
145  {
146  return model_;
147  }
148 
149 private:
150  static std::vector< std::vector<int> > jacStamp;
151  static std::vector< std::vector<int> > jacStampPDE;
153 
154  Model & model_; //< Owning model
155 
156  // state variables:
157  double srcCurrent;
158  double srcVoltage;
159  double srcDrop;
160  double srcBC;
161 
162  // scale factor
163  double scale;
164  int nlstep;
165 
166  // Parameters
167  // user-specified paramters:
168  double R; // resistance (ohms)
169  // these are for the semiconductor resistor
170  double length; // resistor length.
171  double width; // resistor width.
172  double temp; // temperature of this instance
173  // temperature dependence parameters
174  // these can override values specified in the model
175  double tempCoeff1; // first order temperature coeff.
176  double tempCoeff2; // second order temperature coeff.
177  double dtemp; // externally specified device temperature. This parameter
178  // is NOT used and is only here for compatibility in parsing
179  // netlist from simulators that do support it.
180  // flags used to tell if the user has specified one of these values
181  // on the command line.
185 
186  // load variables
187  double source, v_pos, v_neg, i_bra;
188 
189  // indices into state vector:
190  int istate_I; // index for i0;
191 
192  // Matrix equation index variables:
193 
194  //local indices (offsets)
195  int li_Pos;
196  int li_Neg;
197  int li_Bra;
198 
199  // Jacobian matrix indices:
200  //Locally indexed offsets for jacobian
201  int ABraEquPosNodeOffset; // Offset, pos. node voltage contribution,
202  // branch current equ.
203 
204  int ABraEquNegNodeOffset; // Offset, neg. node voltage contribution,
205  // branch current equ.
206 
207  int APosEquBraVarOffset; // Offset, branch current variable
208  // contribution, KCL equation of the pos node
209 
210  int ANegEquBraVarOffset; // Offset, branch current variable
211  // contribution, KCL equation of the neg node
212 
213  // The following jacobian offsets are only neccessary
214  // for 2-level newton.
215  int APosEquPosNodeOffset; // Offset, positive node variable
216  // contribution, positive node KCL.
217 
218  int ANegEquNegNodeOffset; // Offset, negative node variable
219  // contribution, negative node KCL.
220 
221  int ABraEquBraVarOffset; // Offset, branch current variable
222  // contribution, branch current equation.
223 
224 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
225  // Jacobian matrix pointers:
230 
231  // The following jacobian pointers are only neccessary for 2-level newton.
235 #endif
236 };
237 
238 //-----------------------------------------------------------------------------
239 // Class : Model
240 // Purpose :
241 // Special Notes :
242 // Creator : Richard Schiek, Electrical and Microsystems Modeling
243 // Creation Date : 04/06/00
244 //-----------------------------------------------------------------------------
245 class Model : public DeviceModel
246 {
247  friend class ParametricData<Model>;
248  friend class Instance;
249  friend class Traits;
250  friend class Master;
251 
252  typedef std::vector<Instance *> InstanceVector;
253 
254 public:
255  Model(
256  const Configuration & configuration,
257  const ModelBlock & MB,
258  const FactoryBlock & factory_block);
259  ~Model ();
260 
261 private:
262  Model();
263  Model(const Model &);
264  Model &operator=(const Model &);
265 
266 public:
267  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
268 
269  virtual std::ostream &printOutInstances(std::ostream &os) const;
270  virtual bool processParams()
271  {
272  return true;
273  }
274 
275  virtual bool processInstanceParams()
276  {
277  return true;
278  }
279 
280 public:
281  void addInstance(Instance *instance)
282  {
283  instanceContainer.push_back(instance);
284  }
285 
286 private:
287  std::vector<Instance*> instanceContainer;
288 
289 private:
290 
291  // This is the dc and transient analysis value of the source.
292  double DC_TRAN;
293 };
294 
295 //-----------------------------------------------------------------------------
296 // Class : Master
297 // Purpose :
298 // Special Notes :
299 // Creator : Richard Schiek, Electrical and Microsystems Modeling
300 // Creation Date : 11/26/08
301 //-----------------------------------------------------------------------------
302 class Master : public DeviceMaster<Traits>
303 {
304  friend class Instance;
305  friend class Model;
306 
307 public:
309  const Configuration & configuration,
310  const FactoryBlock & factory_block,
311  const SolverState & ss1,
312  const DeviceOptions & do1)
313  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
314  {}
315 
316  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
317 
318  // load functions:
319  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ, double * leadF, double * leadQ, double * junctionV);
320  virtual bool loadDAEMatrices (Linear::Matrix & dFdx, Linear::Matrix & dQdx);
321 };
322 
323 void registerDevice();
324 
325 } // namespace Resistor3
326 } // namespace Device
327 } // namespace Xyce
328 
329 #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.