Xyce  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
N_DEV_2DPDE.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_2DPDE.h,v $
27 //
28 // Purpose : This file contains the classes neccessary for a 2D PDE
29 // based simulation. MOSFETs, BJTs, Diodes, etc.
30 //
31 // Special Notes :
32 //
33 // Creator : Eric R. Keiter, SNL, Parallel Computational Sciences
34 //
35 // Creation Date : 11/14/01
36 //
37 // Revision Information:
38 // ---------------------
39 //
40 // Revision Number: $Revision: 1.90 $
41 //
42 // Revision Date : $Date: 2014/05/21 18:25:50 $
43 //
44 // Current Owner : $Author: dgbaur $
45 //-----------------------------------------------------------------------------
46 
47 #ifndef Xyce_N_DEV_2DPDE_h
48 #define Xyce_N_DEV_2DPDE_h
49 
50 // ---------- Standard Includes ----------
51 
52 // ---------- Xyce Includes ----------
53 #include <N_DEV_Configuration.h>
54 #include <N_DEV_fwd.h>
55 #include <N_DEV_DeviceBlock.h>
57 #include <N_DEV_DevicePDEModel.h>
58 
60 #include <N_DEV_PDE_2DMesh.h>
61 
62 #include <N_DEV_DiodePDE.h>
63 
64 #include <N_UTL_BreakPoint.h>
65 
66 
67 // Have the "new" boundary conditions turned on by default.
68 #if 1
69 #define Xyce_NEW_BC 1
70 #endif
71 
72 namespace Xyce {
73 namespace Device {
74 namespace TwoDPDE {
75 
76 class Model;
77 class Instance;
78 
79 struct Traits : public DeviceTraits<Model, Instance, DiodePDE::Traits>
80 {
81  static const char *name() {return "2D PDE Device";}
82  static const char *deviceTypeName () {return "PDE level 2";}
83  static int numNodes() {return 2;}
84  static int numOptionalNodes() {return 100;}
85  static int numFillNodes() {return 2;}
86  static bool modelRequired() {return true;}
87  static bool isPDEDevice() {return true;}
88  static bool isLinearDevice() {return false;}
89 
90  static Device *factory(const Configuration &configuration, const FactoryBlock &factory_block);
91  static void loadModelParameters(ParametricData<Model> &model_parameters);
92  static void loadInstanceParameters(ParametricData<Instance> &instance_parameters);
93 };
94 
95 //-----------------------------------------------------------------------------
96 // Class : Instance
97 // Purpose : Instance class for .
98 //
99 // Special Notes :
100 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
101 // Creation Date : 11/14/01
102 //-----------------------------------------------------------------------------
104 {
105  friend class ParametricData<Instance>;
106  friend class Model;
107  friend class Traits;
108 
109  // functions
110 public:
111 
112  Instance(
113  const Configuration & configuration,
114  const InstanceBlock & IB,
115  Model & model,
116  const FactoryBlock &factory_block);
117  ~Instance();
118 
119 private:
120  Instance(const Instance &right);
121  Instance &operator=(const Instance &right);
122 
123 public:
124  void registerGIDs (const std::list<index_pair> & intGIDListRef,
125  const std::list<index_pair> & extGIDListRef );
126 
127  void setupIntNameMap ();
128  void setupRowColPairs ();
129 
130  void registerStateGIDs (const std::list<index_pair> & staGIDListRef);
131 
132  void registerLIDs( const std::vector<int> & intLIDVecRef,
133  const std::vector<int> & extLIDVecRef );
134  void registerStateLIDs( const std::vector<int> & staLIDVecRef );
135  std::map<int,std::string> & getIntNameMap ();
136 
137  const std::vector< std::vector<int> > & jacobianStamp() const;
138  void registerJacLIDs( const std::vector< std::vector<int> > & jacLIDVec );
139 
140  bool processParams ();
141 
142  bool processOneTimeParams( Param & ndParam );
143 
144  bool processDopingParams (Param & ndParam, std::string param);
145 
146  bool processElectrodeParams (Param & ndParam);
147 
148  bool setupJacStamp ();
149 
150  bool doSensMeshResize ();
151  bool undoSensMeshResize ();
152 
153  bool setupMesh ();
154  bool doAllocations ();
155 
156  bool setupDINodes ();
157  bool setupBCEdgeAreas ();
158 
159  bool setupBoundaryStencil ();
160  bool setupNumVars ();
161 
162  bool checkForElectrodeOverlap ();
163 
164  bool setupLabelIndex ();
165  bool setupMinDXVector ();
166 
167  bool updateIntermediateVars ();
168  bool updatePrimaryState ();
169  bool updateSecondaryState ();
170 
171  // functions that are used by both new-DAE and old-DAE:
172  bool loadVecNLPoisson (double scalar, N_LAS_Vector * vecPtr);
173  bool loadMatNLPoisson (N_LAS_Matrix * matPtr);
174  bool loadMatKCLDDForm (N_LAS_Matrix * matPtr);
175  bool loadMatDDForm (double dndtScalar, N_LAS_Matrix * matPtr);
176  bool loadVecDDForm (double scalar,double dndtScalar,N_LAS_Vector *vecPtr);
177  bool loadMatCktTrivial (N_LAS_Matrix * matPtr);
178  // end of the "both" DAE functions.
179 
180  bool setInitialGuess ();
181  bool loadRHSNonlinPoisson ();
182  bool loadRHSDDFormulation ();
184 
185  bool plotfileFlag () {return true;}
186 
187  // load functions, residual:
188  bool loadDAEQVector ();
189  bool loadDAEQDDFormulation ();
191 
192  bool loadDAEFVector ();
193  bool loadDAEFNonlinPoisson ();
194  bool loadDAEFDDFormulation ();
196 
197  // load functions, Jacobian:
198  bool loadDAEdQdx ();
199 
200  bool loadDAEdQdxDDFormulation ();
202 
203  bool loadDAEdFdx ();
204  bool loadDAEdFdxNonlinPoisson ();
205  bool loadDAEdFdxDDFormulation ();
207 
208  bool calcLifetimes ();
209  bool calcMobilities ();
210  bool updateTemperature(const double & temp_tmp);
211  bool calcVoltDepDensities ();
212 
213  bool calcDopingProfile ();
214  bool calcInitialGuess ();
215  bool obtainSolution ();
216  bool obtainNodeVoltages ();
217  bool applyVoltageLimiting ();
218  bool calcVequBCs ();
219  bool calcDensityBCs ();
220  bool calcBoundaryConditions ();
221 
222  bool setupMiscConstants ();
223  bool setupScalingVars ();
224  bool scaleVariables ();
225  bool unScaleVariables ();
226  bool scaleDopeVariables ();
227  bool unScaleDopeVariables ();
228 
229  bool calcRecombination ();
230 
231 
232  bool setupPhotogen ();
233  bool calcPhotogen ();
234  bool calcPenalty ();
236  bool sumSources ();
237 
238  bool calcElectronCurrent ();
239  bool calcHoleCurrent ();
240  bool calcEfield ();
241 
242  bool calcTerminalCharges ();
243  bool calcTerminalCurrents ();
244  bool calcConductance (int iElectrode, const N_LAS_Vector * dxdvPtr);
245  bool calcDXDV ();
246  bool loadDFDV (int ielectrode, N_LAS_Vector * dfdvPtr);
247 
248  bool pdRecombination ();
249  bool pdElectronCurrent ();
250  bool pdHoleCurrent ();
251  bool pdTerminalCurrents ();
252  bool pdTerminalCharges ();
253  bool allocatePDTerms ();
254 
255  bool pdPenalty ();
256 
257  bool outputTecplot ();
258  bool outputTecplotVectors ();
259  bool tecplotGeomOutput (FILE *fp1);
260  bool outputSgplot ();
261  bool outputGnuplot ();
262  bool outputTxtData ();
263 
264  bool enablePDEContinuation ();
265  bool disablePDEContinuation ();
266  void setPDEContinuationAlpha (double alpha);
267  void setPDEContinuationBeta (double beta);
268 
269  bool outputPlotFiles ();
270 
271  CompositeParam *constructComposite (const std::string & compositeName, const std::string & paramName);
272 
273 public:
274  // iterator reference to the resistor model which owns this instance.
275  // Getters and setters
277  {
278  return model_;
279  }
280 
281 private:
282 
283  Model & model_; //< Owning model
284 
285 protected:
286 private:
287 
288  // physical constants:
289  double Is; // saturation current
290  double Id; // diode current, analytic form
291 
292  double Emax; // maximum electric field (V/cm)
293 
294  double VminExp; // maximum potential (V), used in exponential expressions
295  double VmaxExp; // minimum potential (V), used in exponential expressions
296 
297  // device interface node vector:
298  std::vector<DeviceInterfaceNode> dIVec;
299 
302 
303  double LeadCurrent1;
304  double LeadCurrent2;
305  double LeadCurrent3;
306  double LeadCurrent4;
307  double LeadCurrent5;
308  double LeadCurrent6;
309  double LeadCurrent7;
310  double LeadCurrent8;
311 
312  // doping profile constants:
313  double Na; // acceptor concentration on p-side (cm^-3)
314  double Nd; // donor concentration on n-side (cm^-3)
315  double WJ; // linearly graded junction width (cm)
316  double XC; // center of graded junction (cm)
317  double XL; // start of graded junction (cm)
318  double XR; // end of graded junction (cm)
319 
320  // boundary condition variables:
321  double NnMax; // maximum electron concentration
322  double NpMax; // maximum hole concentration.
323  double NnMin; // maximum electron concentration
324  double NpMin; // maximum hole concentration.
325 
326  // option to use the old intrinsic calculation, to maintain backward compatibility.
327  bool useOldNi;
329 
330  std::string meshFileName;
331  std::string deviceType;
337 
338 
339  // meshing variables, if using internally generated mesh.
342  double deviceLength;
343  double deviceWidth;
344 
346 
349  double penaltyPow;
350  double PulseData;
351 
352 
353  // diode cross sectional area:
354  double area;
355 
356 #ifdef Xyce_OXIDE_ENABLED
357  bool allOxideFlag;
358 #endif
359 
362  int callsOSG;
367 
370 
371  bool calcConductanceFlag; // Set when calcConductance is
372  // called for the 1st time.
373 
375 
380 
385 
387 
389 
392 
393  // mesh container pointer:
396 
397  // array pointers:
398  std::vector<double> xVec; // x locations
399  std::vector<double> yVec; // y locations
400  std::vector<double> CVec; // doping
401  std::vector<double> CdonorVec; // doping
402  std::vector<double> CacceptorVec; // doping
403 
404  std::vector<double> minDXVec; // minimum mesh spacing connected to this node.
405 
406  std::vector<double> areaVec;
407 
408  std::vector<double> VVec; // electrostatic potential
409  std::vector<double> nnVec; // electron density
410  std::vector<double> npVec; // hole density
411 
412  std::vector<double> totSrcVec; // total source term.
413  std::vector<double> RVec; // recombination.
414  std::vector<double> SVec; // radiation source term.
415 
416  std::vector<double> elecPenalty; // penalty term for negative e- density.
417  std::vector<double> holePenalty; // penalty term for negative h+ density.
418  std::vector<double> pdElecPenalty; // penalty deriv. term for negative e- density.
419  std::vector<double> pdHolePenalty; // penalty deriv. term for negative h+ density.
420 
421  std::vector<double> unVec; // spatially dependent mobility, electron
422  std::vector<double> upVec; // spatially dependent mobility, hole
423  std::vector<double> unE_Vec; // mobility along edge, electron
424  std::vector<double> upE_Vec; // mobility along edge, hole
425  std::vector<double> tnVec; // spatially dependent lifetimes, electron
426  std::vector<double> tpVec; // spatially dependent lifetimes, hole
427 
428  std::vector<double> EfieldVec; // electric field along an edge.
429 
430  std::vector<double> JnVec; // electron current density, along an edge
431  std::vector<double> JpVec; // hole current density, along an edge
432 
433  std::vector<double> displPotential; // time derivative of potential at a node,
434  // used in calculating displacement current.
435 
436  std::vector<double> displCurrent; // displacement current along an edge.
437 
438  std::vector<double> outputVec;
439 
440  // derivative arrays:
441 
442  // derivatives of recombination terms:
443  std::vector<double> dRdpVec; // derivative of R w.r.t. np (at a node)
444  std::vector<double> dRdnVec; // derivative of R w.r.t. nn (at a node)
445 
446  // derivatives of current density terms:
447  std::vector<double> dJndn1Vec;
448  std::vector<double> dJndn2Vec;
449  std::vector<double> dJndV1Vec;
450  std::vector<double> dJndV2Vec;
451 
452  std::vector<double> dJpdn1Vec;
453  std::vector<double> dJpdn2Vec;
454  std::vector<double> dJpdV1Vec;
455  std::vector<double> dJpdV2Vec;
456 
457  // matrix index arrays:
458  // external variable information is in the dIVec data structure.
459 
460  // boundary "neighbor" stencil
461  // This array is set to 1 if we are on a mesh node which has a
462  // nearest neighbor node which is a boundary condition node.
463  // 0 if not.
464  std::vector<int> boundarySten;
465  std::vector<int> boundaryStenV;
466  std::vector<int> boundaryStenN;
467  std::vector<int> boundaryStenP;
468 
469  std::vector<int> boundaryTest;
470 
471  // boundary neighbor stencil
472  // This array is set to 1 if we are next to a boundary, but not on
473  // a boundary. 0 if not. A node directly on the boundary
474  // does should return a zero.
475  std::vector<int> boundaryNeighborSten;
476 
477  // internal variable index arrays:
478 
479  // index arrays for poisson's equation:
480  std::vector<int> Vrowarray;
481  std::vector< std::vector<int> > Vcolarray;
482 
483  // index arrays for electron continuity:
484  std::vector<int> Nrowarray;
485  std::vector< std::vector<int> > Ncolarray;
486 
487  // index arrays for hole continuity:
488  std::vector<int> Prowarray;
489  std::vector< std::vector<int> > Pcolarray;
490 
491  // variable ownership arrays.
492  std::vector<int> vOwnVec; // on processor tag, for voltage variables.
493  std::vector<int> nnOwnVec; // on processor tag, for elec. density variables.
494  std::vector<int> npOwnVec; // on processor tag, for hole density variables.
495 
496  //local id's (offsets)
497  std::vector<int> li_Vrowarray;
498  std::vector<int> li_Nrowarray;
499  std::vector<int> li_Prowarray;
500 
501  std::vector< std::vector<int> > li_VoffsetArray;
502  std::vector< std::vector<int> > li_NoffsetArray;
503  std::vector< std::vector<int> > li_PoffsetArray;
504 
505  std::vector<int> MESHtoLID_V;
506  std::vector<int> MESHtoLID_N;
507  std::vector<int> MESHtoLID_P;
508 
509 
510  // minor arrays used in tecplot output:
511  std::vector<UINT> aiEdge;
512  std::vector<UINT> aiEdge_nf;
513  //std::vector<UINT> electrodeEdge;
516 
517  // this map is mostly used for processing the netlist information
518  // regarding boundary conditions.
519  std::map<std::string,std::string> tmpBCmap;
520 
521  // label index array (of numMeshPoints length)
522  std::vector<int> labelIndex;
523  std::vector<std::string> labelNameVector;
524  std::map<std::string,int> labelDIMap;
525 
526  // map between a mesh point index and a list of nearest neighbors
527  // for that mesh point.
528  std::multimap < int, int* > meshNeighborMultiMap;
529 
530  // vector of electrode data:
531  std::map<std::string,PDE_2DElectrode*> electrodeMap;
532 
533  // displacement current state variable information:
534  std::vector<int> stateDispl;
535  std::vector<int> stateDispl_owned; // this is an int array because
536  // bool arrays are problematic,
537  // esp. with some STL implementations.
538 
539  //local id's (offsets)
540  std::vector<int> li_stateDispl;
541 
543  int numInterfaceMeshPoints; // number of mesh points that
544  // are along electrode boundaries
550 
551  // 2d array of conductances, for 2-level "ckt phase" loads.
552  std::vector< std::vector<double> > condVec;
553 
554  // 2d array of capacitances,
555  std::vector< std::vector<double> > capVec;
556 
558 
559  // data related to DMA matrix loads.
560  std::vector<int> meshToLID;
561  std::vector< std::vector<int> > jacStamp;
562 };
563 
564 //-----------------------------------------------------------------------------
565 // Class : Model
566 // Purpose :
567 // Special Notes :
568 // Creator : Eric Keiter, SNL, Parallel Computational Sciences
569 // Creation Date : 11/14/01
570 //-----------------------------------------------------------------------------
571 class Model : public DevicePDEModel
572 {
573  typedef std::vector<Instance *> InstanceVector;
574 
575  friend class ParametricData<Model>;
576  friend class Instance;
577  friend class Traits;
578 
579 public:
580  Model(
581  const Configuration & configuration,
582  const ModelBlock & MB,
583  const FactoryBlock & factory_block);
584 
585  ~Model();
586 
587 private:
588  Model();
589  Model(const Model &);
590  Model &operator=(const Model &);
591 
592 public:
593  virtual void forEachInstance(DeviceInstanceOp &op) const /* override */;
594 
595  virtual std::ostream &printOutInstances(std::ostream &os) const;
596 
597  bool processParams ();
598  bool processInstanceParams ();
599 
600 
601 public:
602  void addInstance(Instance *instance)
603  {
604  instanceContainer.push_back(instance);
605  }
606 
607 private:
608  std::vector<Instance*> instanceContainer;
609 
610 private:
611 };
612 
613 void registerDevice();
614 
615 } // namespace TwoDPDE
616 } // namespace Device
617 } // namespace Xyce
618 
621 
622 #endif