Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_characteristics_1d_trapezoid_conservative.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 !http://en.wikipedia.org/wiki/Trapezoidal_rule_%28differential_equations%29
19 
23 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "sll_assert.h"
25 #include "sll_memory.h"
26 #include "sll_working_precision.h"
27 
29  sll_p_periodic, &
30  sll_p_set_to_limit, &
31  sll_p_user_defined
32 
38 
39  use sll_m_interpolators_1d_base, only: &
41 
42  implicit none
43 
44  public :: &
47 
48  private
49 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50 
52  sll_int32 :: npts
53  sll_real64 :: eta_min
54  sll_real64 :: eta_max
55  procedure(sll_i_signature_process_outside_point_1d), pointer, nopass :: &
56  process_outside_point
57  class(sll_c_interpolator_1d), pointer :: a_interp
58  sll_int32 :: maxiter
59  sll_real64 :: tol
60  sll_int32 :: bc_type
61  contains
62  procedure, pass(charac) :: init => &
64  procedure, pass(charac) :: compute_characteristics => &
67 
68 contains
70  Npts, &
71  A_interp, &
72  bc_type, &
73  eta_min, &
74  eta_max, &
75  process_outside_point, &
76  maxiter, &
77  tol) &
78  result(charac)
79 
80  type(sll_t_trapezoid_conservative_1d_charac), pointer :: charac
81  sll_int32, intent(in) :: npts
82  sll_int32, intent(in), optional :: bc_type
83  sll_real64, intent(in), optional :: eta_min
84  sll_real64, intent(in), optional :: eta_max
85  procedure(sll_i_signature_process_outside_point_1d), optional :: &
86  process_outside_point
87  class(sll_c_interpolator_1d), target :: a_interp
88  sll_int32, intent(in), optional :: maxiter
89  sll_real64, intent(in), optional :: tol
90  sll_int32 :: ierr
91 
92  sll_allocate(charac, ierr)
94  charac, &
95  npts, &
96  a_interp, &
97  bc_type, &
98  eta_min, &
99  eta_max, &
100  process_outside_point, &
101  maxiter, &
102  tol)
103 
106  charac, &
107  Npts, &
108  A_interp, &
109  bc_type, &
110  eta_min, &
111  eta_max, &
112  process_outside_point, &
113  maxiter, &
114  tol)
115 
117  sll_int32, intent(in) :: npts
118  sll_int32, intent(in), optional :: bc_type
119  sll_real64, intent(in), optional :: eta_min
120  sll_real64, intent(in), optional :: eta_max
121  procedure(sll_i_signature_process_outside_point_1d), optional :: &
122  process_outside_point
123  class(sll_c_interpolator_1d), target :: A_interp
124  sll_int32, intent(in), optional :: maxiter
125  sll_real64, intent(in), optional :: tol
126 
127  charac%Npts = npts
128 
129  if (present(eta_min)) then
130  charac%eta_min = eta_min
131  else
132  charac%eta_min = 0._f64
133  end if
134  if (present(eta_max)) then
135  charac%eta_max = eta_max
136  else
137  charac%eta_max = 1._f64
138  end if
139 
140  if (present(process_outside_point)) then
141  charac%process_outside_point => process_outside_point
142  charac%bc_type = sll_p_user_defined
143  else if (.not. (present(bc_type))) then
144  print *, '#provide boundary condition'
145  print *, '#bc_type or process_outside_point function'
146  print *, '#in initialize_trapezoid_conservative_1d_charac'
147  stop
148  else
149  charac%bc_type = bc_type
150  select case (bc_type)
151  case (sll_p_periodic)
152  charac%process_outside_point => sll_f_process_outside_point_periodic
153  case (sll_p_set_to_limit)
154  charac%process_outside_point => sll_f_process_outside_point_set_to_limit
155  case default
156  print *, '#bad value of boundary condition'
157  print *, '#in initialize_trapezoid_conservative_1d_charac'
158  stop
159  end select
160  end if
161 
162  if ((present(process_outside_point)) .and. (present(bc_type))) then
163  print *, '#provide either process_outside_point or bc_type'
164  print *, '#and not both'
165  print *, '#in initialize_trapezoid_conservative_1d_charac'
166  stop
167  end if
168 
169  charac%A_interp => a_interp
170 
171  if (present(maxiter)) then
172  charac%maxiter = maxiter
173  else
174  charac%maxiter = 1000
175  end if
176 
177  if (present(tol)) then
178  charac%tol = tol
179  else
180  charac%tol = 1.e-12_f64
181  end if
182 
184 
186  charac, &
187  A, &
188  dt, &
189  input, &
190  output)
191 
193  sll_real64, dimension(:), intent(in) :: a
194  sll_real64, intent(in) :: dt
195  sll_real64, dimension(:), intent(in) :: input
196  sll_real64, dimension(:), intent(out) :: output
197  sll_int32 :: j
198  sll_real64 :: x2
199  sll_real64 :: x2_old
200  sll_real64 :: x2_i !i for inside, so that interpolation is possible
201  sll_int32 :: iter
202  sll_int32 :: i
203  sll_int32 :: npts
204  sll_real64 :: eta_min
205  sll_real64 :: eta_max
206  sll_real64 :: output_min
207  sll_real64 :: output_max
208 
209  npts = charac%Npts
210  eta_min = charac%eta_min
211  eta_max = charac%eta_max
212 
213  sll_assert(size(a) >= npts)
214  sll_assert(size(input) >= npts)
215  sll_assert(size(output) >= npts)
216 
217  ! [YG: 8 Aug 2016]
218  ! Optional arguments 'eta_coords=input' and 'size_eta_coords=Npts'
219  ! not passed because:
220  ! 1. most interpolators do not implement such an option
221  ! 2. 'input' is (usually) the same mesh used to initialize the interpolator
222  call charac%A_interp%compute_interpolants(a)
223 ! call charac%A_interp%compute_interpolants( &
224 ! A, &
225 ! input, &
226 ! Npts)
227 
228  do j = 1, npts - 1
229  !We start from Y(t_{n+1})=y_j
230  !and look for Y(t_n) = Yn
231  !Yn = y_j-(A(y_j)+A(Yn))*dt/2
232  x2 = 0.5_f64*(input(j) + input(j + 1)) - dt*a(j)
233  x2_old = 0._f64
234  iter = 0
235  do while (iter < charac%maxiter .and. abs(x2_old - x2) > charac%tol)
236  x2_old = x2
237  x2_i = x2
238  if ((x2 <= eta_min) .or. (x2 >= eta_max)) then
239  x2_i = charac%process_outside_point(x2, eta_min, eta_max)
240  else
241  x2_i = x2
242  end if
243  x2 = 0.5_f64*(input(j) + input(j + 1)) &
244  - 0.5_f64*dt*(charac%A_interp%interpolate_from_interpolant_value(x2_i) + a(j))
245  end do
246  if (iter == charac%maxiter .and. abs(x2_old - x2) > charac%tol) then
247  print *, '#not enough iterations for compute_trapezoid_conservative_1d_charac', &
248  iter, abs(x2_old - x2)
249  stop
250  end if
251  !if((x2<=eta_min).or.(x2>=eta_max))then
252  ! x2 = charac%process_outside_point(x2,eta_min,eta_max)
253  !endif
254  output(j) = x2
255  end do
256 
257  select case (charac%bc_type)
258  case (sll_p_periodic)
259  output_min = output(npts - 1) - (eta_max - eta_min)
260  output_max = output(1) + (eta_max - eta_min)
261  case (sll_p_set_to_limit)
262  output_min = 2._f64*eta_min - output(1)
263  output_max = 2._f64*eta_max - output(npts - 1)
264  case default
265  print *, '#bad value for charac%bc_type'
266  stop
267  end select
268 
269  output(npts) = 0.5_f64*(output(npts - 1) + output_max)
270 
271  do i = npts - 1, 2, -1
272  output(i) = 0.5_f64*(output(i) + output(i - 1))
273  end do
274  output(1) = 0.5_f64*(output(1) + output_min)
275 
277 
Abstract class for characteristic derived type.
function, public sll_f_process_outside_point_set_to_limit(eta, eta_min, eta_max)
function, public sll_f_process_outside_point_periodic(eta, eta_min, eta_max)
subroutine initialize_trapezoid_conservative_1d_charac(charac, Npts, A_interp, bc_type, eta_min, eta_max, process_outside_point, maxiter, tol)
type(sll_t_trapezoid_conservative_1d_charac) function, pointer, public sll_f_new_trapezoid_conservative_1d_charac(Npts, A_interp, bc_type, eta_min, eta_max, process_outside_point, maxiter, tol)
Module for 1D interpolation and reconstruction.
Abstract class for 1D interpolation and reconstruction.
    Report Typos and Errors