Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_advection_1d_ampere.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 
22 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23 #include "sll_errors.h"
24 #include "sll_memory.h"
25 #include "sll_working_precision.h"
26 
28 
29  use sll_m_constants, only: sll_p_pi
30 
31  use sll_m_fft, only: &
37  sll_t_fft
38 
39  implicit none
40 
41  public :: &
45 
46  private
47 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
48 
50 
51  sll_int32 :: nc_eta1
52  sll_real64 :: eta1_min
53  sll_real64 :: eta1_max
54  sll_real64 :: delta_eta1
55  sll_real64, dimension(:), pointer :: d_dx
56  sll_real64, dimension(:), pointer :: kx
57  type(sll_t_fft) :: fwx
58  type(sll_t_fft) :: bwx
59  sll_comp64, dimension(:), pointer :: fk
60  sll_comp64, dimension(:), pointer :: r0
61  sll_comp64, dimension(:), pointer :: r1
62  sll_comp64, dimension(:), pointer :: ek
63 
64  contains
65 
66  procedure, pass(adv) :: init => advector_1d_ampere_init
67  procedure, pass(adv) :: advect_1d
68  procedure, pass(adv) :: advect_1d_constant
69  procedure, pass(adv) :: delete
70 
72 
74  class(sll_t_advector_1d_ampere), pointer :: ptr
76 
77 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
78 contains
79 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
80 
81  function sll_f_new_advector_1d_ampere(nc_eta1, &
82  eta1_min, &
83  eta1_max) result(adv)
84 
85  type(sll_t_advector_1d_ampere), pointer :: adv
86 
87  sll_int32, intent(in) :: nc_eta1
88  sll_real64, intent(in) :: eta1_min
89  sll_real64, intent(in) :: eta1_max
90 
91  sll_int32 :: error
92 
93  sll_allocate(adv, error)
94 
95  call adv%init(nc_eta1, eta1_min, eta1_max)
96 
97  end function sll_f_new_advector_1d_ampere
98 
99  subroutine advector_1d_ampere_init(adv, nc_eta1, eta1_min, eta1_max)
100 
101  class(sll_t_advector_1d_ampere), intent(inout) :: adv
102  sll_int32, intent(in) :: nc_eta1
103  sll_real64, intent(in) :: eta1_min
104  sll_real64, intent(in) :: eta1_max
105 
106  sll_int32 :: i
107  sll_int32 :: error
108  sll_real64 :: kx0
109 
110  adv%eta1_min = eta1_min
111  adv%eta1_max = eta1_max
112  adv%nc_eta1 = nc_eta1
113  adv%delta_eta1 = (eta1_max - eta1_min)/real(nc_eta1, f64)
114 
115  sll_clear_allocate(adv%d_dx(1:nc_eta1), error)
116  sll_allocate(adv%fk(1:nc_eta1/2 + 1), error)
117  sll_allocate(adv%ek(1:nc_eta1/2 + 1), error)
118  sll_allocate(adv%r0(1:nc_eta1/2 + 1), error)
119  sll_allocate(adv%r1(1:nc_eta1/2 + 1), error)
120  adv%fk = (0.0_f64, 0.0_f64)
121  adv%ek = (0.0_f64, 0.0_f64)
122  adv%r0 = (0.0_f64, 0.0_f64)
123  adv%r1 = (0.0_f64, 0.0_f64)
124 
125  call sll_s_fft_init_r2c_1d(adv%fwx, nc_eta1, adv%d_dx, adv%fk)
126  call sll_s_fft_init_c2r_1d(adv%bwx, nc_eta1, adv%fk, adv%d_dx)
127 
128  sll_clear_allocate(adv%kx(1:nc_eta1/2 + 1), error)
129 
130  kx0 = 2._f64*sll_p_pi/(eta1_max - eta1_min)
131 
132  adv%kx(1) = 1.0_f64
133  do i = 2, nc_eta1/2 + 1
134  adv%kx(i) = real(i - 1, f64)*kx0
135  end do
136 
137  end subroutine advector_1d_ampere_init
138 
139  subroutine advect_1d(adv, a, dt, input, output)
140 
141  class(sll_t_advector_1d_ampere) :: adv
142  sll_real64, dimension(:), intent(in) :: a
143  sll_real64, intent(in) :: dt
144  sll_real64, dimension(:), intent(in) :: input
145  sll_real64, dimension(:), intent(out) :: output
146 
147  character(len=*), parameter :: this_sub_name = 'advect_1d'
148  sll_int32 :: num_cells
149 
150  num_cells = adv%nc_eta1
151  output(1:num_cells) = a(1:num_cells)*input(1:num_cells)*dt
152  sll_error(this_sub_name, "ampere advect_1d not implemented.")
153 
154  end subroutine advect_1d
155 
156  subroutine delete(adv)
157 
158  class(sll_t_advector_1d_ampere), intent(inout) :: adv
159 
160  call sll_s_fft_free(adv%fwx)
161  call sll_s_fft_free(adv%bwx)
162 
163  end subroutine delete
164 
165  subroutine advect_1d_constant(adv, a, dt, input, output)
166 
167  class(sll_t_advector_1d_ampere) :: adv
168  sll_real64, intent(in) :: a
169  sll_real64, intent(in) :: dt
170  sll_real64, dimension(:), intent(in) :: input
171  sll_real64, dimension(:), intent(out) :: output
172 
173  sll_int32 :: i, nc_x
174 
175  nc_x = adv%nc_eta1
176 
177  adv%d_dx = input(1:nc_x)
178  call sll_s_fft_exec_r2c_1d(adv%fwx, adv%d_dx, adv%fk)
179  do i = 2, nc_x/2 + 1
180  adv%fk(i) = adv%fk(i)*cmplx(cos(adv%kx(i)*a*dt), -sin(adv%kx(i)*a*dt), kind=f64)
181  end do
182  call sll_s_fft_exec_c2r_1d(adv%bwx, adv%fk, adv%d_dx)
183 
184  output(1:nc_x) = adv%d_dx/real(nc_x, f64)
185  output(nc_x + 1) = output(1)
186 
187  end subroutine advect_1d_constant
188 
189 end module sll_m_advection_1d_ampere
190 
subroutine advect_1d(adv, a, dt, input, output)
subroutine advector_1d_ampere_init(adv, nc_eta1, eta1_min, eta1_max)
type(sll_t_advector_1d_ampere) function, pointer, public sll_f_new_advector_1d_ampere(nc_eta1, eta1_min, eta1_max)
subroutine advect_1d_constant(adv, a, dt, input, output)
Abstract class for advection.
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
FFT interface for FFTW.
subroutine, public sll_s_fft_exec_r2c_1d(plan, array_in, array_out)
Compute fast Fourier transform in real to complex mode.
subroutine, public sll_s_fft_free(plan)
Delete a plan.
subroutine, public sll_s_fft_init_r2c_1d(plan, nx, array_in, array_out, normalized, aligned, optimization)
Create new 1d real to complex plan for forward FFT.
subroutine, public sll_s_fft_exec_c2r_1d(plan, array_in, array_out)
Compute fast Fourier transform in complex to real mode.
subroutine, public sll_s_fft_init_c2r_1d(plan, nx, array_in, array_out, normalized, aligned, optimization)
Create new 1d complex to real plan for backward FFT.
Type for FFT plan in SeLaLib.
    Report Typos and Errors