1#ifndef VIENNASHE_SHE_LINEAR_SOLVER_HPP
2#define VIENNASHE_SHE_LINEAR_SOLVER_HPP
42 template <
typename DeviceType,
45 SHEQuantity
const & quan,
46 std::size_t system_size,
47 std::vector<std::pair<std::size_t, std::size_t> > & indices)
49 typedef typename DeviceType::mesh_type MeshType;
51 typedef typename viennagrid::result_of::const_cell_range<MeshType>::type CellContainer;
52 typedef typename viennagrid::result_of::iterator<CellContainer>::type CellIterator;
54 indices.resize(quan.get_value_H_size());
56 std::size_t last_found = 0;
59 for (std::size_t index_H = 0; index_H < indices.size(); ++index_H)
61 indices[index_H].first = last_found;
63 for (CellIterator cit = cells.begin();
67 if (quan.get_unknown_index(*cit, index_H) > -1)
69 last_found = std::size_t(quan.get_unknown_index(*cit, index_H));
70 indices[index_H].first = last_found;
72 indices[index_H-1].second = last_found;
78 if (indices[index_H].second < indices[index_H].first)
79 indices[index_H].second = indices[index_H].first;
82 indices[indices.size()-1].second = system_size;
96 template <
typename DeviceType,
101 SHEQuantity
const & quan,
103 MatrixType & full_matrix,
104 VectorType & full_rhs,
105 std::size_t reduced_unknowns)
107 typedef typename VectorType::value_type NumericType;
114 VectorType compressed_rhs(reduced_unknowns);
115 compressed_rhs.clear();
116 compressed_rhs.resize(reduced_unknowns);
131 compressed_matrix, compressed_rhs);
143 std::vector<double> scaling_vector(compressed_matrix.
size1(), 1.0);
174 for (std::size_t i=0; i<compressed_result.size(); ++i)
175 compressed_result[i] *= scaling_vector[i]*scale_factors[i];
185 if (relative_residual > 1e-7)
186 log::info<log_linear_solver>() <<
"* solve(): Relative linear solver residual of full system: " << relative_residual << std::endl;
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.
linear_solver_config_type & linear_solver()
Returns the configuration object for the linear solver.
MeshT const & mesh() const
Returns the underlying mesh.
Defines the physical properties of a device, e.g. doping. This is the implementation for 2d and highe...
Sparse matrix class based on a vector of binary trees for holding the entries.
A configuration class holding options for use within the different linear solvers.
void scale(bool value)
Controls the scaling of unkowns. Give "false" to disable unkown scaling.
block_preconditioner_boundaries_container & block_preconditioner_boundaries()
The SHE configuration class is defined here.
Implements the elimination and the recovery of odd-order unknowns from the discrete system of equatio...
Contains forward declarations and definition of small classes that must be defined at an early stage.
Implementation of various utilities related to linear algebra.
A logging facility providing fine-grained control over logging in ViennaSHE.
VectorType::value_type norm_2(VectorType const &v)
VectorType subtract(VectorType const &x, VectorType const &y)
Helper routine for the generic vector subtraction z = x - y;.
VectorType prod(sparse_matrix< NumericT > const &system_matrix, VectorType const &x)
Computes A * x for a sparse A and a vector x.
VectorT row_normalize_system(sparse_matrix< NumericT > &system_matrix, VectorT &rhs)
Normalizes an equation system such that all diagonal entries are non-negative, and such that all 2-no...
VectorT recover_odd_unknowns(MatrixT const &full_matrix, VectorT const &full_rhs, VectorT const &compressed_result)
Recovers the odd-order unknowns from the even-order unknowns.
void eliminate_odd_unknowns(FullMatrixType &system_matrix, VectorType const &rhs, CompressedMatrixType &compressed_matrix, VectorType &compressed_rhs)
Eliminates all odd spherical harmonics expansion coefficients from the system matrix.
void rescale_system(MatrixType &system_matrix, VectorType const &scaling)
Scales the system matrix (right-preconditioner) with respect to the rescaled unknowns.
void setup_unknown_scaling(DeviceType const &device, viennashe::config const &conf, SHEQuantity &quan, VectorType &scaling_vector)
Initializes the unknown scaling. Returns a vector holding the scaling factors.
void diagonalise_odd2odd_coupling_matrix(FullMatrixType &system_matrix, VectorType &rhs, std::size_t num_even)
Eliminates all odd spherical harmonics expansion coefficients in the off diagonals of S^oo from the s...
void fill_block_indices(DeviceType const &device, SHEQuantity const &quan, std::size_t system_size, std::vector< std::pair< std::size_t, std::size_t > > &indices)
Writes an array of block indices.
VectorType solve(DeviceType const &device, SHEQuantity const &quan, viennashe::config const &configuration, MatrixType &full_matrix, VectorType &full_rhs, std::size_t reduced_unknowns)
Public interface for solving the provided system of discretized SHE equations.
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.
The main ViennaSHE namespace. All functionality resides inside this namespace.
Rescales the linear system such that unknowns are approximately the same order of magnitude.
Provides the exceptions used inside the viennashe::she namespace.
Forward declarations for a generic solver layer, providing bindings to a native Gauss solver,...
Defines the log keys used within the viennashe::she namespace.