Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_gaussian_2d_initializer.F90
Go to the documentation of this file.
1 
3 !--------------------------------------------
5 #include "sll_working_precision.h"
6 #include "sll_assert.h"
9  implicit none
10 
12  class(sll_coordinate_transformation_2d_base), pointer :: transf
13  sll_real64 :: xc, yc
14  sll_real64 :: sigma_x, sigma_y
15  contains
16  procedure, pass(init_obj) :: initialize => initialize_gaussian_2d
17  procedure, pass(init_obj) :: f_of_x1x2 => f_x1x2_gaussian_2d
18  end type init_gaussian_2d
19 
20 contains
21 
22  subroutine initialize_gaussian_2d(init_obj, transf, data_position, xc, yc, sigma_x, sigma_y)
23  class(init_gaussian_2d), intent(inout) :: init_obj
24  class(sll_coordinate_transformation_2d_base), target :: transf
25  sll_int32 :: data_position
26  sll_real64, intent(in), optional :: xc, yc, sigma_x, sigma_y
27  init_obj%data_position = data_position
28 
29  init_obj%transf => transf
30  if (present(xc)) then
31  init_obj%xc = xc
32  else
33  init_obj%xc = 0.0_f64 ! default center is 0
34  end if
35  if (present(yc)) then
36  init_obj%yc = yc
37  else
38  init_obj%yc = 0.0_f64 ! default center is 0
39  end if
40  if (present(sigma_x)) then
41  init_obj%sigma_x = sigma_x
42  else
43  init_obj%sigma_x = 1.0_f64 ! default radius is 1
44  end if
45  if (present(sigma_y)) then
46  init_obj%sigma_y = sigma_y
47  else
48  init_obj%sigma_y = 1.0_f64 ! default radius is 1
49  end if
50  end subroutine
51 
52  subroutine f_x1x2_gaussian_2d(init_obj, data_out)
53  class(init_gaussian_2d), intent(inout) :: init_obj
54  class(sll_coordinate_transformation_2d_base), pointer :: transf
55  sll_real64, dimension(:, :), intent(out) :: data_out
56  class(sll_t_cartesian_mesh_2d), pointer :: mesh
57  sll_int32 :: i
58  sll_int32 :: j
59  sll_int32 :: num_pts1
60  sll_int32 :: num_pts2
61  sll_real64 :: x
62  sll_real64 :: y
63  sll_real64 :: jac
64 
65  mesh => init_obj%transf%get_cartesian_mesh()
66 
67  if (init_obj%data_position == cell_centered_field) then
68  num_pts1 = mesh%num_cells1
69  num_pts2 = mesh%num_cells2
70  else if (init_obj%data_position == node_centered_field) then
71  num_pts1 = mesh%num_cells1 + 1
72  num_pts2 = mesh%num_cells2 + 1
73  else
74  print *, 'sll_m_gaussian_2d_initializer: Pb with data_position', init_obj%data_position
75  end if
76  sll_assert(size(data_out, 1) .ge. num_pts1)
77  sll_assert(size(data_out, 2) .ge. num_pts2)
78  if (init_obj%data_position == node_centered_field) then
79  do j = 1, num_pts2
80  do i = 1, num_pts1
81  y = transf%x2_at_node(i, j)
82  x = transf%x1_at_node(i, j)
83  data_out(i, j) = &
84  1.0_f64/(2*sll_p_pi*init_obj%sigma_x*init_obj%sigma_y)*exp(-0.5_f64*( &
85  (x - init_obj%xc)**2/init_obj%sigma_x**2 + &
86  (y - init_obj%yc)**2/init_obj%sigma_y**2))
87  end do
88  end do
89  else if (init_obj%data_position == cell_centered_field) then
90  ! jacobian times distribution function is stored
91  do j = 1, num_pts2
92  do i = 1, num_pts1
93  y = transf%x2_at_cell(i, j)
94  x = transf%x1_at_cell(i, j)
95  jac = transf%jacobian_at_cell(i, j)
96  data_out(i, j) = &
97  jac/(2*sll_p_pi*init_obj%sigma_x*init_obj%sigma_y)*exp(-0.5_f64*( &
98  (x - init_obj%xc)**2/init_obj%sigma_x**2 + &
99  (y - init_obj%yc)**2/init_obj%sigma_y**2))
100  end do
101  end do
102  end if
103  end subroutine
104 
Fortran module where set some physical and mathematical constants.
real(kind=f64), parameter, public sll_p_pi
Initializes a Gaussian of the form exp -((x-xc)**2/(2*sigma_x)**2 + (y-yc)**2/(2*sigma_y)**2)
subroutine f_x1x2_gaussian_2d(init_obj, data_out)
subroutine initialize_gaussian_2d(init_obj, transf, data_position, xc, yc, sigma_x, sigma_y)
    Report Typos and Errors