Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_DiodePDE.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 //-----------------------------------------------------------------------------
27 // Filename : $RCSfile: N_DEV_DiodePDE.h,v $
28 //
29 // Purpose : This file contains the classes neccessary for a PDE
30 // based diode simulation.
31 //
32 // Special Notes :
33 //
34 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
35 //
36 // Creation Date : 02/28/00
37 //
38 // Revision Information:
39 // ---------------------
40 //
41 // Revision Number: $Revision: 1.88 $
42 //
43 // Revision Date : $Date: 2014/05/21 18:25:50 $
44 //
45 // Current Owner : $Author: dgbaur $
46 //-----------------------------------------------------------------------------
47 
48 #ifndef Xyce_N_DEV_DiodePDE_h
49 #define Xyce_N_DEV_DiodePDE_h
50 
51 // ---------- Xyce Includes ----------
52 #include <N_DEV_Configuration.h>
53 #include <N_DEV_fwd.h>
54 #include <N_DEV_DeviceBlock.h>
55 #include <N_DEV_Configuration.h>
57 #include <N_DEV_DevicePDEModel.h>
58 #include <N_DEV_bcData.h>
59 #include <N_DEV_CompositeParam.h>
60 #include <N_DEV_PDE_Electrode.h>
61 #include <N_DEV_MaterialLayer.h>
62 
63 #include <N_DEV_Param.h>
64 #include <N_UTL_BreakPoint.h>
65 #include <N_UTL_Expression.h>
66 
67 namespace Xyce {
68 namespace Device {
69 namespace DiodePDE {
70 
71 class Model;
72 class Instance;
73 
74 struct Traits : public DeviceTraits<Model, Instance>
75 {
76  static const char *name() {return "1D PDE Device";}
77  static const char *deviceTypeName() {return "PDE level 3";}
78  static int numNodes() {return 2;}
79  static int numOptionalNodes() {return 100;}
80  static bool modelRequired() {return true;}
81  static bool isPDEDevice() {return true;}
82  static bool isLinearDevice() {return false;}
83 
84  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
85  static void loadModelParameters(ParametricData<Model> &model_parameters);
86  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
87 };
88 
89 //-----------------------------------------------------------------------------
90 // Class : Instance
91 // Purpose : Instance class for DiodePDE.
92 //
93 // Special Notes :6
94 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
95 // Creation Date : 6/29/00
96 //-----------------------------------------------------------------------------
98 {
99  friend class Model;
100  friend class ParametricData<Instance>;
101  friend class Traits;
102 
103 public:
104  Instance(
105  const Configuration & configuration,
106  const InstanceBlock & IB,
107  Model & model,
108  const FactoryBlock & factory_block);
109 
110  Instance(const Instance &right);
111  ~Instance();
112 
113  CompositeParam *constructComposite (const std::string & ccompositeName, const std::string & paramName);
114 
115  std::map<int,std::string> & getIntNameMap ();
116 
117  void registerLIDs( const std::vector<int> & intLIDVecRef,
118  const std::vector<int> & extLIDVecRef );
119  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
120 
121  const std::vector< std::vector<int> > & jacobianStamp() const;
122  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
123 
124  void setupPointers();
125 
126  bool processParams ();
127 
128  bool doAllocations ();
129  bool setupNodes ();
130 
131  bool setupNumVars ();
132 
133  bool setupJacStamp ();
134  bool cleanupJacStamp ();
135 
136  bool updateIntermediateVars ();
137  bool updatePrimaryState ();
138  bool updateSecondaryState ();
139 
140  bool loadDeviceMask ();
141 
142  // functions that are used by both new-DAE and old-DAE:
143  bool loadVecNLPoisson (double * rhs);
144  bool loadMatNLPoisson (N_LAS_Matrix & mat);
145  bool loadMatKCLDDForm (N_LAS_Matrix & mat);
146  bool loadMatDDForm (N_LAS_Matrix & mat);
147  bool loadVecDDForm (double * rhs);
148  bool loadMatCktTrivial (N_LAS_Matrix & mat);
149  // end of the "both" DAE functions.
150 
151  bool setInitialGuess ();
152  bool loadRHSNonlinPoisson ();
153  bool loadRHSDDFormulation ();
155 
156  bool getInstanceBreakPoints( std::vector<N_UTL_BreakPoint> &breakPointTimes);
157 
158  bool plotfileFlag () {return true;}
159 
160  bool loadJacNonlinPoisson ();
161  bool loadJacKCLDDFormulation ();
162  bool loadJacDDFormulation ();
164 
165  // load functions, residual:
166  bool loadDAEQVector ();
167  bool loadDAEQDDFormulation ();
169 
170  bool loadDAEFVector ();
171  bool loadDAEFNonlinPoisson ();
172  bool loadDAEFDDFormulation ();
174 
175  // load functions, Jacobian:
176  bool loadDAEdQdx ();
177 
178  bool loadDAEdQdxDDFormulation ();
180 
181  bool loadDAEdFdx ();
182  bool loadDAEdFdxNonlinPoisson ();
183  bool loadDAEdFdxDDFormulation ();
185 
186  bool calcLifetimes ();
187  bool calcMobilities ();
188  bool updateTemperature(const double & temp_tmp);
189  bool calcVoltDepDensities ();
190 
191  bool setEH_inChemistry ();
192 
193  bool setupSourceProfile ();
194 
195  bool setupDopingProfile ();
196  bool calcDopingProfile ();
197 
198  bool setupDefaultLayer ();
199  bool setupMesh ();
200  bool setupMaterialArrays ();
201  bool calcInitialGuess ();
202  bool obtainSolution ();
203  bool obtainNodeVoltages ();
204  bool applyVoltageLimiting ();
205  bool calcVequBCs ();
206  bool calcDensityBCs ();
207  bool calcBoundaryConditions ();
208  bool setupMiscConstants ();
209  bool setupScalingVars ();
210  bool scaleVariables ();
211  bool unScaleVariables ();
212 
213  bool calcRecombination ();
214  bool calcElectronCurrent ();
215  bool calcHoleCurrent ();
216  bool calcEfield ();
217 
218  bool calcTerminalCurrents ();
219  bool calcConductance (int iElectrode, const N_LAS_Vector * dxdvPtr);
220  bool calcDXDV ();
221  bool loadDFDV (int ielectrode, N_LAS_Vector * dfdvPtr);
222 
223  bool pdRecombination ();
224  bool pdElectronCurrent ();
225  bool pdHoleCurrent ();
226  bool pdTerminalCurrents ();
227 
228  bool outputTecplot ();
229  bool outputSgplot ();
230 
231  bool enablePDEContinuation ();
232  bool disablePDEContinuation ();
233  void setPDEContinuationAlpha (double alpha);
234 
235  // bool continuationStatus();
236  // void changeContinuationStepSize(double scale);
237  // void updateOldContinuationParam();
238 
239  bool outputPlotFiles ();
240 
241 public:
242  // iterator reference to the resistor model which owns this instance.
243  // Getters and setters
245  {
246  return model_;
247  }
248 
249 private:
250 
251  Model & model_; //< Owning model
252 
259 
264 
265  // physical constants:
266 
267  double Emax; // maximum electric field (V/cm)
268 
269  double VminExp; // maximum potential (V), used in exponential expressions
270  double VmaxExp; // minimum potential (V), used in exponential expressions
271 
272  double diodeCap; // estimated diode capacitance (F)
273 
274  double LeadCurrent;
275 
276  // inputted doping profiles.
277  // pdope is often phosphorus
278  std::vector<double> xloc_pdope_vec;
279  std::vector<double> pdope_vec;
280  std::vector<double> y2_pdope_vec;
281 
282  // ndope is often boron.
283  std::vector<double> xloc_ndope_vec;
284  std::vector<double> ndope_vec;
285  std::vector<double> y2_ndope_vec;
286 
287  // source file arrays
288  std::vector<double> xloc_source_vec;
289  std::vector<double> source_vec;
290  std::vector<double> y2_source_vec;
291 
292  // temp spline arrays:
293  std::vector<double> xlocVec;
294  std::vector<double> specVec;
295  std::vector<double> y2Vec;
296 
297  // new doping/initial condition storage:
298  std::map<std::string, std::vector<double> > xlocMap;
299  std::map<std::string, std::vector<double> > specMap;
300 
301  // vector of electrode data:
302  std::map<std::string, PDE_1DElectrode*> electrodeMap;
303 
304  // boundary condition array. probably will be of size 2 or 3.
305  std::vector<bcData> bcVec;
306 
307  std::map<std::string,int> bcIndexMap;
308 
309  // doping profile constants:
310  double Na; // acceptor concentration on p-side (cm^-3)
311  double Nd; // donor concentration on n-side (cm^-3)
312  double WJ; // linearly graded junction width (cm)
313  double XC; // center of graded junction (cm)
314  double XL; // start of graded junction (cm)
315  double XR; // end of graded junction (cm)
316 
317  // boundary condition variables:
318  // These should eventually replace Nd and Na.
319  double NnMax; // maximum electron concentration
320  double NpMax; // maximum hole concentration.
321  double NnMin; // maximum electron concentration
322  double NpMin; // maximum hole concentration.
323 
324  // mesh constants:
325  int NX; // number of x mesh points
326  int LX; // index of last x point.
327 
328  bool NXGiven;
329 
330  // continuation parameters:
331  double maxVoltDelta;
333 
334  // option to use the old intrinsic calculation, to maintain backward compatibility.
335  bool useOldNi;
337 
338  // some 2D mesh stuff - mostly to catch netlist mistakes (as this is a 1D device model)
339  std::string meshFileName;
340 
341  // doping files.
342  std::string dopingFileName;
343  std::string ndopeFileName;
344  std::string pdopeFileName;
345 
346  // diode width:
347  double width;
348  double length;
349 
352 
353  double basex; // location of base electrode, if running bjt mode.
354 
355  // diode cross sectional area:
356  double area;
357 
358  // boundary condition variables. These are superceded by
359  // the data in the bcVec and PDE_1DElectrode structures.
360  double anodebc;
361  double cathodebc;
362  double emitterbc;
363  double collectorbc;
364  double basebc;
365 
366  double anodeArea;
367  double cathodeArea;
368 
369  double emitterArea;
371  double baseArea;
372 
373  double baseLocation;
375 
380  int callsOSG;
381 
383 
385 
391 
396 
400 
403  std::string tunnelingModelName;
404 
405 #ifdef Xyce_DEBUG_DEVICE
406  int anodeIndex_user;
407  bool anodeIndex_userGiven;
408  int cathodeIndex_user;
409  bool cathodeIndex_userGiven;
410 #endif
411 
412  int NUMRC; // number of row-column pairs.
413 
414  std::vector<double> displCurrent;
415 
416  //*************************************
417  // Neutron reaction model stuff:
418  double junctionArea;
419 
420  std::vector<int> boundarySten;
421  std::vector<int> edgeBoundarySten;
422  std::vector<int> internalBoundarySten;
423  std::vector<int> heterojunctionSten;
424  std::vector<int> matIndex;
425  std::vector< std::pair<int,int> > heterojunctionBCs;
426 
427  std::vector<int> regBaseIndexVec;
428  std::vector<int> regNumSpecieVec;
429  std::vector<int> regElectronIndexVec;
430  std::vector<int> regHoleIndexVec;
431 
432  std::vector<double> dxVec; // mesh spacing.
433  std::vector<double> xVec; // mesh points.
434  std::vector<double> CVec; // doping
435  std::vector<double> CdonorVec; // doping
436  std::vector<double> CacceptorVec; // doping
437  std::vector<double> VVec; // electrostatic potential
438  std::vector<double> ExVec; // electric field, x-direction.
439 
440  std::vector<double> JnxVec; // electron current density
441  std::vector<double> JpxVec; // hole current density
442 
443  std::vector<double> RVec; // recombination.
444  std::vector<double> SVec; // radiation source term.
445 
446  std::vector<double> nnVec; // electron density
447  std::vector<double> npVec; // hole density
448 
449 #if 0
450  std::vector<double> unE_Vec; // mobility along edge, electron
451  std::vector<double> upE_Vec; // mobility along edge, hole
452 #else
453  std::vector<pdeFadType> unE_Vec; // mobility along edge, electron
454  std::vector<pdeFadType> upE_Vec; // mobility along edge, hole
455 #endif
456 
457  std::vector<double> tnVec; // spatially dependent lifetimes, electron
458  std::vector<double> tpVec; // spatially dependent lifetimes, hole
459 
460 
461  std::vector<double> NcVec; // conduction band DOS
462  std::vector<double> NvVec; // valance band DOS
463 
464  std::vector<double> EcVec; // conduction band
465  std::vector<double> EvVec; // valance band
466  std::vector<double> EcEffVec; // conduction band, including BGN
467  std::vector<double> EvEffVec; // valance band, including BGN
468 
469  std::vector<double> bgnCVec; // Band-gap narrowing, conduction band
470  std::vector<double> bgnVVec; // Band-gap narrowing, valance band
471 
472  std::vector<double> NiVec; // intrinsic concentration
473  std::vector<double> NiEffVec; // intrinsic concentration
474  std::vector<double> EiVec; // intrinsic Fermi-Level vector.
475  std::vector<double> EiEffVec; // intrinsic Fermi-Level vector.
476  std::vector<double> EfVec; // Fermi-Level vector.
477  std::vector<double> EfEffVec; // Fermi-Level vector.
478  std::vector<double> relPermVec; // relative Permittivity
479 
480  std::vector<std::string> bulkMaterialVec; // material
481 
482  // derivative arrays:
483 
484  std::vector<double> dRdpVec;
485  std::vector<double> dRdnVec;
486 
487  std::vector<double> dJndn1Vec;
488  std::vector<double> dJndn2Vec;
489  std::vector<double> dJndV1Vec;
490  std::vector<double> dJndV2Vec;
491  std::vector<double> dJndp1Vec;
492  std::vector<double> dJndp2Vec;
493 
494  std::vector<double> dJpdn1Vec;
495  std::vector<double> dJpdn2Vec;
496  std::vector<double> dJpdV1Vec;
497  std::vector<double> dJpdV2Vec;
498  std::vector<double> dJpdp1Vec;
499  std::vector<double> dJpdp2Vec;
500 
501  // LID indices.
502  std::vector<int> li_Vrowarray;
503  std::vector< std::vector<int> > li_Vcolarray;
504 
505  std::vector<int> li_Nrowarray;
506  std::vector< std::vector<int> > li_Ncolarray;
507 
508  std::vector<int> li_Prowarray;
509  std::vector< std::vector<int> > li_Pcolarray;
510 
511  // columns needed for coupledMode==2
512  std::vector< std::vector<int> > li_N_rxn_colarray;
513  std::vector< std::vector<int> > li_P_rxn_colarray;
514 
515  std::vector<int> li_stateDispl;
516 
517  // matrix pointers
518  std::vector< std::vector<double *> > fVmatPtr;
519  std::vector< std::vector<double *> > fNmatPtr;
520  std::vector< std::vector<double *> > fPmatPtr;
521  std::vector< std::vector<double *> > qVmatPtr;
522  std::vector< std::vector<double *> > qNmatPtr;
523  std::vector< std::vector<double *> > qPmatPtr;
524 
525  // map between a mesh point index and a list of nearest neighbors
526  // for that mesh point.
527  std::multimap< int, int* > meshNeighborMultiMap;
528 
529  // state variable arrays associated with displacement current.
530  std::vector<int> stateDispl;
531  std::vector<int> stateDispl_owned;
532  // this is an int array because I think bool arrays
533  // might be problematic for some compilers.
534 
537 
538  // 2d array of conductances, for 2-level "ckt phase" loads.
539  std::vector< std::vector<double> > condVec;
540 
541  // data related to DMA matrix loads.
542  std::vector<int> meshToLID;
543  std::vector< std::vector<int> > jacStamp;
544  std::vector<int> jacMap;
545  std::vector< std::vector<int> > jacMap2;
546 
547  // flags related to chemistry.
550 
552  std::vector<MaterialLayer*> materialVec;
553 
555 };
556 
557 //-----------------------------------------------------------------------------
558 // Class : Model
559 // Purpose :
560 // Special Notes :
561 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
562 // Creation Date : 6/29/00
563 //-----------------------------------------------------------------------------
564 class Model : public DevicePDEModel
565 {
566  typedef std::vector<Instance *> InstanceVector;
567 
568  friend class Instance;
569  friend class ParametricData<Model>;
570  friend class Traits;
571 
572 public:
573  Model(
574  const Configuration & configuration,
575  const ModelBlock & MB,
576  const FactoryBlock & factory_block);
577  ~Model();
578 
579 private:
580  Model();
581  Model(const Model &);
582  Model &operator=(const Model &);
583 
584 public:
585  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
586 
587  virtual std::ostream &printOutInstances(std::ostream &os) const;
588 
589  bool processParams ();
590  bool processInstanceParams ();
591 
592 private:
593 
594 
595 public:
596  void addInstance(Instance *instance)
597  {
598  instanceContainer.push_back(instance);
599  }
600 
601 private:
602  std::vector<Instance*> instanceContainer;
603 };
604 
605 void registerDevice();
606 
607 } // namespace DiodePDE
608 } // namespace Device
609 } // namespace Xyce
610 
613 
614 #endif