ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
solve.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_SOLVERS_SOLVE_HPP
2#define VIENNASHE_SOLVERS_SOLVE_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// std
19#include <stdexcept>
20
26
28#include "viennacl/linalg/norm_2.hpp"
29
34namespace viennashe
35{
37 namespace solvers
38 {
39
40
47 template <typename MatrixType,
48 typename VectorType>
49 VectorType solve_impl(MatrixType & system_matrix,
50 VectorType const & rhs,
52 {
53 // check for invalid entries first
54 const long invalid_row = viennashe::util::matrix_consistency_check(system_matrix);
55 if (invalid_row >= 0)
56 {
57 throw viennashe::util::linear_solver_exception("solve(): Found empty row in system_matrix.");
58 }
60 //check for trivial solution (some solvers have problems with that, hence we do it explicitly here)
62 {
63 VectorType result(rhs.size());
64 std::fill(result.begin(), result.end(), 0);
65 return result;
66 }
67
68 switch (config.id())
69 {
78#ifdef VIENNASHE_HAVE_GPU_SOLVER
83#endif
84 default:
86 }
87 }
88
89
90
91
92 }
93}
94
95#endif
Convenience header file for all the ViennaCL solver bindings.
Defines a set of checker functors for micro-tests within ViennaSHE.
The main SHE configuration class. To be adjusted by the user for his/her needs.
Definition: config.hpp:124
Internal tag used for the specification of a dense linear solver (Gauss, single-threaded)
Definition: forwards.h:203
Internal tag used for the specification of a GPU-accelerated linear solver.
Definition: forwards.h:216
Exception for the case that an invalid solver is in use.
Definition: exception.hpp:36
A configuration class holding options for use within the different linear solvers.
Definition: config.hpp:57
Internal tag used for the specification of a CPU-based multi-threaded linear solver.
Definition: forwards.h:209
Internal tag used for the specification of a CPU-based PETSC solver.
Definition: forwards.h:212
Internal tag used for the specification of a single-threaded linear solver.
Definition: forwards.h:206
Exception for the case that a linear solver fails (typically with NaN due to zero inner product)
Definition: exception.hpp:39
Implements a dense Gauss solver.
VectorType::value_type norm_2(VectorType const &v)
Definition: linalg_util.hpp:37
VectorType solve_impl(MatrixType &system_matrix, VectorType const &rhs, linear_solver_config const &config)
Public interface for solving a system of linear equations.
Definition: solve.hpp:49
std::vector< double > solve(viennashe::math::sparse_matrix< double > &A, std::vector< double > const &b, linear_solver_config const &config)
Public interface for solving a system of linear equations represented using a sparse matrix.
long matrix_consistency_check(MatrixType const &matrix)
Checks a matrix for empty rows.
Definition: checks.hpp:246
void check_vector_for_valid_entries(VectorType const &vec, std::string message="Location not specified")
Checks a vector for valid entries (i.e. no NaN).
Definition: checks.hpp:111
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40
The SHE configuration class is defined here.
Provides the exceptions used inside the viennashe::she namespace.
@ 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