4 #include "sll_assert.h"
5 #include "sll_errors.h"
6 #include "sll_memory.h"
7 #include "sll_working_precision.h"
54 sll_real64,
dimension(:, :),
pointer ::
data
55 sll_int32 :: data_position
56 character(len=64) :: name
57 sll_int32 :: plot_counter
67 sll_real64,
intent(in) :: eta1
68 sll_real64,
intent(in) :: eta2
89 character(len=*),
intent(in) :: field_name
91 sll_int32,
intent(in) :: data_position
96 character(len=*),
parameter :: this_sub_name =
'sll_s_scalar_field_2d_init'
99 sll_int32 :: num_cells1
100 sll_int32 :: num_cells2
101 sll_int32 :: num_pts1
102 sll_int32 :: num_pts2
104 sll_real64 :: eta1, eta2
105 sll_real64 :: delta1, delta2
107 sll_warning(this_sub_name,
"The sll_t_scalar_field_2d object is deprecated.")
109 this%transf => transf
110 this%transf%written = .false.
112 associate(mesh => transf%mesh)
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
124 if (
associated(eta1_interpolator))
then
125 this%eta1_interpolator => eta1_interpolator
127 print *,
'sll_s_scalar_field_2d_init(): eta1_interpolator pointer ', &
128 'is not associated. Exiting...'
131 if (
associated(eta2_interpolator))
then
132 this%eta2_interpolator => eta2_interpolator
134 print *,
'sll_s_scalar_field_2d_init(): eta2_interpolator pointer ', &
135 'is not associated. Exiting...'
139 this%data_position = data_position
141 sll_allocate(this%data(num_pts1, num_pts2), ierr)
142 if (
present(initializer))
then
143 call initializer%f_of_x1x2(this%data)
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)
159 this%plot_counter = 0
191 multiply_by_jacobian, &
196 logical,
optional :: multiply_by_jacobian
197 sll_int32,
optional :: output_format
198 character(len=*),
optional :: output_file_name
199 sll_int32 :: local_format
207 sll_real64,
dimension(:, :),
allocatable :: val
208 sll_int32 :: num_pts1
209 sll_int32 :: num_pts2
211 character(len=32) :: name
212 character(len=4) :: counter
213 character(len=4) :: center
215 if (
present(output_format))
then
216 local_format = output_format
218 local_format = sll_p_io_xdmf
221 associate(transf => scalar_field%transf)
223 if (.not. transf%written)
then
224 call transf%write_to_file(local_format)
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)
232 sll_allocate(val(num_pts1 - 1, num_pts2 - 1), ierr)
235 if (.not.
present(multiply_by_jacobian))
then
236 multiply_by_jacobian = .false.
237 val = scalar_field%data
239 else if (multiply_by_jacobian)
then
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
249 eta2 = eta2 + transf%mesh%delta_eta2
256 val(i1, i2) = scalar_field%data(i1, i2)
257 eta1 = eta1 + transf%mesh%delta_eta1
259 eta2 = eta2 + transf%mesh%delta_eta2
267 print *, local_format
269 select case (local_format)
272 if (scalar_field%data_position == sll_p_node_centered_field)
then
274 else if (scalar_field%data_position == sll_p_cell_centered_field)
then
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
283 name = output_file_name
285 call sll_o_xdmf_open(trim(name)//
".xmf", &
286 scalar_field%transf%label, &
287 num_pts1, num_pts2, file_id, ierr)
289 call sll_o_xdmf_write_array(trim(name), &
291 scalar_field%name, ierr, file_id, &
293 call sll_s_xdmf_close(file_id, ierr)
297 call sll_s_ascii_file_create(trim(name)//
".vtr", file_id, ierr)
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>"
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)
323 print *,
"sll_s_write_scalar_field_2d: requested output format not recognized."
327 sll_deallocate_array(val, ierr)
Write the field in xdmf format.
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.
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)
integer, parameter, public sll_p_node_centered_field
integer, parameter, public sll_p_cell_centered_field
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.
subroutine, public sll_s_xdmf_close(file_id, error)
Close the XML file and finish to write last lines.
Abstract class for 1D interpolation and reconstruction.