![]() |
Hex
1.0
Hydrogen-electron collision solver
|
#include <chrono>
#include <iostream>
#include "arrays.h"
#include "complex.h"
#include "matrix.h"
#include "misc.h"
Go to the source code of this file.
Functions | |
cArray | default_new_complex_array (size_t n) |
Return new complex array. More... | |
double | default_compute_norm (const cArrayView x) |
Compute norm of an array. More... | |
void | default_complex_axby (Complex a, cArrayView x, Complex b, const cArrayView y) |
Do the \( \alpha x + \beta y \) operation. More... | |
template<class TArray , class TArrayView , class Preconditioner , class MatrixMultiplication , class NewArray = decltype(default_new_complex_array), class AxbyOperation = decltype(default_complex_axby), class ScalarProduct = decltype(operator|<Complex>), class ComputeNorm = decltype(default_compute_norm)> | |
unsigned | cg_callbacks (const TArrayView b, TArrayView x, double eps, unsigned min_iterations, unsigned max_iterations, Preconditioner apply_preconditioner, MatrixMultiplication matrix_multiply, bool verbose=true, NewArray new_array=default_new_complex_array, AxbyOperation axby=default_complex_axby, ScalarProduct scalar_product=operator|< Complex >, ComputeNorm compute_norm=default_compute_norm) |
Conjugate gradients solver. More... | |
template<typename TFunctor1 , typename TFunctor2 > | |
int | bicgstab_callbacks (const cArrayView b, cArrayView x, double eps, int min_iterations, int max_iterations, TFunctor1 apply_preconditioner, TFunctor2 matrix_multiply, bool verbose=false) |
template<typename TFunctor1 , typename TFunctor2 > | |
int | cgs_callbacks (const cArrayView b, cArrayView x, double eps, int min_iterations, int max_iterations, TFunctor1 apply_preconditioner, TFunctor2 matrix_multiply, bool verbose=false) |
CGS solver. More... | |
int bicgstab_callbacks | ( | const cArrayView | b, |
cArrayView | x, | ||
double | eps, | ||
int | min_iterations, | ||
int | max_iterations, | ||
TFunctor1 | apply_preconditioner, | ||
TFunctor2 | matrix_multiply, | ||
bool | verbose = false |
||
) |
Callback-based BiCGSTAB.
Bi-Conjugate gradients stabilized method.
b | Right hand side. |
x | Output vector. An initial guess may be present at beginning. |
eps | Relative tolerance. |
min_iterations | Minimal iterations count. |
max_iterations | Maximal iterations count. |
apply_preconditioner | Functor compatible with void(*)(const Array&, Array&) prototype. Should apply a custom preconditioner to a given vector. |
matrix_multiply | Functor compatible with void(*)(const Array&, Array&) prototype. Should multiply the given vector by the matrix of the equation set. |
verbose | Whether to comment the progress to stdout. |
unsigned cg_callbacks | ( | const TArrayView | b, |
TArrayView | x, | ||
double | eps, | ||
unsigned | min_iterations, | ||
unsigned | max_iterations, | ||
Preconditioner | apply_preconditioner, | ||
MatrixMultiplication | matrix_multiply, | ||
bool | verbose = true , |
||
NewArray | new_array = default_new_complex_array , |
||
AxbyOperation | axby = default_complex_axby , |
||
ScalarProduct | scalar_product = operator|<Complex> , |
||
ComputeNorm | compute_norm = default_compute_norm |
||
) |
Callback-based conjugate gradients. There is a variety of template arguments and function parameters that aim at generality so that the function can be used with various implementations of array arithmetic. The numerically intensive sections are being computed by user-supplied routines. Also the array types have a template character; they are
b | Right hand side. |
x | Output vector. An initial guess may be present at beginning. |
eps | Relative tolerance. |
min_iterations | Minimal iterations count. |
max_iterations | Maximal iterations count. |
apply_preconditioner | Functor compatible with the signature * void (*) (const TArrayView, TArrayView)
*
|
matrix_multiply | Functor compatible with the signature * void (*) (const TArrayView, TArrayView)
*
|
verbose | Whether to display progress information. |
new_array | Functor compatible with the signature * TArray (*) (size_t)
*
|
axby | Functor compatible with the signature Stores the linear combination \( a\mathbf{x} + b\mathbf{y} \) into the array \( \mathbf{x} \). |
scalar_product | Functor compatible with the signature *
\[ \sum_{i = 1}^N x_i y_i \ . \] |
compute_norm | Functor compatible with signature * double (*) (const TArrayView x)
*
|
int cgs_callbacks | ( | const cArrayView | b, |
cArrayView | x, | ||
double | eps, | ||
int | min_iterations, | ||
int | max_iterations, | ||
TFunctor1 | apply_preconditioner, | ||
TFunctor2 | matrix_multiply, | ||
bool | verbose = false |
||
) |
Conjugate gradients squared,
b | Right hand side. |
x | Output vector. An initial guess may be present at beginning. |
eps | Relative tolerance. |
min_iterations | Minimal iterations count. |
max_iterations | Maximal iterations count. |
apply_preconditioner | Functor compatible with void(*)(const Array&, Array&) prototype. Should apply a custom preconditioner to a given vector. |
matrix_multiply | Functor compatible with void(*)(const Array&, Array&) prototype. Should multiply the given vector by the matrix of the equation set. |
verbose | Whether to comment the progress to stdout. |
|
inline |
Computes a linear combination of two vectors and stores the output in the first vector. This is a default implementation of the method. It can be substituted by another, if necessary; for example one could call specialized routine from BLAS or use a GPU kernel.
|
inline |
This routine is the default way of how to compute a norm of an object. It can be overloaded by some more sophisticated implementation (e.g. BLAS or OpenCL version).
|
inline |
Create (and return a copy of) a NumberArray<Complex> object. This is used as a default method of creating an array in cg_callbacks. It can be substituted by a different method, if necessary; for example when the created array needs to be registered at GPU first.