Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_nml_mesh_1d_two_grid_cart.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 !**************************************************************
79 
87 
88 !-----------------------------------------------------------------
89 ! SPECIFIC DOCUMENTATION (BEGIN)
90 !-----------------------------------------------------------------
91 
123 
124 !-----------------------------------------------------------------
125 ! SPECIFIC DOCUMENTATION (END)
126 !-----------------------------------------------------------------
127 
129 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130 #include "sll_errors.h"
131 #include "sll_memory.h"
132 #include "sll_working_precision.h"
133 
134  use sll_m_utilities, only: &
138 
139  implicit none
140 
141  public :: &
143 
144  private
145 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
146 
148  sll_int32 :: num_cells
149  sll_real64 :: eta_min
150  sll_real64 :: eta_max
151  sll_real64 :: eta_in_min
152  sll_real64 :: eta_in_max
153  sll_real64 :: density_out_min
154  sll_real64 :: density_in
155  sll_real64 :: density_out_max
156  character(len=256) :: label
157  contains
158  procedure, pass(self) :: init => init_nml_mesh_1d_two_grid_cart
159  procedure, pass(self) :: init_1 => init_nml_mesh_1d_two_grid_cart_1
160  procedure, pass(self) :: init_2 => init_nml_mesh_1d_two_grid_cart_2
161  procedure, pass(self) :: init_3 => init_nml_mesh_1d_two_grid_cart_3
162  procedure, pass(self) :: init_4 => init_nml_mesh_1d_two_grid_cart_4
163  procedure, pass(self) :: init_clone => init_clone_nml_mesh_1d_two_grid_cart
165 
166  !-----------------------------------------------------------------
167  ! SPECIFIC DECLARATION (BEGIN)
168  !-----------------------------------------------------------------
169 
171  module procedure &
174  end interface sll_o_nml_mesh_1d_two_grid_cart
175 
176  !-----------------------------------------------------------------
177  ! SPECIFIC DECLARATION (END)
178  !-----------------------------------------------------------------
179 
180 contains
181 
182  !-----------------------------------------------------------------
183  ! SPECIFIC SUBROUTINES (BEGIN)
184  !-----------------------------------------------------------------
185 
188  filename, &
189  array, &
190  clone, &
191  proc_id)
192  character(len=*), intent(in) :: filename
193  sll_real64, pointer, intent(out) :: array(:)
194  character(len=*), intent(in), optional :: clone
195  sll_int32, intent(in), optional :: proc_id
196 
197  type(sll_t_nml_mesh_1d_two_grid_cart) :: self
198  sll_int32 :: ierr
199  !sll_int32 :: i
200  sll_int32 :: num_cells
201  sll_real64 :: eta_min
202  sll_real64 :: eta_max
203  sll_real64 :: bloc_coord(2)
204  sll_int32 :: bloc_index(3)
205 
206  if (present(clone)) then
207  call self%init_clone(clone, filename, proc_id)
208  else
209  call self%init(filename, proc_id)
210  end if
211 
212  num_cells = self%num_cells
213  eta_min = self%eta_min
214  eta_max = self%eta_max
215  sll_allocate(array(num_cells + 1), ierr)
216  bloc_coord(1) = (self%eta_in_max - self%eta_in_min)/(eta_max - eta_min)
217  bloc_coord(2) = (self%eta_in_max - self%eta_in_min)/(eta_max - eta_min)
218  bloc_index(1) = floor(self%density_out_min)
219  bloc_index(2) = floor(self%density_in)
220  bloc_index(3) = floor(self%density_out_max)
221 
222  call sll_s_compute_bloc(bloc_coord, bloc_index, num_cells)
223  call sll_s_compute_mesh_from_bloc(bloc_coord, bloc_index, array)
224  array = eta_min + array*(eta_max - eta_min)
225 
226  end subroutine s_nml_mesh_1d_two_grid_cart_array
227 
228  !-----------------------------------------------------------------
229  ! SPECIFIC SUBROUTINES (END)
230  !-----------------------------------------------------------------
231 
234  filename, &
235  clone, &
236  proc_id)
237  character(len=*), intent(in) :: filename
238  character(len=*), intent(in), optional :: clone
239  sll_int32, intent(in), optional :: proc_id
240 
241  type(sll_t_nml_mesh_1d_two_grid_cart) :: self
242  sll_int32 :: proc_id_loc
243 
244  if (present(clone)) then
245  call self%init_clone(clone, filename, proc_id)
246  else
247  call self%init(filename, proc_id)
248  end if
249 
250  if (present(proc_id)) then
251  proc_id_loc = proc_id
252  else
253  proc_id_loc = 0
254  end if
255 
256  if (proc_id_loc == 0) then
257  print *, '#nml_mesh_1d_two_grid_cart:'
258 
259  print *, '#label=', trim(self%label)
260  print *, '#num_cells=', self%num_cells
261  print *, '#eta_min=', self%eta_min
262  print *, '#eta_max=', self%eta_max
263  print *, '#eta_in_min=', self%eta_in_min
264  print *, '#eta_in_max=', self%eta_in_max
265  print *, '#density_out_min=', self%density_out_min
266  print *, '#density_in=', self%density_in
267  print *, '#density_out_max=', self%density_out_max
268  end if
269 
270  end subroutine s_nml_mesh_1d_two_grid_cart_print
271 
272 #ifndef DOXYGEN_SHOULD_SKIP_THIS
273 
274  subroutine init_clone_nml_mesh_1d_two_grid_cart( &
275  self, &
276  clone, &
277  filename, &
278  proc_id)
279  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
280  character(len=*), intent(in) :: clone
281  character(len=*), intent(in) :: filename
282  sll_int32, intent(in), optional :: proc_id
283 
284  character(len=256) :: err_msg
285  character(len=256) :: caller
286 
287  caller = 'init_clone_nml_mesh_1d_two_grid_cart'
288  select case (clone)
289  case ("_1")
290  call self%init_1(filename, proc_id)
291  case ("_2")
292  call self%init_2(filename, proc_id)
293  case ("_3")
294  call self%init_3(filename, proc_id)
295  case ("_4")
296  call self%init_4(filename, proc_id)
297  case default
298  err_msg = 'bad value for clone'
299  sll_error(trim(caller), trim(err_msg))
300  end select
301 
302  end subroutine init_clone_nml_mesh_1d_two_grid_cart
303 
304  subroutine init_nml_mesh_1d_two_grid_cart( &
305  self, &
306  filename, &
307  proc_id)
308  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
309  character(len=*), intent(in) :: filename
310  sll_int32, intent(in), optional :: proc_id
311 
312  sll_int32 :: namelist_id
313  sll_int32 :: ierr
314  sll_int32 :: io_stat
315  character(len=256) :: err_msg
316  character(len=256) :: caller
317  sll_int32 :: num_cells
318  sll_real64 :: eta_min
319  sll_real64 :: eta_max
320  sll_real64 :: eta_in_min
321  sll_real64 :: eta_in_max
322  sll_real64 :: density_out_min
323  sll_real64 :: density_in
324  sll_real64 :: density_out_max
325  sll_int32 :: proc_id_loc
326 
327  namelist /mesh_1d_two_grid_cart/ &
328  num_cells, &
329  eta_min, &
330  eta_max, &
331  eta_in_min, &
332  eta_in_max, &
333  density_out_min, &
334  density_in, &
335  density_out_max
336  caller = 'init_nml_mesh_1d_two_grid_cart'
337  if (present(proc_id)) then
338  proc_id_loc = proc_id
339  else
340  proc_id_loc = 0
341  end if
342 
343  call set_default_values( &
344  num_cells, &
345  eta_min, &
346  eta_max, &
347  eta_in_min, &
348  eta_in_max, &
349  density_out_min, &
350  density_in, &
351  density_out_max)
352 
353  call sll_s_new_file_id(namelist_id, ierr)
354  open ( &
355  unit=namelist_id, &
356  file=trim(filename)//'.nml', &
357  iostat=io_stat)
358  if (io_stat /= 0) then
359  err_msg = &
360  'failed to open first file '//trim(filename)//'.nml'
361  sll_error(trim(caller), trim(err_msg))
362  end if
363 
364  read (namelist_id, mesh_1d_two_grid_cart)
365  self%label = "no_label"
366  self%num_cells = num_cells
367  self%eta_min = eta_min
368  self%eta_max = eta_max
369  self%eta_in_min = eta_in_min
370  self%eta_in_max = eta_in_max
371  self%density_out_min = density_out_min
372  self%density_in = density_in
373  self%density_out_max = density_out_max
374  close (namelist_id)
375 
376  end subroutine init_nml_mesh_1d_two_grid_cart
377 
378  subroutine init_nml_mesh_1d_two_grid_cart_1( &
379  self, &
380  filename, &
381  proc_id)
382  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
383  character(len=*), intent(in) :: filename
384  sll_int32, intent(in), optional :: proc_id
385 
386  sll_int32 :: namelist_id
387  sll_int32 :: ierr
388  sll_int32 :: io_stat
389  character(len=256) :: err_msg
390  character(len=256) :: caller
391  sll_int32 :: num_cells_1
392  sll_real64 :: eta_min_1
393  sll_real64 :: eta_max_1
394  sll_real64 :: eta_in_min_1
395  sll_real64 :: eta_in_max_1
396  sll_real64 :: density_out_min_1
397  sll_real64 :: density_in_1
398  sll_real64 :: density_out_max_1
399  sll_int32 :: proc_id_loc
400 
401  namelist /mesh_1d_two_grid_cart_1/ &
402  num_cells_1, &
403  eta_min_1, &
404  eta_max_1, &
405  eta_in_min_1, &
406  eta_in_max_1, &
407  density_out_min_1, &
408  density_in_1, &
409  density_out_max_1
410 
411  caller = 'init_nml_mesh_1d_two_grid_cart_1'
412  if (present(proc_id)) then
413  proc_id_loc = proc_id
414  else
415  proc_id_loc = 0
416  end if
417 
418  call set_default_values( &
419  num_cells_1, &
420  eta_min_1, &
421  eta_max_1, &
422  eta_in_min_1, &
423  eta_in_max_1, &
424  density_out_min_1, &
425  density_in_1, &
426  density_out_max_1)
427 
428  call sll_s_new_file_id(namelist_id, ierr)
429  open ( &
430  unit=namelist_id, &
431  file=trim(filename)//'.nml', &
432  iostat=io_stat)
433  if (io_stat /= 0) then
434  err_msg = &
435  'failed to open first file '//trim(filename)//'.nml'
436  sll_error(trim(caller), trim(err_msg))
437  end if
438 
439  read (namelist_id, mesh_1d_two_grid_cart_1)
440  self%label = "_1"
441  self%num_cells = num_cells_1
442  self%eta_min = eta_min_1
443  self%eta_max = eta_max_1
444  self%eta_in_min = eta_in_min_1
445  self%eta_in_max = eta_in_max_1
446  self%density_out_min = density_out_min_1
447  self%density_in = density_in_1
448  self%density_out_max = density_out_max_1
449  close (namelist_id)
450 
451  end subroutine init_nml_mesh_1d_two_grid_cart_1
452 
453  subroutine init_nml_mesh_1d_two_grid_cart_2( &
454  self, &
455  filename, &
456  proc_id)
457  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
458  character(len=*), intent(in) :: filename
459  sll_int32, intent(in), optional :: proc_id
460 
461  sll_int32 :: namelist_id
462  sll_int32 :: ierr
463  sll_int32 :: io_stat
464  character(len=256) :: err_msg
465  character(len=256) :: caller
466  sll_int32 :: num_cells_2
467  sll_real64 :: eta_min_2
468  sll_real64 :: eta_max_2
469  sll_real64 :: eta_in_min_2
470  sll_real64 :: eta_in_max_2
471  sll_real64 :: density_out_min_2
472  sll_real64 :: density_in_2
473  sll_real64 :: density_out_max_2
474  sll_int32 :: proc_id_loc
475 
476  namelist /mesh_1d_two_grid_cart_2/ &
477  num_cells_2, &
478  eta_min_2, &
479  eta_max_2, &
480  eta_in_min_2, &
481  eta_in_max_2, &
482  density_out_min_2, &
483  density_in_2, &
484  density_out_max_2
485 
486  caller = 'init_nml_mesh_1d_two_grid_cart_2'
487  if (present(proc_id)) then
488  proc_id_loc = proc_id
489  else
490  proc_id_loc = 0
491  end if
492 
493  call set_default_values( &
494  num_cells_2, &
495  eta_min_2, &
496  eta_max_2, &
497  eta_in_min_2, &
498  eta_in_max_2, &
499  density_out_min_2, &
500  density_in_2, &
501  density_out_max_2)
502 
503  call sll_s_new_file_id(namelist_id, ierr)
504  open ( &
505  unit=namelist_id, &
506  file=trim(filename)//'.nml', &
507  iostat=io_stat)
508  if (io_stat /= 0) then
509  err_msg = &
510  'failed to open first file '//trim(filename)//'.nml'
511  sll_error(trim(caller), trim(err_msg))
512  end if
513 
514  read (namelist_id, mesh_1d_two_grid_cart_2)
515  self%label = "_2"
516  self%num_cells = num_cells_2
517  self%eta_min = eta_min_2
518  self%eta_max = eta_max_2
519  self%eta_in_min = eta_in_min_2
520  self%eta_in_max = eta_in_max_2
521  self%density_out_min = density_out_min_2
522  self%density_in = density_in_2
523  self%density_out_max = density_out_max_2
524  close (namelist_id)
525 
526  end subroutine init_nml_mesh_1d_two_grid_cart_2
527 
528  subroutine init_nml_mesh_1d_two_grid_cart_3( &
529  self, &
530  filename, &
531  proc_id)
532  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
533  character(len=*), intent(in) :: filename
534  sll_int32, intent(in), optional :: proc_id
535 
536  sll_int32 :: namelist_id
537  sll_int32 :: ierr
538  sll_int32 :: io_stat
539  character(len=256) :: err_msg
540  character(len=256) :: caller
541  sll_int32 :: num_cells_3
542  sll_real64 :: eta_min_3
543  sll_real64 :: eta_max_3
544  sll_real64 :: eta_in_min_3
545  sll_real64 :: eta_in_max_3
546  sll_real64 :: density_out_min_3
547  sll_real64 :: density_in_3
548  sll_real64 :: density_out_max_3
549  sll_int32 :: proc_id_loc
550 
551  namelist /mesh_1d_two_grid_cart_3/ &
552  num_cells_3, &
553  eta_min_3, &
554  eta_max_3, &
555  eta_in_min_3, &
556  eta_in_max_3, &
557  density_out_min_3, &
558  density_in_3, &
559  density_out_max_3
560 
561  caller = 'init_nml_mesh_1d_two_grid_cart_3'
562  if (present(proc_id)) then
563  proc_id_loc = proc_id
564  else
565  proc_id_loc = 0
566  end if
567 
568  call set_default_values( &
569  num_cells_3, &
570  eta_min_3, &
571  eta_max_3, &
572  eta_in_min_3, &
573  eta_in_max_3, &
574  density_out_min_3, &
575  density_in_3, &
576  density_out_max_3)
577 
578  call sll_s_new_file_id(namelist_id, ierr)
579  open ( &
580  unit=namelist_id, &
581  file=trim(filename)//'.nml', &
582  iostat=io_stat)
583  if (io_stat /= 0) then
584  err_msg = &
585  'failed to open first file '//trim(filename)//'.nml'
586  sll_error(trim(caller), trim(err_msg))
587  end if
588 
589  read (namelist_id, mesh_1d_two_grid_cart_3)
590  self%label = "_3"
591  self%num_cells = num_cells_3
592  self%eta_min = eta_min_3
593  self%eta_max = eta_max_3
594  self%eta_in_min = eta_in_min_3
595  self%eta_in_max = eta_in_max_3
596  self%density_out_min = density_out_min_3
597  self%density_in = density_in_3
598  self%density_out_max = density_out_max_3
599  close (namelist_id)
600 
601  end subroutine init_nml_mesh_1d_two_grid_cart_3
602 
603  subroutine init_nml_mesh_1d_two_grid_cart_4( &
604  self, &
605  filename, &
606  proc_id)
607  class(sll_t_nml_mesh_1d_two_grid_cart), intent(inout) :: self
608  character(len=*), intent(in) :: filename
609  sll_int32, intent(in), optional :: proc_id
610 
611  sll_int32 :: namelist_id
612  sll_int32 :: ierr
613  sll_int32 :: io_stat
614  character(len=256) :: err_msg
615  character(len=256) :: caller
616  sll_int32 :: num_cells_4
617  sll_real64 :: eta_min_4
618  sll_real64 :: eta_max_4
619  sll_real64 :: eta_in_min_4
620  sll_real64 :: eta_in_max_4
621  sll_real64 :: density_out_min_4
622  sll_real64 :: density_in_4
623  sll_real64 :: density_out_max_4
624  sll_int32 :: proc_id_loc
625 
626  namelist /mesh_1d_two_grid_cart_4/ &
627  num_cells_4, &
628  eta_min_4, &
629  eta_max_4, &
630  eta_in_min_4, &
631  eta_in_max_4, &
632  density_out_min_4, &
633  density_in_4, &
634  density_out_max_4
635 
636  caller = 'init_nml_mesh_1d_two_grid_cart_4'
637  if (present(proc_id)) then
638  proc_id_loc = proc_id
639  else
640  proc_id_loc = 0
641  end if
642 
643  call set_default_values( &
644  num_cells_4, &
645  eta_min_4, &
646  eta_max_4, &
647  eta_in_min_4, &
648  eta_in_max_4, &
649  density_out_min_4, &
650  density_in_4, &
651  density_out_max_4)
652 
653  call sll_s_new_file_id(namelist_id, ierr)
654  open ( &
655  unit=namelist_id, &
656  file=trim(filename)//'.nml', &
657  iostat=io_stat)
658  if (io_stat /= 0) then
659  err_msg = &
660  'failed to open first file '//trim(filename)//'.nml'
661  sll_error(trim(caller), trim(err_msg))
662  end if
663 
664  read (namelist_id, mesh_1d_two_grid_cart_4)
665  self%label = "_4"
666  self%num_cells = num_cells_4
667  self%eta_min = eta_min_4
668  self%eta_max = eta_max_4
669  self%eta_in_min = eta_in_min_4
670  self%eta_in_max = eta_in_max_4
671  self%density_out_min = density_out_min_4
672  self%density_in = density_in_4
673  self%density_out_max = density_out_max_4
674  close (namelist_id)
675 
676  end subroutine init_nml_mesh_1d_two_grid_cart_4
677 
678  subroutine set_default_values( &
679  num_cells, &
680  eta_min, &
681  eta_max, &
682  eta_in_min, &
683  eta_in_max, &
684  density_out_min, &
685  density_in, &
686  density_out_max)
687  sll_int32, intent(inout) :: num_cells
688  sll_real64, intent(inout) :: eta_min
689  sll_real64, intent(inout) :: eta_max
690  sll_real64, intent(inout) :: eta_in_min
691  sll_real64, intent(inout) :: eta_in_max
692  sll_real64, intent(inout) :: density_out_min
693  sll_real64, intent(inout) :: density_in
694  sll_real64, intent(inout) :: density_out_max
695 
696  num_cells = 32
697  eta_min = -6._f64
698  eta_max = 6._f64
699  eta_in_min = 0._f64
700  eta_in_max = 1._f64
701  density_out_min = 1._f64
702  density_in = 1._f64
703  density_out_max = 1._f64
704 
705  end subroutine set_default_values
706 
707 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
708 
initialization of 1d two grid cartesian mesh from namelist
subroutine s_nml_mesh_1d_two_grid_cart_array(filename, array, clone, proc_id)
create 1d array from namelist
subroutine s_nml_mesh_1d_two_grid_cart_print(filename, clone, proc_id)
print namelist info
Some common numerical utilities.
subroutine, public sll_s_compute_mesh_from_bloc(bloc_coord, bloc_index, node_positions)
subroutine, public sll_s_compute_bloc(bloc_coord, bloc_index, N)
subroutine, public sll_s_new_file_id(file_id, error)
Get a file unit number free before creating a file.
    Report Typos and Errors