ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
config.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_SOLVERS_CONFIG_HPP
2#define VIENNASHE_SOLVERS_CONFIG_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#include <iostream>
19#include <algorithm>
20
21#include "viennashe/forwards.h"
22
24
29namespace viennashe
30{
31 namespace solvers
32 {
33
34 //
35 // Part 1: Linear solvers
36 //
37
40 {
41 enum
42 {
49 };
50 };
51
57 {
58 public:
59 typedef std::vector<std::pair<std::size_t, std::size_t> > block_preconditioner_boundaries_container;
60
62 : id_(linear_solver_ids::serial_linear_solver), tol_(1e-13), max_iters_(
63 1000), ilut_entries_(60), ilut_drop_tol_(1e-4), do_scale_(true)
64 {
65 }
66
68 void scale(bool value)
69 {
70 do_scale_ = value;
71 }
73 bool scale() const
74 {
75 return do_scale_;
76 }
77
79 long id() const
80 {
81 return id_;
82 }
84 void set(long solver_id)
85 {
86 switch (solver_id)
87 {
93#ifdef VIENNASHE_HAVE_GPU_SOLVER
95#endif
96 id_ = solver_id;
97 break;
98 default:
100 }
101 }
102
104 void set(std::string solver_name)
105 {
106 // to upper to ease the comparison and to be case insensitive
107 std::transform(solver_name.begin(), solver_name.end(),
108 solver_name.begin(), ::tolower);
109
110 if (solver_name == "dense_linear_solver")
111 {
113 } else if (solver_name == "serial_linear_solver")
114 {
116 } else if (solver_name == "parallel_linear_solver")
117 {
119 } else if (solver_name == "petsc_parallel_linear_solver")
120 {
122 }
123 else if (solver_name == "petsc_parallel_AMGX_solver")
124 {
126 }
127#ifdef VIENNASHE_HAVE_GPU_SOLVER
128 else if (solver_name == "gpu_parallel_linear_solver")
129 {
131 }
132#endif
133 else
134 {
136 }
137 }
139
140
141 }
143 double tolerance() const
144 {
145 return tol_;
146 }
148 void tolerance(double tol)
149 {
150 if (tol > 0)
151 tol_ = tol;
152 }
153
155 std::size_t max_iters() const
156 {
157 return max_iters_;
158 }
160 void max_iters(std::size_t iters)
161 {
162 max_iters_ = iters;
163 }
164
166 std::size_t ilut_entries() const
167 {
168 return ilut_entries_;
169 }
171 void ilut_entries(std::size_t num)
172 {
173 ilut_entries_ = num;
174 }
175
177 double ilut_drop_tolerance() const
178 {
179 return ilut_drop_tol_;
180 }
182 void ilut_drop_tolerance(double tol)
183 {
184 if (tol > 0)
185 ilut_drop_tol_ = tol;
186 }
187
189 {
190 return block_precond_boundaries_;
191 }
193 {
194 return block_precond_boundaries_;
195 }
196
197 int getArgc() const
198 {
199 return argc;
200 }
201
202 void setArgc(int argc)
203 {
204 this->argc = argc;
205 }
206
207 char** getArgv() const
208 {
209 return argv;
210 }
211
212 void setArgv(char** argv)
213 {
214 this->argv = argv;
215 }
216
217 void finalize() const
218 {
219 // viennashe::solvers::PETSC_handler<NumericT,VectorType>->finalize();
220 }
221 private:
222 //linear solver:
223 long id_;
224 double tol_;
225 int argc;
226 char **argv;
227 std::size_t max_iters_;
228 std::size_t ilut_entries_;
229 double ilut_drop_tol_;
230 block_preconditioner_boundaries_container block_precond_boundaries_;
231 bool do_scale_;
232 };
233
234 //
235 // Part 2: Nonlinear solvers
236 //
237
240 {
241 enum
242 {
245 };
246 };
247
253 {
254 public:
256 : id_(nonlinear_solver_ids::gummel_nonlinear_solver), iterN(0), THRESHOLD(400), tol_(1e-8), max_iters_(
257 100), damping_(0.3)
258 {
259 }
260
262 long id() const
263 {
264 return
265 iterN > THRESHOLD ?
267 //return id_;
268 }
270 void set(long solver_id)
271 {
272 switch (solver_id)
273 {
276 id_ = solver_id;
277 break;
278 default:
280 }
281 }
282
284 void set(std::string solver_name)
285 {
286 // to upper to ease the comparison and to be case insensitive
287 std::transform(solver_name.begin(), solver_name.end(),
288 solver_name.begin(), ::tolower);
289
290 if (solver_name == "gummel_nonlinear_solver"
291 || solver_name == "gummel")
292 {
294 } else if (solver_name == "newton_nonlinear_solver"
295 || solver_name == "newton")
296 {
298 } else
299 {
301 }
302 }
303
305 double tolerance() const
306 {
307 return tol_;
308 }
310 void tolerance(double tol)
311 {
312 if (tol > 0)
313 tol_ = tol;
314 }
315
317 std::size_t max_iters() const
318 {
319 return max_iters_;
320 }
322 void max_iters(std::size_t iters)
323 {
324 max_iters_ = iters;
325 }
326
328 double damping() const
329 {
330 return damping_;
331 }
333 void damping(double d)
334 {
335 if (damping_ >= 0)
336 damping_ = d;
337 }
338
341 void operator++(int)
342 {
343 iterN++;
344 }
345
346 long getThreshold() const
347 {
348 return THRESHOLD;
349 }
350
351 void setThreshold(long threshold)
352 {
353 THRESHOLD = threshold;
354 }
355
356 ;
357
358 private:
359 long id_;
360 long iterN;
361 long THRESHOLD;
362 double tol_;
363 std::size_t max_iters_;
364 double damping_;
365 };
366
367 }
368}
369
370#endif
Exception for the case that an invalid solver is in use.
Definition: exception.hpp:36
Exception for the case that an invalid nonlinear solver is in use.
Definition: exception.hpp:47
A configuration class holding options for use within the different linear solvers.
Definition: config.hpp:57
void set(long solver_id)
Sets a new linear solver. Provide IDs defined in.
Definition: config.hpp:84
std::vector< std::pair< std::size_t, std::size_t > > block_preconditioner_boundaries_container
Definition: config.hpp:59
void max_iters(std::size_t iters)
Sets the maximum number of iterations within the iterative linear solver.
Definition: config.hpp:160
double ilut_drop_tolerance() const
Returns the drop tolerance for the ILUT preconditioenr.
Definition: config.hpp:177
void set(std::string solver_name)
Sets a new linear solver. Provide IDs defined in.
Definition: config.hpp:104
std::size_t ilut_entries() const
Returns the maximum number of entries in each of the two factors of the ILUT preconditioner.
Definition: config.hpp:166
long id() const
Returns the current linear solver ID.
Definition: config.hpp:79
block_preconditioner_boundaries_container const & block_preconditioner_boundaries() const
Definition: config.hpp:192
double tolerance() const
Returns the tolerance for the (iterative) linear solver.
Definition: config.hpp:143
std::size_t max_iters() const
Returns the maximum number of iterative linear solver iterations.
Definition: config.hpp:155
void scale(bool value)
Controls the scaling of unkowns. Give "false" to disable unkown scaling.
Definition: config.hpp:68
bool scale() const
Returns whether or not the unkowns are scaled before solving the equation set.
Definition: config.hpp:73
void tolerance(double tol)
Sets the tolerance for the (iterative) linear solver. Non-positive values are ignored.
Definition: config.hpp:148
block_preconditioner_boundaries_container & block_preconditioner_boundaries()
Definition: config.hpp:188
void ilut_drop_tolerance(double tol)
Sets the drop tolerance for the ILUT preconditioner. Non-positive values are ignored.
Definition: config.hpp:182
void ilut_entries(std::size_t num)
Sets the maximum number of entries in each of the two factors of the ILUT preconditioner.
Definition: config.hpp:171
A configuration class holding options for use within the different linear solvers.
Definition: config.hpp:253
void operator++(int)
Increment the Number of Iterations for the nonlinear solver.
Definition: config.hpp:341
double tolerance() const
Returns the tolerance for the nonlinear solver potential update.
Definition: config.hpp:305
std::size_t max_iters() const
Returns the maximum number of nonlinear solver iterations.
Definition: config.hpp:317
double damping() const
Returns the damping for the nonlinear solver.
Definition: config.hpp:328
void damping(double d)
Sets the tolerance for the nonlinear solver. Negative values are ignored.
Definition: config.hpp:333
void max_iters(std::size_t iters)
Sets the maximum number of iterations within the nonlinear solver.
Definition: config.hpp:322
long id() const
Returns the current linear solver ID.
Definition: config.hpp:262
void set(long solver_id)
Sets a new linear solver. Provide IDs defined in.
Definition: config.hpp:270
void tolerance(double tol)
Sets the tolerance for the nonlinear solver potential update. Non-positive values are ignored.
Definition: config.hpp:310
void set(std::string solver_name)
Sets a new nonlinear solver.
Definition: config.hpp:284
Contains forward declarations and definition of small classes that must be defined at an early stage.
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
Provides the exceptions used inside the viennashe::she namespace.
Provides IDs for the linear solvers.
Definition: config.hpp:40
@ petsc_parallel_AMGX_solver
PETSC-assisted solver (Hypre AMG)
Definition: config.hpp:48
@ gpu_parallel_linear_solver
multi-threaded solver (block ILUT)
Definition: config.hpp:46
@ parallel_linear_solver
single-threaded solver (using ILUT)
Definition: config.hpp:45
@ serial_linear_solver
Gauss solver (use for systems up to ~1000-by-1000 only)
Definition: config.hpp:44
@ petsc_parallel_linear_solver
gpu-assisted solver (block ILUT)
Definition: config.hpp:47
Provides IDs for the nonlinear iteration schemes.
Definition: config.hpp:240
@ newton_nonlinear_solver
Gummel iteration.
Definition: config.hpp:244