Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_nufft_interpolator_2d.F90
Go to the documentation of this file.
1 !**************************************************************
2 ! Copyright INRIA
3 ! Authors :
4 ! CALVI project team
5 !
6 ! This code SeLaLib (for Semi-Lagrangian-Library)
7 ! is a parallel library for simulating the plasma turbulence
8 ! in a tokamak.
9 !
10 ! This software is governed by the CeCILL-B license
11 ! under French law and abiding by the rules of distribution
12 ! of free software. You can use, modify and redistribute
13 ! the software under the terms of the CeCILL-B license as
14 ! circulated by CEA, CNRS and INRIA at the following URL
15 ! "http://www.cecill.info".
16 !**************************************************************
17 
24 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include "sll_errors.h"
26 #include "sll_assert.h"
27 #include "sll_memory.h"
28 #include "sll_working_precision.h"
29 
30  use sll_m_nufft_interpolation, only: &
37 
39 
40  implicit none
41 
42  public :: &
46 
47  private
48 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 
58 
59  sll_int32 :: num_cells1
60  sll_int32 :: num_cells2
61  type(sll_t_nufft_2d) :: nufft
62  sll_real64 :: eta1_min
63  sll_real64 :: eta1_max
64  sll_real64 :: eta2_min
65  sll_real64 :: eta2_max
66 
67  contains
68 
70  procedure, pass(interpolator) :: init => sll_s_nufft_interpolator_2d_init
72  procedure :: compute_interpolants => compute_interpolants_nufft2d
74  procedure :: interpolate_from_interpolant_value => interpolate_value_nufft2d
76  procedure :: interpolate_from_interpolant_derivative_eta1 => interpolate_deriv1_nufft2d
78  procedure :: interpolate_from_interpolant_derivative_eta2 => interpolate_deriv2_nufft2d
80  procedure, pass :: interpolate_array => nufft_interpolate2d
82  procedure, pass :: interpolate_array_disp => nufft_interpolate2d_disp
84  procedure, pass :: set_coefficients => set_coefficients_nufft2d
86  procedure, pass :: get_coefficients => get_coefficients_nufft2d
88  procedure, pass :: coefficients_are_set => coefficients_are_set_nufft2d
90  procedure, pass :: delete => sll_s_nufft_interpolator_2d_free
91 
93 
96  type(sll_t_nufft_interpolator_2d), pointer :: interp
98 
99 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
100 contains
101 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
102 
103  subroutine sll_s_nufft_interpolator_2d_free(interpolator)
104  class(sll_t_nufft_interpolator_2d), intent(inout) :: interpolator
105 
106  call sll_s_nufft_2d_free(interpolator%nufft)
107 
108  end subroutine sll_s_nufft_interpolator_2d_free
109 
110 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
111 
113  interpolator, &
114  npts1, &
115  npts2, &
116  eta1_min, &
117  eta1_max, &
118  eta2_min, &
119  eta2_max)
120 
121  class(sll_t_nufft_interpolator_2d), intent(inout) :: interpolator
122  sll_int32, intent(in) :: npts1
123  sll_int32, intent(in) :: npts2
124  sll_real64, intent(in) :: eta1_min
125  sll_real64, intent(in) :: eta1_max
126  sll_real64, intent(in) :: eta2_min
127  sll_real64, intent(in) :: eta2_max
128 
129  interpolator%num_cells1 = npts1 - 1
130  interpolator%num_cells2 = npts2 - 1
131  interpolator%eta1_min = eta1_min
132  interpolator%eta1_max = eta1_max
133  interpolator%eta2_min = eta2_min
134  interpolator%eta2_max = eta2_max
135 
136  call sll_s_nufft_2d_init( &
137  interpolator%nufft, &
138  npts1 - 1, &
139  eta1_min, &
140  eta1_max, &
141  npts2 - 1, &
142  eta2_min, &
143  eta2_max)
144 
145  end subroutine sll_s_nufft_interpolator_2d_init
146 
147 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
148 
150  interpolator, &
151  data_array, &
152  eta1_coords, &
153  size_eta1_coords, &
154  eta2_coords, &
155  size_eta2_coords)
156 
157  class(sll_t_nufft_interpolator_2d), intent(inout) :: interpolator
158  sll_real64, dimension(:, :), intent(in) :: data_array
159  sll_real64, dimension(:), intent(in), optional :: eta1_coords
160  sll_real64, dimension(:), intent(in), optional :: eta2_coords
161  sll_int32, intent(in), optional :: size_eta1_coords
162  sll_int32, intent(in), optional :: size_eta2_coords
163  sll_int32 :: nc1, nc2
164 
165  nc1 = interpolator%num_cells1
166  nc2 = interpolator%num_cells2
167 
168  call sll_s_nufft_2d_compute_fft(interpolator%nufft, &
169  data_array(1:nc1, 1:nc2))
170 
171  end subroutine compute_interpolants_nufft2d
172 
173 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
174 
175  function interpolate_value_nufft2d(interpolator, eta1, eta2) result(val)
176 
177  class(sll_t_nufft_interpolator_2d), intent(in) :: interpolator
178  sll_real64, intent(in) :: eta1
179  sll_real64, intent(in) :: eta2
180 
181  sll_real64 :: val
182 
183  val = sll_f_nufft_2d_interpolate_value_from_fft(interpolator%nufft, eta1, eta2)
184 
185  end function
186 
187 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
188 
189  function interpolate_deriv1_nufft2d(interpolator, eta1, eta2) result(val)
190 
191  class(sll_t_nufft_interpolator_2d), intent(in) :: interpolator
192  sll_real64, intent(in) :: eta1
193  sll_real64, intent(in) :: eta2
194 
195  sll_real64 :: val
196 
197  val = 0.0_f64
198  sll_error('interpolate_deriv1_nufft2d', 'not implemented')
199 
200  end function
201 
202 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
203 
204  function interpolate_deriv2_nufft2d(interpolator, eta1, eta2) result(val)
205 
206  class(sll_t_nufft_interpolator_2d), intent(in) :: interpolator
207  sll_real64, intent(in) :: eta1
208  sll_real64, intent(in) :: eta2
209 
210  sll_real64 :: val
211 
212  val = 0.0_f64
213  sll_error('interpolate_deriv2_nufft2d', 'not implemented')
214 
215  end function
216 
217 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
218 
219  subroutine nufft_interpolate2d(this, &
220  num_points1, &
221  num_points2, &
222  data_in, &
223  eta1, &
224  eta2, &
225  data_out)
226 
227  class(sll_t_nufft_interpolator_2d), intent(inout) :: this
228  sll_int32, intent(in) :: num_points1
229  sll_int32, intent(in) :: num_points2
230  sll_real64, dimension(:, :), intent(in) :: eta1
231  sll_real64, dimension(:, :), intent(in) :: eta2
232  sll_real64, dimension(:, :), intent(in) :: data_in
233  sll_real64, intent(out):: data_out(num_points1, num_points2)
234 
235  sll_int32 :: nc1, nc2
236 
237  nc1 = this%num_cells1
238  nc2 = this%num_cells2
239 
240  call sll_s_nufft_2d_interpolate_array_values(this%nufft, &
241  data_in(1:nc1, 1:nc2), &
242  eta1(1:nc1, 1:nc2), &
243  eta2(1:nc1, 1:nc2), &
244  data_out(1:nc1, 1:nc2))
245 
246  data_out(nc1 + 1, :) = data_out(1, :)
247  data_out(:, nc2 + 1) = data_out(:, 1)
248 
249  end subroutine nufft_interpolate2d
250 
251 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
252 
253  subroutine nufft_interpolate2d_disp(this, &
254  num_points1, &
255  num_points2, &
256  data_in, &
257  alpha1, &
258  alpha2, &
259  data_out)
260 
261  class(sll_t_nufft_interpolator_2d), intent(inout) :: this
262 
263  sll_int32, intent(in) :: num_points1
264  sll_int32, intent(in) :: num_points2
265  sll_real64, dimension(:, :), intent(in) :: alpha1
266  sll_real64, dimension(:, :), intent(in) :: alpha2
267  sll_real64, dimension(:, :), intent(in) :: data_in
268  sll_real64, intent(out) :: data_out(num_points1, num_points2)
269 
270  sll_real64, dimension(:, :), allocatable :: eta1
271  sll_real64, dimension(:, :), allocatable :: eta2
272 
273  sll_real64 :: eta1_min
274  sll_real64 :: eta1_max
275  sll_real64 :: delta_eta1
276  sll_real64 :: eta2_min
277  sll_real64 :: eta2_max
278  sll_real64 :: delta_eta2
279  sll_int32 :: i
280  sll_int32 :: j
281  sll_int32 :: error
282  sll_int32 :: nc1
283  sll_int32 :: nc2
284 
285  nc1 = this%num_cells1
286  nc2 = this%num_cells2
287 
288  eta1_min = this%eta1_min
289  eta1_max = this%eta1_max
290  eta2_min = this%eta2_min
291  eta2_max = this%eta2_max
292  delta_eta1 = (this%eta1_max - this%eta1_min)/real(this%num_cells1, f64)
293  delta_eta2 = (this%eta2_max - this%eta2_min)/real(this%num_cells2, f64)
294 
295  sll_allocate(eta1(1:nc1, 1:nc2), error)
296  sll_allocate(eta2(1:nc1, 1:nc2), error)
297  do j = 1, nc2
298  do i = 1, nc1
299  eta1(i, j) = real(i - 1, f64)*delta_eta1
300  eta2(i, j) = real(j - 1, f64)*delta_eta2
301  eta1(i, j) = eta1_min + modulo(eta1(i, j) + alpha1(i, j), eta1_max - eta1_min)
302  eta2(i, j) = eta2_min + modulo(eta2(i, j) + alpha2(i, j), eta2_max - eta2_min)
303  end do
304  end do
305 
306  call sll_s_nufft_2d_interpolate_array_values(this%nufft, &
307  data_in(1:nc1, 1:nc2), &
308  eta1, &
309  eta2, &
310  data_out(1:nc1, 1:nc2))
311 
312  data_out(nc1 + 1, :) = data_out(1, :)
313  data_out(:, nc2 + 1) = data_out(:, 1)
314 
315  end subroutine nufft_interpolate2d_disp
316 
317 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
318 
320  interpolator, &
321  coeffs_1d, &
322  coeffs_2d, &
323  coeff2d_size1, &
324  coeff2d_size2, &
325  knots1, &
326  size_knots1, &
327  knots2, &
328  size_knots2)
329 
330  class(sll_t_nufft_interpolator_2d), intent(inout) :: interpolator
331  sll_real64, dimension(:), intent(in), optional :: coeffs_1d
332  sll_real64, dimension(:, :), intent(in), optional :: coeffs_2d
333  sll_int32, intent(in), optional :: coeff2d_size1
334  sll_int32, intent(in), optional :: coeff2d_size2
335  sll_real64, dimension(:), intent(in), optional :: knots1
336  sll_real64, dimension(:), intent(in), optional :: knots2
337  sll_int32, intent(in), optional :: size_knots1
338  sll_int32, intent(in), optional :: size_knots2
339 
340  print *, interpolator%num_cells1, interpolator%num_cells2
341 
342  if (present(coeffs_1d)) print *, 'coeffs_1d present but not used'
343  if (present(coeffs_2d)) print *, 'coeffs_2d present but not used'
344  if (present(coeff2d_size1)) print *, 'coeff2d_size1 present but not used'
345  if (present(coeff2d_size2)) print *, 'coeff2d_size2 present but not used'
346  if (present(knots1)) print *, 'knots1 present but not used'
347  if (present(knots2)) print *, 'knots2 present but not used'
348  if (present(size_knots1)) print *, 'size_knots1 present but not used'
349  if (present(size_knots2)) print *, 'size_knots2 present but not used'
350 
351  sll_error('set_coefficients', 'Not implemented for nufft2d')
352 
353  end subroutine !set_coefficients_nufft2d
354 
355 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
356 
357  function get_coefficients_nufft2d(interpolator) result(res)
358  class(sll_t_nufft_interpolator_2d), intent(in) :: interpolator
359  sll_real64, pointer :: res(:, :)
360 
361  res => null()
362 
363  sll_error('get_coefficients', 'Not implemented for nufft2d')
364 
365  end function get_coefficients_nufft2d
366 
367 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
368 
369  function coefficients_are_set_nufft2d(interpolator) result(res)
370  class(sll_t_nufft_interpolator_2d), intent(in) :: interpolator
371 
372  logical :: res
373 
374  res = .false.
375 
376  sll_error('coefficients_are_set', 'Not implemented for nufft2d')
377 
378  end function coefficients_are_set_nufft2d
379 
380 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
382 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
abstract data type for 2d interpolation
subroutine sll_s_nufft_2d_compute_fft(self, f_in)
Compute the fft and prepare data for nufft call.
subroutine sll_s_nufft_2d_interpolate_array_values(self, f_in, x, y, f_out)
Compute the fft and interpolate array values.
subroutine sll_s_nufft_2d_free(self)
Delete the nufft object.
real(kind=f64) function sll_f_nufft_2d_interpolate_value_from_fft(self, x, y)
Interpolate single value when the fft is already compute.
subroutine sll_s_nufft_2d_init(self, nc_eta1, eta1_min, eta1_max, nc_eta2, eta2_min, eta2_max)
Allocate and initialize data and prepare the fft plan.
Nufft object for 2d interpolation. It contains fft plan and 1d array to pass data to nufft2d subrouti...
Class for the nufft inmplementation of sll_c_interpolator_2d.
real(kind=f64) function interpolate_deriv1_nufft2d(interpolator, eta1, eta2)
subroutine nufft_interpolate2d_disp(this, num_points1, num_points2, data_in, alpha1, alpha2, data_out)
real(kind=f64) function interpolate_deriv2_nufft2d(interpolator, eta1, eta2)
subroutine nufft_interpolate2d(this, num_points1, num_points2, data_in, eta1, eta2, data_out)
subroutine, public sll_s_nufft_interpolator_2d_init(interpolator, npts1, npts2, eta1_min, eta1_max, eta2_min, eta2_max)
subroutine, public sll_s_nufft_interpolator_2d_free(interpolator)
logical function coefficients_are_set_nufft2d(interpolator)
real(kind=f64) function interpolate_value_nufft2d(interpolator, eta1, eta2)
subroutine compute_interpolants_nufft2d(interpolator, data_array, eta1_coords, size_eta1_coords, eta2_coords, size_eta2_coords)
real(kind=f64) function, dimension(:, :), pointer get_coefficients_nufft2d(interpolator)
subroutine set_coefficients_nufft2d(interpolator, coeffs_1d, coeffs_2d, coeff2d_size1, coeff2d_size2, knots1, size_knots1, knots2, size_knots2)
Base class/basic interface for 2D interpolators.
The nufft-based interpolator is only a wrapper around the capabilities of the nufft package.
    Report Typos and Errors