ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
simulator.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
16#include "viennashe_all.hpp"
17
18// C includes
20
21
22namespace libviennashe
23{
24
30 template < typename SimulatorT >
31 void set_initial_guess(SimulatorT & sim, SimulatorT const & other_sim)
32 {
33 sim.set_initial_guess(viennashe::quantity::potential(), other_sim.potential());
34 sim.set_initial_guess(viennashe::quantity::electron_density(), other_sim.electron_density());
35 sim.set_initial_guess(viennashe::quantity::hole_density(), other_sim.hole_density());
36 }
37
44 template < typename SimulatorT >
45 void set_initial_guess(SimulatorT & sim, std::string name, double * values)
46 {
48 sim.set_initial_guess(name, tacc);
49 }
50
51} // namespace libviennashe
52
53
54
55#ifdef __cplusplus
56extern "C"
57{
58#endif
59
60
62{
63 try
64 {
65 //
66 // Checks
68 CHECK_ARGUMENT_FOR_NULL(conf,3,"conf");
69
70 // Get internal configuration and device
71 viennashe::config * int_conf = reinterpret_cast<viennashe::config *>(conf);
72 viennashe_device_impl * int_dev = dev;
73
74 // Check the device
75 if (!int_dev->is_valid())
76 {
77 viennashe::log::error() << "ERROR! create_simulator(): The device (dev) must be valid!" << std::endl;
78 return 2;
79 }
80 // Create the internal simulator object and init with grid type and config
81 viennashe_simulator_impl * int_sim = new viennashe_simulator_impl(int_dev->stype, int_conf);
82
83 //
84 // Create viennashe::simulator per grid type
86 {
87 int_sim->sim1d = new viennashe_simulator_impl::sim1d_type(*(int_dev->device_1d), *int_conf);
88 }
90 {
91 int_sim->simq2d = new viennashe_simulator_impl::simq2d_type(*(int_dev->device_quad_2d), *int_conf);
92 }
94 {
95 int_sim->simt2d = new viennashe_simulator_impl::simt2d_type(*(int_dev->device_tri_2d), *int_conf);
96 }
98 {
99 int_sim->simh3d = new viennashe_simulator_impl::simh3d_type(*(int_dev->device_hex_3d), *int_conf);
100 }
102 {
103 int_sim->simt3d = new viennashe_simulator_impl::simt3d_type(*(int_dev->device_tet_3d), *int_conf);
104 }
105 else
106 {
107 viennashe::log::error() << "ERROR! create_device(): The given mesh is malconfigured!" << std::endl;
108 return 2;
109 }
110 // RETURN
111 *sim = int_sim;
112 }
113 catch(...)
114 {
115 viennashe::log::error() << "ERROR! create_simulator(): UNKOWN ERROR!" << std::endl;
116 return -1;
117 }
118 return 0;
119}
120
122{
123 try
124 {
125 if (sim != NULL)
126 {
127 // The internal configuration is not destroyed!
128 delete sim;
129 }
130 }
131 catch(...)
132 {
133 viennashe::log::error() << "ERROR! free_simulator(): UNKOWN ERROR!" << std::endl;
134 return -1;
135 }
136 return 0;
137}
138
140{
141 try
142 {
143 //
144 // Checks
145 CHECK_ARGUMENT_FOR_NULL(sim,1,"sim");
146 CHECK_ARGUMENT_FOR_NULL(other_sim,2,"other_sim");
147
148 //
149 // Get internal structures
150 viennashe_simulator_impl * int_sim = (sim);
151 viennashe_simulator_impl * int_other_sim = (other_sim);
152 //
153 // Checks
154 if (!int_sim->is_valid())
155 {
156 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): The simulator (sim) must be valid!" << std::endl;
157 return 1;
158 }
159 if (!int_other_sim->is_valid())
160 {
161 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): The simulator (other_sim) must be valid!" << std::endl;
162 return 1;
163 }
164 if (int_sim->stype != int_other_sim->stype)
165 {
166 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): The simulators (sim and other_sim)"
167 << " must be operating on the same grid!" << std::endl;
168 return 2;
169 }
170
171 //
172 // Transfer the initial guess
173
175 {
176 libviennashe::set_initial_guess(*(int_sim->sim1d), *(int_other_sim->sim1d));
177 }
179 {
180 libviennashe::set_initial_guess(*(int_sim->simq2d), *(int_other_sim->simq2d));
181 }
183 {
184 libviennashe::set_initial_guess(*(int_sim->simt2d), *(int_other_sim->simt2d));
185 }
187 {
188 libviennashe::set_initial_guess(*(int_sim->simh3d), *(int_other_sim->simh3d));
189 }
191 {
192 libviennashe::set_initial_guess(*(int_sim->simt3d), *(int_other_sim->simt3d));
193 }
194 else
195 {
196 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): Unkown grid type!" << std::endl;
197 return 1;
198 }
199 }
201 {
202 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): Quantity not found exception! What? '" << ex.what() << "'" << std::endl;
203 return 2;
204 }
205 catch(...)
206 {
207 viennashe::log::error() << "ERROR! set_initial_guess_from_other_sim(): UNKOWN ERROR!" << std::endl;
208 return -1;
209 }
210 return 0;
211}
212
213viennasheErrorCode viennashe_set_initial_guess(viennashe_simulator_impl * sim, const char * name, double * values)
214{
215 try
216 {
217 CHECK_ARGUMENT_FOR_NULL(sim,1,"sim");
218
219 //
220 // Get internal structures
221 viennashe_simulator_impl * int_sim = sim;
222 //
223 // Checks
224 if (!int_sim->is_valid())
225 {
226 viennashe::log::error() << "ERROR! set_initial_guess(): The simulator (sim) must be valid!" << std::endl;
227 return 1;
228 }
229
230 //
231 // Transfer the initial guess
232
234 {
235 libviennashe::set_initial_guess(*(int_sim->sim1d), name, values);
236 }
238 {
239 libviennashe::set_initial_guess(*(int_sim->simq2d), name, values);
240 }
242 {
243 libviennashe::set_initial_guess(*(int_sim->simt2d), name, values);
244 }
246 {
247 libviennashe::set_initial_guess(*(int_sim->simh3d), name, values);
248 }
250 {
251 libviennashe::set_initial_guess(*(int_sim->simt3d), name, values);
252 }
253 else
254 {
255 viennashe::log::error() << "ERROR! set_initial_guess(): Unkown grid type!" << std::endl;
256 return -2;
257 }
258 }
260 {
261 viennashe::log::error() << "ERROR! set_initial_guess(): Quantity not found exception! What? '" << ex.what() << "'" << std::endl;
262 return 2;
263 }
264 catch(...)
265 {
266 viennashe::log::error() << "ERROR! set_initial_guess(): UNKOWN ERROR!" << std::endl;
267 return -1;
268 }
269 return 0;
270}
271
273{
274 try
275 {
276 CHECK_ARGUMENT_FOR_NULL(sim,1,"sim");
277
278
279 viennashe_simulator_impl * int_sim = sim;
280
281 if (!int_sim->is_valid())
282 {
283 viennashe::log::error() << "ERROR! run(): The simulator (sim) must be valid!" << std::endl;
284 return 1;
285 }
286
288 {
289 int_sim->sim1d->run();
290 }
292 {
293 int_sim->simq2d->run();
294 }
296 {
297 int_sim->simt2d->run();
298 }
300 {
301 int_sim->simh3d->run();
302 }
304 {
305 int_sim->simt3d->run();
306 }
307 else
308 {
309 viennashe::log::error() << "ERROR! run(): Unkown grid type!" << std::endl;
310 return -2;
311 }
312 }
313 catch(...)
314 {
315 viennashe::log::error() << "ERROR! run(): UNKOWN ERROR!" << std::endl;
316 return -1;
317 }
318 return 0;
319}
320
321
322#ifdef __cplusplus
323}
324#endif
Maps a C-array to an element based accessor. Uses element.id() as an index to the C-array.
The main SHE configuration class. To be adjusted by the user for his/her needs.
Definition: config.hpp:124
Exception in case a (requested) quantity cannot be found.
Definition: exception.hpp:133
void run()
Launches the solver. Uses the built-in potential as initial guess for the potential and the doping co...
Definition: simulator.hpp:877
viennashe_config_impl * viennashe_config
Definition: config.h:31
int viennasheErrorCode
Definition: error.h:25
The internal C++ namespace of the library.
void set_initial_guess(DeviceT const &device, QuantityT &quan, BoundaryValueAccessorT const &initial_guess_accessor)
Sets the initial guess per quantity and device.
Definition: simulator.hpp:200
logger< true > error()
Used to log errors. The logging level is logERROR.
Definition: log.hpp:301
std::string electron_density()
VIENNASHE_EXPORT viennasheErrorCode viennashe_run(viennashe_simulator sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_initial_guess_from_other_sim(viennashe_simulator sim, viennashe_simulator other_sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_initial_guess(viennashe_simulator sim, const char *name, double *values)
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_simulator(viennashe_simulator sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_simulator(viennashe_simulator *sim, viennashe_device dev, viennashe_config conf)
Internal C++ to C wrapper for the device. Has typedefs and destructor.
devq2d_type * device_quad_2d
devt2d_type * device_tri_2d
devh3d_type * device_hex_3d
devt3d_type * device_tet_3d
Internal C++ to C wrapper for the simulator. Has typedefs and destructor.
viennashe::simulator< dev1d_type > sim1d_type
viennashe::simulator< devq2d_type > simq2d_type
viennashe::simulator< devh3d_type > simh3d_type
viennashe::simulator< devt3d_type > simt3d_type
viennashe::simulator< devt2d_type > simt2d_type
struct viennashe_simulator_impl viennashe_simulator_impl
Simulator implementation type.
Definition: sys.h:37
Contains all viennashe includes and most of the C++/C-wrappers. Contains macros.
#define CHECK_ARGUMENT_FOR_NULL(arg, pos, name)