Langmuir
Simulation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
parameters.h
Go to the documentation of this file.
1 #ifndef PARAMETERS_H
2 #define PARAMETERS_H
3 
4 #include <QDateTime>
5 #include <QFileInfo>
6 #include <QDebug>
7 #include <cmath>
8 #include <QDir>
9 
10 namespace LangmuirCore
11 {
12 
15 {
17  QList<qint32> electrons;
18 
20  QList<qint32> holes;
21 
23  QList<qint32> defects;
24 
26  QList<qint32> traps;
27 
29  QList<qreal> trapPotentials;
30 
32  QList<quint64> fluxInfo;
33 };
34 
47 {
49  QString simulationType;
50 
52  quint64 randomSeed;
53 
55  qint32 gridZ;
56 
58  qint32 gridY;
59 
61  qint32 gridX;
62 
65 
68 
70  qint32 defectsCharge;
71 
73  qint32 outputXyz;
74 
76  bool outputXyzE;
77 
79  bool outputXyzH;
80 
82  bool outputXyzD;
83 
85  bool outputXyzT;
86 
88  qint32 outputXyzMode;
89 
92 
94  qint32 outputCoulomb;
95 
97  qint32 outputStepChk;
98 
101 
104 
107 
110 
113 
116 
119 
122 
125 
127  qint32 outputWidth;
128 
130  QString outputStub;
131 
134 
137 
139  qreal seedCharges;
140 
143 
146 
149 
152 
155 
158 
160  qreal voltageLeft;
161 
164 
167 
169  qreal sourceRate;
170 
173 
176 
179 
182 
185 
188 
190  qreal drainRate;
191 
193  qreal eDrainLRate;
194 
196  qreal eDrainRRate;
197 
199  qreal hDrainLRate;
200 
202  qreal hDrainRRate;
203 
205  bool useOpenCL;
206 
208  qint32 workX;
209 
211  qint32 workY;
212 
214  qint32 workZ;
215 
217  qint32 workSize;
218 
221 
224 
227 
230 
233 
236 
238  qreal gridFactor;
239 
242 
245 
247  qreal inverseKT;
248 
250  bool okCL;
251 
253  quint32 currentStep;
254 
256  QDateTime simulationStart;
257 
259  qint32 hoppingRange;
260 
262  qreal slopeZ;
263 
266 
269 
272 
275 
278 
281 
283  qint32 maxThreads;
284 
286 
287  simulationType ("transistor"),
288  randomSeed (0),
289 
290  gridZ (1),
291  gridY (128),
292  gridX (128),
293 
294  coulombCarriers (false),
295  coulombGaussianSigma (0.0),
296  defectsCharge (0),
297 
298  outputXyz (0),
299  outputXyzE (true),
300  outputXyzH (true),
301  outputXyzD (true),
302  outputXyzT (true),
303  outputXyzMode (0),
304 
305  outputIdsOnDelete (false),
306  outputCoulomb (0),
307  outputStepChk (1),
308  outputChkTrapPotential (false),
309  outputPotential (false),
310  outputIsOn (true),
311 
312  imageDefects (false),
313  imageTraps (false),
314  imageCarriers (0),
315 
316  iterationsPrint (10),
317  iterationsReal (1000),
318  outputPrecision (15),
319  outputWidth (23),
320  outputStub ("out"),
321 
322  electronPercentage (0.01),
323  holePercentage (0.00),
324  seedCharges (0.00),
325  defectPercentage (0.00),
326  trapPercentage (0.00),
327  trapPotential (0.10),
328  gaussianStdev (0.00),
329  seedPercentage (1.0),
330 
331  voltageRight (0.00),
332  voltageLeft (0.00),
333  excitonBinding (0.00),
334  temperatureKelvin (300.0),
335 
336  sourceRate (0.90),
337  eSourceLRate (-1.0),
338  eSourceRRate (-1.0),
339  hSourceLRate (-1.0),
340  hSourceRRate (-1.0),
341  generationRate (0.001),
342  balanceCharges (false),
343 
344  drainRate (0.90),
345  eDrainLRate (-1.0),
346  eDrainRRate (-1.0),
347  hDrainLRate (-1.0),
348  hDrainRRate (-1.0),
349 
350  useOpenCL (false),
351  workX (4),
352  workY (4),
353  workZ (4),
354  workSize (256),
355  openclThreshold (256),
356  openclDeviceID (0),
357 
358  boltzmannConstant (1.3806504e-23),
359  dielectricConstant (3.5),
360  elementaryCharge (1.60217646e-19),
361  permittivitySpace (8.854187817e-12),
362  gridFactor (1e-9),
363  electrostaticCutoff (50),
364  electrostaticPrefactor (0),
365  inverseKT (0),
366  okCL (false),
367  currentStep (0),
368  simulationStart (QDateTime::currentDateTime()),
369  hoppingRange (1),
370  slopeZ (0.00),
371  sourceMetropolis (false),
372  sourceCoulomb (false),
373  recombinationRate (0.00),
374  recombinationRange (0),
375  outputIdsOnEncounter (false),
376  sourceScaleArea (65536),
377  maxThreads (-1)
378  {
379  }
380 
381 };
382 
385 {
388  if (par.outputWidth < 8 ) { par.outputWidth = 8; }
389  if (par.outputWidth < (par.outputPrecision + 8)) { par.outputWidth = par.outputPrecision + 8; }
390 }
391 
394 {
395  setCalculatedValues(par);
396  // simulation type
397  if (!(QStringList()<<"transistor"<<"solarcell").contains(par.simulationType))
398  {
399  qFatal("langmuir: simulation.type(%s) must be transistor or solarcell",qPrintable(par.simulationType));
400  }
401 
402  // grid size
403  if (par.gridZ < 1)
404  {
405  qFatal("langmuir: grid.x(%d) >= 1",par.gridX);
406  }
407  if (par.gridY < 1)
408  {
409  qFatal("langmuir: grid.y(%d) >= 1",par.gridY);
410  }
411  if (par.gridX < 1)
412  {
413  qFatal("langmuir: grid.z(%d) >= 1",par.gridZ);
414  }
415 
416  // output
417  if (par.iterationsPrint <= 0 )
418  {
419  qFatal("langmuir: iterations.print(%d) <= 0",par.iterationsPrint);
420  }
421  if (par.iterationsReal < 0 )
422  {
423  qFatal("langmuir: iterations.real(%d) < 0",par.iterationsReal);
424  }
425  if (par.iterationsReal % par.iterationsPrint != 0 )
426  {
427  qFatal("langmuir: iterations.real(%d) %% iterations.print(%d) != 0",par.iterationsReal,par.iterationsPrint);
428  }
429 
430  // percentages
431  if (par.electronPercentage < 0.0 || par.electronPercentage > 1.0 )
432  {
433  qFatal("langmuir: electron.pecentage(%f) < 0 || > 1.0",par.electronPercentage);
434  }
435 
436  if (par.holePercentage < 0.0 ||par. holePercentage > 1.0 )
437  {
438  qFatal("langmuir: hole.pecentage(%f) < 0 || > 1.0",par.holePercentage);
439  }
440 
441  if (par.defectPercentage < 0.0 || par.defectPercentage > 1.0 )
442  {
443  qFatal("langmuir: defect.pecentage(%f) < 0 || > 1.0",par.defectPercentage);
444  }
445 
446  if (par.trapPercentage < 0.0 || par.trapPercentage > 1.0 )
447  {
448  qFatal("langmuir: trap.pecentage(%f) < 0 || > 1.0",par.trapPercentage);
449  }
450 
451  if (par.seedPercentage < 0.0 || par.seedPercentage > 1.0 )
452  {
453  qFatal("langmuir: seed.pecentage(%f) < 0 || > 1.0",par.seedPercentage);
454  }
455 
456  if (par.defectPercentage > 1.00 - par.trapPercentage)
457  {
458  qFatal("langmuir: trap.percentage(%f) > 1.0 - trap.percentage(%f)",par.defectPercentage,par.trapPercentage);
459  }
460 
461  if (par.sourceRate < 0.0 || par.sourceRate > 1.0 )
462  {
463  qFatal("langmuir: source.rate(%f) < 0 || > 1.0",par.sourceRate);
464  }
465 
466  if (par.eSourceLRate >= 0.0)
467  {
468  if (par.eSourceLRate < 0.0 || par.eSourceLRate > 1.0 )
469  {
470  qFatal("langmuir: e.source.l.rate(%f) < 0 || > 1.0", par.eSourceLRate);
471  }
472  }
473 
474  if (par.eSourceRRate >= 0.0)
475  {
476  if (par.eSourceRRate < 0.0 || par.eSourceRRate > 1.0 )
477  {
478  qFatal("langmuir: e.source.r.rate(%f) < 0 || > 1.0", par.eSourceRRate);
479  }
480  }
481 
482  if (par.hSourceLRate >= 0.0)
483  {
484  if (par.hSourceLRate < 0.0 || par.hSourceLRate > 1.0 )
485  {
486  qFatal("langmuir: h.source.l.rate(%f) < 0 || > 1.0", par.hSourceLRate);
487  }
488  }
489 
490  if (par.hSourceRRate >= 0.0)
491  {
492  if (par.hSourceRRate < 0.0 || par.hSourceRRate > 1.0 )
493  {
494  qFatal("langmuir: h.source.r.rate(%f) < 0 || > 1.0", par.hSourceRRate);
495  }
496  }
497 
498  if (par.generationRate >= 0.0)
499  {
500  if (par.generationRate < 0.0 || par.generationRate > 1.0 )
501  {
502  qFatal("langmuir: x.source.rate(%f) < 0 || > 1.0", par.generationRate);
503  }
504  }
505 
506  if (par.drainRate < 0.0 || par.drainRate > 1.0 )
507  {
508  qFatal("langmuir: drain.rate(%f) < 0 || > 1.0",par.drainRate);
509  }
510 
511  if (par.eDrainLRate >= 0.0)
512  {
513  if (par.eDrainLRate < 0.0 || par.eDrainLRate > 1.0 )
514  {
515  qFatal("langmuir: e.drain.l.rate(%f) < 0 || > 1.0", par.eDrainLRate);
516  }
517  }
518 
519  if (par.eDrainRRate >= 0.0)
520  {
521  if (par.eDrainRRate < 0.0 || par.eDrainRRate > 1.0 )
522  {
523  qFatal("langmuir: e.drain.r.rate(%f) < 0 || > 1.0", par.eDrainRRate);
524  }
525  }
526 
527  if (par.hDrainLRate >= 0.0)
528  {
529  if (par.hDrainLRate < 0.0 || par.hDrainLRate > 1.0 )
530  {
531  qFatal("langmuir: h.drain.l.rate(%f) < 0 || > 1.0", par.hDrainLRate);
532  }
533  }
534 
535  if (par.hDrainRRate >= 0.0)
536  {
537  if (par.hDrainRRate < 0.0 || par.hDrainRRate > 1.0 )
538  {
539  qFatal("langmuir: h.drain.r.rate(%f) < 0 || > 1.0", par.hDrainRRate);
540  }
541  }
542 
543  if (par.seedCharges < 0.0 || par.seedCharges > 1.0 )
544  {
545  qFatal("langmuir: seed.charges(%f) < 0 || > 1.0",par.seedCharges);
546  }
547 
548  // other
549  if (par.gaussianStdev < 0.00)
550  {
551  qFatal("langmuir: gaussian.stdev < 0.0");
552  }
553  if (par.temperatureKelvin < 0.0)
554  {
555  qFatal("langmuir: temperature.kelvin < 0.0");
556  }
557 
558  if (par.defectsCharge != 0 && ! par.coulombCarriers)
559  {
560  qFatal("langmuir: defects.charge != 0 && coulomb.carriers = false");
561  }
562 
563  if (par.hoppingRange < 0 || par.hoppingRange > 2)
564  {
565  qFatal("langmuir: hopping.range(%d) < 0 || > 2",par.hoppingRange);
566  }
567 
568  if (!par.sourceMetropolis)
569  {
570  if (par.sourceCoulomb)
571  {
572  qFatal("langmuir: source.metropolis = false, yet source.coulomb = true");
573  }
574  }
575 
576  if (par.recombinationRate < 0.0 || par.recombinationRate > 1.0 )
577  {
578  qFatal("langmuir: recombination.rate(%f) < 0 || > 1.0",par.recombinationRate);
579  }
580 
581  if (par.recombinationRate > 0 && par.simulationType != "solarcell")
582  {
583  qFatal("langmuir: recombination.rate(%f) > 0, yet simulation.type != solarcell",par.recombinationRate);
584  }
585 
586  if (par.recombinationRate && !((par.electronPercentage > 0) && (par.holePercentage > 0)))
587  {
588  qFatal("langmuir: recombination.rate(%f) > 0, yet electron.percentage = %.5f and hole.percentage = %.5f",
590  }
591 
592  if (par.outputIdsOnEncounter && (par.simulationType != "solarcell"))
593  {
594  qFatal("langmuir: output.ids.on.encounter == true, yet simulation.type != solarcell");
595  }
596 
597  if (par.outputIdsOnEncounter && !((par.electronPercentage > 0) && (par.holePercentage > 0)))
598  {
599  qFatal("langmuir: output.ids.on.encounter == true, yet electron.percentage = %.5f and hole.percentage = %.5f",
601  }
602 
603  if (((par.outputXyzE == false) && (par.outputXyzH == false) && (par.outputXyzD == false) && (par.outputXyzT == false)) && par.outputXyz > 0)
604  {
605  qFatal("langmuir: output.xyz > 0, yet output.xyz.e && output.xyz.h && output.xyz.d && output.xyz.t are all false");
606 
607  }
608 
609  if (par.outputXyzMode < 0 || par.outputXyzMode > 1)
610  {
611  qFatal("langmuir: output.xyz.mode must be 0 or 1");
612  }
613 
614  if (par.openclThreshold <= 0)
615  {
616  qFatal("langmuir: opencl.threshold must be >= 0");
617  }
618 
619  if (par.openclDeviceID < 0)
620  {
621  qFatal("langmuir: opencl.device.id must be >= 0");
622  }
623 
624  if (par.balanceCharges && par.simulationType != "solarcell")
625  {
626  qFatal("langmuir: balance.charges == true, yet simulation.type != solarcell");
627  }
628 
629  if (par.coulombGaussianSigma > 0)
630  {
631  if (par.gridX == 1 || par.gridY == 1 || par.gridZ == 1)
632  {
633  qFatal("langmuir: coulomb.gaussian.sigma > 0, yet the simulation is not 3D");
634  }
635  if(qMin(qMin(par.gridX, par.gridY), par.gridZ)
636  < 3 * par.coulombGaussianSigma)
637  {
638  qDebug("langmuir: 3 * coulomb.gaussian.sigma <= qMin(grid.x, grid.y, grid.z)");
639  }
640  }
641 
642  if (par.outputIdsOnEncounter)
643  {
644  qFatal("langmuir: output.ids.on.encouter is deprecated");
645  }
646 }
647 
648 }
649 
650 #endif // PARAMETERS_H
qreal recombinationRate
the rate at which holes and electrons can combine when they sit upon one another
Definition: parameters.h:271
qreal slopeZ
slope of potential along z direction when there are multiple layers (as if there were a gate electrod...
Definition: parameters.h:262
bool outputXyzH
output holes in trajectory file (ignored if outputXyz is off)
Definition: parameters.h:79
void checkSimulationParameters(SimulationParameters &par)
check the parameters, making sure they are valid
Definition: parameters.h:393
bool outputChkTrapPotential
output trap potentials in checkpoint files
Definition: parameters.h:100
bool outputIdsOnEncounter
output carrier lifetime and pathlength when holes and electrons encounter one another ...
Definition: parameters.h:277
qreal drainRate
the rate at which all drains accept charges (default, used when eDrainL, etc. are < 0) ...
Definition: parameters.h:190
qint32 iterationsPrint
if Langmuir, how often to output; if LangmuirView, how many steps between rendering ...
Definition: parameters.h:118
qint32 gridY
the number of sites along the device width, at least one
Definition: parameters.h:58
qreal eSourceRRate
the rate at which the right electron source injects charges (overrides default)
Definition: parameters.h:175
qint32 workSize
the size of OpenCL 1DRange kernel work groups
Definition: parameters.h:217
qreal permittivitySpace
physical constant, the permittivity of free spece
Definition: parameters.h:235
qreal electronPercentage
the percent of the grid that is reserved for electrons, between 0 and 1
Definition: parameters.h:133
qreal eDrainRRate
the rate at which the right electron drain accepts charges (overrides default)
Definition: parameters.h:196
qreal eDrainLRate
the rate at which the left electron drain accepts charges (overrides default)
Definition: parameters.h:193
qreal boltzmannConstant
physical constant, the boltzmann constant
Definition: parameters.h:226
qreal temperatureKelvin
the temperature used in the boltzmann factor
Definition: parameters.h:166
qint32 iterationsReal
number of simulation steps after equilibration
Definition: parameters.h:121
qint32 openclDeviceID
the device to choose if there are multiple
Definition: parameters.h:223
QList< qreal > trapPotentials
a list of current traps site IDs
Definition: parameters.h:29
bool okCL
if true, OpenCL can be used on this platform
Definition: parameters.h:250
QList< qint32 > defects
a list of current defects site IDs
Definition: parameters.h:23
bool coulombCarriers
turn on Coulomb interactions between ChargeAgents
Definition: parameters.h:64
qreal hDrainLRate
the rate at which the left hole drain accepts charges (overrides default)
Definition: parameters.h:199
qint32 gridX
the number of sites along the device length, at least one
Definition: parameters.h:61
qint32 gridZ
the number of sites per layer, at least one
Definition: parameters.h:55
qreal electrostaticPrefactor
a compilation of physical constants
Definition: parameters.h:244
qreal trapPercentage
the percent of the grid that is reserved for traps, between 0 and 1
Definition: parameters.h:145
qint32 outputXyzMode
output mode for xyz file (if 0, particle count varies; if 1, particle count is constant using "phanto...
Definition: parameters.h:88
qint32 workX
the x size of OpenCL 3DRange kernel work groups - only needed if using SimulationParameters::outputCo...
Definition: parameters.h:208
qint32 outputStepChk
output a checkpoint file every this * iterationsPrint
Definition: parameters.h:97
QList< qint32 > traps
a list of current traps site IDs
Definition: parameters.h:26
bool outputIsOn
if false, produce no output (useful for LangmuirView)
Definition: parameters.h:106
qreal sourceScaleArea
for SimulationParameters::simulationType == "solarcell", multiply SimulationParameters::sourceRate by...
Definition: parameters.h:280
bool imageDefects
output images of defects
Definition: parameters.h:109
qreal gridFactor
size constant, the size associated with grid sites (~1nm)
Definition: parameters.h:238
bool outputXyzT
output traps in trajectory file (ignored if outputXyz is off)
Definition: parameters.h:85
qint32 outputCoulomb
output coulomb energy for the entire grid (if n < 0, only at the end; if n == 0, never; if n > 0...
Definition: parameters.h:94
qint32 workY
the y size of OpenCL 3DRange kernel work groups - only needed if using SimulationParameters::outputCo...
Definition: parameters.h:211
qint32 workZ
the z size of OpenCL 3DRange kernel work groups - only needed if using SimulationParameters::outputCo...
Definition: parameters.h:214
qreal hSourceLRate
the rate at which the left hole source injects charges (overrides default)
Definition: parameters.h:178
QDateTime simulationStart
the time this simulation started
Definition: parameters.h:256
qint32 recombinationRange
the number of sites to consider when performing recombinations (0 means same-site, 1 means one-site away and same-site)
Definition: parameters.h:274
bool outputPotential
output grid potential at the start of the simulation, includes the trap potential ...
Definition: parameters.h:103
qreal voltageLeft
the potential on the left side of the grid, used in setting up an electric field
Definition: parameters.h:160
qreal dielectricConstant
physical constant, the dielectic constant
Definition: parameters.h:229
bool outputXyzE
output electrons in trajectory file (ignored if outputXyz is off)
Definition: parameters.h:76
qint32 electrostaticCutoff
the cut off for Coulomb interations
Definition: parameters.h:241
QString outputStub
the stub to use when naming output files
Definition: parameters.h:130
qreal sourceRate
the rate at which all sources inject charges
Definition: parameters.h:169
qreal defectPercentage
the percent of the grid that is reserved for electrons, between 0 and 1
Definition: parameters.h:142
qreal excitonBinding
the energy change (eV) when a hole/electron pair goes from the same site to adjacent sites ...
Definition: parameters.h:163
A struct to temporarily store site IDs.
Definition: parameters.h:14
qint32 outputWidth
width of columns in output, ignored in certain files, like trajectory files
Definition: parameters.h:127
qreal gaussianStdev
the standard deviation of trap sites
Definition: parameters.h:151
quint32 currentStep
the current step of the simulation
Definition: parameters.h:253
qreal hSourceRRate
the rate at which the right hole source injects charges (overrides default)
Definition: parameters.h:181
A struct to store all simulation options.
Definition: parameters.h:46
qreal seedPercentage
the percent of the traps to be placed and grown upon to form islands
Definition: parameters.h:154
bool sourceMetropolis
if true, use an energy change (source potential and site) and metropolis criterion to calculate injec...
Definition: parameters.h:265
Definition: agent.h:12
qreal generationRate
the rate at which the exciton source injects charges (overrides default)
Definition: parameters.h:184
qreal holePercentage
the percent of the grid that is reserved for holes, between 0 and 1
Definition: parameters.h:136
qreal coulombGaussianSigma
multiply Coulomb terms by erf[r/(sigma sqrt[2])]; nothing happens if its zero
Definition: parameters.h:67
qint32 imageCarriers
output images of carriers (if n < 0, only at the end; if n == 0, never; if n > 0, every n * iteration...
Definition: parameters.h:115
qreal elementaryCharge
physical constant, the elementary charge
Definition: parameters.h:232
QList< quint64 > fluxInfo
a list of flux attempt, success values
Definition: parameters.h:32
quint64 randomSeed
seed the random number generator, if negative, uses the current time (making seperate runs random) ...
Definition: parameters.h:52
qint32 defectsCharge
the charge of defect sites
Definition: parameters.h:70
bool imageTraps
output images of defects
Definition: parameters.h:112
qint32 outputXyz
output trajectory file (if n < 0, only at the end; if n == 0, never; if n > 0, every n * iterations...
Definition: parameters.h:73
qreal hDrainRRate
the rate at which the right hole drain accepts charges (overrides default)
Definition: parameters.h:202
qint32 outputPrecision
number of significant figures used for doubles in output
Definition: parameters.h:124
qreal seedCharges
if true, place charges randomly before the simulation starts
Definition: parameters.h:139
bool balanceCharges
if true, try to keep the number of charges in the simulation balanced
Definition: parameters.h:187
bool outputXyzD
output defects in trajectory file (ignored if outputXyz is off)
Definition: parameters.h:82
qint32 openclThreshold
the minimum number of charges that must be present to use OpenCL
Definition: parameters.h:220
qint32 hoppingRange
the number of sites away from a given site used when calculating neighboring sites ...
Definition: parameters.h:259
QString simulationType
tells Langmuir how to set up the sources and drains
Definition: parameters.h:49
qint32 maxThreads
max threads allowed for QThreadPool - if its <= 0 then the QThread::idealThreadCount is used; note th...
Definition: parameters.h:283
bool outputIdsOnDelete
output carrier lifetime and pathlength when they are deleted
Definition: parameters.h:91
qreal voltageRight
the potential on the right side of the grid, used in setting up an electric field ...
Definition: parameters.h:157
bool sourceCoulomb
if true, use the Coulomb + Image interaction when calcualting energy change for injection ...
Definition: parameters.h:268
SimulationParameters()
Definition: parameters.h:285
qreal inverseKT
a compilation of physical constants
Definition: parameters.h:247
bool useOpenCL
if true, try to use OpenCL to speed up Coulomb interaction calculations
Definition: parameters.h:205
void setCalculatedValues(SimulationParameters &par)
sets parameters that depend upon other parameters
Definition: parameters.h:384
qreal eSourceLRate
the rate at which the left electron source injects charges (overrides default)
Definition: parameters.h:172
QList< qint32 > holes
a list of current holes site IDs
Definition: parameters.h:20
QList< qint32 > electrons
a list of current electron site IDs
Definition: parameters.h:17
qreal trapPotential
the potential of traps
Definition: parameters.h:148