ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
mos1d_dg.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_TESTS_MOS1D_DG_HPP
2#define VIENNASHE_TESTS_MOS1D_DG_HPP
3/* ============================================================================
4 Copyright (c) 2011-2022, Institute for Microelectronics,
5 Institute for Analysis and Scientific Computing,
6 TU Wien.
7
8 -----------------
9 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
10 -----------------
11
12 http://viennashe.sourceforge.net/
13
14 License: MIT (X11), see file LICENSE in the base directory
15=============================================================================== */
16
21#if defined(_MSC_VER)
22 // Disable name truncation warning obtained in Visual Studio
23 #pragma warning(disable:4503)
24#endif
25
26#include <iostream>
27#include <cstdlib>
28#include <vector>
29
30#include "tests/src/common.hpp"
31
32// ViennaSHE includes:
33#include "viennashe/core.hpp"
34
35// ViennaGrid default configuration and centroid() algorithm:
36#include "viennagrid/config/default_configs.hpp"
37#include "viennagrid/algorithm/centroid.hpp"
38
39
55{
56
57 mos1d_mesh_generator(double len_gate, double cs_gate, double len_oxide, double cs_ox, double len_bulk, double cs_bulk)
58 : len_gate_(len_gate), cs_gate_(cs_gate), len_oxide_(len_oxide), cs_ox_(cs_ox), len_bulk_(len_bulk), cs_bulk_(cs_bulk)
59 { }
60
61 template < typename MeshT, typename SegmentationT >
62 void operator()(MeshT & mesh, SegmentationT & seg) const
63 {
65
66 gconf.add_segment(0, len_gate_, static_cast<unsigned long>(std::ceil(len_gate_ / cs_gate_)) + 1);
67 gconf.add_segment(len_gate_, len_oxide_, static_cast<unsigned long>(std::ceil(len_oxide_ / cs_ox_) ) );
68 gconf.add_segment(len_gate_+len_oxide_, +20e-9, static_cast<unsigned long>(std::ceil(+20e-9 / 0.05e-9) ) );
69 gconf.add_segment(len_gate_+len_oxide_+20e-9, len_bulk_, static_cast<unsigned long>(std::ceil(len_bulk_ / cs_bulk_)) );
70 gconf.add_segment(len_gate_+len_oxide_+20e-9+len_bulk_, 2e-9, static_cast<unsigned long>(std::ceil(2e-9 / cs_bulk_) ) + 1);
71
72 viennashe::util::generate_device(mesh, seg, gconf);
73 }
74
75private:
76 double len_gate_;
77 double cs_gate_;
78 double len_oxide_;
79 double cs_ox_;
80 double len_bulk_;
81 double cs_bulk_;
82
83};
84
85
93template <typename DeviceType>
94void init_device(DeviceType & device, double Vg_init, double Nd, double Na)
95{
96 typedef typename DeviceType::segment_type SegmentType;
97
98 SegmentType const & gate = device.segment(0);
99 SegmentType const & oxide = device.segment(1);
100 SegmentType const & silicon = device.segment(2);
101 SegmentType const & silicon2 = device.segment(3);
102 SegmentType const & bulk = device.segment(4);
103
104 std::cout << "* init_device(): Setting material ..." << std::endl;
105
106 device.set_material(viennashe::materials::metal(), gate);
107 device.set_material(viennashe::materials::metal(), bulk);
108 device.set_material(viennashe::materials::sio2(), oxide);
109 device.set_material(viennashe::materials::si(), silicon);
110 device.set_material(viennashe::materials::si(), silicon2);
111
112 std::cout << "* init_device(): Setting doping (per cell) ..." << std::endl;
113
114 device.set_doping_n(Nd, silicon);
115 device.set_doping_p(Na, silicon);
116 device.set_doping_n(Nd, silicon2);
117 device.set_doping_p(Na, silicon2);
118
119 std::cout << "* init_device(): Setting contact potentials (per cell) ..." << std::endl;
120
121 device.set_contact_potential(0.0, bulk);
122 device.set_contact_potential(Vg_init, gate);
123
124 std::cout << "* init_device(): DONE!" << std::endl;
125} // init_device()
126
129{
130 typedef std::map<long, std::vector<double> > storage_type;
131
138 bool read_file(std::string filename, char delimiter = ' ')
139 {
140 std::ifstream reader(filename.c_str());
141 if(!reader) return false;
142
143 long i = 0;
144 while(reader.good() && !reader.eof())
145 {
146 std::vector<double> result;
147 std::string line;
148 std::getline(reader,line);
149
150 std::stringstream lineStream(line);
151 std::string cell;
152
153 if(line.length() == 0) continue;
154 if(line[0] == '#' ) continue;
155
156 while(std::getline(lineStream, cell, delimiter))
157 {
158 result.push_back(atof(cell.c_str()));
159 }
160
161 data_.insert(std::make_pair(i,result));
162 i++;
163 }
164 return true;
165 }
166
167 // Returns a map to the reference data ... index is the cell-id
168 storage_type const & data() const { return data_; }
169
170private:
171 storage_type data_;
172};
173
181template <typename DeviceType, typename AccessorType >
182bool test_result(AccessorType const & quan, DeviceType const & device, std::string filename )
183{
184 typedef typename DeviceType::mesh_type MeshType;
185
186 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
187
188 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
189 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
190
191 const double tol = 1e-1;
192
193 std::cout << "test_result(): file = '" << filename << "'" << std::endl;
194 try
195 {
196 reference_values referencefile;
197
198 bool ok = referencefile.read_file(filename);
199 if(!ok)
200 {
201 std::cerr << "test_result(): Unable to read file '" << filename << "'" << std::endl;
202 return false;
203 }
204
205 long linenum = 0;
206 CellContainer cells(device.mesh());
207 for (CellIterator cit = cells.begin();
208 cit != cells.end();
209 ++cit, ++linenum )
210 {
211 //write values at point
212 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i)
213 {
214 const double value = viennagrid::centroid(*cit)[i];
215 const double refvalue = referencefile.data().at(linenum)[i];
216 if(!viennashe::testing::fuzzy_equal(refvalue, value, tol))
217 {
218 std::cerr << "test_result(): Failure at " << *cit << " => " << quan(*cit) << std::endl;
219 return false;
220 }
221 }
222 const double value = quan(*cit);
223 const double refvalue = referencefile.data().at(linenum)[PointType::dim];
224 if(!viennashe::testing::fuzzy_equal(refvalue, value, tol))
225 {
226 std::cerr << "test_result(): Failure at " << *cit << " => " << quan(*cit) << std::endl;
227 return false;
228 }
229 } // for vertices
230 }
231 catch(std::exception & ex)
232 {
233 std::cerr << "test_result(): FAILED! What? " << ex.what() << std::endl;
234 return false;
235 }
236
237 return true;
238}
239
240
241
242#endif /* VIENNASHE_TESTS_MOS1D_DG_HPP */
243
Configuration class for the simple mesh generator.
void add_segment(double start_x, double start_y, double len_x, double len_y, unsigned long points_x, unsigned long points_y)
Convenience header, which includes all core functionality available in ViennaSHE.
bool test_result(AccessorType const &quan, DeviceType const &device, std::string filename)
Tests the given quantity against reference data in a file. Uses reference_values.
Definition: mos1d_dg.hpp:182
void init_device(DeviceType &device, double Vg_init, double Nd, double Na)
Initalizes the MOS 1D device for testing.
Definition: mos1d_dg.hpp:94
list Nd
Definition: resistor.py:59
bool fuzzy_equal(double is, double should, double tol=1e-1)
Performs a fuzzy (up to a tolerance) equal. Returns true if is and should are equal within the tolera...
Definition: common.hpp:39
void generate_device(MeshT &mesh, SegmentationT &seg, device_generation_config const &conf)
Public interface for mesh generation of simple one- or two-dimensional meshes. Device must be rectang...
MOS 1D test-grid generator.
Definition: mos1d_dg.hpp:55
mos1d_mesh_generator(double len_gate, double cs_gate, double len_oxide, double cs_ox, double len_bulk, double cs_bulk)
Definition: mos1d_dg.hpp:57
void operator()(MeshT &mesh, SegmentationT &seg) const
Definition: mos1d_dg.hpp:62
A simple reference data reader.
Definition: mos1d_dg.hpp:129
bool read_file(std::string filename, char delimiter=' ')
Reads reference data from a CSV text file, where the main index to the data is the cell-id.
Definition: mos1d_dg.hpp:138
storage_type const & data() const
Definition: mos1d_dg.hpp:168
std::map< long, std::vector< double > > storage_type
Definition: mos1d_dg.hpp:130
A class referring to any metal contact.
Definition: all.hpp:44
A class referring to silicon and providing certain material parameters Note that this is the default ...
Definition: all.hpp:50
A class referring to silicon dioxide.
Definition: all.hpp:111
Contains common functions, functors and other classes often needed by the tests.