Hex
1.0
Hydrogen-electron collision solver
|
#include <cassert>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <typeinfo>
#include <type_traits>
#include <vector>
#include "hdffile.h"
#include "complex.h"
#include "misc.h"
#include "arrithm.h"
Go to the source code of this file.
Data Structures | |
class | PlainAllocator< T > |
Basic memory allocator. More... | |
class | Array< T, Alloc > |
A comfortable data array class. More... | |
class | NumberArray< T, Alloc > |
A comfortable number array class. More... | |
class | ArrayView< T > |
Array view. More... | |
class | Array< T, Alloc > |
A comfortable data array class. More... | |
class | NumberArray< T, Alloc > |
A comfortable number array class. More... | |
Typedefs | |
typedef NumberArray< int > | iArray |
typedef NumberArray< long > | lArray |
typedef NumberArray< double > | rArray |
typedef NumberArray< Complex > | cArray |
typedef ArrayView< int > | iArrayView |
typedef ArrayView< long > | lArrayView |
typedef ArrayView< double > | rArrayView |
typedef ArrayView< Complex > | cArrayView |
typedef Array< iArray > | iArrays |
typedef Array< lArray > | lArrays |
typedef Array< rArray > | rArrays |
typedef Array< cArray > | cArrays |
Functions | |
template<class T > | |
T | operator| (const ArrayView< T > a, const ArrayView< T > b) |
Scalar product of two arrays. More... | |
template<class T1 , class T2 > | |
auto | outer_product (const ArrayView< T1 > a, const ArrayView< T2 > b) -> NumberArray< decltype(T1(0)*T2(0))> |
Outer product of two arrays. More... | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &out, ArrayView< T > const &a) |
Output to text stream. More... | |
template<typename T > | |
NumberArray< T > | linspace (T start, T end, unsigned samples) |
Generate uniform grid. More... | |
template<typename T > | |
NumberArray< T > | logspace (T x0, T x1, size_t samples) |
Generate logarithmic grid. More... | |
template<typename T > | |
NumberArray< T > | geomspace (T x0, T x1, size_t samples, double q) |
Generate geometric grid. More... | |
template<class T > | |
void | write_array (const ArrayView< T > array, const char *filename) |
template<class T1 , class T2 > | |
void | write_array (const ArrayView< T1 > grid, const ArrayView< T2 > array, const char *filename) |
template<typename Fetcher > | |
bool | write_1D_data (size_t m, const char *filename, Fetcher fetch) |
Write elements. More... | |
template<class Fetcher > | |
bool | write_2D_data (size_t m, size_t n, const char *filename, Fetcher fetch) |
rArray | concatenate () |
template<typename... Params> | |
rArray | concatenate (rArray const &v1, Params...p) |
rArray | abs (const cArrayView u) |
rArrays | abs (cArrays const &u) |
template<typename T > | |
T | min (const ArrayView< T > a) |
Minimal element of array. More... | |
template<typename T > | |
T | max (const ArrayView< T > a) |
Maximal element of array. More... | |
template<typename T > | |
NumberArray< T > | pow (NumberArray< T > const &u, double e) |
Return per-element power. More... | |
template<typename T > | |
Array< T > | pow (Array< T > const &u, double e) |
Return per-element power. More... | |
template<class T > | |
NumberArray< T > | sqrt (NumberArray< T > const &A) |
Return per-element square root. More... | |
template<class T > | |
NumberArray< T > | sin (NumberArray< T > const &A) |
Return per-element sine. More... | |
template<class T > | |
NumberArray< T > | asin (NumberArray< T > const &A) |
Return per-element arcsine. More... | |
template<class T > | |
NumberArray< T > | cos (NumberArray< T > const &A) |
Return per-element cosine. More... | |
NumberArray< double > | hypot (NumberArray< double > const &A, NumberArray< double > const &B) |
Return per-element hypot. More... | |
NumberArray< double > | atan2 (NumberArray< double > const &A, NumberArray< double > const &B) |
Return per-element atan2. More... | |
NumberArray< double > | sqrabs (NumberArray< Complex > const &A) |
Return per-element square of absolute value. More... | |
NumberArray< double > | realpart (NumberArray< Complex > const &A) |
Return per-element real part. More... | |
NumberArray< double > | imagpart (NumberArray< Complex > const &A) |
Return per-element imag part. More... | |
template<typename T > | |
T | sum (const ArrayView< T > v) |
Sum elements in array. More... | |
template<typename T > | |
NumberArray< T > | sums (const ArrayView< NumberArray< T >> v) |
Sum arrays. More... | |
template<typename T > | |
Array< bool > | operator== (const ArrayView< T > u, T x) |
template<typename T > | |
Array< bool > | operator== (const ArrayView< T > u, const ArrayView< T > v) |
Comparison of two arrays. More... | |
bool | all (const ArrayView< bool > B) |
Check that all values are "true". More... | |
bool | any (const ArrayView< bool > B) |
Check if any value is "true". More... | |
template<typename TFunctor , typename TArray > | |
void | eval (TFunctor f, TArray grid, TArray &vals) |
template<typename Tidx , typename Tval > | |
void | merge (NumberArray< Tidx > &idx1, NumberArray< Tval > &arr1, NumberArray< Tidx > const &idx2, NumberArray< Tval > const &arr2) |
template<typename T > | |
NumberArray< T > | join (const ArrayView< NumberArray< T >> arrays) |
Join elements from all subarrays. More... | |
template<class T > | |
NumberArray< T > | sorted_unique (const ArrayView< T > v, int n=1) |
Drop all redundant repetitions from sorted array. More... | |
template<class T > | |
void | smoothen (ArrayView< T > v) |
Running average. More... | |
template<class T > | |
std::string | to_string (const ArrayView< T > v, char sep= ' ') |
Convert ArrayView<T> to a string. More... | |
rArray | threshold (const rArrayView a, double eps) |
Drop small elements of array (replace by zero). More... | |
typedef NumberArray<Complex> cArray |
typedef ArrayView<Complex> cArrayView |
typedef NumberArray<int> iArray |
typedef ArrayView<int> iArrayView |
typedef NumberArray<long> lArray |
typedef ArrayView<long> lArrayView |
typedef NumberArray<double> rArray |
typedef ArrayView<double> rArrayView |
rArray abs | ( | const cArrayView | u | ) |
|
inline |
|
inline |
NumberArray<T> asin | ( | NumberArray< T > const & | A | ) |
NumberArray<double> atan2 | ( | NumberArray< double > const & | A, |
NumberArray< double > const & | B | ||
) |
|
inline |
Variadic template recurrence starter. For documentation of the function itself see the other "concatenate".
Concatenate several arrays. The function template uses variadic templates feature of C++, so the number of subarrays to concatenate is completely arbitrary. It should be noted, though, that long concatenation list may slow down the template instantiation during compilation and hence the overall compilation time.
v1 | First array. |
...p | All other arrays. |
NumberArray<T> cos | ( | NumberArray< T > const & | A | ) |
void eval | ( | TFunctor | f, |
TArray | grid, | ||
TArray & | vals | ||
) |
Evaluation of a function over a grid.
f | Functor to be evaluated using the operator() (double) interface. |
grid | Array-like type containing the evaluation points. |
vals | Array-like type to hold evaluated function on return. It is required that enough space is reserved, at least grid.size(). |
NumberArray<T> geomspace | ( | T | x0, |
T | x1, | ||
size_t | samples, | ||
double | q | ||
) |
Return a geometrically increasing array
\[ a_1, a_2, a_3, \dots, a_n, \]
where \( a_1 \) is equal to "start", \( a_n \) is equal to "end" and \( n \) is equal to "samples". For consecutive elements it holds
\[ \frac{a_{k+1} - a_{k}}{a_k - a_{k-1}} = q \ . \]
Altogether is
\[ a_k = a_1 + (a_n - a_1) \frac{1-q^{k-1}}{1-q^{n-1}} \]
NumberArray<double> hypot | ( | NumberArray< double > const & | A, |
NumberArray< double > const & | B | ||
) |
NumberArray<double> imagpart | ( | NumberArray< Complex > const & | A | ) |
NumberArray<T> join | ( | const ArrayView< NumberArray< T >> | arrays | ) |
NumberArray<T> linspace | ( | T | start, |
T | end, | ||
unsigned | samples | ||
) |
Return a uniform array
\[ a_1, a_2, a_3, \dots, a_n, \]
where \( a_1 \) is equal to "start", \( a_n \) is equal to "end" and \( n \) is equal to "samples". For consecutive elements it holds
\[ a_{k+1} - a_k = \frac{a_n - a_1}{n - 1} \ . \]
start | Left boundary and first sample for "samples" > 0. |
end | Right boundary and last sample for "samples" > 1. |
samples | Sample count. |
NumberArray<T> logspace | ( | T | x0, |
T | x1, | ||
size_t | samples | ||
) |
Return a uniformly diverging array
\[ a_1, a_2, a_3, \dots, a_n, \]
where \( a_1 \) is equal to "start", \( a_n \) is equal to "end" and \( n \) is equal to "samples". For consecutive elements it holds
\[ \frac{a_{k+1}}{a_k} = q = \left(\frac{a_n}{a_1}\right)^{1/(n-1)} \ . \]
x0 | Left boundary and first sample for "samples" > 0. |
x1 | Right boundary and last sample for "samples" > 1. |
samples | Sample count. |
T max | ( | const ArrayView< T > | a | ) |
void merge | ( | NumberArray< Tidx > & | idx1, |
NumberArray< Tval > & | arr1, | ||
NumberArray< Tidx > const & | idx2, | ||
NumberArray< Tval > const & | arr2 | ||
) |
Sum two indexed arrays if their (sorted) indices perfectly match. Or, generally, create output array with elements that are sum of corresponding elements of both arrays or equal to a single element in one array, if that its index doesn't have a counterpart in the other array.
idx1 | Sorted (!) indices of the first array. |
arr1 | Merge TO array. |
idx2 | Sorted (!) indices of the second array. |
arr2 | Merge FROM array. |
T min | ( | const ArrayView< T > | a | ) |
std::ostream& operator<< | ( | std::ostream & | out, |
ArrayView< T > const & | a | ||
) |
Comparison of an array and a number.
u | Array. |
x | Number. |
auto outer_product | ( | const ArrayView< T1 > | a, |
const ArrayView< T2 > | b | ||
) | -> NumberArray<decltype(T1(0) * T2(0))> |
Returns a new array with the following values:
\[ a_1 b_1, a_1 b_2, \dots, a_1, b_n, a_2 b_1, \dots, a_m b_n \]
NumberArray<T> pow | ( | NumberArray< T > const & | u, |
double | e | ||
) |
NumberArray<double> realpart | ( | NumberArray< Complex > const & | A | ) |
NumberArray<T> sin | ( | NumberArray< T > const & | A | ) |
void smoothen | ( | ArrayView< T > | v | ) |
Overwrite the given vector v = {v1, v2, v3, ..., vN} by vector {v1, (v1+v2)/2, (v2+v3)/2, ..., (v_(N-1)+vN)/2}.
NumberArray<T> sorted_unique | ( | const ArrayView< T > | v, |
int | n = 1 |
||
) |
NumberArray<double> sqrabs | ( | NumberArray< Complex > const & | A | ) |
NumberArray<T> sqrt | ( | NumberArray< T > const & | A | ) |
T sum | ( | const ArrayView< T > | v | ) |
NumberArray<T> sums | ( | const ArrayView< NumberArray< T >> | v | ) |
rArray threshold | ( | const rArrayView | a, |
double | eps | ||
) |
std::string to_string | ( | const ArrayView< T > | v, |
char | sep = ' ' |
||
) |
bool write_1D_data | ( | size_t | m, |
const char * | filename, | ||
Fetcher | fetch | ||
) |
For all integers from 0 to m-1 call fetch(i) and save the results to a text file as a single column.
bool write_2D_data | ( | size_t | m, |
size_t | n, | ||
const char * | filename, | ||
Fetcher | fetch | ||
) |
Write 2D data to file. To allow maximum flexibility, only extensions of the data are passed to the function and a functor that will be repeatedly called with coordinate pair for new data element.
m | Row count. |
n | Column count. |
filename | Filename of the file to create/overwrite. |
fetch | Functor with interface double operator() (size_t, size_t);
|
false
for failure). void write_array | ( | const ArrayView< T > | array, |
const char * | filename | ||
) |
Write array to file. Array will be written as a single column into an ASCII file.
array | The array to write. |
filename | Name of the file to create/overwrite. |
void write_array | ( | const ArrayView< T1 > | grid, |
const ArrayView< T2 > | array, | ||
const char * | filename | ||
) |
Write array to file. Array will be written as a two columns into an ASCII file, first column contains grid information.
grid | The 1D grid labels for the data. |
array | The array to write. |
filename | Name of the file to create/overwrite. |