ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
gnuplot_writer_edf.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_IO_GNUPLOT_WRITER_EDF_HPP
2#define VIENNASHE_IO_GNUPLOT_WRITER_EDF_HPP
3
4/* ============================================================================
5 Copyright (c) 2011-2022, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8
9 -----------------
10 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
11 -----------------
12
13 http://viennashe.sourceforge.net/
14
15 License: MIT (X11), see file LICENSE in the base directory
16=============================================================================== */
17
18
19// std
20#include <math.h>
21#include <fstream>
22#include <iostream>
23
24// viennagrid
25#include "viennagrid/mesh/mesh.hpp"
26#include "viennagrid/algorithm/centroid.hpp"
27
28// viennashe
29#include "viennashe/forwards.h"
30#include "viennashe/config.hpp"
33
38namespace viennashe
39{
40 namespace io
41 {
42
45 {
46
54 template < typename DeviceType, typename EDFWrapperT >
55 void operator()(DeviceType const & device,
56 EDFWrapperT const & edf,
57 const double coordinate_x,
58 const std::string filename) const
59 {
60 typedef typename DeviceType::mesh_type MeshType;
61 typedef typename viennagrid::result_of::const_cell_range<MeshType> ::type CellContainer;
62 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
63 typedef typename EDFWrapperT::she_quantity_type she_quantity_type;
64
65 she_quantity_type const & quan = edf.quan();
66 //dispersion_relation_type const & dispersion = edf.dispersion_relation();
67
68 std::map<std::pair<double, double>, double > values; //key is x-coordinate, value is velocity
69 std::ofstream writer(filename.c_str());
70
71 if ( !writer )
72 throw cannot_open_file_exception(filename);
73
74 //iterate over edges:
75 CellContainer cells(device.mesh());
76 for ( CellIterator cit = cells.begin();
77 cit != cells.end();
78 ++cit )
79 {
80 if ( viennagrid::centroid(*cit)[0] != coordinate_x )
81 continue;
82
83 for ( std::size_t index_H = 1; index_H < quan.get_value_H_size() - 1; ++index_H )
84 {
85 const long index = quan.get_unknown_index(*cit, index_H);
86 const double eps = quan.get_kinetic_energy(*cit, index_H);
87 if ( index > -1 )
88 values[std::make_pair(viennagrid::centroid(*cit)[1], eps)] = edf(*cit, eps, index_H);
89 }
90 }
91
92
93 //now stream values to file:
94 double last_x = -1.0;
95 for ( std::map<std::pair<double, double>, double >::iterator it = values.begin();
96 it != values.end();
97 ++it )
98 {
99 double x_coord = it->first.first;
100 if ( x_coord < last_x || x_coord > last_x )
101 {
102 writer << std::endl;
103 last_x = x_coord;
104 }
105 writer << it->first.first << " " << it->first.second << " " << it->second << std::endl;
106 }
107
108 writer.close();
109 }
110
117 template <typename DeviceType,
118 typename CellFilterType,
119 typename EDFWrapperT>
120 void operator()(DeviceType const & device,
121 CellFilterType const & cell_filter,
122 EDFWrapperT const & edf,
123 const std::string filename)
124 {
125 typedef typename DeviceType::mesh_type MeshType;
126
127 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
128 typedef typename viennagrid::result_of::const_cell_range<MeshType> ::type CellContainer;
129 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
130
131 typedef typename EDFWrapperT::dispersion_relation_type dispersion_relation_type;
132 typedef typename EDFWrapperT::she_quantity_type she_quantity_type;
133
134 she_quantity_type const & quan = edf.quan();
135 dispersion_relation_type const & dispersion = edf.dispersion_relation();
136
137 std::ofstream writer(filename.c_str());
138
139 if ( !writer )
140 {
142 }
143
144 CellContainer cells(device.mesh());
145 for ( CellIterator cit = cells.begin();
146 cit != cells.end();
147 ++cit )
148 {
149 // filter vertices
150 if ( !cell_filter(*cit) ) continue;
151
152 //write values at point
153 for ( std::size_t index_H = 1;
154 index_H < quan.get_value_H_size() - 1;
155 ++index_H )
156 {
157
158 const long index = quan.get_unknown_index(*cit, index_H);
159 const double energy = quan.get_kinetic_energy(*cit, index_H);
160 if ( index > -1 && energy > 0 )
161 {
162 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i) writer << viennagrid::centroid(*cit)[i] << " ";
163 writer << (energy / viennashe::physics::constants::q) << " "
164 << edf(*cit, energy, index_H) << " "
165 << dispersion.density_of_states(energy)
166 << std::endl;
167 }
168 } // for index_H
169 writer << std::endl << std::endl; // for gnuplot block index
170 } // for vertices
171 } // operator()
172
173 };
174
175 } //namespace io
176} //namespace viennashe
177
178#endif
MeshT const & mesh() const
Returns the underlying mesh.
Definition: device.hpp:145
Defines the physical properties of a device, e.g. doping. This is the implementation for 2d and highe...
Definition: device.hpp:818
Exception which is thrown if a file cannot be opened.
Definition: exception.hpp:38
The SHE configuration class is defined here.
Contains forward declarations and definition of small classes that must be defined at an early stage.
All the exceptions used within the viennashe::io namespace.
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
Provides a number of fundamental constants. All constants in SI units.
Writes the energy distribution function to a file which can be processed by Gnuplot....
void operator()(DeviceType const &device, EDFWrapperT const &edf, const double coordinate_x, const std::string filename) const
Triggers the write process.
void operator()(DeviceType const &device, CellFilterType const &cell_filter, EDFWrapperT const &edf, const std::string filename)
Helper function for writing the energy distribution function at a particular points to a plain text f...
static const double q
Elementary charge.
Definition: constants.hpp:44