Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_advection_1d_non_uniform_cubic_splines.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 
18 ! for the moment mimic of sll_m_periodic_interpolator_1d.F90
19 
22 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "sll_memory.h"
24 #include "sll_working_precision.h"
25 
26  use sll_m_advection_1d_base, only: &
28 
33 
34  implicit none
35 
36  public :: &
39 
40  private
41 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42 
44 
45  sll_int32 :: num_cells
46  sll_real64 :: xmin
47  sll_real64 :: xmax
48  sll_real64, dimension(:), pointer :: node_positions
49  sll_real64, dimension(:), pointer :: buf
50  sll_int32, dimension(:), pointer :: ibuf
51  sll_real64, dimension(:), pointer :: node_pos
52  sll_real64, dimension(:), pointer :: coeffs
53  sll_real64, dimension(:), pointer :: xstar
54  contains
55  procedure, pass(adv) :: init => &
57  procedure, pass(adv) :: advect_1d_constant => &
59  procedure, pass(adv) :: advect_1d => &
61  procedure, pass(adv) :: delete => delete_non_unif_cubic_splines_1d_adv
63 
64 !!$ interface sll_o_delete
65 !!$ module procedure delete_non_unif_cubic_splines_1d_adv
66 !!$ end interface sll_o_delete
67 
68 contains
69 
71  num_cells, &
72  xmin, &
73  xmax, &
74  order, &
75  node_positions &
76  ) &
77  result(adv)
79  sll_int32, intent(in) :: num_cells
80  sll_real64, intent(in) :: xmin
81  sll_real64, intent(in) :: xmax
82  sll_int32, intent(in) :: order
83  sll_real64, dimension(:), intent(in), optional :: node_positions
84  sll_int32 :: ierr
85 
86  sll_allocate(adv, ierr)
88  adv, &
89  num_cells, &
90  xmin, &
91  xmax, &
92  order, &
93  node_positions)
94 
96 
98  adv, &
99  num_cells, &
100  xmin, &
101  xmax, &
102  order, &
103  node_positions)
104 
106  sll_int32, intent(in) :: num_cells
107  sll_real64, intent(in) :: xmin
108  sll_real64, intent(in) :: xmax
109  sll_int32, intent(in) :: order
110  sll_real64, dimension(:), intent(in), optional :: node_positions
111  sll_int32 :: ierr
112  sll_int32 :: i
113  sll_real64 :: dx
114 
115 ! call initialize_periodic_interp( &
116 ! adv%per_interp, &
117 ! num_cells, &
118 ! type, &
119 ! order)
120 
121  adv%num_cells = num_cells
122  adv%xmin = xmin
123  adv%xmax = xmax
124 
125  dx = (xmax - xmin)/real(num_cells, f64)
126 
127  if (order .ne. 4) then
128  print *, '#Warning order=4 is enforced'
129  print *, '#in initialize_sll_t_advector_1d_non_uniform_cubic_splines'
130  end if
131 
132  if (present(node_positions)) then
133  if (size(node_positions, 1) < num_cells + 1) then
134  print *, '#size problem for node_positions'
135  print *, '#in subroutine initialize_sll_t_advector_1d_non_uniform_cubic_splines'
136  stop
137  end if
138  sll_allocate(adv%node_positions(num_cells + 1), ierr)
139  adv%node_positions(1:num_cells + 1) = &
140  (node_positions(1:num_cells + 1) - xmin)/(xmax - xmin)
141  else
142  sll_allocate(adv%node_positions(num_cells + 1), ierr)
143  do i = 1, num_cells + 1
144  !adv%node_positions(i) = xmin + real(i-1,f64)*dx
145  adv%node_positions(i) = real(i - 1, f64)/real(num_cells, f64)
146  end do
147  end if
148 
149  sll_clear_allocate(adv%buf(10*num_cells), ierr)
150  sll_allocate(adv%ibuf(num_cells), ierr)
151  adv%ibuf = 0
152  sll_clear_allocate(adv%node_pos(-2:num_cells + 2), ierr)
153  sll_clear_allocate(adv%coeffs(-1:num_cells + 1), ierr)
154  !SLL_CLEAR_ALLOCATE(adv%coeffs(-2:num_cells+2),ierr)
155  sll_clear_allocate(adv%Xstar(1:num_cells + 1), ierr)
156 
157  adv%node_pos(0:num_cells) = adv%node_positions(1:num_cells + 1)
158  call sll_s_setup_spline_nonunif_1d_periodic_aux(adv%node_pos, num_cells, adv%buf, adv%ibuf)
159 
161 
163  adv, &
164  A, &
165  dt, &
166  input, &
167  output)
169  sll_real64, intent(in) :: a
170  sll_real64, intent(in) :: dt
171  sll_real64, dimension(:), intent(in) :: input
172  sll_real64, dimension(:), intent(out) :: output
173  sll_real64 :: shift
174  sll_real64 :: xmin
175  sll_real64 :: xmax
176  sll_int32 :: num_cells
177  sll_real64 :: alpha
178 
179  num_cells = adv%num_cells
180  xmin = adv%xmin
181  xmax = adv%xmax
182  shift = a*dt/(xmax - xmin)*real(num_cells, f64)
183 
184  alpha = a*dt/(xmax - xmin)
185 
186  output(1:num_cells + 1) = input(1:num_cells + 1)
187 
189  output, &
190  alpha, &
191  adv%node_positions, &
192  num_cells, &
193  adv%buf, &
194  adv%Xstar, &
195  adv%node_pos, &
196  adv%coeffs, &
197  adv%ibuf)
198  !print *,'#not implemented for the moment'
199  !print *,'#non_uniform_cubic_splines_advect_1d_constant'
200  !stop
201 
202 ! call periodic_interp( &
203 ! adv%per_interp, &
204 ! output, &
205 ! input, &
206 ! shift)
207 ! ! complete by periodicity
208 ! output(num_cells+1) = output(1)
209 
211 
213  adv, &
214  A, &
215  dt, &
216  input, &
217  output)
219  sll_real64, dimension(:), intent(in) :: a
220  sll_real64, intent(in) :: dt
221  sll_real64, dimension(:), intent(in) :: input
222  sll_real64, dimension(:), intent(out) :: output
223 
224  print *, '#non_uniform_cubic_splines_advect_1d'
225  print *, '#not implemented for the moment'
226  print *, maxval(a)
227  print *, dt
228  print *, maxval(input)
229  output = 0._f64
230  print *, adv%num_cells
231  stop
232 
234 
236  alpha, &
237  node_positions, &
238  N, &
239  buf, &
240  Xstar, &
241  node_pos, &
242  coeffs, &
243  ibuf)
244  !alpha and node_positions are normalized to [0,1]
245  !use numeric_constants
246  !use sll_m_cubic_non_uniform_splines
247  implicit none
248 
249  sll_real64, dimension(:), intent(inout) :: f
250  sll_real64, dimension(:), intent(in) :: node_positions
251  !type(sll_t_cubic_nonunif_spline_1d), pointer :: spl_per
252  sll_int32, intent(in):: n
253  sll_real64, intent(in)::alpha
254  sll_real64 :: dx
255  sll_int32 :: i
256  !sll_real64 :: M,tmp,tmp2
257  sll_real64, dimension(:), pointer :: buf, xstar, node_pos, coeffs
258  sll_int32, dimension(:), pointer :: ibuf
259 
260  dx = 1._f64/real(n, f64)
261 
262  !allocate(buf(10*N))
263  !allocate(ibuf(N))
264  !allocate(node_pos(-2:N+2),coeffs(-2:N+2))
265  !allocate(Xstar(1:N+1))
266  !print *,loc(buf)
267 
268  !print *,'#loc node_pos0=',loc(node_pos(0))
269 
270  !node_pos(0:N)=node_positions(1:N+1)
271 
272  !do i=1,N+1
273  ! print *,i,node_positions(i)
274  !enddo
275 
276  !do i=1,N+1
277  ! print *,i,Xstar(i),f(i)
278  !enddo
279 
280  !print *,dx
281 
282  do i = 1, n + 1
283  xstar(i) = node_positions(i) - alpha
284  end do
285 
286  do i = 1, n + 1
287  do while (xstar(i) .gt. 1._f64)
288  xstar(i) = xstar(i) - 1._f64
289  end do
290  do while (xstar(i) .lt. 0._f64)
291  xstar(i) = xstar(i) + 1._f64
292  end do
293  end do
294 
295  !from f compute the mean
296 ! do i=1,N
297 ! f(i)=f(i)*(node_positions(i+1)-node_positions(i))/dx
298 ! enddo
299 
300  !we compute the splines coefficients by solving the LU decomposition
301 ! M=0._f64
302 ! do i=1,N
303 ! M=M+f(i)
304 ! enddo
305 ! !M=M/real(N,rk)
306 ! do i=1,N
307 ! f(i)=f(i)-M*(node_positions(i+1)-node_positions(i))!/dx
308 ! enddo
309 ! tmp=f(1)
310 ! f(1)=0._f64
311 ! do i=2,N
312 ! tmp2=f(i)
313 ! f(i)=f(i-1)+tmp
314 ! tmp=tmp2
315 ! enddo
316 
317  !call sll_s_setup_spline_nonunif_1d_periodic_aux( node_pos, N, buf, ibuf)
318  call sll_s_compute_spline_nonunif_1d_periodic_aux2(f, n, buf, ibuf, coeffs)
319  call sll_s_interpolate_array_value_nonunif_aux(xstar, f, n, node_pos, coeffs, n)
320 
321  !4312190464 4312214392
322 
323 ! tmp=f(1)
324 ! do i=1,N-1
325 ! f(i)=f(i+1)-f(i)+M*(node_positions(i+1)-node_positions(i))
326 ! enddo
327 ! f(N)=tmp-f(N)+M*(node_positions(1)+1._f64-node_positions(N))
328 
329  !from mean compute f
330 ! do i=1,N
331 ! f(i)=f(i)*dx/(node_positions(i+1)-node_positions(i))
332 ! enddo
333 
334  f(n + 1) = f(1)
335 
336  !deallocate(buf)
337  !deallocate(ibuf)
338  !deallocate(node_pos,coeffs)
339  !deallocate(Xstar)
340 
342 
344  class(sll_t_advector_1d_non_uniform_cubic_splines), intent(inout) :: adv
345  sll_int32 :: ierr
346  sll_deallocate(adv%node_positions, ierr)
347  sll_deallocate(adv%buf, ierr)
348  sll_deallocate(adv%ibuf, ierr)
349  sll_deallocate(adv%node_pos, ierr)
350  sll_deallocate(adv%coeffs, ierr)
351  sll_deallocate(adv%Xstar, ierr)
353 
Abstract class for advection.
subroutine initialize_sll_t_advector_1d_non_uniform_cubic_splines(adv, num_cells, xmin, xmax, order, node_positions)
subroutine constant_advection_spl_non_unif_per(f, alpha, node_positions, N, buf, Xstar, node_pos, coeffs, ibuf)
type(sll_t_advector_1d_non_uniform_cubic_splines) function, pointer, public sll_f_new_advector_1d_non_uniform_cubic_splines(num_cells, xmin, xmax, order, node_positions)
Provides capabilities for data interpolation with cubic B-splines on non-uniform meshes.
subroutine, public sll_s_interpolate_array_value_nonunif_aux(a_in, a_out, n, node_pos, coeffs, n_cells)
subroutine, public sll_s_compute_spline_nonunif_1d_periodic_aux2(f, N, buf, ibuf, coeffs)
subroutine, public sll_s_setup_spline_nonunif_1d_periodic_aux(node_pos, N, buf, ibuf)
    Report Typos and Errors