/src/math/nfft_f.c

https://gitlab.com/umbe/octopus · C · 339 lines · 257 code · 59 blank · 23 comment · 17 complexity · a3c6a0c30dfbd58bbb6c736f30b2e4f1 MD5 · raw file

  1. /*
  2. Copyright (C) 2002 M. Marques, A. Castro, A. Rubio, G. Bertsch, M. Oliveira
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  14. 02110-1301, USA.
  15. */
  16. #include <config.h>
  17. #include <stdio.h>
  18. #include <math.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <complex.h>
  22. #ifdef HAVE_NFFT
  23. #include "nfft3util.h"
  24. #include "nfft3.h"
  25. #else
  26. typedef int nfft_plan;
  27. #endif
  28. // NFFT FUNCTIONS
  29. void FC_FUNC(oct_nfft_init_1d,OCT_NFFT_INIT_1D)
  30. (nfft_plan *plan, int *N1, int *M){
  31. #ifdef HAVE_NFFT
  32. nfft_init_1d(plan, *N1, *M);
  33. #endif
  34. }
  35. void FC_FUNC(oct_nfft_init_2d,OCT_NFFT_INIT_2D)
  36. (nfft_plan *plan, int *N1, int *N2, int *M){
  37. #ifdef HAVE_NFFT
  38. nfft_init_2d(plan, *N1, *N2, *M);
  39. #endif
  40. }
  41. void FC_FUNC(oct_nfft_init_3d,OCT_NFFT_INIT_3D)
  42. (nfft_plan *plan, int *N1, int *N2, int *N3, int *M){
  43. #ifdef HAVE_NFFT
  44. nfft_init_3d(plan, *N1, *N2, *N3, *M);
  45. #endif
  46. }
  47. void FC_FUNC(oct_nfft_init_guru,OCT_NFFT_INIT_GURU)
  48. (nfft_plan *ths, int *d, int *N, int *M, int *n, int *m, unsigned *nfft_flags, unsigned *fftw_flags){
  49. #ifdef HAVE_NFFT
  50. nfft_init_guru (ths, *d, N, *M, n, *m, *nfft_flags, *fftw_flags);
  51. #endif
  52. }
  53. void FC_FUNC(oct_nfft_check, OCT_NFFT_CHECK)(nfft_plan *ths){
  54. #ifdef HAVE_NFFT
  55. nfft_check (ths);
  56. #endif
  57. }
  58. void FC_FUNC(oct_nfft_finalize,OCT_NFFT_FINALIZE)(nfft_plan *ths){
  59. #ifdef HAVE_NFFT
  60. nfft_finalize (ths);
  61. #endif
  62. }
  63. void FC_FUNC(oct_nfft_trafo,OCT_NFFT_TRAFO)(nfft_plan *ths){
  64. #ifdef HAVE_NFFT
  65. nfft_trafo (ths);
  66. #endif
  67. }
  68. void FC_FUNC(oct_nfft_adjoint,OCT_NFFT_ADJOINT)(nfft_plan *ths){
  69. #ifdef HAVE_NFFT
  70. nfft_adjoint (ths);
  71. #endif
  72. }
  73. void FC_FUNC(oct_nfft_precompute_one_psi_1d, OCT_NFFT_PRECOMPUTE_ONE_PSI_1D)(nfft_plan *plan, int *m, double *X1){
  74. #ifdef HAVE_NFFT
  75. int ii;
  76. int M = *m;
  77. for (ii=0;ii< M;ii++) plan->x[ii] = X1[ii];
  78. if(plan->nfft_flags & PRE_ONE_PSI) nfft_precompute_one_psi(plan);
  79. #endif
  80. }
  81. void FC_FUNC(oct_nfft_precompute_one_psi_2d, OCT_NFFT_PRECOMPUTE_ONE_PSI_2D)(nfft_plan *plan, int *M, double* X1, double* X2){
  82. #ifdef HAVE_NFFT
  83. int ii;
  84. int jj;
  85. for (ii=0; ii< M[0]; ii++){
  86. for (jj=0; jj< M[1]; jj++){
  87. plan->x[2*(M[1] * ii + jj) + 0] = X1[ii];
  88. plan->x[2*(M[1] * ii + jj) + 1] = X2[jj];
  89. }
  90. }
  91. if(plan->nfft_flags & PRE_ONE_PSI)nfft_precompute_one_psi(plan);
  92. #endif
  93. }
  94. void FC_FUNC(oct_nfft_precompute_one_psi_3d, OCT_NFFT_PRECOMPUTE_ONE_PSI_3D)
  95. (nfft_plan *plan, int *M, double* X1, double* X2, double* X3){
  96. #ifdef HAVE_NFFT
  97. int ii,jj,kk;
  98. for (ii=0;ii< M[0];ii++){
  99. for (jj=0;jj< M[1];jj++){
  100. for (kk=0;kk< M[2];kk++){
  101. plan->x[3*(M[1]*M[2]*ii + M[2]*jj + kk) + 0] = X1[ii];
  102. plan->x[3*(M[1]*M[2]*ii + M[2]*jj + kk) + 1] = X2[jj];
  103. plan->x[3*(M[1]*M[2]*ii + M[2]*jj + kk) + 2] = X3[kk];
  104. }
  105. }
  106. }
  107. if(plan->nfft_flags & PRE_ONE_PSI) nfft_precompute_one_psi(plan);
  108. #endif
  109. }
  110. // Type dependent functions
  111. // ********** COMPLEX ************
  112. void FC_FUNC(zoct_set_f, ZOCT_SET_F)
  113. (nfft_plan *plan, int *M, int *DIM, double complex *VAL, int *IX, int *IY, int *IZ){
  114. #ifdef HAVE_NFFT
  115. int dim = *DIM;
  116. int ix = *IX;
  117. int iy = *IY;
  118. int iz = *IZ;
  119. double complex val = *VAL;
  120. switch (dim){
  121. case 1:
  122. plan->f[ix-1] = val;
  123. break;
  124. case 2:
  125. plan->f[(ix-1)*M[1] + (iy-1)] = val;
  126. break;
  127. case 3:
  128. plan->f[(ix-1)*M[1]*M[2] + (iy-1)*M[2] + (iz-1)] = val;
  129. break;
  130. }
  131. #endif
  132. }
  133. void FC_FUNC(zoct_get_f, ZOCT_GET_F)
  134. (nfft_plan *plan, int *M, int *DIM, double complex *val, int *IX, int *IY, int *IZ){
  135. #ifdef HAVE_NFFT
  136. int dim = *DIM;
  137. int ix = *IX;
  138. int iy = *IY;
  139. int iz = *IZ;
  140. switch (dim){
  141. case 1:
  142. *val = plan->f[ix-1];
  143. break;
  144. case 2:
  145. *val = plan->f[(ix-1)*M[1] + (iy-1)];
  146. break;
  147. case 3:
  148. *val = plan->f[(ix-1)*M[1]*M[2] + (iy-1)*M[2] + (iz-1)];
  149. break;
  150. }
  151. #endif
  152. }
  153. void FC_FUNC(zoct_set_f_hat, ZOCT_SET_F_HAT)
  154. (nfft_plan *plan, int *DIM, double complex *VAL, int *IX, int *IY, int *IZ){
  155. #ifdef HAVE_NFFT
  156. int dim = *DIM;
  157. int ix = *IX;
  158. int iy = *IY;
  159. int iz = *IZ;
  160. double complex val = *VAL;
  161. switch (dim){
  162. case 1:
  163. plan->f_hat[ix-1] = val;
  164. break;
  165. case 2:
  166. plan->f_hat[(ix-1)*plan->N[1] + (iy-1)] = val;
  167. break;
  168. case 3:
  169. plan->f_hat[(ix-1)*plan->N[1]*plan->N[2] + (iy-1)*plan->N[2] + (iz-1)] = val;
  170. break;
  171. }
  172. #endif
  173. }
  174. void FC_FUNC(zoct_get_f_hat, ZOCT_GET_F_HAT)
  175. (nfft_plan *plan, int *DIM, double complex *val, int *IX, int *IY, int *IZ){
  176. #ifdef HAVE_NFFT
  177. int dim = *DIM;
  178. int ix = *IX;
  179. int iy = *IY;
  180. int iz = *IZ;
  181. switch (dim){
  182. case 1:
  183. *val = plan->f_hat[ix-1];
  184. break;
  185. case 2:
  186. *val = plan->f_hat[(ix-1)*plan->N[1] + (iy-1)];
  187. break;
  188. case 3:
  189. *val = plan->f_hat[(ix-1)*plan->N[1]*plan->N[2] + (iy-1)*plan->N[2] + (iz-1)];
  190. break;
  191. }
  192. #endif
  193. }
  194. // ********** DOUBLE ************
  195. void FC_FUNC(doct_set_f, DOCT_SET_F)
  196. (nfft_plan *plan, int *M, int *DIM, double *VAL, int *IX, int *IY, int *IZ){
  197. #ifdef HAVE_NFFT
  198. int dim = *DIM;
  199. int ix = *IX;
  200. int iy = *IY;
  201. int iz = *IZ;
  202. double val = *VAL;
  203. switch (dim){
  204. case 1:
  205. plan->f[ix-1] = val;
  206. break;
  207. case 2:
  208. plan->f[(ix-1)*M[1] + (iy-1)] = val;
  209. break;
  210. case 3:
  211. plan->f[(ix-1)*M[1]*M[2] + (iy-1)*M[2] + (iz-1)] = val;
  212. break;
  213. }
  214. #endif
  215. }
  216. void FC_FUNC(doct_get_f, DOCT_GET_F)
  217. (nfft_plan *plan, int *M, int *DIM, double *val, int *IX, int *IY, int *IZ){
  218. #ifdef HAVE_NFFT
  219. int dim = *DIM;
  220. int ix = *IX;
  221. int iy = *IY;
  222. int iz = *IZ;
  223. switch (dim){
  224. case 1:
  225. *val = plan->f[ix-1];
  226. break;
  227. case 2:
  228. *val = plan->f[(ix-1)*M[1] + (iy-1)];
  229. break;
  230. case 3:
  231. *val = plan->f[(ix-1)*M[1]*M[2] + (iy-1)*M[2] + (iz-1)];
  232. break;
  233. }
  234. #endif
  235. }
  236. void FC_FUNC(doct_set_f_hat, DOCT_SET_F_HAT)
  237. (nfft_plan *plan, int *DIM, double *VAL, int *IX, int *IY, int *IZ){
  238. #ifdef HAVE_NFFT
  239. int dim = *DIM;
  240. int ix = *IX;
  241. int iy = *IY;
  242. int iz = *IZ;
  243. double val = *VAL;
  244. switch (dim){
  245. case 1:
  246. plan->f_hat[ix-1] = val;
  247. break;
  248. case 2:
  249. plan->f_hat[(ix-1)*plan->N[1] + (iy-1)] = val;
  250. break;
  251. case 3:
  252. plan->f_hat[(ix-1)*plan->N[1]*plan->N[2] + (iy-1)*plan->N[2] + (iz-1)] = val;
  253. break;
  254. }
  255. #endif
  256. }
  257. void FC_FUNC(doct_get_f_hat, DOCT_GET_F_HAT)
  258. (nfft_plan *plan, int *DIM, double *val, int *IX, int *IY, int *IZ){
  259. #ifdef HAVE_NFFT
  260. int dim = *DIM;
  261. int ix = *IX;
  262. int iy = *IY;
  263. int iz = *IZ;
  264. switch (dim){
  265. case 1:
  266. *val = plan->f_hat[ix-1];
  267. break;
  268. case 2:
  269. *val = plan->f_hat[(ix-1)*plan->N[1] + (iy-1)];
  270. break;
  271. case 3:
  272. *val = plan->f_hat[(ix-1)*plan->N[1]*plan->N[2] + (iy-1)*plan->N[2] + (iz-1)];
  273. break;
  274. }
  275. #endif
  276. }