ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
output.cpp
Go to the documentation of this file.
1/* ============================================================================
2 Copyright (c) 2011-2022, Institute for Microelectronics,
3 Institute for Analysis and Scientific Computing,
4 TU Wien.
5
6 -----------------
7 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
8 -----------------
9
10 http://viennashe.sourceforge.net/
11
12 License: MIT (X11), see file LICENSE in the base directory
13=============================================================================== */
14
15// C++ includes
18
19
20#include <iostream>
21#include <iosfwd>
22
23// C includes
25
26namespace libviennashe
27{
28
36 template < typename SimulatorT >
37 void write_to_gnuplot(SimulatorT const & sim, libviennashe::quan_register_internal & reg, std::string name, std::string filename)
38 {
39 typedef typename SimulatorT::device_type DeviceType;
40 typedef typename DeviceType::mesh_type MeshType;
41
42 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
43 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
44 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
45
46 DeviceType const & device = sim.device();
47
48 std::ofstream writer(filename.c_str());
49
50 if (!writer)
51 {
52 viennashe::log::error() << "write_to_gnuplot(): Cannot open the file '" << filename << "'" << std::endl;
54 }
55
56 writer << "## ViennaSHE - gnuplot output of '" << name << "' in SI units unless otherwise noted" << std::endl;
57 writer << "## x_i are the vertex coordinates (meter) and a_i are the quantity values " << std::endl;
58
59 bool first = true;
60
61 const std::size_t dim = static_cast<std::size_t>(PointType::dim);
62
63 CellContainer cells(device.mesh());
64
65 for (CellIterator cit = cells.begin();
66 cit != cells.end();
67 ++cit)
68 {
69
70 std::vector<double> values(1);
71 reg.cell_based.get(name).fill_single(std::size_t(cit->id().get()), values);
72
73 if (values.size() == 0) continue;
74
75 // Write preamble
76 if (first)
77 {
78 writer << "# ";
79 for (std::size_t i = 0; i < dim; ++i) writer << " x_" << i << " ";
80 for (std::size_t i = 0; i < values.size(); ++i) writer << " a_" << i << " ";
81 first = false;
82 writer << std::endl;
83 }
84
85 // Write values at point
86 for (std::size_t i = 0; i < dim; ++i) writer << viennagrid::centroid(*cit)[i] << " ";
87 for (std::size_t i = 0; i < values.size(); ++i) writer << values[i] << " ";
88 writer << std::endl;
89 } // for vertices
90
91 viennashe::log::info() << "* write_to_gnuplot(): Writing data to '"
92 << filename
93 << "' (can be viewed with e.g. gnuplot)" << std::endl;
94
95 }
96
103 template < typename SimulatorT >
104 void write_she_to_gnuplot(SimulatorT const & sim, viennashe::carrier_type_id ctype, std::string filename)
105 {
106 typedef typename SimulatorT::device_type DeviceType;
107 typedef typename DeviceType::mesh_type MeshType;
108
109 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
110 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
111 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
112
113 typedef typename SimulatorT::edf_type EDFType;
114 typedef typename SimulatorT::generalized_edf_type GeneralizedEDFType;
115 typedef typename viennashe::config::dispersion_relation_type DispersionRelationType;
116
117 // Safety check
118 if (ctype == viennashe::ELECTRON_TYPE_ID && (!sim.config().with_electrons() || sim.config().get_electron_equation() != viennashe::EQUATION_SHE))
119 {
120 viennashe::log::warning() << "Warning! write_she_to_gnuplot(): Electron SHE Quantities cannot be written to file. There are no quantities to write!" << std::endl;
121 return;
122 }
123 if (ctype == viennashe::HOLE_TYPE_ID && (!sim.config().with_holes() || sim.config().get_hole_equation() != viennashe::EQUATION_SHE))
124 {
125 viennashe::log::warning() << "Warning! write_she_to_gnuplot(): Hole SHE Quantities cannot be written to file. There are no quantities to write!" << std::endl;
126 return;
127 }
128
129 DeviceType const & device = sim.device();
130 viennashe::config const & conf = sim.config();
131 DispersionRelationType disp = conf.dispersion_relation(ctype);
132 EDFType edf = sim.edf(ctype);
133 GeneralizedEDFType gedf = sim.generalized_edf(ctype);
134
135
136 std::ofstream writer(filename.c_str());
137
138 if (!writer)
139 {
141 }
142
143 writer << "## ViennaSHE - gnuplot output of SHE "
144 << ((ctype == viennashe::ELECTRON_TYPE_ID) ? "Electron" : "Hole")
145 << " Quantities in SI units unless otherwise noted" << std::endl;
146 writer << "## x_i are the vertex coordinates (meter) " << std::endl;
147
148 bool first = true;
149
150 CellContainer cells(device.mesh());
151 for (CellIterator cit = cells.begin();
152 cit != cells.end();
153 ++cit)
154 {
155 // Write preamble
156 if (first)
157 {
158 writer << "# ";
159 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i) writer << " x_" << i << " ";
160 writer << " energy edf generalized_edf dos vg" << std::endl;
161 first = false;
162 }
163
164 // Write values at point
165 for (std::size_t index_H = 1; index_H < sim.quantities().carrier_distribution_function(ctype).get_value_H_size()-1; ++index_H)
166 {
167 const double eps = sim.quantities().carrier_distribution_function(ctype).get_kinetic_energy(*cit, index_H);
168 const double dos = disp.density_of_states(eps);
169 const double velo = disp.velocity(eps);
170
171 if (eps >= 0.0)
172 {
173 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i) writer << viennagrid::centroid(*cit)[i] << " ";
174 writer << eps << " " << edf(*cit, eps, index_H) << " " << gedf(*cit, eps, index_H) << " " << dos << " " << velo << std::endl;
175 }
176 }
177
178 writer << std::endl;
179 writer << std::endl;
180 } // for vertices
181
182 viennashe::log::info() << "* write_she_to_gnuplot(): Writing data to '"
183 << filename
184 << "' (can be viewed with e.g. gnuplot)" << std::endl;
185 }
186
187} // namespace libviennashe
188
189
190#ifdef __cplusplus
191extern "C"
192{
193#endif
194
195viennasheErrorCode viennashe_write_to_gnuplot(viennashe_quan_register reg, char const * name, char const * filename)
196{
197 try
198 {
199 //
200 // CHECKS
201 if (reg == NULL)
202 {
203 viennashe::log::error() << "ERROR! write_to_gnuplot: The quantity regiser (reg) must not be NULL!" << std::endl;
204 return 1;
205 }
206 if (filename == NULL)
207 {
208 viennashe::log::error() << "ERROR! write_to_gnuplot: The filename must not be NULL!" << std::endl;
209 return 3;
210 }
211 // Get the internal structure
213 // Get internal simulator
214 viennashe_simulator_impl const * int_sim = int_reg->int_sim;
215 // More checks
216 if (!int_sim->is_valid())
217 {
218 viennashe::log::error() << "ERROR! write_to_gnuplot(): The simulator (sim) must be valid!" << std::endl;
219 return 1;
220 }
221 // Check if the quan exists
222 if(! int_reg->cell_based.has_quan(name))
223 {
224 viennashe::log::error() << "ERROR! write_to_gnuplot(): The quantity '" << name << "' does not exist!" << std::endl;
225 return 2;
226 }
227
228 // Do the actual work
230 {
231 libviennashe::write_to_gnuplot(*(int_sim->sim1d), *int_reg, std::string(name), std::string(filename));
232 }
234 {
235 libviennashe::write_to_gnuplot(*(int_sim->simq2d), *int_reg, std::string(name), std::string(filename));
236 }
238 {
239 libviennashe::write_to_gnuplot(*(int_sim->simt2d), *int_reg, std::string(name), std::string(filename));
240 }
242 {
243 libviennashe::write_to_gnuplot(*(int_sim->simh3d), *int_reg, std::string(name), std::string(filename));
244 }
246 {
247 libviennashe::write_to_gnuplot(*(int_sim->simt3d), *int_reg, std::string(name), std::string(filename));
248 }
249 else
250 {
251 viennashe::log::error() << "ERROR! write_to_gnuplot(): Unkown grid type!" << std::endl;
252 return -2;
253 }
254 }
255 catch (std::exception const & ex)
256 {
257 viennashe::log::error() << "ERROR! write_to_gnuplot: Exception!" << std::endl;
258 viennashe::log::error() << "What? " << ex.what() << std::endl;
259 return -1;
260 }
261 catch (...)
262 {
263 viennashe::log::error() << "ERROR! write_to_gnuplot: UNKOWN ERROR!" << std::endl;
264 return -1;
265 }
266 return 0;
267}
268
269
271{
272 try
273 {
274 //
275 // CHECKS
276 if (reg == NULL)
277 {
278 viennashe::log::error() << "ERROR! viennashe_write_she_results_to_gnuplot: The quantity regiser (reg) must not be NULL!" << std::endl;
279 return 1;
280 }
281 if (filename == NULL)
282 {
283 viennashe::log::error() << "ERROR! viennashe_write_she_results_to_gnuplot: The filename must not be NULL!" << std::endl;
284 return 3;
285 }
286
287 // Get the internal structure
289 // Get internal simulator
290 viennashe_simulator_impl const * int_sim = int_reg->int_sim;
291 // More checks
292 if (!int_sim->is_valid())
293 {
294 viennashe::log::error() << "ERROR! viennashe_write_she_results_to_gnuplot(): The simulator (sim) must be valid!" << std::endl;
295 return 1;
296 }
297
299
300 // Do the actual work
302 {
303 libviennashe::write_she_to_gnuplot(*(int_sim->sim1d), ctype, std::string(filename));
304 }
306 {
307 libviennashe::write_she_to_gnuplot(*(int_sim->simq2d), ctype, std::string(filename));
308 }
309 else if (int_sim->stype == libviennashe::meshtype::triangular_2d)
310 {
311 libviennashe::write_she_to_gnuplot(*(int_sim->simt2d), ctype, std::string(filename));
312 }
313 else if (int_sim->stype == libviennashe::meshtype::hexahedral_3d)
314 {
315 libviennashe::write_she_to_gnuplot(*(int_sim->simh3d), ctype, std::string(filename));
316 }
318 {
319 libviennashe::write_she_to_gnuplot(*(int_sim->simt3d), ctype, std::string(filename));
320 }
321 else
322 {
323 viennashe::log::error() << "ERROR! viennashe_write_she_results_to_gnuplot(): Unkown grid type!" << std::endl;
324 return -2;
325 }
326 }
327 catch (...)
328 {
329 viennashe::log::error() << "ERROR! viennashe_write_she_results_to_gnuplot: UNKOWN ERROR!" << std::endl;
330 return -1;
331 }
332 return 0;
333}
334
335
336#ifdef __cplusplus
337}
338#endif
339
bool has_quan(std::string const &name) const
Returns true if a quantity is registered.
The main SHE configuration class. To be adjusted by the user for his/her needs.
Definition: config.hpp:124
viennashe::physics::dispersion_proxy dispersion_relation(viennashe::carrier_type_id ctype) const
Returns the dispersion relation for electrons.
Definition: config.hpp:266
Exception which is thrown if a file cannot be opened.
Definition: exception.hpp:38
A proxy object for a dispersion relation. Does NOT take ownership of the provided pointer!
Definition: dispersion.hpp:69
int viennasheErrorCode
Definition: error.h:25
The internal C++ namespace of the library.
reg
This is DD, so we do not need to give any inital guess.
Definition: resistor.py:84
logger< true > error()
Used to log errors. The logging level is logERROR.
Definition: log.hpp:301
logger< true > warning()
Used to log warnings. The logging level is logWARNING.
Definition: log.hpp:305
logger< true > info()
Used to log infos. The logging level is logINFO.
Definition: log.hpp:307
carrier_type_id
Enumeration type for selecting the carrier type.
Definition: forwards.h:185
@ HOLE_TYPE_ID
Definition: forwards.h:188
@ ELECTRON_TYPE_ID
Definition: forwards.h:187
@ EQUATION_SHE
Definition: forwards.h:118
VIENNASHE_EXPORT viennasheErrorCode viennashe_write_to_gnuplot(viennashe_quan_register reg, char const *name, char const *filename)
VIENNASHE_EXPORT viennasheErrorCode viennashe_write_she_results_to_gnuplot(viennashe_quan_register reg, viennashe_carrier_ids ctype, char const *filename)
viennashe_quan_register_impl * viennashe_quan_register
Definition: quantity.h:31
viennashe_carrier_ids
Enum of available charge carrier types.
Definition: quantity.h:34
@ viennashe_electron_id
Definition: quantity.h:34
Routines to wrap ViennaSHE quantities (doping, potential, distribution functions, ....
C++ to C wrapper of the quantity registry.
libviennashe::quantity::quantitiy_register cell_based
viennashe_simulator_impl * int_sim
Register for vertex based quantities.
Internal C++ to C wrapper for the simulator. Has typedefs and destructor.
#define VIENNASHE_EXPORT
Definition: sys.h:19
Contains all viennashe includes and most of the C++/C-wrappers. Contains macros.