Skip to content

Commit bceaab5

Browse files
authored
Merge pull request #76 from FastNFT/kdvv_improvements
Kdvv improvements
2 parents 3b4886d + 29d1017 commit bceaab5

File tree

112 files changed

+1202
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1202
-243
lines changed

CHANGELOG.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
# Changelog
22

3+
## [0.5.0]
4+
5+
### Added
6+
7+
- A NFT routine fnft_manakovv for the Manakov equation with vanishing boundaries was added (continuous spectrum only).
8+
- The periodic NFT routine fnft_nsep now also supports pure Newton refinement.
9+
- The routine fnft_kdvv now can now also compute the discrete spectrum. To locate the bound states, either Newton's method or a grid search with additional Newton refinements are available.
10+
- The slow scattering methods for AKNS-type systems now include a normalization procedure to deal with numerical overflow (enabled by default).
11+
- The routine fnft__kdv_finvscatter has been added. The plan is to later use it for a fast inverse KdV NFT.
12+
13+
### Changed
14+
15+
- New criteria for stopping Newton iteration in fnft_nsep.
16+
- Simplified some tests to reduce run times.
17+
- The code for AKNS scattering has been overhauled.
18+
19+
### Fixed
20+
21+
- Several memory leaks have been fixed.
22+
323
## [0.4.1] -- 2020-07-13
424

525
### Changed
626

727
- Number of samples for fnft_nsep again has to be a power of two.
28+
- misc_resample no longer issues a warning when the signal appears to be undersampled. This gave the wrong impression that CFx_y discrizations suffer more in such scenarios than the other ones, which do not use this routine.
829

930
### Fixed
1031

11-
- misc_downsample could return incorrect values for first_last_index[1]
32+
- misc_downsample could return incorrect values for first_last_index[1].
33+
- Some errors in fnft_nsev become meaningless when bound_states==NULL and should not be risen in that case.
1234

1335
## [0.4.0] -- 2020-07-08
1436

CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ cmake_minimum_required(VERSION 3.17.3)
2020
project(fnft C)
2121

2222
set(FNFT_VERSION_MAJOR 0)
23-
set(FNFT_VERSION_MINOR 4)
24-
set(FNFT_VERSION_PATCH 1)
25-
set(FNFT_VERSION_SUFFIX "") # should not be longer than FNFT_SUFFIX_MAXLEN
23+
set(FNFT_VERSION_MINOR 5)
24+
set(FNFT_VERSION_PATCH 0)
25+
set(FNFT_VERSION_SUFFIX "dev") # should not be longer than FNFT_SUFFIX_MAXLEN
2626
set(FNFT_VERSION ${FNFT_VERSION_MAJOR}.${FNFT_VERSION_MINOR}.${FNFT_VERSION_PATCH}${FNFT_VERSION_SUFFIX})
2727

2828
include(CheckIncludeFiles)
@@ -223,4 +223,4 @@ if (WITH_MATLAB)
223223
# -DMEX_DOUBLE_HANDLE avoids the new complex interleaved API
224224
endforeach()
225225
endif()
226-
endif()
226+
endif()

INSTALL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ in the PowerShell to install Scoop. Then, run the commands
7878

7979
scoop install git
8080
scoop install cmake
81-
scoop install gcc
81+
scoop install mingw
8282

