1#ifndef VIENNASHE_UTIL_BLOCK_MATRIX_WRITER_HPP
2#define VIENNASHE_UTIL_BLOCK_MATRIX_WRITER_HPP
44 template <
typename SystemMatrixType,
45 typename BlockMatrixType,
46 typename RowIndexIterator,
47 typename ColumnIndexIterator>
49 std::size_t row_index, std::size_t col_index,
51 BlockMatrixType
const & coupling_matrix,
52 RowIndexIterator row_iter,
53 ColumnIndexIterator
const & col_iter_init,
54 bool elastic_scattering_roundoff_error_prevention =
false)
58 assert(prefactor == prefactor &&
bool(
"Writing nan to matrix!"));
60 std::size_t row = row_index;
61 for (; row_iter.valid(); ++row_iter, ++row)
63 assert( *row_iter <
static_cast<long>(coupling_matrix.size1() ));
64 std::size_t col = col_index;
66 for (ColumnIndexIterator col_iter(col_iter_init);
70 assert( *col_iter <
static_cast<long>(coupling_matrix.size2() ));
71 double entry = coupling_matrix(std::size_t(*row_iter), std::size_t(*col_iter));
75 if (elastic_scattering_roundoff_error_prevention && row == row_index && col == col_index)
77 system_matrix(row, col) += prefactor * entry;
96 template <
typename SystemMatrixType,
97 typename BlockMatrixType,
98 typename RowIndexIterator,
99 typename ColumnIndexIterator,
100 typename FoldVectorType>
102 long row_index,
long col_index,
104 BlockMatrixType
const & coupling_matrix,
105 RowIndexIterator row_iter,
106 ColumnIndexIterator
const & col_iter_init,
107 FoldVectorType
const & fold_vector,
long fold_index_start
111 assert(row_index >= 0 &&
"Row index must be non-negative!");
112 assert(col_index >= 0 &&
"Col index must be non-negative!");
114 assert(prefactor == prefactor &&
bool(
"Writing nan to matrix!"));
116 long row = row_index;
117 for (; row_iter.valid(); ++row_iter)
119 assert( *row_iter <
static_cast<long>(coupling_matrix.size1()) );
121 double folded_val = 0;
122 std::size_t inner_iters = 0;
123 for (ColumnIndexIterator col_iter(col_iter_init);
125 ++col_iter, ++inner_iters)
127 assert( *col_iter <
static_cast<long>(coupling_matrix.size2()) );
128 folded_val += coupling_matrix(*row_iter, *col_iter) * fold_vector[fold_index_start + inner_iters];
132 system_matrix(row, col_index) += prefactor * folded_val;
149 template <
typename VectorType,
150 typename BlockMatrixType,
151 typename RowIndexIterator,
152 typename ColumnIndexIterator>
154 std::size_t row_index,
156 BlockMatrixType
const & coupling_matrix,
157 RowIndexIterator row_iter,
158 ColumnIndexIterator
const & col_iter_init,
159 double const * fold_vector)
161 assert(prefactor == prefactor &&
bool(
"Writing nan to vector!"));
165 std::size_t row = row_index;
166 for (; row_iter.valid(); ++row_iter)
168 assert( *row_iter <
static_cast<long>(coupling_matrix.size1() ));
170 double folded_val = 0;
171 std::size_t inner_iters = 0;
172 for (ColumnIndexIterator col_iter(col_iter_init);
174 ++col_iter, ++inner_iters)
176 assert( *col_iter <
static_cast<long>(coupling_matrix.size2() ));
177 folded_val += coupling_matrix(std::size_t(*row_iter), std::size_t(*col_iter)) * fold_vector[inner_iters];
181 residual[row] -= prefactor * folded_val;
void add_folded_block_matrix(SystemMatrixType &system_matrix, long row_index, long col_index, double prefactor, BlockMatrixType const &coupling_matrix, RowIndexIterator row_iter, ColumnIndexIterator const &col_iter_init, FoldVectorType const &fold_vector, long fold_index_start)
Writes a sub-matrix of a block matrix 'coupling_matrix' into the global system matrix,...
void add_block_matrix(SystemMatrixType &system_matrix, std::size_t row_index, std::size_t col_index, double prefactor, BlockMatrixType const &coupling_matrix, RowIndexIterator row_iter, ColumnIndexIterator const &col_iter_init, bool elastic_scattering_roundoff_error_prevention=false)
Writes a sub-matrix of a block matrix 'coupling_matrix' into the global system matrix,...
void subtract_folded_block_vector(VectorType &residual, std::size_t row_index, double prefactor, BlockMatrixType const &coupling_matrix, RowIndexIterator row_iter, ColumnIndexIterator const &col_iter_init, double const *fold_vector)
Writes a sub-matrix of a block matrix 'coupling_matrix' to the residual vector. The columns are 'fold...
The main ViennaSHE namespace. All functionality resides inside this namespace.
Provides a number of fundamental constants. All constants in SI units.
Implementation of spherical harmonics plus helper functions.