Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_lagrange_interpolator_1d.F90
Go to the documentation of this file.
1 
7 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 #include "sll_memory.h"
9 #include "sll_errors.h"
10 #include "sll_working_precision.h"
11 
13  sll_p_one_sided, &
14  sll_p_halo, &
15  sll_p_periodic
16 
17  use sll_m_interpolators_1d_base, only: &
19 
25 
31 
32  implicit none
33 
34  public :: &
38 
39  private
40 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
41 
45  type(sll_t_lagrange_interpolation_1d), pointer :: lagrange
47  sll_int32 :: bc_type
49  sll_int32 :: stencil_width
51  sll_int32 :: interval_selection
52  contains
54  procedure, pass(interpolator) :: init => initialize_li1d_interpolator
56  procedure :: compute_interpolants => compute_interpolants_li1d
58  procedure :: interpolate_from_interpolant_derivatives_eta1 => interpolate_array_derivatives_li1d
60  procedure :: interpolate_array => interpolate_array_li1d
62  procedure :: interpolate_array_disp => interpolate_array_disp_li1d
64  procedure :: interpolate_array_disp_inplace => interpolate_array_disp_inplace_li1d
66  procedure :: interpolate_from_interpolant_derivative_eta1 => interpolate_derivative_eta1_li1d
68  procedure :: interpolate_from_interpolant_array => interpolate_array_values_li1d
70  procedure :: interpolate_from_interpolant_value => interpolate_value_li1d
72  procedure, pass :: set_coefficients => set_coefficients_li1d
74  procedure, pass :: get_coefficients => get_coefficients_li1d
76 
77 !PN DEFINED BUT NOT USED
78 ! !> Deallocate the class interpolator
79 ! interface sll_o_delete
80 ! module procedure delete_li1d
81 ! end interface
82 
83  ! Flags for way how to choose the Lagrange points
84  sll_int32, parameter :: sll_p_lagrange_centered = 0
85  sll_int32, parameter :: sll_p_lagrange_fixed = 1
86 
87 contains !**********************************************************
88 
89  subroutine initialize_li1d_interpolator(interpolator, num_points, xmin, xmax, bc_type, d, periodic_last, interval_selection)
90  class(sll_t_lagrange_interpolator_1d), intent(inout) :: interpolator
91  sll_int32, intent(in) :: d, num_points, bc_type
92  sll_real64, intent(in) :: xmin, xmax
93  sll_int32, intent(in), optional :: periodic_last
94  sll_int32, intent(in), optional :: interval_selection
95 
96  sll_int32 :: last
97 
98  if (present(periodic_last)) then
99  last = periodic_last
100  else
101  last = 1
102  end if
103 
104  interpolator%lagrange => sll_f_new_lagrange_interpolation_1d( &
105  num_points, &
106  xmin, &
107  xmax, &
108  bc_type, &
109  d, &
110  last)
111  call sll_s_compute_lagrange_interpolation_1d(interpolator%lagrange)
112 
113  if (present(interval_selection)) then
114  interpolator%interval_selection = interval_selection
115  else
116  interpolator%interval_selection = sll_p_lagrange_centered
117  end if
118 
119  select case (interpolator%interval_selection)
121  interpolator%stencil_width = 2*d
122  case (sll_p_lagrange_fixed)
123  interpolator%stencil_width = 2*d + 1
124  case default
125  sll_error('interpolate_array_disp_li1d', 'Interval selection not implemented.')
126  end select
127 
128  interpolator%bc_type = bc_type
129 
130  end subroutine
131 
133  num_points, &
134  xmin, &
135  xmax, &
136  bc_type, &
137  d, &
138  periodic_last) result(res)
139 
140  type(sll_t_lagrange_interpolator_1d), pointer :: res
141  sll_int32, intent(in) :: num_points
142  sll_real64, intent(in) :: xmin
143  sll_real64, intent(in) :: xmax
144  sll_int32, intent(in) :: bc_type
145  sll_int32, intent(in) :: d
146  sll_int32 :: ierr
147  sll_int32, intent(in), optional :: periodic_last
148  sll_int32 :: last
149 
150  sll_allocate(res, ierr)
151 
152  if (present(periodic_last)) then
153  last = periodic_last
154  else
155  last = 1
156  end if
157 
159  res, &
160  num_points, &
161  xmin, &
162  xmax, &
163  bc_type, &
164  d, &
165  last)
166 
167  end function new_lagrange_interpolator_1d
168 
169  subroutine interpolate_array_disp_li1d(this, num_pts, data, alpha, output_array)
170  class(sll_t_lagrange_interpolator_1d), intent(inout) :: this
171  sll_real64, intent(in) :: alpha
172  sll_int32, intent(in) :: num_pts ! size of output array
173  sll_real64, dimension(:), intent(in) :: data ! data to be interpolated points where output is desired
174  sll_real64, dimension(1:num_pts), intent(out) :: output_array
175 
176  select case (this%interval_selection)
178  call sll_s_cubic_spline_1d_eval_array(data, -alpha, this%lagrange)
179  output_array = this%lagrange%data_out
180  case (sll_p_lagrange_fixed)
181  select case (this%bc_type)
182  case (sll_p_periodic)
183  if (this%lagrange%periodic_last == 0) then
184  call sll_s_lagrange_interpolation_1d_fast_disp_fixed_periodic(data, output_array, alpha/this%lagrange%deta, this%stencil_width)
185  else
186  call sll_s_lagrange_interpolation_1d_fast_disp_fixed_periodicl(data, output_array, alpha/this%lagrange%deta, this%stencil_width)
187  end if
188  case (sll_p_one_sided)
189  call sll_s_lagrange_interpolation_1d_fast_disp_fixed_no_bc(data, output_array, alpha/this%lagrange%deta, this%stencil_width)
190  case (sll_p_halo)
191  call sll_s_lagrange_interpolation_1d_fast_disp_fixed_haloc_cells(data, output_array, alpha/this%lagrange%deta, this%stencil_width)
192  case default
193  sll_error('interpolate_array_disp_li1d', 'Boundary type not implemented.')
194  end select
195  case default
196  sll_error('interpolate_array_disp_li1d', 'Interval selection not implemented.')
197  end select
198 
199  end subroutine interpolate_array_disp_li1d
200 
201  subroutine interpolate_array_disp_inplace_li1d(this, num_pts, data, alpha)
202  class(sll_t_lagrange_interpolator_1d), intent(inout) :: this
203  sll_real64, intent(in) :: alpha
204  sll_int32, intent(in) :: num_pts ! size of output array
205  sll_real64, dimension(num_pts), intent(inout) :: data ! data to be interpolated points where output is desired
206 
207  call sll_s_cubic_spline_1d_eval_array(data, -alpha, this%lagrange)
208  data = this%lagrange%data_out
209 
211 
212 !PN DEFINED BUT NOT USED
213 !subroutine delete_li1d (obj)
214 ! class(sll_t_lagrange_interpolator_1d) :: obj
215 ! call delete(obj%lagrange)
216 !end subroutine delete_li1d
217 
219  interpolator, &
220  num_pts, &
221  vals_to_interpolate, &
222  output_array)
223  class(sll_t_lagrange_interpolator_1d), intent(inout) :: interpolator
224  sll_int32, intent(in) :: num_pts
225  sll_real64, dimension(num_pts), intent(in) :: vals_to_interpolate
226  sll_real64, dimension(num_pts), intent(out) :: output_array
227  !sll_int32 :: ierr
228  output_array = 0.0_f64
229  print *, 'sll_s_cubic_spline_1d_eval_array:', &
230  ' not implemented for lagrange interpolation'
231  print *, num_pts
232  print *, maxval(vals_to_interpolate)
233  output_array = 0._f64
234  print *, interpolator%bc_type
235  stop
236  end subroutine interpolate_array_values_li1d
237 
239  interpolator, &
240  num_pts, &
241  vals_to_interpolate, &
242  output_array)
243  class(sll_t_lagrange_interpolator_1d), intent(inout) :: interpolator
244  sll_int32, intent(in) :: num_pts
245  sll_real64, dimension(:), intent(in) :: vals_to_interpolate
246  sll_real64, dimension(:), intent(out) :: output_array
247  !sll_int32 :: ierr
248  output_array = 0.0_f64
249  print *, 'interpolate_from_interpolant_derivatives_eta1: ', &
250  'not implemented for lagrange interpolation'
251  print *, num_pts
252  print *, maxval(vals_to_interpolate)
253  print *, maxval(output_array)
254  print *, interpolator%bc_type
255  stop
257 
258  function interpolate_derivative_eta1_li1d(interpolator, eta1) result(val)
259  class(sll_t_lagrange_interpolator_1d), intent(in) :: interpolator
260  sll_real64 :: val
261  sll_real64, intent(in) :: eta1
262  print *, 'interpolate_derivative_eta1_li1d: ', &
263  'not implemented for lagrange interpolation'
264  print *, interpolator%bc_type
265  print *, eta1
266  val = 0._f64
267  stop
268  end function
269 
270  function interpolate_value_li1d(interpolator, eta1) result(val)
271  class(sll_t_lagrange_interpolator_1d), intent(in) :: interpolator
272  sll_real64 :: val
273  sll_real64, intent(in) :: eta1
274  print *, 'interpolate_value_li1d: ', &
275  'not implemented for lagrange interpolation'
276  val = 0._f64
277  print *, eta1
278  print *, interpolator%bc_type
279  stop
280  end function
281 
282  subroutine interpolate_array_li1d(this, num_pts, data, coordinates, output_array)
283  class(sll_t_lagrange_interpolator_1d), intent(inout) :: this
284  !class(sll_spline_1D), intent(in) :: this
285  sll_int32, intent(in) :: num_pts
286  sll_real64, dimension(num_pts), intent(in) :: coordinates
287  sll_real64, dimension(:), intent(in) :: data
288  sll_real64, dimension(num_pts), intent(out) :: output_array
289  ! local variables
290  !sll_int32 :: ierr
291  ! lagrange interpolation only implemented for constant displacement
292  print *, 'interpolate_array_li1d: ', &
293  'not implemented for lagrange interpolation'
294  print *, maxval(coordinates)
295  print *, maxval(data)
296  print *, this%bc_type
297  output_array = 0._f64
298  stop
299  end subroutine interpolate_array_li1d
300 
301  subroutine compute_interpolants_li1d(interpolator, data_array, &
302  eta_coords, &
303  size_eta_coords)
304  class(sll_t_lagrange_interpolator_1d), intent(inout) :: interpolator
305  sll_real64, dimension(:), intent(in) :: data_array
306  sll_real64, dimension(:), intent(in), optional :: eta_coords
307  sll_int32, intent(in), optional :: size_eta_coords
308 
309  print *, 'compute_interpolants_li1d:', &
310  ' not implemented for lagrange interpolation'
311 
312  if (present(eta_coords) .or. present(size_eta_coords)) then
313  sll_error('compute_interpolants_li1d', 'This case is not yet implemented')
314  end if
315 
316  print *, maxval(data_array)
317  print *, interpolator%bc_type
318  stop
319  end subroutine
320 
321  subroutine set_coefficients_li1d(interpolator, coeffs)
322  class(sll_t_lagrange_interpolator_1d), intent(inout) :: interpolator
323  sll_real64, dimension(:), intent(in), optional :: coeffs
324  print *, 'set_coefficients_li1d(): ERROR: This function has not been ', &
325  'implemented yet.'
326  if (present(coeffs)) then
327  print *, '#coeffs present but not used'
328  end if
329  print *, interpolator%bc_type
330  stop
331  end subroutine set_coefficients_li1d
332 
333  function get_coefficients_li1d(interpolator)
334  class(sll_t_lagrange_interpolator_1d), intent(in) :: interpolator
335  sll_real64, dimension(:), pointer :: get_coefficients_li1d
336 
337  print *, 'get_coefficients_li1d(): ERROR: This function has not been ', &
338  'implemented yet.'
339  print *, interpolator%bc_type
340  get_coefficients_li1d => null()
341  stop
342  end function get_coefficients_li1d
343  !DEFINE_NULL_INTERP_1D_ARRAY_SUB(sll_t_lagrange_interpolator_1d, interpolate_array_values_li1d)
344 !DEFINE_NULL_INTERP_1D_ARRAY_SUB(sll_t_lagrange_interpolator_1d, interpolate_array_derivatives_li1d)
345 !DEFINE_NULL_INTERP_1D_POINTER_SUB(sll_t_lagrange_interpolator_1d, interpolate_pointer_derivatives_li1d)
346 !DEFINE_NULL_INTERP_ONE_ARG_MSG(sll_t_lagrange_interpolator_1d, interpolate_derivative_eta1_li1d)
347 !DEFINE_NULL_INTERP_1D_POINTER_SUB(sll_t_lagrange_interpolator_1d, interpolate_pointer_values_li1d)
348 !DEFINE_NULL_INTERP_ONE_ARG_MSG(sll_t_lagrange_interpolator_1d, interpolate_value_li1d)
349 !DEFINE_NULL_RECONSTRUCT_1D_ARRAY(sll_t_lagrange_interpolator_1d, reconstruct_array_li1d)
350 !DEFINE_NULL_INTERP_1D_ARRAY(sll_t_lagrange_interpolator_1d, interpolate_array_li1d)
351 !DEFINE_NULL_INTERP_1D_ARRAY_MSG(sll_t_lagrange_interpolator_1d, compute_interpolants_li1d)
352 
Module for 1D interpolation and reconstruction.
Module for 1D Lagrange interpolation on a uniform grid (only odd order)
subroutine, public sll_s_lagrange_interpolation_1d_fast_disp_fixed_no_bc(fi, fp, p, stencil)
Lagrange interpolation, without boundary conditions. One sided a the outermost points.
subroutine, public sll_s_lagrange_interpolation_1d_fast_disp_fixed_periodicl(fi, fp, p, stencil)
Lagrange interpolation, periodic boundary conditions, first value repeated at the end.
subroutine, public sll_s_lagrange_interpolation_1d_fast_disp_fixed_periodic(fi, fp, p, stencil)
Lagrange interpolation, periodic boundary conditions.
subroutine, public sll_s_lagrange_interpolation_1d_fast_disp_fixed_haloc_cells(fi, fp, p, stencil)
Lagrange interpolation with halo cell boundaries, where the input array already contains halo cells....
subroutine, public sll_s_cubic_spline_1d_eval_array(fi, alpha, lagrange)
This function computes the value at the grid points displacement by -alpha.
subroutine, public sll_s_compute_lagrange_interpolation_1d(lagrange)
This function computes the weights w_j for the barycentric formula.
type(sll_t_lagrange_interpolation_1d) function, pointer, public sll_f_new_lagrange_interpolation_1d(num_points, xmin, xmax, bc_type, d, periodic_last)
Interpolator class and methods of Lagrange 1D interpolator.
subroutine initialize_li1d_interpolator(interpolator, num_points, xmin, xmax, bc_type, d, periodic_last, interval_selection)
real(kind=f64) function, dimension(:), pointer get_coefficients_li1d(interpolator)
subroutine interpolate_array_values_li1d(interpolator, num_pts, vals_to_interpolate, output_array)
subroutine compute_interpolants_li1d(interpolator, data_array, eta_coords, size_eta_coords)
subroutine interpolate_array_disp_li1d(this, num_pts, data, alpha, output_array)
subroutine set_coefficients_li1d(interpolator, coeffs)
subroutine interpolate_array_disp_inplace_li1d(this, num_pts, data, alpha)
real(kind=f64) function interpolate_derivative_eta1_li1d(interpolator, eta1)
real(kind=f64) function interpolate_value_li1d(interpolator, eta1)
subroutine interpolate_array_li1d(this, num_pts, data, coordinates, output_array)
subroutine interpolate_array_derivatives_li1d(interpolator, num_pts, vals_to_interpolate, output_array)
integer(kind=i32), parameter, public sll_p_lagrange_fixed
Flag to specify Lagrange interpolation on a fixed interval centered around the point that is displace...
integer(kind=i32), parameter, public sll_p_lagrange_centered
Flag to specify Lagrange interpolation centered around the interpolation point.
type(sll_t_lagrange_interpolator_1d) function, pointer new_lagrange_interpolator_1d(num_points, xmin, xmax, bc_type, d, periodic_last)
Abstract class for 1D interpolation and reconstruction.
    Report Typos and Errors