ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
simulator_quantity.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_SIMULATOR_QUANTITY_HPP
2#define VIENNASHE_SIMULATOR_QUANTITY_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
23#include <vector>
24#include <string>
25
26#include "viennagrid/mesh/mesh.hpp"
27
28#include "viennashe/forwards.h"
29
30namespace viennashe
31{
32
34 namespace quantity
35 {
36 inline std::string potential() { return "Electrostatic potential"; }
37 inline std::string electron_density() { return "Electron density"; }
38 inline std::string hole_density() { return "Hole density"; }
39 inline std::string density_gradient_electron_correction() { return "DG electron correction potential"; }
40 inline std::string density_gradient_hole_correction() { return "DG hole correction potential"; }
41 inline std::string lattice_temperature() { return "Lattice temperature"; }
42 inline std::string electron_distribution_function() { return "Electron distribution function"; }
43 inline std::string hole_distribution_function() { return "Hole distribution function"; }
44 }
45
50 template<typename AssociatedT, typename ValueT = double>
52 {
53 public:
55
56 typedef ValueT value_type;
57 typedef AssociatedT associated_type;
59
60 const_quantity(std::string quan_name,
61 std::size_t num_values,
62 value_type default_value = value_type())
63 : name_(quan_name),
64 values_(num_values, default_value) {}
65
66 const_quantity(std::string quan_name,
67 std::vector<ValueT> const & values_array)
68 : name_(quan_name),
69 values_(values_array) {}
70
71 const_quantity(self_type const & o) : name_(o.name_), values_(o.values_) { }
72 void operator=(self_type const & o) { name_ = o.name_; values_ = o.values_; }
73
74 ValueT get_value (associated_type const & elem) const { return values_.at(static_cast<std::size_t>(elem.id().get())); }
75 ValueT at (associated_type const & elem) const { return this->get_value(elem); }
76 ValueT operator()(associated_type const & elem) const { return this->get_value(elem); }
77
78 std::string name() const { return name_; }
79
80 private:
81 std::string name_;
82 std::vector<ValueT> values_;
83 };
84
85 template<typename AssociatedT, typename ValueT = double>
87 {
88 public:
90
91 typedef ValueT value_type;
92 typedef AssociatedT associated_type;
93
94 non_const_quantity(std::string quan_name,
95 std::size_t num_values,
96 value_type default_value = value_type())
97 : name_(quan_name), values_(num_values, default_value) {}
98
99 non_const_quantity(std::string quan_name,
100 std::vector<ValueT> const & values_array)
101 : name_(quan_name), values_(values_array) {}
102
103 non_const_quantity(self_type const & o) : name_(o.name_), values_(o.values_) { }
104 void operator=(self_type const & o) { name_ = o.name_; values_ = o.values_; }
105
106
107 ValueT get_value(associated_type const & elem) const { return values_.at(static_cast<std::size_t>(elem.id().get())); }
108 ValueT at (associated_type const & elem) const { return this->get_value(elem); }
109 ValueT operator()(associated_type const & elem) const { return this->get_value(elem); }
110 void set_value(associated_type const & elem, ValueT value) { values_.at(static_cast<std::size_t>(elem.id().get())) = value; }
111
112 std::string name() const { return name_; }
113
114 private:
115 std::string name_;
116 std::vector<ValueT> values_;
117 };
118
119 template <typename ValueT = double>
121 {
122 ValueT alpha;
123 ValueT beta;
124 };
125
126 template<typename AssociatedT, typename ValueT = double>
128 {
129 std::size_t get_id(AssociatedT const & elem) const { return static_cast<std::size_t>(elem.id().get()); }
130
131 public:
133
134 typedef ValueT value_type;
135 typedef AssociatedT associated_type;
137
138 unknown_quantity() {} // to fulfill default constructible concept!
139
140 unknown_quantity(std::string const & quan_name,
141 equation_id quan_equation,
142 std::size_t num_values,
143 value_type default_value = value_type())
144 : name_(quan_name),
145 equation_(quan_equation),
146 values_ (num_values, default_value),
147 boundary_types_ (num_values, BOUNDARY_NONE),
148 boundary_values_ (num_values, default_value),
149 boundary_values_alpha_ (num_values, 0),
150 defined_but_unknown_mask_(num_values, false),
151 unknowns_indices_ (num_values, -1),
152 log_damping_(false)
153 {}
154
156 : name_(o.name_),
157 equation_(o.equation_),
158 values_ (o.values_),
159 boundary_types_ (o.boundary_types_),
160 boundary_values_ (o.boundary_values_),
161 boundary_values_alpha_ (o.boundary_values_alpha_),
162 defined_but_unknown_mask_(o.defined_but_unknown_mask_),
163 unknowns_indices_ (o.unknowns_indices_),
164 log_damping_ (o.log_damping_)
165 { }
166
167 void operator=(self_type const & o)
168 {
169 name_ = o.name_;
170 equation_ = o.equation_;
171 values_ = o.values_;
172 boundary_types_ = o.boundary_types_;
173 boundary_values_ = o.boundary_values_;
174 boundary_values_alpha_ = o.boundary_values_alpha_;
175 defined_but_unknown_mask_= o.defined_but_unknown_mask_;
176 unknowns_indices_ = o.unknowns_indices_;
177 log_damping_ = o.log_damping_;
178 }
179
180 std::string get_name() const { return name_; }
181
182 equation_id get_equation() const { return equation_; }
183
184 ValueT get_value(associated_type const & elem) const { return values_.at(get_id(elem)); }
185 ValueT at (associated_type const & elem) const { return this->get_value(elem); }
186 ValueT operator()(associated_type const & elem) const { return this->get_value(elem); }
187
188 void set_value(associated_type const & elem, ValueT value) { values_.at(get_id(elem)) = value; }
189 void set_value(associated_type const & elem, robin_boundary_type value) { (void)elem; (void)value; } //TODO: Fix this rather ugly hack which stems from set_boundary_for_material()
190
191 // Dirichlet and Neumann
192 ValueT get_boundary_value(associated_type const & elem) const { return boundary_values_.at(get_id(elem)); }
193 void set_boundary_value(associated_type const & elem, ValueT value) { boundary_values_.at(get_id(elem)) = value; }
194
195 // Robin boundary conditions
202 {
204 ret.alpha = boundary_values_alpha_.at(get_id(elem));
205 ret.beta = boundary_values_.at(get_id(elem));
206 return ret;
207 }
208
214 {
215 boundary_values_.at(get_id(elem)) = values.beta;
216 boundary_values_alpha_.at(get_id(elem)) = values.alpha;
217 }
218
219 boundary_type_id get_boundary_type(associated_type const & elem) const { return boundary_types_.at(get_id(elem)); }
220 void set_boundary_type(associated_type const & elem, boundary_type_id value) { boundary_types_.at(get_id(elem)) = value; }
221
222 bool get_unknown_mask(associated_type const & elem) const { return defined_but_unknown_mask_.at(get_id(elem)); }
223 void set_unknown_mask(associated_type const & elem, bool value) { defined_but_unknown_mask_.at(get_id(elem)) = value; }
224
225 long get_unknown_index(associated_type const & elem) const { return unknowns_indices_.at(get_id(elem)); }
226 void set_unknown_index(associated_type const & elem, long value) { unknowns_indices_.at(get_id(elem)) = value; }
227
228 std::size_t get_unknown_num() const
229 {
230 std::size_t num = 0;
231 for (std::size_t i=0; i<unknowns_indices_.size(); ++i)
232 {
233 if (unknowns_indices_[i] >= 0)
234 ++num;
235 }
236 return num;
237 }
238
239 // possible design flaws:
240 std::vector<ValueT> const & values() const { return values_; }
241 std::vector<boundary_type_id> const & boundary_types() const { return boundary_types_; }
242 std::vector<ValueT> const & boundary_values() const { return boundary_values_; }
243 std::vector<bool> const & defined_but_unknown_mask() const { return defined_but_unknown_mask_; }
244 std::vector<long> const & unknowns_indices() const { return unknowns_indices_; }
245
246
247 bool get_logarithmic_damping() const { return log_damping_; }
248 void set_logarithmic_damping(bool b) { log_damping_ = b; }
249
250 private:
251 std::string name_;
252 equation_id equation_;
253 std::vector<ValueT> values_;
254 std::vector<boundary_type_id> boundary_types_;
255 std::vector<ValueT> boundary_values_;
256 std::vector<ValueT> boundary_values_alpha_;
257 std::vector<bool> defined_but_unknown_mask_;
258 std::vector<long> unknowns_indices_;
259 bool log_damping_;
260 };
261
262
263} //namespace viennashe
264
265#endif
Common representation of any quantity associated with objects of a certain type.
ValueT operator()(associated_type const &elem) const
const_quantity(std::string quan_name, std::size_t num_values, value_type default_value=value_type())
const_quantity(self_type const &o)
ValueT at(associated_type const &elem) const
void operator=(self_type const &o)
ValueT get_value(associated_type const &elem) const
const_quantity< AssociatedT, ValueT > self_type
const_quantity(std::string quan_name, std::vector< ValueT > const &values_array)
non_const_quantity(std::string quan_name, std::size_t num_values, value_type default_value=value_type())
ValueT operator()(associated_type const &elem) const
non_const_quantity(std::string quan_name, std::vector< ValueT > const &values_array)
non_const_quantity(self_type const &o)
ValueT at(associated_type const &elem) const
non_const_quantity< AssociatedT, ValueT > self_type
void operator=(self_type const &o)
void set_value(associated_type const &elem, ValueT value)
ValueT get_value(associated_type const &elem) const
unknown_quantity< AssociatedT, ValueT > self_type
std::vector< long > const & unknowns_indices() const
std::vector< bool > const & defined_but_unknown_mask() const
void set_boundary_value(associated_type const &elem, robin_boundary_type const &values)
Setter function for Robin boundary conditions.
unknown_quantity(self_type const &o)
ValueT at(associated_type const &elem) const
bool get_unknown_mask(associated_type const &elem) const
ValueT get_value(associated_type const &elem) const
void set_boundary_value(associated_type const &elem, ValueT value)
robin_boundary_coefficients< ValueT > robin_boundary_type
void set_value(associated_type const &elem, robin_boundary_type value)
std::vector< ValueT > const & values() const
ValueT get_boundary_value(associated_type const &elem) const
std::vector< boundary_type_id > const & boundary_types() const
ValueT operator()(associated_type const &elem) const
long get_unknown_index(associated_type const &elem) const
std::size_t get_unknown_num() const
std::vector< ValueT > const & boundary_values() const
robin_boundary_type get_boundary_values(associated_type const &elem) const
Returns the coefficients alpha and beta for the Robin boundary condition du/dn = beta - alpha u.
boundary_type_id get_boundary_type(associated_type const &elem) const
void set_boundary_type(associated_type const &elem, boundary_type_id value)
unknown_quantity(std::string const &quan_name, equation_id quan_equation, std::size_t num_values, value_type default_value=value_type())
void operator=(self_type const &o)
void set_unknown_mask(associated_type const &elem, bool value)
void set_value(associated_type const &elem, ValueT value)
void set_unknown_index(associated_type const &elem, long value)
Contains forward declarations and definition of small classes that must be defined at an early stage.
std::string lattice_temperature()
std::string electron_distribution_function()
std::string density_gradient_hole_correction()
std::string hole_distribution_function()
std::string density_gradient_electron_correction()
std::string electron_density()
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
equation_id
An enumeration of all equation types ViennaSHE supports.
Definition: forwards.h:114
boundary_type_id
An enumeration of all boundary conditions ViennaSHE supports.
Definition: forwards.h:125
@ BOUNDARY_NONE
Definition: forwards.h:126