-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathresistor2D.cpp
136 lines (108 loc) · 4.52 KB
/
resistor2D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <chrono>
#include <memory>
#include <PMSchemes/emcNGPScheme.hpp>
#include <ParticleHandler/emcBasicParticleHandler.hpp>
#include <ParticleType/emcElectron.hpp>
#include <PoissonSolver/emcSORSolver.hpp>
#include <emcGrainScatterMechanism.hpp>
#include <emcSimulation.hpp>
#include "../SiliconFunctions.hpp"
using namespace std::chrono;
const SizeType Dim = 2;
const std::string fileNamePrefix = "resistor";
using NumType = double;
using MaterialType = emcMaterial<NumType>;
using DeviceType = emcDevice<NumType, Dim>;
using PMScheme = emcNGPScheme<NumType, DeviceType>;
using ParticleHandler = emcBasicParticleHandler<NumType, DeviceType, PMScheme>;
using PoissonSolver = emcSORSolver<NumType, DeviceType, ParticleHandler>;
using SimulationType = emcSimulation<NumType, DeviceType, PoissonSolver,
ParticleHandler, PMScheme>;
using GridType = emcGrid<NumType, Dim>;
using ValueVec = DeviceType::ValueVec;
using SizeVec = DeviceType::SizeVec;
// boolean that determines if the parameters of the simulation should be
// included in the filename of the resulting files
bool includeParameterInFileName = true;
emcMaterial<NumType> material = Silicon::getSiliconMaterial<NumType>();
NumType device_extent_x = 1e-6; // m
NumType device_extent_y = 1e-6; // m
NumType device_extent_z = 1e-6; // m
NumType spacing_x = 1e-8; // m
NumType spacing_y = 5e-8; // m
std::vector<NumType> appliedVoltages = {0.05}; // [V]
NumType dT = 1e-15; // s
NumType totalSimTime = 5e-11; // s
NumType transientTime = 2e-11; // s
// add grain scattering
bool addGrainScattering = false;
// mean rate at which grain scattering appears
NumType grainScatterRate = 1e13; // 1 / s
// probability of transmission through grain boundary
NumType transmissionProb = 1;
//! number of used threads (in parallel region)
const SizeType nrThreads = 4;
/// example device: Resistor
int main() {
#ifdef _OPENMP
omp_set_num_threads(nrThreads);
std::cout << ">> Parallel version, using " << nrThreads << " threads.\n\n";
#else
std::cout << "\n>> Sequential version.\n\n";
#endif
for (auto voltage : appliedVoltages) {
std::cout << "Current applied voltage = " << voltage << "\n";
auto startSetup = high_resolution_clock::now();
// create device
ValueVec deviceMaxPos = {device_extent_x, device_extent_y};
ValueVec spacing = {spacing_x, spacing_y};
DeviceType device{material, deviceMaxPos, spacing};
device.setDeviceWidth(device_extent_z);
// add n-doped region
ValueVec origin = {0, 0};
device.addConstantDopingRegion(origin, deviceMaxPos, 1e22);
// add Contacts
device.addOhmicContact(emcBoundaryPos::XMAX, 0, {origin[1]},
{deviceMaxPos[1]});
device.addOhmicContact(emcBoundaryPos::XMIN, voltage, {origin[1]},
{deviceMaxPos[1]});
// set Poisson Solver (SOR - Solver)
PoissonSolver solver(device, 1e-4, 1.8);
PMScheme pmScheme;
// set Simulation Parameter
emcSimulationParameter<NumType, DeviceType> param;
param.setTimes(totalSimTime, dT, transientTime);
std::string parameter = "";
if (includeParameterInFileName) {
// applied voltage in mV appended to filename
parameter += "V" + std::to_string((int)(voltage * 1000));
// time in attoseconds appended to filename
parameter += "as" + std::to_string((int)(dT * 1e18));
}
param.setNamePrefix(fileNamePrefix + parameter);
param.setNrStepsBetweenShowProgress(5000);
param.setNrStepsForFinalAvg(20000);
// add simulated Particle Type, Valleys and Scatter Mechanisms
auto electrons =
std::make_unique<emcElectron<NumType, DeviceType>>(1000, 4, false);
Silicon::addXValley(electrons);
Silicon::addAcousticScattering(0, electrons, device, {0});
Silicon::addZeroOrderInterValleyScattering(0, electrons, device, {0});
Silicon::addFirstOrderInterValleyScattering(0, electrons, device, {0});
Silicon::addCoulombScattering(0, electrons, device, {0});
if (addGrainScattering) {
electrons->setGrainScatterMechanism(
std::make_unique<emcGrainScatterMechanism<NumType>>(
transmissionProb, grainScatterRate));
}
param.addParticleType(std::move(electrons));
SimulationType simulation(param, device, solver, pmScheme);
// execute + time simulation
auto start = high_resolution_clock::now();
simulation.execute();
auto end = high_resolution_clock::now();
std::cout << "CPU time: " << duration_cast<seconds>(end - start).count()
<< " s\n";
}
return 0;
}