8383
in the PowerShell to install the required tools. Change (for example) to your home directory,
8484
download FNFT, and change into the new dir:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,4 @@ The algorithms in FNFT utilize ideas from the following references. More informa
118118
- P. J. Prins and S. Wahls, ["Soliton Phase Shift Calculation for the Korteweg–De Vries Equation"](https://doi.org/10.1109/ACCESS.2019.2932256), IEEE Access, vol. 7, pp. 122914--122930, July 2019.
119119
- S. Medvedev, I. Vaseva, I. Chekhovskoy and M. Fedoruk, ["Exponential fourth order schemes for direct Zakharov-Shabat problem"](https://doi.org/10.1364/OE.377140), Optics Express, vol. 28, pp. 20--39, 2020.
120120
- J. Mertsching, ["Quasiperiodie Solutions of the Nonlinear Schroedinger Equation"](https://doi.org/10.1002/prop.2190350704), Fortschritte der Physik, vol. 35, pp. 519--536, 1987.
121+
- L. de Vries, ["Fast Numerical Nonlinear Fourier Transform Algorithms for the Manakov Equation"](http://resolver.tudelft.nl/uuid:0276e693-3408-4472-9749-b754c2114183"), Master thesis, TU Delft, 2021.

examples/mex_fnft_kdvv_example.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939

4040
%%% Compute the nonlinear Fourier transform %%%
4141

42-
[contspec, bound_states, norming_constants] = mex_fnft_kdvv(q, T, XI);
42+
dxi = sqrt(max(q)) / 1000; % use approximately 1000 grid points for the
43+
% bound state localization step
44+
[contspec, bound_states, norming_constants] = mex_fnft_kdvv(q, T, XI, ...
45+
'grid_spacing', dxi);
4346
% mex_fnft_kdvv has many options => run "help mex_fnft_kdvv" to learn more
4447

4548
%%% Plot the results %%%

examples/mex_fnft_kdvv_example_4.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@
4646

4747
t = linspace(T(1),T(2),D);
4848
q = double(q_fun(t)); % signal samples
49+
dxi = sqrt(max(q)) / 1000; % use approximately 1000 grid points for the
50+
% bound state localization step
4951
[~,bound_states_computed,normconsts_computed]=mex_fnft_kdvv(q, T, XI,...
50-
'discr_CF4_2','bsloc_gridsearch_refine','skip_cs', 'bsloc_niter',20);
52+
'discr_CF4_2','bsloc_gridsearch_refine', 'grid_spacing', dxi, ...
53+
'skip_cs', 'bsloc_niter',20);
5154

5255
%%% Plot results %%%
5356

include/fnft_kdvv.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
1616
* Contributors:
17-
* Sander Wahls (TU Delft) 2017-2018.
17+
* Sander Wahls (TU Delft) 2017-2018, 2023.
1818
* Shrinivas Chimmalgi (TU Delft) 2019-2020.
1919
* Peter J Prins (TU Delft) 2020-2021.
2020
*/
@@ -54,9 +54,13 @@
5454
* \f$ O(niter (*K\_ptr) D) \f$. \n \n
5555
* fnft_kdvv_bsloc_GRIDSEARCH_AND_REFINE: The algorithm evaluates \f$ a(\xi) \f$ on the grid
5656
* \f$ \xi = \{j nexttoward(0,1), jh,2jh,3jh,\ldots,(M-3)jh\,(M-2)jh,j nexttoward((M-1)h,0)\\}\f$,
57-
* where \f$ h:= \sqrt{c \max_t q(t)} / (M-1)\f$, where \f$ M=1000\f$ and
58-
* \f$ c=1\f$ for all second order discretizations, `fnft_kdv_discretization_4SPLIT4A'/'B'('_VANILLA'), and `fnft_kdv_discretization_CF4_2`(`_VANILLA`); \f$ c \f$ is approximately 2 for
59-
* other discretizations. The sign changes of \f$ a(\xi) \f$ on this grid are used as initial
57+
* where \f$ h:= \sqrt{c \max_t q(t)} / (M-1)\f$, where \f$ c=1\f$ for all second order discretizations,
58+
* `fnft_kdv_discretization_4SPLIT4A'/'B'('_VANILLA'), and `fnft_kdv_discretization_CF4_2`(`_VANILLA`);
59+
* \f$ c \f$ is approximately 2 for other discretizations. The constant \f$ M \f$ is chosen
60+
* such that the distance between the neighboring grid points is not larger than the
61+
* parameter \link fnft_kdvv_opts_t::grid_spacing \endlink. This parameter therefore must
62+
* be set if this algorithm is used.
63+
* The sign changes of \f$ a(\xi) \f$ on this grid are used as initial
6064
* guesses for the bound states, which are then refined as in `fnft_kdvv_bsloc_NEWTON`.
6165
*/
6266
typedef enum {
@@ -119,7 +123,7 @@ typedef enum {
119123
* @var fnft_kdvv_opts_t::niter
120124
* Number of Newton iterations to be carried out when either the
121125
* fnft_kdvv_bsloc_NEWTON, or the fnft_kdvv_bsloc_GRIDSEARCH_AND_REFINE method
122-
* is used.
126+
* is used. Can be zero or positive.
123127
*
124128
* @var fnft_kdvv_opts_t::discspec_type
125129
* Controls how \link fnft_kdvv \endlink fills the array
@@ -141,7 +145,7 @@ typedef enum {
141145
* Controls which discretization is applied to the continuous-time Zakharov-
142146
* Shabat scattering problem. See \link fnft_kdv_discretization_t \endlink.\n\n
143147
*
144-
* @var fnft_kdvv_opts_t::richardson_extrapolation_flag
148+
* @var fnft_kdvv_opts_t::richardson_extrapolation_flag
145149
* Controls whether Richardson extrapolation is applied to try and improve
146150
* the accuracy of the computed spectrum. First approximation is computed
147151
* as usual using all the supplied samples. A second approximation is computed
@@ -154,7 +158,12 @@ typedef enum {
154158
* worse accuracy compared to the first approximation.
155159
* By default, Richardson extrapolation is disabled (i.e., the
156160
* flag is zero). To enable, set the flag to one.
157-
*/
161+
*
162+
* @var fnft_kdvv_opts_t::grid_spacing
163+
* Grid spacing parameter for the fnft_kdvv_bsloc_GRIDSEARCH_AND_REFINE method,
164+
* where the number of grid points is chosen such that the distance between two
165+
* consequtive grid points is not larger than grid_spacing, which has to be
166+
* positive. This option has to be set if GRIDSEARCH_AND_REFINE is used. */
158167
typedef struct {
159168
fnft_kdvv_bsloc_t bound_state_localization;
160169
FNFT_UINT niter;
@@ -163,6 +172,7 @@ typedef struct {
163172
FNFT_INT normalization_flag;
164173
fnft_kdv_discretization_t discretization;
165174
FNFT_UINT richardson_extrapolation_flag;
175+
FNFT_REAL grid_spacing;
166176
} fnft_kdvv_opts_t;
167177

168178
/**

include/private/fnft__akns_scatter.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
1616
* Contributors:
17-
* Sander Wahls (TU Delft) 2017-2018.
17+
* Sander Wahls (TU Delft) 2017-2018, 2023.
1818
* Shrinivas Chimmalgi (TU Delft) 2017-2020.
1919
* Peter J. Prins (TU Delft) 2021.
20+
* Sander Wahls (KIT), 2023.
2021
*/
2122

2223
/**
@@ -59,6 +60,10 @@
5960
* If derivative_flag=1 returns [S11 S12 S21 S22 S11' S12' S21' S22'] in
6061
* result where S11' is the derivative of S11 w.r.t to \f$\lambda\f$.
6162
* Should be preallocated with size 4*K or 8*K accordingly.
63+
* @param[in,out] W Pass an array of size K. Upon exit, it contains scaling factors that
64+
* arise due to an internal normalization of the scattering matrix (to deal with potential
65+
* overflow issues). The result has to be scaled by the power of 2 to obtain the final
66+
* values. No normalization is carried out if NULL is passed.
6267
* @param[in] discretization The type of discretization to be used. Should be of type
6368
* \link fnft__akns_discretization_t \endlink. Not all akns_discretization_t
6469
* discretizations are supported. Check \link fnft__akns_discretization_t \endlink
@@ -79,6 +84,7 @@ FNFT_INT fnft__akns_scatter_matrix(FNFT_UINT const D,
7984
FNFT_UINT const K,
8085
FNFT_COMPLEX const * const lambda,
8186
FNFT_COMPLEX * const result,
87+
FNFT_INT * const W,
8288
fnft__akns_discretization_t discretization,
8389
fnft__akns_pde_t const PDE,
8490
FNFT_UINT const vanilla_flag,
@@ -115,12 +121,20 @@ FNFT_INT fnft__akns_scatter_matrix(FNFT_UINT const D,
115121
* The \f$b(\lambda)\f$ are calculated using the criterion from
116122
* Prins and Wahls, <a href="https://doi.org/10.1109/ACCESS.2019.2932256">&quot;
117123
* Soliton Phase Shift Calculation for the Korteweg–De Vries Equation,&quot;</a>.
124+
* @param[in,out] Ws Pass an array of size K. Upon exit, it contains scaling factors that
125+
* arise due to an internal normalization of the scattering process (to deal with potential
126+
* overflow issues). The returned values for a and a_prime still have to be multiplied with
127+
* corresponding power of two (i.e. POW(2, Ws[i])) to obtain the final values. Note
128+
* that this is not required for the values of b. No normalization is carried out if NULL
129+
* is passed.
118130
* @param[in] discretization The type of discretization to be used. Should be of type
119131
* \link fnft__akns_discretization_t \endlink. Not all akns_discretization_t discretizations are supported.
120132
* Check \link fnft_nse_discretization_t \endlink for list of supported types.
121133
* @param[in] PDE The partial differential equation for which the calculation
122134
* has to be done. Should be of type \link fnft__akns_pde_t \endlink.
123-
* @param[in] vanilla_flag For calculations for the KdV equation, pass 1 for the original mapping to the AKNS framework with r=-1. Pass 0 for the alternative mapping with q=-1. Unused for NSE.
135+
* @param[in] vanilla_flag For calculations for the KdV equation, pass 1 for the
136+
* original mapping to the AKNS framework with r=-1. Pass 0 for the alternative
137+
* mapping with q=-1. Unused for NSE.
124138
* @param[in] skip_b_flag If set to 1 the routine will not compute \f$b(\lambda)\f$.
125139
* @return \link FNFT_SUCCESS \endlink or one of the FNFT_EC_... error codes
126140
* defined in \link fnft_errwarn.h \endlink.
@@ -136,6 +150,7 @@ FNFT_INT akns_scatter_bound_states(FNFT_UINT const D,
136150
FNFT_COMPLEX * const a_vals,
137151
FNFT_COMPLEX * const aprime_vals,
138152
FNFT_COMPLEX * const b,
153+
FNFT_INT * Ws,
139154
fnft__akns_discretization_t const discretization,
140155
fnft__akns_pde_t const PDE,
141156
FNFT_UINT const vanilla_flag,

include/private/fnft__errwarn.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
1616
* Contributors:
17-
* Sander Wahls (TU Delft) 2017-2018.
17+
* Sander Wahls (TU Delft) 2017-2018, 2023.
1818
*/
1919

2020
/**
@@ -100,6 +100,13 @@
100100
*/
101101
#define FNFT__CHECK_RETCODE(ret_code, label) {if (ret_code!=FNFT_SUCCESS) {ret_code=FNFT__E_SUBROUTINE(ret_code);goto label;}}
102102

103+
/**
104+
* Macro for checking if memory has been allocated. If var!=NULL, a
105+
* FNFT__E_NOMEM error is assigned to ret_code and the macro uses goto to jump to label.
106+
* @ingroup private_errwarn
107+
*/
108+
#define FNFT__CHECK_NOMEM(var,ret_code,label) {if (var==NULL) {ret_code=FNFT__E_NOMEM;goto label;}}
109+
103110
#ifdef FNFT_ENABLE_SHORT_NAMES
104111
#define WARN(msg) FNFT__WARN(msg)
105112
#define E_NOMEM FNFT__E_NOMEM
@@ -112,6 +119,7 @@
112119
#define E_SANITY_CHECK_FAILED(msg) FNFT__E_SANITY_CHECK_FAILED(msg)
113120
#define E_ASSERTION_FAILED FNFT__E_ASSERTION_FAILED
114121
#define CHECK_RETCODE(ret_code,label) FNFT__CHECK_RETCODE(ret_code,label)
122+
#define CHECK_NOMEM(var,ret_code,label) FNFT__CHECK_NOMEM(var,ret_code,label)
115123
#endif
116124

117125
/* --- Auxiliary macros and functions. Do not use directly. --- */

include/private/fnft__kdv_scatter.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
*
1616
* Contributors:
17-
* Sander Wahls (TU Delft) 2017-2018.
17+
* Sander Wahls (TU Delft) 2017-2018, 2023.
1818
* Shrinivas Chimmalgi (TU Delft) 2017.
1919
* Peter J Prins (TU Delft) 2020.
20+
* Sander Wahls (KIT) 2023.
2021
*/
2122

2223
/**
@@ -66,6 +67,12 @@
6667
* The \f$b(\lambda)\f$ are calculated using the criterion from
6768
* Prins and Wahls, <a href="https://doi.org/10.1109/ACCESS.2019.2932256">&quot;
6869
* Soliton Phase Shift Calculation for the Korteweg–De Vries Equation,&quot;</a>.
70+
* @param[in,out] Ws Pass an array of size K. Upon exit, it contains scaling factors that
71+
* arise due to an internal normalization of the scattering process (to deal with potential
72+
* overflow issues). The returned values for a and a_prime still have to be multiplied with
73+
* corresponding power of two (i.e. POW(2, Ws[i])) to obtain the final values. Note
74+
* that this is not required for the values of b. No normalization is carried out if NULL
75+
* is passed.
6976
* @param[in] discretization The type of discretization to be used. Should be of type
7077
* \link fnft_kdv_discretization_t \endlink. Not all kdv_discretization_t discretizations are supported.
7178
* Check \link fnft_kdv_discretization_t \endlink for list of supported types.
@@ -77,7 +84,7 @@
7784
FNFT_INT fnft__kdv_scatter_bound_states(const FNFT_UINT D, FNFT_COMPLEX const * const q,
7885
FNFT_COMPLEX const * const r, FNFT_REAL const * const T, FNFT_UINT const K,
7986
FNFT_COMPLEX * const bound_states, FNFT_COMPLEX * const a_vals,
80-
FNFT_COMPLEX * const aprime_vals, FNFT_COMPLEX * const b,
87+
FNFT_COMPLEX * const aprime_vals, FNFT_COMPLEX * const b, FNFT_INT * const Ws,
8188
fnft_kdv_discretization_t const discretization, FNFT_UINT const skip_b_flag);
8289

8390
/**
@@ -106,6 +113,10 @@ FNFT_INT fnft__kdv_scatter_bound_states(const FNFT_UINT D, FNFT_COMPLEX const *
106113
* If derivative_flag=1 returns [S11 S12 S21 S22 S11' S12' S21' S22'] in
107114
* result where S11' is the derivative of S11 w.r.t to lambda.
108115
* Should be preallocated with size 4*K or 8*K accordingly.
116+
* @param[in,out] W Pass an array of size K. Upon exit, it contains scaling factors that
117+
* arise due to an internal normalization of the scattering matrix (to deal with potential
118+
* overflow issues). The result has to be scaled by the power of 2 to obtain the final
119+
* values. No normalization is carried out if NULL is passed.
109120
* @param[in] discretization The type of discretization to be used. Should be of type
110121
* \link fnft_kdv_discretization_t \endlink. Not all kdv_discretization_t discretizations are supported.
111122
* Check \link fnft_kdv_discretization_t \endlink for list of supported types.
@@ -116,10 +127,11 @@ FNFT_INT fnft__kdv_scatter_bound_states(const FNFT_UINT D, FNFT_COMPLEX const *
116127
* defined in \link fnft_errwarn.h \endlink.
117128
* @ingroup kdv
118129
*/
119-
FNFT_INT fnft__kdv_scatter_matrix(const FNFT_UINT D, FNFT_COMPLEX const * const q, FNFT_COMPLEX const * const r,
130+
FNFT_INT fnft__kdv_scatter_matrix(const FNFT_UINT D,
131+
FNFT_COMPLEX const * const q, FNFT_COMPLEX const * const r,
120132
const FNFT_REAL eps_t, const FNFT_INT kappa, const FNFT_UINT K,
121-
FNFT_COMPLEX const * const lambda,
122-
FNFT_COMPLEX * const result, fnft_kdv_discretization_t const discretization,
133+
FNFT_COMPLEX const * const lambda, FNFT_COMPLEX * const result,
134+
FNFT_INT * const W, fnft_kdv_discretization_t const discretization,
123135
const FNFT_UINT derivative_flag);
124136

125137
#ifdef FNFT_ENABLE_SHORT_NAMES

0 commit comments

Comments
 (0)