Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_particle_visualization_interface.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 
21 
23 
24 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
25 #include "sll_assert.h"
26 #include "sll_errors.h"
27 #include "sll_memory.h"
28 #include "sll_working_precision.h"
29 
30  use sll_m_cartesian_meshes, only: &
33 
34  use sll_m_particle_group_base, only: &
36 
39 
40  use sll_m_gnuplot, only: &
42 
43  implicit none
44 
45  public :: &
48 
49  private
50 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51 
53  character(len=256) :: field_name
54  sll_int32 :: plot_count
55  sll_int32 :: plot_np_x
56  sll_int32 :: plot_np_vx
57  sll_real64 :: slice_y ! position of the slice in y dimension
58  sll_real64 :: slice_vy ! position of the slice in vy dimension
59  contains
60  procedure :: reset_params
62 
63 contains
64 
65  subroutine reset_params(self, &
66  field_name, &
67  plot_np_x, &
68  plot_np_vx, &
69  slice_y, &
70  slice_vy &
71  )
72  class(sll_t_plotting_params_2d), intent( inout ) :: self
73  character(len=*), intent( in ) :: field_name
74  sll_int32, intent( in ) :: plot_np_x
75  sll_int32, intent( in ) :: plot_np_vx
76  sll_real64, intent( in ) :: slice_y
77  sll_real64, intent( in ) :: slice_vy
78 
79  self%field_name = trim(field_name)
80  self%plot_np_x = plot_np_x
81  self%plot_np_vx = plot_np_vx
82  self%slice_y = slice_y
83  self%slice_vy = slice_vy
84  self%plot_count = 0
85 
86  end subroutine
87 
90  particle_group, &
91  plotting_params_2d, &
92  iplot )
93 
94  class(sll_c_particle_group_base), pointer, intent( inout ) :: particle_group
95  class(sll_t_plotting_params_2d), intent( inout ) :: plotting_params_2d
96  sll_int32, intent( in ) :: iplot
97 
98  sll_real64, dimension(:,:,:,:), pointer :: grid_values_4d
99  type(sll_t_cartesian_mesh_4d), pointer :: plotting_grid_4d
100  sll_real64 :: dummy_total_charge
101  logical :: enforce_total_charge
102  logical :: reconstruct_f_on_last_node(4)
103  sll_int32 :: file_id
104  sll_int32 :: ierr
105 
106  select type ( particle_group )
107 
109 
110  sll_allocate( grid_values_4d(plotting_params_2d%plot_np_x, 1, plotting_params_2d%plot_np_vx, 1), ierr)
111 
112  sll_assert( plotting_params_2d%plot_np_x > 1 )
113  sll_assert( plotting_params_2d%plot_np_vx > 1 )
114  sll_assert( plotting_params_2d%slice_y >= particle_group%lbf_grid%eta2_min )
115  sll_assert( plotting_params_2d%slice_y < particle_group%lbf_grid%eta2_max )
116  sll_assert( plotting_params_2d%slice_vy >= particle_group%lbf_grid%eta4_min )
117  sll_assert( plotting_params_2d%slice_vy < particle_group%lbf_grid%eta4_max )
118 
119  plotting_grid_4d => sll_f_new_cartesian_mesh_4d( &
120  plotting_params_2d%plot_np_x - 1, &
121  1, &
122  plotting_params_2d%plot_np_vx - 1, &
123  1, &
124  particle_group%lbf_grid%eta1_min, &
125  particle_group%lbf_grid%eta1_max, &
126  plotting_params_2d%slice_y, &
127  particle_group%lbf_grid%eta2_max, & ! max value along y does not matter because upper bound will not be plotted
128  particle_group%lbf_grid%eta3_min, &
129  particle_group%lbf_grid%eta3_max, &
130  plotting_params_2d%slice_vy, &
131  particle_group%lbf_grid%eta4_max & ! max value along vy does not matter because upper bound will not be plotted
132  )
133  reconstruct_f_on_last_node(1) = .true.
134  reconstruct_f_on_last_node(2) = .false.
135  reconstruct_f_on_last_node(3) = .true.
136  reconstruct_f_on_last_node(4) = .false.
137 
138  dummy_total_charge = 0.0_f64
139  enforce_total_charge = .false.
140 
141  call particle_group%reconstruct_f_lbf_on_given_grid( &
142  plotting_grid_4d, &
143  grid_values_4d, &
144  reconstruct_f_on_last_node,&
145  dummy_total_charge, &
146  enforce_total_charge &
147  )
148 
149  if( plotting_params_2d%plot_count == 0 )then
150 
151  ! Open Gnuplot script file: a new ASCII file will be created (replaced if already existing)
152  open( file= trim(plotting_params_2d%field_name)//'.gnu', &
153  status = 'replace', &
154  form = 'formatted', &
155  position= 'append', &
156  newunit = file_id, &
157  iostat = ierr )
158 
159  ! Write Gnuplot instructions for plotting f, then close file
160  write(file_id,*) '# run this script with $ gnuplot ' // trim(plotting_params_2d%field_name) // '.gnu' // ' -persist'
161  write(file_id,*) 'set view 0,0'
162  write(file_id,*) 'set pm3d'
163  write(file_id,*) 'set hid'
164  close(file_id)
165  end if
166 
167  ! todo: avoid gnuplot triggering an error if iplot <= 0
168 
169  call sll_o_gnuplot_2d( &
170  particle_group%lbf_grid%eta1_min, &
171  particle_group%lbf_grid%eta1_max, &
172  plotting_params_2d%plot_np_x, & ! (note: this is indeed the nb of plotted points, not 'cells')
173  particle_group%lbf_grid%eta3_min, &
174  particle_group%lbf_grid%eta3_max, &
175  plotting_params_2d%plot_np_vx, & ! (same comment)
176  grid_values_4d(:,1,:,1), &
177  trim(plotting_params_2d%field_name), &
178  iplot, &
179  ierr &
180  )
181  ! todo: use this: force_keep_gnu_file=.true. ) ! optional argument do avoid replacing existing file even if iplot=1
182 
183  plotting_params_2d%plot_count = plotting_params_2d%plot_count + 1
184 
185  class default
186  sll_error("sll_s_visualize_particle_group", "procedure not implemented for this type of particle group")
187  end select
188 
189  end subroutine sll_s_visualize_particle_group
190 
Write file for gnuplot to display 2d field.
Cartesian mesh basic types.
type(sll_t_cartesian_mesh_4d) function, pointer, public sll_f_new_cartesian_mesh_4d(num_cells1, num_cells2, num_cells3, num_cells4, eta1_min, eta1_max, eta2_min, eta2_max, eta3_min, eta3_max, eta4_min, eta4_max)
allocates the memory space for a new 4D cartesian mesh on the heap,
Implements the functions to write data file plotable by GNUplot.
Module for a particle group with linearized-backward-flow (lbf) resamplings.
Interface routines for visualizing particle groups.
subroutine reset_params(self, field_name, plot_np_x, plot_np_vx, slice_y, slice_vy)
subroutine, public sll_s_visualize_particle_group(particle_group, plotting_params_2d, iplot)
visualization interface
    Report Typos and Errors