ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
gnuplot_writer.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_IO_GNUPLOT_WRITER_HPP
2#define VIENNASHE_IO_GNUPLOT_WRITER_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"
33#include "viennashe/log/log.hpp"
34
35
40namespace viennashe
41{
42 namespace io
43 {
44
47 {
48
50 template <typename DeviceType,
51 typename CellFilterType,
52 typename QuantitiyAccessorType>
53 void operator()(DeviceType const & device,
54 CellFilterType const & cell_filter,
55 QuantitiyAccessorType const & quan,
56 const std::string filename) const
57 {
58 typedef typename DeviceType::mesh_type MeshType;
59
60 typedef typename viennagrid::result_of::point<MeshType>::type PointType;
61
62 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
63 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
64
65 std::ofstream writer(filename.c_str());
66
67 if ( !writer )
68 {
70 }
71
72 writer << "## ViennaSHE - gnuplot output " << std::endl;
73
74 CellContainer cells(device.mesh());
75 for ( CellIterator cit = cells.begin();
76 cit != cells.end();
77 ++cit )
78 {
79 // filter vertices
80 if ( !cell_filter(*cit) ) continue;
81
82 //write values at point
83 PointType p = viennagrid::centroid(*cit);
84 for (std::size_t i = 0; i < static_cast<std::size_t>(PointType::dim); ++i) writer << p[i] << " ";
85 this->write_value(writer, quan(*cit));
86 writer << std::endl;
87 } // for vertices
88
89 log::info() << "* write_vertex_quantity_for_gnuplot(): Writing data to '"
90 << filename
91 << "' (can be viewed with e.g. gnuplot)" << std::endl;
92 } // operator()
93
95 template <typename DeviceType,
96 typename QuantitiyAccessorType>
97 void operator()(DeviceType const & device,
98 QuantitiyAccessorType const & quan,
99 const std::string filename) const
100 {
101 this->operator ()(device, viennashe::util::any_filter(), quan, filename);
102 }
103
104
105 private:
106
107 template < typename WriterT, typename ValueT >
108 void write_value(WriterT &, ValueT const &) const
109 {
111 error_type * obj; obj = 0; // fixes compiler warning; does not provide any functionality
112 }
113
114 template < typename WriterT >
115 void write_value(WriterT & writer, double const & val) const
116 {
117 writer << val << " " ;
118 }
119
120 template < typename WriterT >
121 void write_value(WriterT & writer, std::vector<double> const & val) const
122 {
123 for (std::size_t i = 0; i < val.size(); ++i)
124 writer << val[i] << " ";
125 }
126
127
128 }; // gnuplot_writer
129
131 template < typename DeviceType, typename AccessorType >
132 void write_cell_quantity_for_gnuplot(AccessorType const & quan, DeviceType const & device, std::string filename)
133 {
134 gnuplot_writer my_writer;
135 my_writer(device, viennashe::util::any_filter(), quan, filename);
136 } // write_vertex_quantity_for_gnuplot())
137
138 } //namespace io
139
140} //namespace viennashe
141
142#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
Defines several filter functors for the device. A filter functor returns true if the supplied argumen...
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.
A logging facility providing fine-grained control over logging in ViennaSHE.
void write_cell_quantity_for_gnuplot(AccessorType const &quan, DeviceType const &device, std::string filename)
Writes a quantity (on vertices) per point to a text file suitable for gnuplot.
logger< true > info()
Used to log infos. The logging level is logINFO.
Definition: log.hpp:307
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.
A helper class to raise compile time errors.
Definition: forwards.h:93
Writes quantities to a file which can be processed by Gnuplot. Works for 1d, 2d and 3d only.
void operator()(DeviceType const &device, QuantitiyAccessorType const &quan, const std::string filename) const
Helper function for writing a quantity at all cells to a plain text file. Output can be processed by ...
void operator()(DeviceType const &device, CellFilterType const &cell_filter, QuantitiyAccessorType const &quan, const std::string filename) const
Helper function for writing a quantity at particular cells to a plain text file. Output can be proces...
A trivial filter, all objects are accepted.
Definition: filter.hpp:41