Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_dk_curv_mesh.F90
Go to the documentation of this file.
1 ! Copyright INRIA
2 ! Authors :
3 ! CALVI project team
4 !
5 ! This code SeLaLib (for Semi-Lagrangian-Library)
6 ! is a parallel library for simulating the plasma turbulence
7 ! in a tokamak.
8 !
9 ! This software is governed by the CeCILL-B license
10 ! under French law and abiding by the rules of distribution
11 ! of free software. You can use, modify and redistribute
12 ! the software under the terms of the CeCILL-B license as
13 ! circulated by CEA, CNRS and INRIA at the following URL
14 ! "http://www.cecill.info".
15 !**************************************************************
24 
26 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27 #include "sll_errors.h"
28 #include "sll_memory.h"
29 #include "sll_working_precision.h"
30 
31  use sll_m_cartesian_meshes, only: &
36 
56 
59 
62 
63  use sll_m_utilities, only: &
65 
66  implicit none
67 
68  public :: &
70 
71  private
72 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
73 
74 contains
75  !----------------------------------------------------------------------------
77  function compute_num_params_mesh(mesh_case) result(res)
78  character(len=*), intent(in) :: mesh_case
79  sll_int32 :: res
80  character(len=256) :: err_msg
81 
82  select case (mesh_case)
83  case ("SLL_POLAR_MESH")
84  res = 1
85  case ("SLL_POLAR_SHEAR_MESH")
86  res = 4
87  case ("SLL_D_SHAPED_MESH")
88  res = 9
89  case default
90  err_msg = 'bad mesh_case: '//trim(mesh_case)
91  sll_error('compute_num_params_mesh', trim(err_msg))
92  end select
93 
94  end function compute_num_params_mesh
95 
96  !----------------------------------------------------------------------------
98 
99  subroutine compute_params_mesh( &
100  mesh_case, &
101  eta1_min, &
102  eta1_max, &
103  eta2_min, &
104  eta2_max, &
105  mesh_alpha, &
106  params_mesh, &
107  num_params_mesh)
108  character(len=*), intent(in) :: mesh_case
109  sll_real64, intent(in) :: eta1_min
110  sll_real64, intent(in) :: eta1_max
111  sll_real64, intent(in) :: eta2_min
112  sll_real64, intent(in) :: eta2_max
113  sll_real64, intent(in) :: mesh_alpha(:)
114  sll_real64, intent(out) :: params_mesh(:)
115  sll_int32, intent(in) :: num_params_mesh
116 
117  character(len=256) :: err_msg
118 
119  if (size(params_mesh) < num_params_mesh) then
120  err_msg = 'bad size for params_mesh: '
121  sll_error('compute_params_mesh', trim(err_msg))
122  end if
123 
124  params_mesh(1:num_params_mesh) = 0._f64
125 
126  select case (mesh_case)
127  case ("SLL_POLAR_MESH")
128  case ("SLL_POLAR_SHEAR_MESH")
129  params_mesh(1) = mesh_alpha(1)
130  params_mesh(2) = mesh_alpha(2)
131  case ("SLL_D_SHAPED_MESH")
132  params_mesh(1:5) = mesh_alpha(1:5)
133  params_mesh(6) = eta1_min
134  params_mesh(7) = eta1_max
135  params_mesh(8) = eta2_min
136  params_mesh(9) = eta2_max
137  case default
138  err_msg = 'bad mesh_case: '//trim(mesh_case)
139  sll_error('compute_params_mesh', trim(err_msg))
140  end select
141 
142  end subroutine compute_params_mesh
143 
144  !----------------------------------------------------------------------------
146 
147  subroutine select_transformation( &
148  mesh_case, &
149  mesh_2d, &
150  params_mesh, &
151  num_params_mesh, &
152  transformation)
153  character(len=*), intent(in) :: mesh_case
154  type(sll_t_cartesian_mesh_2d), pointer :: mesh_2d
155  sll_real64, intent(out) :: params_mesh(:)
156  sll_int32, intent(in) :: num_params_mesh
157  class(sll_c_coordinate_transformation_2d_base), pointer :: transformation
158 
159  character(len=256) :: err_msg
160 
161  if (size(params_mesh) < num_params_mesh) then
162  err_msg = 'bad size for params_mesh: '
163  sll_error('select_transformation', trim(err_msg))
164  end if
165 
166  select case (mesh_case)
167  case ("SLL_POLAR_MESH")
169  "analytic_polar_transformation", &
170  mesh_2d, &
171  sll_f_polar_x1, &
172  sll_f_polar_x2, &
177  params_mesh)
178  case ("SLL_POLAR_SHEAR_MESH")
180  "analytic_polar_shear_transformation", &
181  mesh_2d, &
188  params_mesh)
189  case ("SLL_D_SHAPED_MESH")
191  "analytic_D_SHAPED_transformation", &
192  mesh_2d, &
199  params_mesh)
200  case default
201  err_msg = 'bad mesh_case: '//trim(mesh_case)
202  sll_error('select_transformation', trim(err_msg))
203  end select
204 
205  end subroutine select_transformation
206 
207  !----------------------------------------------------------------------------
210  filename, &
211  m_x1x2, &
212  m_x3, &
213  m_x4, &
214  transformation, &
215  proc_id)
216  character(len=*), intent(in) :: filename
217  type(sll_t_cartesian_mesh_2d), pointer :: m_x1x2
218  type(sll_t_cartesian_mesh_1d), pointer :: m_x3
219  type(sll_t_cartesian_mesh_1d), pointer :: m_x4
220  class(sll_c_coordinate_transformation_2d_base), pointer :: transformation
221  sll_int32, intent(in) :: proc_id
222 
223  !--> mesh
224  character(len=256) :: mesh_case
225  sll_int32 :: num_cells_eta1
226  sll_int32 :: num_cells_eta2
227  sll_real64 :: eta1_min
228  sll_real64 :: eta1_max
229  sll_real64 :: eta2_min
230  sll_real64 :: eta2_max
231  sll_real64 :: mesh_alpha1
232  sll_real64 :: mesh_alpha2
233  sll_real64 :: mesh_alpha3
234  sll_real64 :: mesh_alpha4
235  sll_real64 :: mesh_alpha5
236  sll_real64 :: mesh_alpha6
237  sll_int32 :: num_cells_x3
238  sll_int32 :: num_cells_x4
239  sll_real64 :: z_min
240  sll_real64 :: z_max
241  sll_real64 :: v_min
242  sll_real64 :: v_max
243 
244  !--> local variables
245  sll_int32 :: namelist_id
246  sll_int32 :: ierr
247  sll_int32 :: io_stat
248  character(len=256) :: err_msg
249  sll_real64, allocatable :: params_mesh(:)
250  sll_int32 :: num_params_mesh
251  sll_real64 :: mesh_alpha(6)
252 
253  namelist /mesh/ &
254  mesh_case, &
255  num_cells_eta1, &
256  num_cells_eta2, &
257  eta1_min, &
258  eta1_max, &
259  eta2_min, &
260  eta2_max, &
261  mesh_alpha1, &
262  mesh_alpha2, &
263  mesh_alpha3, &
264  mesh_alpha4, &
265  mesh_alpha5, &
266  mesh_alpha6, &
267  num_cells_x3, &
268  num_cells_x4, &
269  z_min, &
270  z_max, &
271  v_min, &
272  v_max
273 
275 
276  mesh_case = "SLL_POLAR_MESH"
277  num_cells_eta1 = 32
278  num_cells_eta2 = 64
279  eta1_min = 0.1_f64
280  eta1_max = 14.5_f64
281  eta2_min = 0._f64
282  eta2_max = 6.283185307179586477_f64
283  mesh_alpha1 = 0._f64
284  mesh_alpha2 = 0._f64
285  mesh_alpha3 = 0._f64
286  mesh_alpha4 = 0._f64
287  mesh_alpha5 = 0._f64
288  mesh_alpha6 = 0._f64
289  num_cells_x3 = 32
290  num_cells_x4 = 64
291  z_min = 0.0_f64
292  z_max = 1506.759067_f64
293  v_min = -7.32_f64
294  v_max = 7.32_f64
295 
296  call sll_s_new_file_id(namelist_id, ierr)
297  open (unit=namelist_id, file=trim(filename)//'.nml', iostat=io_stat)
298  if (io_stat /= 0) then
299  err_msg = 'failed to open file '//trim(filename)//'.nml'
300  sll_error('sll_s_init_dk_curv_mesh', trim(err_msg))
301  end if
302  read (namelist_id, mesh)
303 
304  if (proc_id == 0) then
305  print *, '#Mesh:'
306  print *, '#mesh_case=', trim(mesh_case)
307  print *, '#num_cells_eta1=', num_cells_eta1
308  print *, '#num_cells_eta2=', num_cells_eta2
309  print *, '#eta1_min=', eta1_min
310  print *, '#eta1_max=', eta1_max
311  print *, '#eta2_min=', eta2_min
312  print *, '#eta2_max=', eta2_max
313  print *, '#mesh_alpha1=', mesh_alpha1
314  print *, '#mesh_alpha2=', mesh_alpha2
315  print *, '#mesh_alpha3=', mesh_alpha3
316  print *, '#mesh_alpha4=', mesh_alpha4
317  print *, '#mesh_alpha5=', mesh_alpha5
318  print *, '#mesh_alpha6=', mesh_alpha6
319  print *, '#num_cells_x3=', num_cells_x3
320  print *, '#num_cells_x4=', num_cells_x4
321  print *, '#z_min=', z_min
322  print *, '#z_max=', z_max
323  print *, '#v_min=', v_min
324  print *, '#v_max=', v_max
325  end if
326 
327  m_x1x2 => sll_f_new_cartesian_mesh_2d( &
328  num_cells_eta1, &
329  num_cells_eta2, &
330  eta1_min, &
331  eta1_max, &
332  eta2_min, &
333  eta2_max)
334  m_x3 => sll_f_new_cartesian_mesh_1d(num_cells_x3, eta_min=z_min, eta_max=z_max)
335  m_x4 => sll_f_new_cartesian_mesh_1d(num_cells_x4, eta_min=v_min, eta_max=v_max)
336 
337  num_params_mesh = compute_num_params_mesh(mesh_case)
338  sll_allocate(params_mesh(num_params_mesh), ierr)
339  mesh_alpha(1:3) = (/mesh_alpha1, mesh_alpha2, mesh_alpha3/)
340  mesh_alpha(4:6) = (/mesh_alpha4, mesh_alpha5, mesh_alpha6/)
341 
342  call compute_params_mesh( &
343  mesh_case, &
344  eta1_min, &
345  eta1_max, &
346  eta2_min, &
347  eta2_max, &
348  mesh_alpha, &
349  params_mesh, &
350  num_params_mesh)
351 
352  call select_transformation( &
353  mesh_case, &
354  m_x1x2, &
355  params_mesh, &
356  num_params_mesh, &
357  transformation)
358 
359  end subroutine sll_s_init_dk_curv_mesh
360 
361 end module sll_m_dk_curv_mesh
Cartesian mesh basic types.
type(sll_t_cartesian_mesh_2d) function, pointer, public sll_f_new_cartesian_mesh_2d(num_cells1, num_cells2, eta1_min, eta1_max, eta2_min, eta2_max)
allocates the memory space for a new 2D cartesian mesh on the heap, initializes it with the given arg...
type(sll_t_cartesian_mesh_1d) function, pointer, public sll_f_new_cartesian_mesh_1d(num_cells, eta_min, eta_max)
allocates the memory space for a new 1D cartesian mesh on the heap, initializes it with the given arg...
Functions for analytic coordinate transformations.
function, public sll_f_polar_shear_jac12(eta1, eta2, params)
jacobian matrix
function, public sll_f_sharped_geo_x2(eta1, eta2, params)
direct mapping
function, public sll_f_sharped_geo_x1(eta1, eta2, params)
direct mapping
function, public sll_f_polar_jac12(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_shear_jac11(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_jac11(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_shear_x2(eta1, eta2, params)
direct mapping
function, public sll_f_polar_x1(eta1, eta2, params)
direct mapping
function, public sll_f_sharped_geo_jac12(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_x2(eta1, eta2, params)
direct mapping
function, public sll_f_polar_shear_x1(eta1, eta2, params)
direct mapping
function, public sll_f_polar_jac21(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_shear_jac22(eta1, eta2, params)
jacobian matrix
function, public sll_f_sharped_geo_jac22(eta1, eta2, params)
jacobian matrix
function, public sll_f_sharped_geo_jac11(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_jac22(eta1, eta2, params)
jacobian matrix
function, public sll_f_sharped_geo_jac21(eta1, eta2, params)
jacobian matrix
function, public sll_f_polar_shear_jac21(eta1, eta2, params)
jacobian matrix
Abstract class for coordinate transformations.
type(sll_t_coordinate_transformation_2d_analytic) function, pointer, public sll_f_new_coordinate_transformation_2d_analytic(label, mesh_2d, x1_func, x2_func, j11_func, j12_func, j21_func, j22_func, params)
Create the analytic coordinate transformation.
initialization from dk_curv_mesh namelist this module is then used in sl_dk_3d1v_curv_field_aligned w...
subroutine, public sll_s_init_dk_curv_mesh(filename, m_x1x2, m_x3, m_x4, transformation, proc_id)
Initialize simulation from input file.
subroutine select_transformation(mesh_case, mesh_2d, params_mesh, num_params_mesh, transformation)
select transformation
subroutine compute_params_mesh(mesh_case, eta1_min, eta1_max, eta2_min, eta2_max, mesh_alpha, params_mesh, num_params_mesh)
compute params_mesh
integer(kind=i32) function compute_num_params_mesh(mesh_case)
compute num_params_mesh
Some common numerical utilities.
subroutine, public sll_s_new_file_id(file_id, error)
Get a file unit number free before creating a file.
    Report Typos and Errors