Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_derivative_2d_oblic.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 ! in development
19 ! compute lim_{h->0} (phi(x1+A1h,x2+A2h)-phi(x1,x2))/h
20 ! we explore here the spaghetti to compute this derivative
21 
23 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24 #include "sll_memory.h"
25 #include "sll_working_precision.h"
26 
27  use sll_m_advection_1d_base, only: &
29 
30  use sll_m_fcisl, only: &
32 
33  implicit none
34 
35  public :: &
39 
40  private
41 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42 
44  sll_int32 :: nc_x1
45  class(sll_c_advector_1d), pointer :: adv_x1
46  sll_int32 :: nc_x2
47  sll_real64 :: x2_min
48  sll_real64 :: x2_max
49  sll_int32 :: stencil_r
50  sll_int32 :: stencil_s
51  sll_real64, dimension(:), pointer :: weights
52  sll_real64, dimension(:, :), pointer :: buf
53 
55 
56 contains
57 
59  Nc_x1, &
60  adv_x1, &
61  Nc_x2, &
62  x2_min, &
63  x2_max, &
64  stencil_r, &
65  stencil_s) &
66  result(deriv)
67  type(sll_t_oblic_2d_derivative), pointer :: deriv
68  sll_int32, intent(in) :: nc_x1
69  class(sll_c_advector_1d), pointer :: adv_x1
70  sll_int32, intent(in) :: nc_x2
71  sll_real64, intent(in) :: x2_min
72  sll_real64, intent(in) :: x2_max
73  sll_int32, intent(in) :: stencil_r
74  sll_int32, intent(in) :: stencil_s
75  !local variables
76  sll_int32 :: ierr
77  sll_allocate(deriv, ierr)
78 
80  deriv, &
81  nc_x1, &
82  adv_x1, &
83  nc_x2, &
84  x2_min, &
85  x2_max, &
86  stencil_r, &
87  stencil_s)
88 
90 
92  deriv, &
93  Nc_x1, &
94  adv_x1, &
95  Nc_x2, &
96  x2_min, &
97  x2_max, &
98  stencil_r, &
99  stencil_s)
100  type(sll_t_oblic_2d_derivative), intent(inout) :: deriv
101  sll_int32, intent(in) :: nc_x1
102  class(sll_c_advector_1d), pointer :: adv_x1
103  sll_int32, intent(in) :: nc_x2
104  sll_real64, intent(in) :: x2_min
105  sll_real64, intent(in) :: x2_max
106  sll_int32, intent(in) :: stencil_r
107  sll_int32, intent(in) :: stencil_s
108  !local variables
109  sll_int32 :: ierr
110  sll_int32 :: r
111  sll_int32 :: s
112 
113  deriv%Nc_x1 = nc_x1
114  deriv%adv_x1 => adv_x1
115  deriv%Nc_x2 = nc_x2
116  deriv%x2_min = x2_min
117  deriv%x2_max = x2_max
118  deriv%stencil_r = stencil_r
119  deriv%stencil_s = stencil_s
120  r = stencil_r
121  s = stencil_s
122 
123  sll_allocate(deriv%weights(r:s), ierr)
124  sll_allocate(deriv%buf(r:s, nc_x1 + 1), ierr)
125 
126  call sll_s_compute_w_hermite(deriv%weights(r:s), r, s)
127 
128  end subroutine initialize_oblic_2d_derivative
129 
130 
135  deriv, &
136  A1, &
137  A2, &
138  input, &
139  output)
140  type(sll_t_oblic_2d_derivative), pointer :: deriv
141  sll_real64, intent(in) :: a1
142  sll_real64, intent(in) :: a2
143  sll_real64, dimension(:, :), intent(in) :: input
144  sll_real64, dimension(:, :), intent(out) :: output
145  !local variables
146  sll_int32 :: i2
147  sll_int32 :: ell
148  sll_int32 :: i2_loc
149  sll_real64, dimension(:, :), pointer :: buf
150  sll_real64, dimension(:), pointer :: w
151  class(sll_c_advector_1d), pointer :: adv_x1
152  sll_int32 :: r
153  sll_int32 :: s
154  sll_real64 :: delta_x2
155  sll_real64 :: dt_loc
156  sll_int32 :: nc_x1
157  sll_int32 :: nc_x2
158  sll_real64 :: length
159  sll_int32 :: i1
160  !sll_int32 :: ind
161  sll_real64 :: tmp
162 
163  nc_x1 = deriv%Nc_x1
164  nc_x2 = deriv%Nc_x2
165  length = (deriv%x2_max - deriv%x2_min)
166  delta_x2 = length/real(nc_x2, f64)
167 
168  buf => deriv%buf
169  w => deriv%weights
170  adv_x1 => deriv%adv_x1
171  r = deriv%stencil_r
172  s = deriv%stencil_s
173 
174  do i2 = 1, nc_x2 + 1
175  !choose several dt_loc so that advection in x2 is exact
176  do ell = r, s
177  dt_loc = -real(ell, f64)*delta_x2/a2
178  i2_loc = modulo(i2 + ell - 1, nc_x2) + 1
179  call adv_x1%advect_1d_constant( &
180  a1, &
181  dt_loc, &
182  input(1:nc_x1 + 1, i2_loc), &
183  buf(ell, 1:nc_x1 + 1))
184  end do
185  !compute the derivative using these values
186  do i1 = 1, nc_x1 + 1
187  tmp = 0._f64
188  do ell = r, s
189  tmp = tmp + w(ell)*buf(ell, i1)
190  end do
191  output(i1, i2) = tmp*a2/delta_x2
192  end do
193  end do
194 
195  end subroutine sll_s_compute_oblic_derivative_2d
196 
197 end module sll_m_derivative_2d_oblic
Abstract class for advection.
subroutine, public sll_s_compute_oblic_derivative_2d(deriv, A1, A2, input, output)
type(sll_t_oblic_2d_derivative) function, pointer, public sll_f_new_oblic_2d_derivative(Nc_x1, adv_x1, Nc_x2, x2_min, x2_max, stencil_r, stencil_s)
subroutine initialize_oblic_2d_derivative(deriv, Nc_x1, adv_x1, Nc_x2, x2_min, x2_max, stencil_r, stencil_s)
subroutine, public sll_s_compute_w_hermite(w, r, s)
    Report Typos and Errors