Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_Diode.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_Diode.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.129 $
40 //
41 // Revision Date : $Date: 2014/08/01 23:02:59 $
42 //
43 // Current Owner : $Author: erkeite $
44 //-----------------------------------------------------------------------------
45 
46 #ifndef Xyce_N_DEV_Diode_h
47 #define Xyce_N_DEV_Diode_h
48 
49 #include <Sacado.hpp>
50 
51 // ---------- Xyce Includes ----------
52 #include <N_DEV_Configuration.h>
53 #include <N_DEV_DeviceMaster.h>
54 #include <N_DEV_DeviceBlock.h>
55 #include <N_DEV_DeviceInstance.h>
56 #include <N_DEV_DeviceModel.h>
57 
58 #include <N_DEV_Param.h>
59 
60 namespace Xyce {
61 namespace Device {
62 namespace Diode {
63 
64 class Model;
65 class Instance;
66 
67 typedef Sacado::Fad::SFad<double, 1> fadType;
68 
69 
70 template <typename ScalarT>
71 inline ScalarT Xycemax ( ScalarT f1, ScalarT f2) { return f1 > f2 ? f1 : f2; }
72 
73 template <typename ScalarT>
74 inline ScalarT Xycemin ( ScalarT f1, ScalarT f2) { return f1 < f2 ? f1 : f2; }
75 
76 /// general sensitivity functor for all params.
78 {
79  public:
81  baseSensitivity() {};
82 
83  virtual ~diodeSensitivity() {};
84 
85  virtual void operator()(
86  const ParameterBase &entity,
87  const std::string &param,
88  std::vector<double> & dfdp,
89  std::vector<double> & dqdp,
90  std::vector<double> & dbdp,
91  std::vector<int> & Findices,
92  std::vector<int> & Qindices,
93  std::vector<int> & Bindices
94  ) const ;
95 };
96 
98 
99 struct Traits : public DeviceTraits<Model, Instance>
100 {
101  static const char *name() {return "Diode";}
102  static const char *deviceTypeName() {return "D level 1,2";}
103  static int numNodes() {return 2;}
104  static bool modelRequired() {return true;}
105  static bool isLinearDevice() {return false;}
106 
107  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
108  static void loadModelParameters(ParametricData<Model> &model_parameters);
109  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
110 };
111 
112 
113 template <typename ScalarT>
114 bool processParams (
115  ScalarT & M,
116  ScalarT & EG,
117  ScalarT & FC,
118  const ScalarT & RS,
119  ScalarT & COND,
120  ScalarT & F2,
121  ScalarT & F3
122  );
123 
124 template <typename ScalarT>
125 bool updateTemperature
126 (
127  //const double & temp, Instance & instance, Model & model_,
128  // instance params:
129  ScalarT & Temp,
130  ScalarT & tJctCap,
131  ScalarT & tJctPot,
132  ScalarT & tDepCap,
133  ScalarT & tF1,
134  ScalarT & tSatCur,
135  ScalarT & tSatCurR,
136  ScalarT & tVcrit,
137  ScalarT & tRS,
138  ScalarT & tCOND,
139  ScalarT & tIRF,
140  ScalarT & tIKF,
141  ScalarT & tBrkdwnV,
142 
143  // model variables/params:
144  const ScalarT & TNOM,
145  const ScalarT & VJ,
146  const ScalarT & CJO,
147  const ScalarT & M,
148  const ScalarT & N,
149  const ScalarT & IS,
150  const ScalarT & EG,
151  const ScalarT & XTI,
152  const ScalarT & RS,
153  const ScalarT & COND,
154  const ScalarT & IRF,
155  const ScalarT & NR,
156  const ScalarT & IKF,
157  const ScalarT & TIKF,
158  const ScalarT & ISR,
159  const ScalarT & IBV,
160  const ScalarT & BV,
161  const bool & BVGiven,
162  const ScalarT & TBV1,
163  const ScalarT & TBV2,
164  const ScalarT & TRS1,
165  const ScalarT & TRS2,
166  const ScalarT & FC,
167  const int level
168 
169  );
170 
171 template <typename ScalarT>
173  (
174  // inputs:
175  const ScalarT & Vp,
176  const ScalarT & Vpp,
177  const ScalarT & Vn,
178  const ScalarT & Vd,
179 
180  // instance params:
181  const ScalarT & Temp,
182  const ScalarT & tJctCap,
183  const ScalarT & tJctPot,
184  const ScalarT & tDepCap,
185  const ScalarT & tF1,
186  const ScalarT & tSatCur,
187  const ScalarT & tSatCurR,
188  const ScalarT & tVcrit,
189  const ScalarT & tRS,
190  const ScalarT & tCOND,
191  const ScalarT & tIRF,
192  const ScalarT & tIKF,
193  const ScalarT & tBrkdwnV,
194 
195  // instance variables:
196  const ScalarT & Area,
197  const int & lambertWFlag,
198  const double & gmin,
199 
200  // model params:
201  const ScalarT M , // grading parameter
202  const ScalarT BV , // breakdown voltage
203  const ScalarT IBV , // reverse breakdown current
204  const ScalarT NBV , // reverse breakdown ideality factor
205  const ScalarT IBVL, // low-level reverse breakdown current
206  const ScalarT NBVL, // low-level reverse breakdown ideality factor
207  const ScalarT N , // non-ideality factor.
208  const ScalarT NR , // emission coeff. for ISR.
209  const ScalarT TT , // transit time.
210  const ScalarT F2 , // capacitive polynomial factor
211  const ScalarT F3 , // capacitive polynomial factor
212 
213  const int level,
214 
215  // outputs:
216  ScalarT & Id,
217  ScalarT & Gd,
218  ScalarT & Qd,
219  ScalarT & Cd,
220  ScalarT & Gspr
221  );
222 
223 template <typename ScalarT>
224 bool applyLimiters
225 (
226  N_DEV_DeviceSupport & devSupport,
227 
228  // inputs:
229  const ScalarT & Vp,
230  const ScalarT & Vpp,
231  const ScalarT & Vn,
232 
233  // parameters:
234  const ScalarT & tVcrit,
235 
236  // output
237  ScalarT & Vd,
238  ScalarT & Vd_orig,
239  ScalarT & Vd_old,
240 
241  const ScalarT & currVd_old,
242  const ScalarT & nextVd_old,
243 
244  const double InitCond,
245  const bool InitCondGiven,
246  const bool BVGiven,
247 
248  // instance vars:
249  const int off,
250  int & newtonIterOld,
251  bool & origFlag,
252 
253  const bool dotICapplies, // check all the "flagSol". if any == 1, then true
254 
255  // solver state variables:
256  const int & newtonIter,
257  const bool initJctFlag,
258  const bool voltageLimiterFlag,
259  const bool dcopFlag,
260  const bool locaEnabledFlag
261  );
262 
263 //-----------------------------------------------------------------------------
264 // Class : Instance
265 //
266 // Purpose : This class represents a single instance of the diode
267 // device. It mainly contains indices and pointers into
268 // the matrix equation (see the resistor instance class for
269 // more details).
270 //
271 // The diode will have 1 internal node, in addition to the
272 // nodes which are connected to it. This is so that it
273 // can be placed in series with a resistor that represents
274 // the resistance of intrinsic Si.
275 //
276 // Special Notes :
277 // Creator : Eric Keiter, Parallel Computational Sciences
278 // Creation Date : 02/28/00
279 //-----------------------------------------------------------------------------
280 class Instance : public DeviceInstance
281 {
282  friend class ParametricData<Instance>;
283  friend class Model;
284  friend class Traits;friend class Master;
285  friend class diodeSensitivity;
286 
287 public:
288  Instance(
289  const Configuration & configuration,
290  const InstanceBlock & instance_block,
291  Model & model,
292  const FactoryBlock & factory_block);
293 
294  ~Instance();
295 
296 private:
297  Instance(const Instance &);
298  Instance &operator=(const Instance &);
299 
300 public:
301  void registerLIDs( const std::vector<int> & intLIDVecRef,
302  const std::vector<int> & extLIDVecRef );
303  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
304  void registerStoreLIDs( const std::vector<int> & stoLIDVecRef);
305 
306  std::map<int,std::string> & getIntNameMap ();
307  std::map<int, std::string> & getStoreNameMap ();
308 
309  const std::vector< std::vector<int> > & jacobianStamp() const;
310  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
311 
312  bool processParams ();
313  bool updateTemperature ( const double & temp = -999.0 );
314  bool lambertWCurrent (double Isat, double Vte, double RS);
315  bool lambertWBreakdownCurrent (double Isat, double Vte, double RS);
316  bool lambertWLinearReverseBias (double Isat, double Vte, double RS);
317 
318  bool updateIntermediateVars ();
319  bool updatePrimaryState ();
320 
321  // load functions, residual:
322  bool loadDAEQVector ();
323  bool loadDAEFVector ();
324 
325  // load functions, Jacobian:
326  bool loadDAEdQdx ();
327  bool loadDAEdFdx ();
328 
329  void setupPointers();
330 
331 public:
332  // iterator reference to the diode model which owns this instance.
333  // Getters and setters
335  {
336  return model_;
337  }
338 
339 private:
340  static std::vector< std::vector<int> > jacStamp_RS;
341  static std::vector< std::vector<int> > jacStamp;
342 
343  static std::vector<int> jacMap_RS;
344  static std::vector<int> jacMap;
345 
346  static std::vector< std::vector<int> > jacMap2_RS;
347  static std::vector< std::vector<int> > jacMap2;
348 
349 
350  Model & model_; //< Owning model
351 
352  int off;
353  double Area;
354  double InitCond;
355  double Temp;
358 
359  double tJctPot;
360  double tJctCap;
361  double tDepCap;
362  double tSatCur;
363  double tVcrit;
364  double tF1;
365  double tBrkdwnV;
366  double tSatCurR;
367  double tIKF;
368  double tRS;
369  double tCOND;
370  double tIRF;
371 
372  double Id; //diode current
373  double Gd; //diode conductivity
374  double Cd; //depletion capacitance
375  double Gcd; //dep cap conductivity
376  double Qd; //capacitor charge
377  double Icd; //capacitor current
378  double Gspr;
379  //double LeadCurrent;
380 
381  double Vpp;
382  double Vp;
383  double Vn;
384  double Vc;
385 
386  double Vd;
387  double Vd_old;
388  double Vd_orig;
389 
391 
392  // end of intermediate variables
393 
394  // state variables:
395  double q0; // charge in the capacitor
396  double i0; // current throught the capacitor
397 
398  //local indices (offsets)
399  // int li_QState;
400 
401  // for voltage limiting
403 
404  // for lead current
406 
407  int li_Pos;
408  int li_Neg;
409  int li_Pri;
410 
411  // Matrix equation local offset variables
419 
420 #ifndef Xyce_NONPOINTER_MATRIX_LOAD
421  // Matrix equation local pointer variables
429 
437 #endif
438 
439 
440  // Flags
443 };
444 
445 //-----------------------------------------------------------------------------
446 // Class : Model
447 // Purpose :
448 // Special Notes :
449 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
450 // Creation Date : 02/28/00
451 //-----------------------------------------------------------------------------
452 class Model : public DeviceModel
453 {
454  typedef std::vector<Instance *> InstanceVector;
455 
456  friend class ParametricData<Model>;
457  friend class Instance;
458  friend class Traits;friend class Master;
459  friend class diodeSensitivity;
460 
461 public:
462  Model(
463  const Configuration & configuration,
464  const ModelBlock & MB,
465  const FactoryBlock & factory_block);
466  ~Model();
467 
468 private:
469  Model();
470  Model(const Model &);
471  Model &operator=(const Model &);
472 
473 public:
474  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
475 
476  virtual std::ostream &printOutInstances(std::ostream &os) const;
477  bool processParams ();
478  bool processInstanceParams ();
479 
480 
481 public:
482  void addInstance(Instance *instance)
483  {
484  instanceContainer.push_back(instance);
485  }
486 
487 private:
488  std::vector<Instance*> instanceContainer;
489 
490 private:
491 
492  double IS; // saturation current (A)
493  double RS; // ohmic resistance (ohms)
494  double COND; // corresponding conductance
495  double N; // emission coefficient
496  double ISR; // recombination saturation current (A)
497  double NR; // emission coefficient for ISR
498  double IKF; // high-injection knee current (A)
499  double TT; // transit time (sec)
500  double CJO; // zero-bias junction capacitance (F)
501  double VJ; // built-in junction potential (V)
502  double M; // grading coefficient
503  double EG; // activation energy (eV).
504  // For Si, EG = 1.11
505  // Ge, EG = 0.67
506  // Sbd, EG = 0.69
507  double XTI; // isaturation-current temp. exp
508  double TIKF; // IKF temperature coeff.
509  double TBV1; // BV linear temperature coeff.
510  double TBV2; // BV quadratic temperature coeff.
511  double TRS1; // RS linear temperature coeff.
512  double TRS2; // RS quadratic temperature coeff.
513  double FC; // coefficient for forward-bias depletion capacitance
514  // formula
515  double BV; // reverse breakdown voltage
516  double IBV; // current at breakdown voltage (A)
517  double IRF; // adjustment for linear portion of reverse current
518  double NBV; // reverse breakdown ideality factor
519  double IBVL; // low-level current at breakdown voltage (A)
520  double NBVL; // low-level reverse breakdown ideality factor
521  double F2;
522  double F3;
523  double TNOM; // parameter measurement temperature (C)
524  double KF; // flicker noise coefficient
525  double AF; // flicker noise exponent
526 
527  bool BVGiven;
528 };
529 
530 //-----------------------------------------------------------------------------
531 // Class : Master
532 // Purpose :
533 // Special Notes :
534 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
535 // Creation Date : 11/26/08
536 //-----------------------------------------------------------------------------
537 class Master : public DeviceMaster<Traits>
538 {
539  friend class Instance;
540  friend class Model;
541 
542 public:
544  const Configuration & configuration,
545  const FactoryBlock & factory_block,
546  const SolverState & ss1,
547  const DeviceOptions & do1)
548  : DeviceMaster<Traits>(configuration, factory_block, ss1, do1)
549  {}
550 
551  virtual bool updateState (double * solVec, double * staVec, double * stoVec);
552 
553  // new DAE stuff:
554  // new DAE load functions, residual:
555  virtual bool loadDAEVectors (double * solVec, double * fVec, double * qVec, double * bVec, double * storeLeadF, double * storeLeadQ);
556 
557  // new DAE load functions, Jacobian:
558  virtual bool loadDAEMatrices (N_LAS_Matrix & dFdx, N_LAS_Matrix & dQdx);
559 };
560 
561 void registerDevice();
562 
563 } // namespace Diode
564 } // namespace Device
565 } // namespace Xyce
566 
570 
571 #endif
572