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