7 #include "sll_assert.h"
8 #include "sll_errors.h"
9 #include "sll_memory.h"
10 #include "sll_working_precision.h"
56 sll_real64,
dimension(:),
allocatable :: params
57 character(len=64) :: name
64 logical :: present_deriv_eta1_int
65 logical :: present_deriv_eta2_int
75 procedure, pass(field) :: first_deriv_eta1_value_at_point => &
77 procedure, pass(field) :: first_deriv_eta2_value_at_point => &
79 procedure, pass(field) :: first_deriv_eta1_value_at_indices => &
81 procedure, pass(field) :: first_deriv_eta2_value_at_indices => &
84 procedure, pass(field) :: update_interpolation_coefficients => &
94 sll_real64,
dimension(:, :),
pointer :: values => null()
95 logical :: owns_memory = .true.
96 character(len=64) :: name
101 sll_real64,
dimension(:),
pointer :: point1_1d
102 sll_real64,
dimension(:),
pointer :: point2_1d
112 procedure, pass(field) :: update_interpolation_coefficients => &
119 procedure, pass(field) :: first_deriv_eta1_value_at_point => &
121 procedure, pass(field) :: first_deriv_eta2_value_at_point => &
123 procedure, pass(field) :: first_deriv_eta1_value_at_indices => &
125 procedure, pass(field) :: first_deriv_eta2_value_at_indices => &
145 sll_real64,
intent(in) :: eta1
146 sll_real64,
intent(in) :: eta2
147 sll_real64,
dimension(:),
intent(in) :: params
157 sll_real64,
intent(in) :: eta1
158 sll_real64,
intent(in) :: eta2
178 sll_real64,
intent(in) :: eta1
179 sll_real64,
intent(in) :: eta2
189 sll_int32,
intent(in) :: i
190 sll_int32,
intent(in) :: j
197 eta1 = lm%eta1_min + (i - 1)*lm%delta_eta1
198 eta2 = lm%eta2_min + (j - 1)*lm%delta_eta2
206 sll_real64,
intent(in) :: eta1
207 sll_real64,
intent(in) :: eta2
211 character(len=128) :: err_msg
212 character(len=*),
parameter :: this_fun_name = &
213 'first_deriv_eta1_value_at_pt_analytic'
215 if (field%present_deriv_eta1_int)
then
217 field%first_deriv_eta1(eta1, eta2, field%params)
220 err_msg =
"In "//field%name// &
221 ": first derivative in eta1 not given in the initialization."
222 sll_error(this_fun_name, err_msg)
230 sll_real64,
intent(in) :: eta1
231 sll_real64,
intent(in) :: eta2
235 character(len=128) :: err_msg
236 character(len=*),
parameter :: this_fun_name = &
237 'first_deriv_eta2_value_at_pt_analytic'
239 if (field%present_deriv_eta2_int)
then
241 field%first_deriv_eta2(eta1, eta2, field%params)
244 err_msg =
"In "//field%name// &
245 ": first derivative in eta2 &
246 & not given in the initialization."
247 sll_error(this_fun_name, err_msg)
255 sll_int32,
intent(in) :: i
256 sll_int32,
intent(in) :: j
264 eta1 = lm%eta1_min + real(i - 1, f64)*lm%delta_eta1
265 eta2 = lm%eta2_min + real(j - 1, f64)*lm%delta_eta2
267 if (field%present_deriv_eta1_int)
then
269 field%first_deriv_eta1(eta1, eta2, field%params)
272 print *, field%name, &
273 'first_deriv_eta1_value_at_index_analytic(): ERROR, ', &
274 'first derivative in eta1 is not given in the initialization'
282 sll_int32,
intent(in) :: i
283 sll_int32,
intent(in) :: j
291 eta1 = lm%eta1_min + real(i - 1, f64)*lm%delta_eta1
292 eta2 = lm%eta2_min + real(j - 1, f64)*lm%delta_eta2
294 if (field%present_deriv_eta2_int)
then
296 field%first_deriv_eta2(eta1, eta2, field%params)
298 print *,
' first derivative in eta2 is not given in the initialization'
312 first_deriv_eta2)
result(obj)
316 character(len=*),
intent(in) :: field_name
318 sll_int32,
intent(in) :: bc1_min
319 sll_int32,
intent(in) :: bc1_max
320 sll_int32,
intent(in) :: bc2_min
321 sll_int32,
intent(in) :: bc2_max
322 sll_real64,
dimension(:),
intent(in) :: func_params
327 sll_warning(
"sll_f_new_scalar_field_2d_analytic",
"This function is deprecated, use init subroutine instead")
328 sll_allocate(obj, ierr)
330 call obj%init(func, &
338 & first_deriv_eta1, &
346 sll_real64,
dimension(:, :),
intent(in) :: values
348 print *,
'WARNING: set_field_data_analytic_2d(): it is useless to ', &
349 'call this function on an analytic scalar field.'
350 sll_assert(
associated(field%mesh))
351 sll_assert(
size(values, 1) > 0)
358 print *,
'WARNING: update_interpolation_coefficients_2d_analytic(): ', &
359 ' it is useless to call this function on an analytic scalar field.'
360 sll_assert(
associated(field%mesh))
369 if (
associated(field%func))
nullify (field%func)
370 if (
associated(field%T))
nullify (field%T)
371 if (
allocated(field%params))
deallocate (field%params)
386 & first_deriv_eta1, &
391 character(len=*),
intent(in) :: field_name
393 sll_int32,
intent(in) :: bc1_min
394 sll_int32,
intent(in) :: bc1_max
395 sll_int32,
intent(in) :: bc2_min
396 sll_int32,
intent(in) :: bc2_max
397 sll_real64,
dimension(:),
intent(in) :: func_params
402 sll_allocate(field%params(
size(func_params)), ierr)
404 field%params(:) = func_params
405 field%T => transformation
407 field%name = trim(field_name)
408 field%bc1_min = bc1_min
409 field%bc1_max = bc1_max
410 field%bc2_min = bc2_min
411 field%bc2_max = bc2_max
413 if (
present(first_deriv_eta1))
then
414 field%first_deriv_eta1 => first_deriv_eta1
415 field%present_deriv_eta1_int = .true.
417 if (
present(first_deriv_eta2))
then
418 field%first_deriv_eta2 => first_deriv_eta2
419 field%present_deriv_eta2_int = .true.
450 res => field%T%get_cartesian_mesh()
457 sll_real64,
intent(in) :: eta1
458 sll_real64,
intent(in) :: eta2
459 sll_real64,
dimension(2, 2) :: res
460 res = (field%T%jacobian_matrix(eta1, eta2))
467 sll_int32,
intent(in) :: tag
470 sll_real64,
dimension(:, :),
allocatable :: x1coords
471 sll_real64,
dimension(:, :),
allocatable :: x2coords
472 sll_real64,
dimension(:, :),
allocatable :: values
483 t => field%get_transformation()
484 mesh => field%get_cartesian_mesh()
485 nptsx1 = mesh%num_cells1 + 1
486 nptsx2 = mesh%num_cells2 + 1
487 sll_allocate(x1coords(nptsx1, nptsx2), ierr)
488 sll_allocate(x2coords(nptsx1, nptsx2), ierr)
489 sll_allocate(values(nptsx1, nptsx2), ierr)
493 eta2 = mesh%eta2_min + (j - 1)*mesh%delta_eta2
495 eta1 = mesh%eta1_min + (i - 1)*mesh%delta_eta1
496 x1coords(i, j) = t%x1(eta1, eta2)
497 x2coords(i, j) = t%x2(eta1, eta2)
498 values(i, j) = field%value_at_point(eta1, eta2)
507 & trim(field%name), &
511 sll_deallocate_array(x1coords, ierr)
512 sll_deallocate_array(x2coords, ierr)
513 sll_deallocate_array(values, ierr)
533 sz_point2)
result(obj)
536 character(len=*),
intent(in) :: field_name
539 sll_int32,
intent(in) :: bc1_min
540 sll_int32,
intent(in) :: bc1_max
541 sll_int32,
intent(in) :: bc2_min
542 sll_int32,
intent(in) :: bc2_max
543 sll_real64,
dimension(:),
optional :: point1_1d
544 sll_real64,
dimension(:),
optional :: point2_1d
545 sll_int32,
optional :: sz_point1
546 sll_int32,
optional :: sz_point2
549 sll_warning(
"sll_f_new_scalar_field_2d_discrete",
"is deprectated, use init subroutine instead")
551 sll_allocate(obj, ierr)
553 call obj%init(field_name, &
581 character(len=*),
intent(in) :: field_name
584 sll_int32,
intent(in) :: bc1_min
585 sll_int32,
intent(in) :: bc1_max
586 sll_int32,
intent(in) :: bc2_min
587 sll_int32,
intent(in) :: bc2_max
588 sll_real64,
dimension(:),
optional :: point1_1d
589 sll_real64,
dimension(:),
optional :: point2_1d
590 sll_int32,
optional :: sz_point1
591 sll_int32,
optional :: sz_point2
593 sll_int32 :: num_cells1
594 sll_int32 :: num_cells2
597 field%T => transformation
599 field%interp_2d => interpolator_2d
601 field%name = trim(field_name)
602 field%bc1_min = bc1_min
603 field%bc1_max = bc1_max
604 field%bc2_min = bc2_min
605 field%bc2_max = bc2_max
607 num_cells1 = transformation%mesh%num_cells1
608 num_cells2 = transformation%mesh%num_cells2
611 sll_allocate(field%values(num_cells1 + 1, num_cells2 + 1), ierr)
614 sll_assert(
present(point1_1d))
615 sll_assert(
present(point2_1d))
616 sll_assert(
present(sz_point1))
617 sll_assert(
present(sz_point2))
626 if (field%owns_memory)
then
627 if (
associated(field%values)) sll_deallocate(field%values, ierr)
629 if (
associated(field%T))
nullify (field%T)
630 if (
associated(field%interp_2d))
nullify (field%interp_2d)
631 if (
associated(field%point1_1d))
nullify (field%point1_1d)
632 if (
associated(field%point2_1d))
nullify (field%point2_1d)
637 sll_real64,
dimension(:, :),
intent(in) :: values
640 m => field%get_cartesian_mesh()
641 if ((
size(values, 1) < m%num_cells1) .or. &
642 (
size(values, 2) < m%num_cells2))
then
643 print *,
'WARNING, set_field_data_discrete_2d(), passed array ', &
644 'is smaller than the size of data originally declared for ', &
645 'this field. Size of values in first dimension:',
size(values, 1), &
646 ' Size of mesh: ', m%num_cells1,
' Size of values in second ', &
647 'dimension:',
size(values, 2),
'Size of mesh: ', m%num_cells2
649 field%values(:, :) = values(:, :)
667 if (.not.
associated(field%values))
then
668 print *,
'ERROR, free_data_discrete_2d(): the internal copy of the ', &
669 'data has been already freed or never allocated.'
671 sll_deallocate(field%values, ierr)
672 field%owns_memory = .false.
677 sll_real64,
dimension(:, :),
target :: values
678 if (field%owns_memory .eqv. .true.)
then
679 print *,
'ERROR, reset_ptr_discrete_2d(): the data pointer can not ', &
680 'be reset without a previous call to free_internal_data_copy().', &
681 'This object is not being used properly. A memory leak has ', &
682 'occurred. Continue at your peril.'
684 field%values => values
689 sll_real64,
dimension(:, :),
pointer :: ptr
691 sll_assert(
associated(field%values))
699 call field%interp_2d%compute_interpolants(field%values)
718 res => transf%get_cartesian_mesh()
725 sll_real64,
intent(in) :: eta1
726 sll_real64,
intent(in) :: eta2
727 sll_real64,
dimension(2, 2) :: res
729 res(:, :) = field%T%jacobian_matrix(eta1, eta2)
736 sll_real64,
intent(in) :: eta1
737 sll_real64,
intent(in) :: eta2
746 sll_int32,
intent(in) :: i
747 sll_int32,
intent(in) :: j
753 lm => field%get_cartesian_mesh()
754 eta1 = lm%eta1_min + real(i - 1, f64)*lm%delta_eta1
755 eta2 = lm%eta2_min + real(j - 1, f64)*lm%delta_eta2
761 sll_real64,
intent(in) :: eta1
762 sll_real64,
intent(in) :: eta2
766 field%interp_2d%interpolate_from_interpolant_derivative_eta1(eta1, eta2)
771 sll_real64,
intent(in) :: eta1
772 sll_real64,
intent(in) :: eta2
776 field%interp_2d%interpolate_from_interpolant_derivative_eta2(eta1, eta2)
781 sll_int32,
intent(in) :: i
782 sll_int32,
intent(in) :: j
788 lm => field%get_cartesian_mesh()
789 eta1 = lm%eta1_min + real(i - 1, f64)*lm%delta_eta1
790 eta2 = lm%eta2_min + real(j - 1, f64)*lm%delta_eta2
792 field%interp_2d%interpolate_from_interpolant_derivative_eta1(eta1, eta2)
798 sll_int32,
intent(in) :: i
799 sll_int32,
intent(in) :: j
805 lm => field%get_cartesian_mesh()
806 eta1 = lm%eta1_min + real(i - 1, f64)*lm%delta_eta1
807 eta2 = lm%eta2_min + real(j - 1, f64)*lm%delta_eta2
809 field%interp_2d%interpolate_from_interpolant_derivative_eta2(eta1, eta2)
815 sll_int32,
intent(in) :: tag
818 sll_real64,
dimension(:, :),
allocatable :: x1coords
819 sll_real64,
dimension(:, :),
allocatable :: x2coords
820 sll_real64,
dimension(:, :),
allocatable :: values
828 character(len=4) :: ctag
832 t => field%get_transformation()
833 mesh => field%get_cartesian_mesh()
834 nptsx1 = mesh%num_cells1 + 1
835 nptsx2 = mesh%num_cells2 + 1
836 sll_allocate(x1coords(nptsx1, nptsx2), ierr)
837 sll_allocate(x2coords(nptsx1, nptsx2), ierr)
838 sll_allocate(values(nptsx1, nptsx2), ierr)
842 eta2 = mesh%eta2_min + (j - 1)*mesh%delta_eta2
844 eta1 = mesh%eta1_min + (i - 1)*mesh%delta_eta1
845 x1coords(i, j) = field%T%x1(eta1, eta2)
846 x2coords(i, j) = field%T%x2(eta1, eta2)
847 values(i, j) = field%value_at_point(eta1, eta2)
856 & trim(field%name), &
862 values,
"values", x1coords, x2coords,
"HDF5")
864 sll_deallocate_array(x1coords, ierr)
865 sll_deallocate_array(x2coords, ierr)
866 sll_deallocate_array(values, ierr)
Write file for gnuplot to display 2d field.
Cartesian mesh basic types.
Implements the functions to write data file plotable by GNUplot.
abstract data type for 2d interpolation
Implements the field descriptor types.
subroutine write_to_file_discrete_2d(field, tag)
type(sll_t_scalar_field_2d_discrete) function, pointer, public sll_f_new_scalar_field_2d_discrete(field_name, interpolator_2d, transformation, bc1_min, bc1_max, bc2_min, bc2_max, point1_1d, sz_point1, point2_1d, sz_point2)
real(kind=f64) function first_deriv_eta2_value_at_pt_analytic(field, eta1, eta2)
function first_deriv_eta1_value_at_pt_discrete(field, eta1, eta2)
function first_deriv_eta2_value_at_pt_discrete(field, eta1, eta2)
type(sll_t_scalar_field_2d_analytic) function, pointer, public sll_f_new_scalar_field_2d_analytic(func, field_name, transformation, bc1_min, bc1_max, bc2_min, bc2_max, func_params, first_deriv_eta1, first_deriv_eta2)
subroutine update_interpolation_coefficients_2d_analytic(field)
class(sll_c_coordinate_transformation_2d_base) function, pointer get_transformation_analytic(field)
function first_deriv_eta1_value_at_index_discrete(field, i, j)
real(kind=f64) function value_at_index_analytic(field, i, j)
pointer get_data_ptr_discrete_2d(field)
subroutine initialize_scalar_field_2d_discrete(field, field_name, interpolator_2d, transformation, bc1_min, bc1_max, bc2_min, bc2_max, point1_1d, sz_point1, point2_1d, sz_point2)
subroutine delete_field_2d_analytic(field)
class(sll_c_coordinate_transformation_2d_base) function, pointer get_transformation_discrete(field)
subroutine set_field_data_discrete_2d(field, values)
real(kind=f64) function value_at_pt_analytic(field, eta1, eta2)
subroutine reset_ptr_discrete_2d(field, values)
subroutine initialize_scalar_field_2d_analytic(field, func, field_name, transformation, bc1_min, bc1_max, bc2_min, bc2_max, func_params, first_deriv_eta1, first_deriv_eta2)
function first_deriv_eta2_value_at_index_discrete(field, i, j)
real(kind=f64) function first_deriv_eta1_value_at_pt_analytic(field, eta1, eta2)
function value_at_pt_discrete(field, eta1, eta2)
subroutine delete_field_2d_discrete(field)
subroutine write_to_file_analytic_2d(field, tag)
real(kind=f64) function first_deriv_eta1_value_at_index_analytic(field, i, j)
class(sll_t_cartesian_mesh_2d) function, pointer get_cartesian_mesh_2d_discrete(field)
real(kind=f64) function first_deriv_eta2_value_at_index_analytic(field, i, j)
subroutine free_data_discrete_2d(field)
subroutine update_interp_coeffs_2d_discrete(field)
function value_at_index_discrete(field, i, j)
dimension(2, 2) get_jacobian_matrix_discrete(field, eta1, eta2)
dimension(2, 2) get_jacobian_matrix_analytic(field, eta1, eta2)
subroutine set_field_data_analytic_2d(field, values)
class(sll_t_cartesian_mesh_2d) function, pointer get_cartesian_mesh_2d_analytic(field)
Some common numerical utilities.
subroutine, public sll_s_int2string(istep, cstep)
Convert an integer < 9999 to a 4 characters string.
subroutine, public sll_s_new_file_id(file_id, error)
Get a file unit number free before creating a file.
Module to select the kind parameter.
Implements the functions to write xdmf file plotable by VisIt.
subroutine, public sll_s_xdmf_curv2d_nodes(file_name, array, array_name, eta1, eta2, file_format, iplot)
Subroutine to write a 2D array in xdmf format. The field is describe on a cartesian mesh....
Base class/basic interface for 2D interpolators.