Report Typos and Errors    
Semi-Lagrangian Library
Modular library for kinetic and gyrokinetic simulations of plasmas in fusion energy devices.
sll_m_scalar_field_2d_old.F90
Go to the documentation of this file.
1 
3 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 #include "sll_assert.h"
5 #include "sll_errors.h"
6 #include "sll_memory.h"
7 #include "sll_working_precision.h"
8 
9  use sll_m_ascii_io, only: &
12 
13  use sll_m_cartesian_meshes, only: &
15 
19  sll_p_io_vtk, &
21 
22  use sll_m_interpolators_1d_base, only: &
24 
29 
30  use sll_m_utilities, only: &
32 
33  use sll_m_xdmf, only: &
37 
38  implicit none
39 
40  public :: &
44  sll_o_create, &
46 
47  private
48 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
49 
51  class(sll_c_coordinate_transformation_2d_base), pointer :: transf
52  class(sll_c_interpolator_1d), pointer :: eta1_interpolator
53  class(sll_c_interpolator_1d), pointer :: eta2_interpolator
54  sll_real64, dimension(:, :), pointer :: data
55  sll_int32 :: data_position
56  character(len=64) :: name
57  sll_int32 :: plot_counter
58  contains
59  procedure :: write_to_file => sll_s_write_scalar_field_2d
60  procedure :: initialize => sll_s_scalar_field_2d_init
61  end type sll_t_scalar_field_2d
62 
63  abstract interface
64  function sll_i_scalar_function_2d_old(eta1, eta2)
66  sll_real64 :: sll_i_scalar_function_2d_old
67  sll_real64, intent(in) :: eta1
68  sll_real64, intent(in) :: eta2
69  end function sll_i_scalar_function_2d_old
70  end interface
71 
72  interface sll_o_create
73  module procedure sll_s_scalar_field_2d_init
74  end interface sll_o_create
75 
76 contains ! *****************************************************************
77  ! this used to be new_scalar_field_2d
78  ! initializer is not use whith fortran95
80  this, &
81  field_name, &
82  transf, &
83  data_position, &
84  eta1_interpolator, &
85  eta2_interpolator, &
86  initializer)
87 
88  class(sll_t_scalar_field_2d), intent(inout) :: this
89  character(len=*), intent(in) :: field_name
90  class(sll_c_coordinate_transformation_2d_base), pointer :: transf
91  sll_int32, intent(in) :: data_position
92  class(sll_c_interpolator_1d), pointer :: eta1_interpolator
93  class(sll_c_interpolator_1d), pointer :: eta2_interpolator
94  class(sll_c_scalar_field_2d_initializer_base), pointer, optional :: initializer
95 
96  character(len=*), parameter :: this_sub_name = 'sll_s_scalar_field_2d_init'
97 
98  sll_int32 :: ierr
99  sll_int32 :: num_cells1
100  sll_int32 :: num_cells2
101  sll_int32 :: num_pts1
102  sll_int32 :: num_pts2
103  !sll_int32 :: i1, i2
104  sll_real64 :: eta1, eta2
105  sll_real64 :: delta1, delta2
106 
107  sll_warning(this_sub_name, "The sll_t_scalar_field_2d object is deprecated.")
108 
109  this%transf => transf
110  this%transf%written = .false.
111 
112  associate(mesh => transf%mesh)
113 
114  this%name = trim(field_name)
115  num_cells1 = mesh%num_cells1
116  num_cells2 = mesh%num_cells2
117  num_pts1 = mesh%num_cells1 + 1
118  num_pts2 = mesh%num_cells2 + 1
119 
120  end associate
121 
122  ! For an initializing function, argument check should not be assertions
123  ! but more permanent if-tests. There is no reason to turn these off ever.
124  if (associated(eta1_interpolator)) then
125  this%eta1_interpolator => eta1_interpolator
126  else
127  print *, 'sll_s_scalar_field_2d_init(): eta1_interpolator pointer ', &
128  'is not associated. Exiting...'
129  stop
130  end if
131  if (associated(eta2_interpolator)) then
132  this%eta2_interpolator => eta2_interpolator
133  else
134  print *, 'sll_s_scalar_field_2d_init(): eta2_interpolator pointer ', &
135  'is not associated. Exiting...'
136  stop
137  end if
138 
139  this%data_position = data_position
140  if (data_position == sll_p_node_centered_field) then
141  sll_allocate(this%data(num_pts1, num_pts2), ierr)
142  if (present(initializer)) then
143  call initializer%f_of_x1x2(this%data)
144  else
145  this%data = 0.0_f64
146  end if
147  else if (data_position == sll_p_cell_centered_field) then
148  sll_allocate(this%data(num_cells1, num_cells2), ierr)
149  delta1 = 1.0_f64/real(num_cells1, f64)
150  delta2 = 1.0_f64/real(num_cells2, f64)
151  eta1 = 0.5_f64*delta1
152  eta2 = 0.5_f64*delta2
153  if (present(initializer)) then
154  call initializer%f_of_x1x2(this%data)
155  else
156  this%data = 0.0_f64
157  end if
158  end if
159  this%plot_counter = 0
160  end subroutine sll_s_scalar_field_2d_init
161 
162 !PN DEFINED BUT NOT USED
163 ! ! The following pair of subroutines are tricky. We want them as general
164 ! ! services by the fields, hence we need this subroutine interface, yet
165 ! ! we would also like a flexibility in how the derivatives are computed.
166 ! ! A general interpolator interface would cover most of the cases, maybe
167 ! ! all. It could be that a finite difference scheme would also work, if
168 ! ! we ignore some of the interpolator services, like the ability to return
169 ! ! values anywhere instead of at the nodes.
170 ! ! For now, this interface would permit to have multiple implementations.
171 ! subroutine compute_eta1_derivative_on_col( field2d, ith_col, deriv_out )
172 ! type(sll_t_scalar_field_2d), intent(in) :: field2d
173 ! sll_int32, intent(in) :: ith_col
174 ! sll_real64, dimension(:),intent(out) :: deriv_out
175 ! deriv_out = 0.0_f64 * ith_col
176 ! SLL_ASSERT(associated(field2d%transf))
177 ! end subroutine compute_eta1_derivative_on_col
178 
179 !PN DEFINED BUT NOT USED
180 ! ! need to do something about deallocating the field proper, when allocated
181 ! ! in the heap...
182 ! subroutine delete_scalar_field_2d( this )
183 ! type(sll_t_scalar_field_2d), pointer :: this
184 ! sll_int32 :: ierr
185 ! nullify(this%transf)
186 ! SLL_DEALLOCATE(this%data, ierr)
187 ! end subroutine delete_scalar_field_2d
188 
190  scalar_field, &
191  multiply_by_jacobian, &
192  output_file_name, &
193  output_format)
194 
195  class(sll_t_scalar_field_2d) :: scalar_field
196  logical, optional :: multiply_by_jacobian
197  sll_int32, optional :: output_format
198  character(len=*), optional :: output_file_name
199  sll_int32 :: local_format
200 
201  sll_int32 :: i1
202  sll_int32 :: i2
203  sll_real64 :: eta1
204  sll_real64 :: eta2
205  !sll_real64 :: avg
206  sll_int32 :: ierr
207  sll_real64, dimension(:, :), allocatable :: val
208  sll_int32 :: num_pts1
209  sll_int32 :: num_pts2
210  sll_int32 :: file_id
211  character(len=32) :: name
212  character(len=4) :: counter
213  character(len=4) :: center
214 
215  if (present(output_format)) then
216  local_format = output_format
217  else
218  local_format = sll_p_io_xdmf
219  end if
220 
221  associate(transf => scalar_field%transf)
222 
223  if (.not. transf%written) then
224  call transf%write_to_file(local_format)
225  end if
226 
227  num_pts1 = transf%mesh%num_cells1 + 1
228  num_pts2 = transf%mesh%num_cells2 + 1
229  if (scalar_field%data_position == sll_p_node_centered_field) then
230  sll_allocate(val(num_pts1, num_pts2), ierr)
231  else
232  sll_allocate(val(num_pts1 - 1, num_pts2 - 1), ierr)
233  end if
234 
235  if (.not. present(multiply_by_jacobian)) then
236  multiply_by_jacobian = .false.
237  val = scalar_field%data
238 
239  else if (multiply_by_jacobian) then
240 
241  if (scalar_field%data_position == sll_p_cell_centered_field) then
242  eta2 = 0.5_f64*transf%mesh%delta_eta2
243  do i2 = 1, transf%mesh%num_cells2
244  eta1 = 0.5_f64*transf%mesh%delta_eta1
245  do i1 = 1, transf%mesh%num_cells1
246  val(i1, i2) = scalar_field%data(i1, i2)/transf%jacobian(eta1, eta2)
247  eta1 = eta1 + transf%mesh%delta_eta1
248  end do
249  eta2 = eta2 + transf%mesh%delta_eta2
250  end do
251  else
252  eta2 = 0.0_f64
253  do i2 = 1, num_pts2
254  eta1 = 0.0_f64
255  do i1 = 1, num_pts1
256  val(i1, i2) = scalar_field%data(i1, i2)
257  eta1 = eta1 + transf%mesh%delta_eta1
258  end do
259  eta2 = eta2 + transf%mesh%delta_eta2
260  end do
261  end if
262 
263  end if
264 
265  end associate
266 
267  print *, local_format
268 
269  select case (local_format)
270  case (sll_p_io_xdmf)
271 
272  if (scalar_field%data_position == sll_p_node_centered_field) then
273  center = "Node"
274  else if (scalar_field%data_position == sll_p_cell_centered_field) then
275  center = "Cell"
276  end if
277 
278  if (.not. present(output_file_name)) then
279  scalar_field%plot_counter = scalar_field%plot_counter + 1
280  call sll_s_int2string(scalar_field%plot_counter, counter)
281  name = trim(scalar_field%name)//counter
282  else
283  name = output_file_name
284  end if
285  call sll_o_xdmf_open(trim(name)//".xmf", &
286  scalar_field%transf%label, &
287  num_pts1, num_pts2, file_id, ierr)
288 
289  call sll_o_xdmf_write_array(trim(name), &
290  val, &
291  scalar_field%name, ierr, file_id, &
292  center)
293  call sll_s_xdmf_close(file_id, ierr)
294 
295  case (sll_p_io_vtk)
296 
297  call sll_s_ascii_file_create(trim(name)//".vtr", file_id, ierr)
298 
299  write (file_id, "(a)") "<VTKFile type='RectilinearGrid'>"
300  write (file_id, "(a,6i5,a)") "<RectilinearGrid WholeExtent='", 1, num_pts1, 1, num_pts2, 1, 1, "'>"
301  write (file_id, "(a,6i5,a)") "<Piece Extent='", 1, num_pts1, 1, num_pts2, 1, 1, "'>"
302  write (file_id, "(a)") "<PointData>"
303  write (file_id, "(a)") "<DataArray type='Float64' Name='"//scalar_field%name//"' format='ascii'>"
304  write (file_id, "(a)") "</DataArray>"
305  write (file_id, "(a)") "</PointData>"
306  write (file_id, "(a)") "<Coordinates>"
307  write (file_id, "(a)") "<DataArray type='Float64' Name='"//scalar_field%name//"' format='ascii'>"
308  write (file_id, "(a)") "</DataArray>"
309  write (file_id, "(a)") "</Coordinates>"
310  write (file_id, "(a)") "</Piece>"
311  write (file_id, "(a)") "</RectilinearGrid>"
312  write (file_id, "(a)") "</VTKFile>"
313 
314  close (file_id)
315 
316  case (sll_p_io_gnuplot)
317  call sll_s_ascii_file_create(trim(name)//".vtr", file_id, ierr)
318  call sll_s_ascii_write_array_2d(file_id, val, ierr)
319  close (file_id)
320 
321  case default
322 
323  print *, "sll_s_write_scalar_field_2d: requested output format not recognized."
324  stop
325  end select
326 
327  sll_deallocate_array(val, ierr)
328  end subroutine sll_s_write_scalar_field_2d
329 
330 end module sll_m_scalar_field_2d_old
Create a xmf file.
Definition: sll_m_xdmf.F90:76
Write the field in xdmf format.
Definition: sll_m_xdmf.F90:82
Module that contains routines to write data in ASCII format file.
subroutine, public sll_s_ascii_file_create(file_name, file_id, error)
Create ASCII file.
subroutine, public sll_s_ascii_write_array_2d(file_id, array, error)
Write a 2d array ASCII format.
Cartesian mesh basic types.
Abstract class for coordinate transformations.
Module for 1D interpolation and reconstruction.
Scalar field on mesh with coordinate transformation.
subroutine, public sll_s_write_scalar_field_2d(scalar_field, multiply_by_jacobian, output_file_name, output_format)
subroutine, public sll_s_scalar_field_2d_init(this, field_name, transf, data_position, eta1_interpolator, eta2_interpolator, initializer)
Some common numerical utilities.
subroutine, public sll_s_int2string(istep, cstep)
Convert an integer < 9999 to a 4 characters string.
Module to select the kind parameter.
Implements the functions to write xdmf file plotable by VisIt.
Definition: sll_m_xdmf.F90:24
subroutine, public sll_s_xdmf_close(file_id, error)
Close the XML file and finish to write last lines.
Definition: sll_m_xdmf.F90:895
Abstract class for 1D interpolation and reconstruction.
    Report Typos and Errors