11 std::vector<T>
flatten(
const std::vector<thrust::complex<T>> &input) {
12 std::vector<T> output;
13 for(
auto val : input) {
14 output.push_back(val.real());
15 output.push_back(val.imag());
20 std::vector<fpcomplex>
complex_derivative(
const std::vector<fptype> &x,
const std::vector<fpcomplex> &y) {
21 if(x.size() != y.size())
22 throw GeneralError(
"x and y must have the same diminsions!");
25 unsigned int n = x.size();
26 std::vector<fpcomplex> u(n);
27 std::vector<fpcomplex> y2(n);
30 fpcomplex yp1 = 2. * (y[1] - y[0]) / (x[1] - x[0]);
31 fpcomplex ypn = 2. * (y[n - 1] - y[n - 2]) / (x[n - 1] - x[n - 2]);
34 if(yp1.real() > 0.99e30) {
39 u[0].real(3.0 / (x[1] - x[0]) * ((y[1].real() - y[0].real()) / (x[1] - x[0]) - yp1.real()));
41 if(yp1.imag() > 0.99e30) {
46 u[0].imag(3.0 / (x[1] - x[0]) * ((y[1].imag() - y[0].imag()) / (x[1] - x[0]) - yp1.imag()));
52 for(i = 1; i < n - 1; i++) {
53 sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
54 p = sig * y2[i - 1].real() + 2.0;
55 y2[i].real((sig - 1.0) / p);
56 u[i].real((y[i + 1].real() - y[i].real()) / (x[i + 1] - x[i])
57 - (y[i].real() - y[i - 1].real()) / (x[i] - x[i - 1]));
58 u[i].real((6.0 * u[i].real() / (x[i + 1] - x[i - 1]) - sig * u[i - 1].real()) / p);
59 p = sig * y2[i - 1].imag() + 2.0;
60 y2[i].imag((sig - 1.0) / p);
61 u[i].imag((y[i + 1].imag() - y[i].imag()) / (x[i + 1] - x[i])
62 - (y[i].imag() - y[i - 1].imag()) / (x[i] - x[i - 1]));
63 u[i].imag((6.0 * u[i].imag() / (x[i + 1] - x[i - 1]) - sig * u[i - 1].imag()) / p);
68 if(ypn.real() > 0.99e30) {
73 un = (3.0 / (x[n - 1] - x[n - 2])) * (ypn.real() - (y[n - 1].real() - y[n - 2].real()) / (x[n - 1] - x[n - 2]));
75 y2[n - 1].real((un - qn * u[n - 2].real()) / (qn * y2[n - 2].real() + 1.0));
76 if(ypn.imag() > 0.99e30) {
81 un = (3.0 / (x[n - 1] - x[n - 2])) * (ypn.imag() - (y[n - 1].imag() - y[n - 2].imag()) / (x[n - 1] - x[n - 2]));
83 y2[n - 1].imag((un - qn * u[n - 2].imag()) / (qn * y2[n - 2].imag() + 1.0));
87 for(k = n - 2; k >= 0; k--) {
88 y2[k].real(y2[k].real() * y2[k + 1].real() + u[k].real());
89 y2[k].imag(y2[k].imag() * y2[k + 1].imag() + u[k].imag());
Thrown when a general error is encountered.
std::vector< fpcomplex > complex_derivative(const std::vector< fptype > &x, const std::vector< fpcomplex > &y)
std::vector< T > flatten(const std::vector< thrust::complex< T >> &input)
Flatten a complex array into a standard one (1r, 1i, 2r, 2i, ...)
thrust::complex< fptype > fpcomplex