1#ifndef VIENNASHE_TESTS_MOS1D_DG_HPP
2#define VIENNASHE_TESTS_MOS1D_DG_HPP
23 #pragma warning(disable:4503)
36#include "viennagrid/config/default_configs.hpp"
37#include "viennagrid/algorithm/centroid.hpp"
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)
61 template <
typename MeshT,
typename SegmentationT >
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);
93template <
typename DeviceType>
94void init_device(DeviceType & device,
double Vg_init,
double Nd,
double Na)
96 typedef typename DeviceType::segment_type SegmentType;
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);
104 std::cout <<
"* init_device(): Setting material ..." << std::endl;
112 std::cout <<
"* init_device(): Setting doping (per cell) ..." << std::endl;
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);
119 std::cout <<
"* init_device(): Setting contact potentials (per cell) ..." << std::endl;
121 device.set_contact_potential(0.0, bulk);
122 device.set_contact_potential(Vg_init, gate);
124 std::cout <<
"* init_device(): DONE!" << std::endl;
138 bool read_file(std::string filename,
char delimiter =
' ')
140 std::ifstream reader(filename.c_str());
141 if(!reader)
return false;
144 while(reader.good() && !reader.eof())
146 std::vector<double> result;
148 std::getline(reader,line);
150 std::stringstream lineStream(line);
153 if(line.length() == 0)
continue;
154 if(line[0] ==
'#' )
continue;
156 while(std::getline(lineStream, cell, delimiter))
158 result.push_back(atof(cell.c_str()));
161 data_.insert(std::make_pair(i,result));
181template <
typename DeviceType,
typename AccessorType >
182bool test_result(AccessorType
const & quan, DeviceType
const & device, std::string filename )
184 typedef typename DeviceType::mesh_type MeshType;
186 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
188 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
189 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
191 const double tol = 1e-1;
193 std::cout <<
"test_result(): file = '" << filename <<
"'" << std::endl;
198 bool ok = referencefile.
read_file(filename);
201 std::cerr <<
"test_result(): Unable to read file '" << filename <<
"'" << std::endl;
206 CellContainer cells(device.mesh());
207 for (CellIterator cit = cells.begin();
212 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i)
214 const double value = viennagrid::centroid(*cit)[i];
215 const double refvalue = referencefile.
data().at(linenum)[i];
218 std::cerr <<
"test_result(): Failure at " << *cit <<
" => " << quan(*cit) << std::endl;
222 const double value = quan(*cit);
223 const double refvalue = referencefile.
data().at(linenum)[PointType::dim];
226 std::cerr <<
"test_result(): Failure at " << *cit <<
" => " << quan(*cit) << std::endl;
231 catch(std::exception & ex)
233 std::cerr <<
"test_result(): FAILED! What? " << ex.what() << std::endl;
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.
void init_device(DeviceType &device, double Vg_init, double Nd, double Na)
Initalizes the MOS 1D device for testing.
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...
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.
mos1d_mesh_generator(double len_gate, double cs_gate, double len_oxide, double cs_ox, double len_bulk, double cs_bulk)
void operator()(MeshT &mesh, SegmentationT &seg) const
A simple reference data reader.
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.
storage_type const & data() const
std::map< long, std::vector< double > > storage_type
A class referring to silicon and providing certain material parameters Note that this is the default ...
A class referring to silicon dioxide.
Contains common functions, functors and other classes often needed by the tests.