|
| 1 | +/* |
| 2 | + * This file is part of FNFT. |
| 3 | + * |
| 4 | + * FNFT is free software; you can redistribute it and/or |
| 5 | + * modify it under the terms of the version 2 of the GNU General |
| 6 | + * Public License as published by the Free Software Foundation. |
| 7 | + * |
| 8 | + * FNFT is distributed in the hope that it will be useful, |
| 9 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | + * GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License |
| 14 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + * |
| 16 | + * Contributors: |
| 17 | + * Lianne de Vries (TU Delft student) 2021. |
| 18 | + */ |
| 19 | + |
| 20 | +#define FNFT_ENABLE_SHORT_NAMES |
| 21 | + |
| 22 | +#include <stdio.h> // for printf |
| 23 | +#include "fnft_manakovv.h" |
| 24 | +#include "fnft_manakov_discretization_t.h" |
| 25 | +#include "fnft__misc.h" |
| 26 | + |
| 27 | +int main() |
| 28 | +{ |
| 29 | + /** Step 1: Set up the signal **/ |
| 30 | + |
| 31 | + // Number of time-domain samples. Increase to improve precision of results. |
| 32 | + FNFT_UINT D = 1024; |
| 33 | + |
| 34 | + // Contains the samples of q(t) |
| 35 | + FNFT_COMPLEX q1[D], q2[D]; |
| 36 | + |
| 37 | + // Location of the 1st and last time-domain sample |
| 38 | + FNFT_REAL T[2] = { -2.0, 2.0 }; |
| 39 | + |
| 40 | + // Define a simple rectangular signal |
| 41 | + // TODO: use rectangular signal |
| 42 | + for (UINT i=0; i<D; i++){ |
| 43 | + q1[i] = 2; |
| 44 | + q2[i] = 0.65; |
| 45 | + } |
| 46 | + |
| 47 | + // The types FNFT_UINT, FNFT_INT, FNFT_REAL and FNFT_COMPLEX are defined |
| 48 | + // in the header fnft_numtypes.h |
| 49 | + |
| 50 | + |
| 51 | + /** Step 2: Prepare calling fnft_manakovv **/ |
| 52 | + |
| 53 | + // Location of the 1st and last sample of the continuous spectrum |
| 54 | + FNFT_REAL XI[2] = {-1.75, 2.0 }; |
| 55 | + |
| 56 | + // Number of samples of the continuous spectrum |
| 57 | + FNFT_UINT M = 8; |
| 58 | + |
| 59 | + // Buffer for result: Samples of the continuous spectrum |
| 60 | + FNFT_COMPLEX contspec[3*M]; |
| 61 | + |
| 62 | + |
| 63 | + // Maximum number of bound states we expect = size of the two arrays below |
| 64 | + FNFT_UINT K = D; |
| 65 | + |
| 66 | + // Buffer for result: Bound states |
| 67 | + FNFT_COMPLEX bound_states[K]; |
| 68 | + |
| 69 | + // Buffer for result: Norming constants |
| 70 | + FNFT_COMPLEX normconsts[K]; |
| 71 | + |
| 72 | + // Focusing nonlinear Schroedinger equation |
| 73 | + int kappa = +1; |
| 74 | + |
| 75 | + // Default options |
| 76 | + fnft_manakovv_opts_t opts = fnft_manakovv_default_opts(); |
| 77 | + opts.discretization = manakov_discretization_2SPLIT3A; |
| 78 | + |
| 79 | + // Uncomment the next line to compute residues instead of norming constants |
| 80 | + //opts.discspec_type = fnft_nsev_dstype_RESIDUES; |
| 81 | + |
| 82 | + // See the header file fnft_nsev.h for other options |
| 83 | + |
| 84 | + /** Step 3: Call fnft_nsev and check for errors **/ |
| 85 | + |
| 86 | + int ret_code = fnft_manakovv(D, q1, q2, T, M, contspec, XI, &K, bound_states, |
| 87 | + normconsts, kappa, &opts); |
| 88 | + if (ret_code != FNFT_SUCCESS) { |
| 89 | + printf("An error occured!\n"); |
| 90 | + return EXIT_FAILURE; |
| 91 | + } |
| 92 | + |
| 93 | + /** Step 4: Print the results **/ |
| 94 | + |
| 95 | + printf("Number of samples:\n D = %u\n", (unsigned int)D); |
| 96 | + |
| 97 | + FNFT_REAL eps_xi = (XI[1] - XI[0]) / (M - 1); |
| 98 | + printf("Continuous spectrum (first entry):\n"); |
| 99 | + for (FNFT_UINT i=0; i<M; i++) { |
| 100 | + FNFT_REAL xi = XI[0] + i*eps_xi; |
| 101 | + printf(" continuous_spectrum(xi=%f) \t= %g + %gI\n", |
| 102 | + (double)xi, |
| 103 | + (double)FNFT_CREAL(contspec[i]), |
| 104 | + (double)FNFT_CIMAG(contspec[i]) |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + printf("Continuous spectrum (second entry):\n"); |
| 109 | + for (FNFT_UINT i=M; i<2*M; i++) { |
| 110 | + FNFT_REAL xi = XI[0] + (i-8)*eps_xi; |
| 111 | + printf(" continuous_spectrum(xi=%f) \t= %g + %gI\n", |
| 112 | + (double)xi, |
| 113 | + (double)FNFT_CREAL(contspec[i]), |
| 114 | + (double)FNFT_CIMAG(contspec[i]) |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | +/* printf("Discrete spectrum:\n"); |
| 119 | + for (FNFT_UINT i=0; i<K; i++) { |
| 120 | + printf(" bound state at %g + %gI with norming constant %g + %gI\n", |
| 121 | + (double)FNFT_CREAL(bound_states[i]), |
| 122 | + (double)FNFT_CIMAG(bound_states[i]), |
| 123 | + (double)FNFT_CREAL(normconsts[i]), |
| 124 | + (double)FNFT_CIMAG(normconsts[i]) |
| 125 | + ); |
| 126 | + }*/ |
| 127 | + |
| 128 | + return EXIT_SUCCESS; |
| 129 | +} |
0 commit comments