update fortran2 module

This commit is contained in:
Axel Kohlmeyer
2020-10-01 23:20:52 -04:00
parent 51d55aa036
commit 2c7a686220
3 changed files with 2026 additions and 1207 deletions

View File

@ -12,8 +12,9 @@
!-------------------------------------------------------------------------- !--------------------------------------------------------------------------
!! ------------------------------------------------------------------------ !! ------------------------------------------------------------------------
! Contributing author: Karl D. Hammond <karlh@ugcs.caltech.edu> ! Contributing author: Karl D. Hammond <hammondkd@missouri.edu>
! University of Tennessee, Knoxville (USA), 2012 ! University of Tennessee, Knoxville (USA), 2012
! Updated October 2020 by the author (now at the University of Missouri).
!-------------------------------------------------------------------------- !--------------------------------------------------------------------------
!! LAMMPS, a Fortran 2003 module containing an interface between Fortran !! LAMMPS, a Fortran 2003 module containing an interface between Fortran
@ -30,34 +31,114 @@
!! subroutine lammps_open (command_line, communicator, ptr) !! subroutine lammps_open (command_line, communicator, ptr)
!! subroutine lammps_open_no_mpi (command_line, ptr) !! subroutine lammps_open_no_mpi (command_line, ptr)
!! subroutine lammps_close (ptr) !! subroutine lammps_close (ptr)
!! integer (kind=C_int) lammps_version (ptr)
!! subroutine lammps_file (ptr, str) !! subroutine lammps_file (ptr, str)
!! subroutine lammps_command (ptr, str) !! subroutine lammps_command (ptr, str)
!! subroutine lammps_commands_list (ptr, cmds)
!! subroutine lammps_commands_string (ptr, str)
!! subroutine lammps_free (ptr) !! subroutine lammps_free (ptr)
!! integer function lammps_extract_setting (ptr, name)
!! subroutine lammps_extract_global (global, ptr, name) !! subroutine lammps_extract_global (global, ptr, name)
!! subroutine lammps_extract_box (ptr, boxlo, boxhi, xy, yz, xz, &
!! periodicity, box_change)
!! subroutine lammps_extract_atom (atom, ptr, name) !! subroutine lammps_extract_atom (atom, ptr, name)
!! subroutine lammps_extract_fix (fix, ptr, id, style, type, i, j)
!! subroutine lammps_extract_compute (compute, ptr, id, style, type) !! subroutine lammps_extract_compute (compute, ptr, id, style, type)
!! subroutine lammps_extract_fix (fix, ptr, id, style, type, i, j)
!! subroutine lammps_extract_variable (variable, ptr, name, group) !! subroutine lammps_extract_variable (variable, ptr, name, group)
!! function lammps_get_natoms (ptr) !! double precision function lammps_get_thermo (ptr, name)
!! integer function lammps_get_natoms (ptr)
!! subroutine lammps_set_variable (ptr, name, str, [err])
!! subroutine lammps_reset_box (ptr, boxlo, boxhi, xy, yz, xz)
!! subroutine lammps_gather_atoms (ptr, name, count, data) !! subroutine lammps_gather_atoms (ptr, name, count, data)
!! subroutine lammps_gather_atoms_concat (ptr, name, count, data)
!! subroutine lammps_gather_atoms_subset (ptr, name, count, ids, data)
!! subroutine lammps_scatter_atoms (ptr, name, data) !! subroutine lammps_scatter_atoms (ptr, name, data)
!! subroutine lammps_scatter_atoms_subset (ptr, name, ids, data)
!! logical function lammps_config_has_package (package_name)
!! integer function lammps_config_package_count ()
!! logical function lammps_config_package_name (index, buffer)
!! logical function lammps_config_has_gzip_support ()
!! logical function lammps_config_has_png_support ()
!! logical function lammps_config_has_jpeg_support ()
!! logical function lammps_config_has_ffmpeg_support ()
!! logical function lammps_config_has_exceptions ()
!! integer function lammps_find_pair_neighlist (ptr, style, exact, nsub,
!! request)
!! integer function lammps_find_fix_neighlist (ptr, id, request)
!! integer function lammps_find_compute_neighlist (ptr, id, request)
!! integer function lammps_neighlist_num_elements (ptr, idx)
!! subroutine lammps_neighlist_element_neighbors (ptr, idx, element, iatom,
!! numneigh, neighbors)
!! subroutine lammps_create_atoms (ptr, n, id, type, x, v, image,
!1 shrinkexceed)
!!
!! The following are also available if compiled with -DLAMMPS_EXCEPTIONS
!! function lammps_has_error (ptr)
!! function lammps_get_last_error_message (ptr, buffer)
!!
!! Note that the following function is not implemented from this interface:
!! lammps_set_fix_external_callback
#define FLERR __FILE__,__LINE__ #define FLERR __FILE__,__LINE__
! The above line allows for similar error checking as is done with standard ! The above line allows for similar error checking as is done with standard
! LAMMPS files. ! LAMMPS files.
! This should (?) allow this module to work with settings in lmptype.h
#if !defined(LAMMPS_SMALLSMALL) && !defined(LAMMPS_BIGBIG) && !defined(LAMMPS_SMALLBIG)
#define LAMMPS_SMALLBIG
#endif
#ifdef LAMMPS_SMALLBIG
#define C_smallint C_int
#define C_imageint C_int
#define C_tagint C_int
#define C_bigint C_int64_t
#endif
#ifdef LAMMPS_BIGBIG
#define C_smallint C_int
#define C_imageint C_int64_t
#define C_tagint C_int64_t
#define C_bigint C_int64_t
#endif
#ifdef LAMMPS_SMALLSMALL
#define C_smallint C_int
#define C_imageint C_int
#define C_tagint C_int
#define C_bigint C_int
#endif
module LAMMPS module LAMMPS
use, intrinsic :: ISO_C_binding, only : C_double, C_int, C_ptr, C_char, & use, intrinsic :: ISO_C_binding, only : C_double, C_int, C_ptr, C_char, &
C_NULL_CHAR, C_loc, C_F_pointer, lammps_instance => C_ptr C_NULL_CHAR, C_NULL_PTR, C_loc, C_F_pointer, C_int64_t, &
lammps_instance => C_ptr
implicit none implicit none
private private
public :: lammps_open, lammps_open_no_mpi, lammps_close, lammps_file, & ! We inherit some ISO_C_BINDING entities for ease of use
lammps_command, lammps_free, lammps_extract_global, &
lammps_extract_atom, lammps_extract_compute, lammps_extract_fix, &
lammps_extract_variable, lammps_get_natoms, lammps_gather_atoms, &
lammps_scatter_atoms
public :: lammps_instance, C_ptr, C_double, C_int public :: lammps_instance, C_ptr, C_double, C_int
! Only the following functions may be called by the user:
public :: lammps_open, lammps_open_no_mpi, lammps_close, &
lammps_version, lammps_file, lammps_command, lammps_commands_list, &
lammps_commands_string, lammps_free, lammps_extract_setting, &
lammps_extract_global, lammps_extract_box, lammps_extract_atom, &
lammps_extract_compute, lammps_extract_fix, lammps_extract_variable, &
lammps_get_thermo, lammps_get_natoms, lammps_set_variable, &
lammps_reset_box, lammps_gather_atoms, lammps_gather_atoms_concat, &
lammps_gather_atoms_subset, lammps_scatter_atoms, &
lammps_scatter_atoms_subset, lammps_config_has_package, &
lammps_config_package_count, lammps_config_package_name, &
lammps_config_has_gzip_support, lammps_config_has_png_support, &
lammps_config_has_jpeg_support, lammps_config_has_ffmpeg_support, &
lammps_config_has_exceptions, lammps_find_pair_neighlist, &
lammps_find_fix_neighlist, lammps_find_compute_neighlist, &
lammps_neighlist_num_elements, lammps_neighlist_element_neighbors, &
lammps_create_atoms
#ifdef LAMMPS_EXCEPTIONS
public :: lammps_has_error, lammps_get_last_error_message
#endif
!! Functions supplemental to the prototypes in library.h. {{{1 !! Functions supplemental to the prototypes in library.h. {{{1
!! The function definitions (in C++) are contained in LAMMPS-wrapper.cpp. !! The function definitions (in C++) are contained in LAMMPS-wrapper.cpp.
@ -78,7 +159,7 @@ module LAMMPS
bind (C, name='lammps_error_all') bind (C, name='lammps_error_all')
import :: C_int, C_char, C_ptr import :: C_int, C_char, C_ptr
type (C_ptr), value :: ptr type (C_ptr), value :: ptr
character (kind=C_char), dimension(*), intent(in) :: file, str character (kind=C_char), dimension(*) :: file, str
integer (C_int), value :: line integer (C_int), value :: line
end subroutine lammps_actual_error_all end subroutine lammps_actual_error_all
function lammps_get_ntypes (ptr) result (ntypes) & function lammps_get_ntypes (ptr) result (ntypes) &
@ -137,6 +218,13 @@ module LAMMPS
type (C_ptr), value :: ptr type (C_ptr), value :: ptr
end subroutine lammps_close end subroutine lammps_close
function lammps_version (ptr) result (version) &
bind (C, name='lammps_version')
import :: C_ptr, C_int
type (C_ptr), value :: ptr
integer (kind=C_int) :: version
end function lammps_version
subroutine lammps_actual_file (ptr, str) bind (C, name='lammps_file') subroutine lammps_actual_file (ptr, str) bind (C, name='lammps_file')
import :: C_ptr, C_char import :: C_ptr, C_char
type (C_ptr), value :: ptr type (C_ptr), value :: ptr
@ -151,11 +239,34 @@ module LAMMPS
type (C_ptr) :: command type (C_ptr) :: command
end function lammps_actual_command end function lammps_actual_command
subroutine lammps_actual_commands_list (ptr, ncmd, cmds) &
bind (C, name='lammps_commands_list')
import :: C_ptr, C_int
type (C_ptr), value :: ptr
type (C_ptr), dimension(*) :: cmds
integer (C_int), value :: ncmd
end subroutine lammps_actual_commands_list
subroutine lammps_actual_commands_string (ptr, str) &
bind (C, name='lammps_commands_string')
import :: C_ptr, C_char
type (C_ptr), value :: ptr
character (kind=C_char), dimension(*) :: str
end subroutine lammps_actual_commands_string
subroutine lammps_free (ptr) bind (C, name='lammps_free') subroutine lammps_free (ptr) bind (C, name='lammps_free')
import :: C_ptr import :: C_ptr
type (C_ptr), value :: ptr type (C_ptr), value :: ptr
end subroutine lammps_free end subroutine lammps_free
function lammps_actual_extract_setting (ptr, name) result (setting) &
bind(C, name='lammps_extract_setting')
import :: C_ptr, C_char, C_int
type (C_ptr), value :: ptr
character (kind=C_char), dimension(*) :: name
integer (kind=C_int) :: setting
end function lammps_actual_extract_setting
function lammps_actual_extract_global (ptr, name) & function lammps_actual_extract_global (ptr, name) &
bind (C, name='lammps_extract_global') result (global) bind (C, name='lammps_extract_global') result (global)
import :: C_ptr, C_char import :: C_ptr, C_char
@ -164,6 +275,14 @@ module LAMMPS
type (C_ptr) :: global type (C_ptr) :: global
end function lammps_actual_extract_global end function lammps_actual_extract_global
subroutine lammps_actual_extract_box (ptr, boxlo, boxhi, xy, yz, &
xz, periodicity, box_change) bind (C, name='lammps_extract_box')
import :: C_ptr, C_double, C_int
type (C_ptr), value :: ptr
real (C_double) :: boxlo(3), boxhi(3), xy, yz, xz
integer (C_int) :: periodicity(3), box_change
end subroutine lammps_actual_extract_box
function lammps_actual_extract_atom (ptr, name) & function lammps_actual_extract_atom (ptr, name) &
bind (C, name='lammps_extract_atom') result (atom) bind (C, name='lammps_extract_atom') result (atom)
import :: C_ptr, C_char import :: C_ptr, C_char
@ -198,6 +317,14 @@ module LAMMPS
type (C_ptr) :: variable type (C_ptr) :: variable
end function lammps_actual_extract_variable end function lammps_actual_extract_variable
function lammps_actual_get_thermo (ptr, name) result (dval) &
bind (C, name='lammps_get_thermo')
import :: C_ptr, C_char, C_double
type (C_ptr), value :: ptr
character (kind=C_char), dimension(*) :: name
real (C_double) :: dval
end function lammps_actual_get_thermo
function lammps_get_natoms (ptr) result (natoms) & function lammps_get_natoms (ptr) result (natoms) &
bind (C, name='lammps_get_natoms') bind (C, name='lammps_get_natoms')
import :: C_ptr, C_int import :: C_ptr, C_int
@ -205,6 +332,21 @@ module LAMMPS
integer (C_int) :: natoms integer (C_int) :: natoms
end function lammps_get_natoms end function lammps_get_natoms
function lammps_actual_set_variable (ptr, name, str) result (err) &
bind (C, name='lammps_set_variable')
import :: C_ptr, C_char, C_int
type (C_ptr), value :: ptr
character (kind=C_char), dimension(*) :: name, str
integer (C_int) :: err
end function lammps_actual_set_variable
subroutine lammps_actual_reset_box (ptr, boxlo, boxhi, xy, yz, xz) &
bind (C, name='lammps_reset_box')
import :: C_ptr, C_double, C_int
type (C_ptr), value :: ptr
real (C_double) :: boxlo(3), boxhi(3), xy, yz, xz
end subroutine lammps_actual_reset_box
subroutine lammps_actual_gather_atoms (ptr, name, type, count, data) & subroutine lammps_actual_gather_atoms (ptr, name, type, count, data) &
bind (C, name='lammps_gather_atoms') bind (C, name='lammps_gather_atoms')
import :: C_ptr, C_int, C_char import :: C_ptr, C_int, C_char
@ -213,6 +355,23 @@ module LAMMPS
integer (C_int), value :: type, count integer (C_int), value :: type, count
end subroutine lammps_actual_gather_atoms end subroutine lammps_actual_gather_atoms
subroutine lammps_actual_gather_atoms_concat (ptr, name, type, count, &
data) bind (C, name='lammps_gather_atoms_concat')
import :: C_ptr, C_int, C_char
type (C_ptr), value :: ptr, data
character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count
end subroutine lammps_actual_gather_atoms_concat
subroutine lammps_actual_gather_atoms_subset (ptr, name, type, count, &
ndata, ids, data) bind (C, name='lammps_gather_atoms_subset')
import :: C_ptr, C_int, C_char
type (C_ptr), value :: ptr, data
character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count, ndata
integer (C_int) :: ids(:)
end subroutine lammps_actual_gather_atoms_subset
subroutine lammps_actual_scatter_atoms (ptr, name, type, count, data) & subroutine lammps_actual_scatter_atoms (ptr, name, type, count, data) &
bind (C, name='lammps_scatter_atoms') bind (C, name='lammps_scatter_atoms')
import :: C_ptr, C_int, C_char import :: C_ptr, C_int, C_char
@ -220,6 +379,146 @@ module LAMMPS
character (kind=C_char), dimension(*) :: name character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count integer (C_int), value :: type, count
end subroutine lammps_actual_scatter_atoms end subroutine lammps_actual_scatter_atoms
subroutine lammps_actual_scatter_atoms_subset (ptr, name, type, count, &
ndata, ids, data) bind (C, name='lammps_scatter_atoms_subset')
import :: C_ptr, C_int, C_char
type (C_ptr), value :: ptr, data
character (kind=C_char), dimension(*) :: name
integer (C_int), value :: type, count, ndata
integer (C_int), dimension(*) :: ids
end subroutine lammps_actual_scatter_atoms_subset
function lammps_actual_config_has_package (package_name) &
result (has_it) bind (C, name='lammps_config_has_package')
import :: C_char, C_int
character (len=1, kind=C_char), dimension(*) :: package_name
integer (C_int) :: has_it
end function lammps_actual_config_has_package
function lammps_config_package_count () result (count) &
bind (C, name='lammps_config_package_count')
import :: C_int
integer (C_int) :: count
end function lammps_config_package_count
function lammps_actual_config_package_name (index, buffer, max_size) &
result (num) bind (C, name='lammps_config_package_name')
import :: C_int, C_char
integer (C_int), value :: index, max_size
character (len=1, kind=C_char), dimension(*) :: buffer
integer (C_int) :: num
end function lammps_actual_config_package_name
function lammps_actual_config_has_gzip_support () result (C_has_it) &
bind (C, name='lammps_config_has_gzip_support')
import :: C_int
integer (C_int) :: C_has_it
end function lammps_actual_config_has_gzip_support
function lammps_actual_config_has_png_support () result (C_has_it) &
bind (C, name='lammps_config_has_png_support')
import :: C_int
integer (C_int) :: C_has_it
end function lammps_actual_config_has_png_support
function lammps_actual_config_has_jpeg_support () result (C_has_it) &
bind (C, name='lammps_config_has_jpeg_support')
import :: C_int
integer (C_int) :: C_has_it
end function lammps_actual_config_has_jpeg_support
function lammps_actual_config_has_ffmpeg_support () result (C_has_it) &
bind (C, name='lammps_config_has_ffmpeg_support')
import :: C_int
integer (C_int) :: C_has_it
end function lammps_actual_config_has_ffmpeg_support
function lammps_actual_config_has_exceptions () result (C_has_it) &
bind (C, name='lammps_config_has_exceptions')
import :: C_int
integer (C_int) :: C_has_it
end function lammps_actual_config_has_exceptions
function lammps_actual_find_pair_neighlist (ptr, style, exact, nsub, &
request) result (C_neighlist) &
bind (C, name='lammps_find_pair_neighlist')
import :: C_ptr, C_int, C_char
integer (C_int) :: C_neighlist
type (C_ptr), value :: ptr
character (len=1, kind=C_char), dimension(*) :: style
integer (C_int), value :: exact, nsub, request
end function lammps_actual_find_pair_neighlist
function lammps_actual_find_fix_neighlist (ptr, id, request) &
result (C_neighlist) bind (C, name='lammps_find_fix_neighlist')
import :: C_ptr, C_int, C_char
integer (C_int) :: C_neighlist
type (C_ptr), value :: ptr
character (len=1, kind=C_char), dimension(*) :: id
integer (C_int), value :: request
end function lammps_actual_find_fix_neighlist
function lammps_actual_find_compute_neighlist (ptr, id, request) &
result (C_neighlist) bind (C, name='lammps_find_compute_neighlist')
import :: C_ptr, C_int, C_char
integer (C_int) :: C_neighlist
type (C_ptr), value :: ptr
character (len=1, kind=C_char), dimension(*) :: id
integer (C_int), value :: request
end function lammps_actual_find_compute_neighlist
function lammps_actual_neighlist_num_elements (ptr, idx) &
result (nelements) bind (C, name='lammps_neighlist_num_elements')
import :: C_ptr, C_int
integer (C_int) :: nelements
type (C_ptr), value :: ptr
integer (C_int), value :: idx
end function lammps_actual_neighlist_num_elements
subroutine lammps_actual_neighlist_element_neighbors (ptr, idx, &
element, iatom, numneigh, neighbors) &
bind (C, name='lammps_neighlist_element_neighbors')
import :: C_ptr, C_int
type (C_ptr), value :: ptr
integer (C_int), value :: idx, element
integer (C_int) :: iatom, numneigh
type (C_ptr) :: neighbors
end subroutine lammps_actual_neighlist_element_neighbors
subroutine lammps_actual_create_atoms (ptr, n, id, type, x, v, image, &
shrinkexceed) bind (C, name='lammps_create_atoms')
import :: C_ptr, C_int64_t, C_double, C_int
type (C_ptr), value :: ptr
integer (C_int), value :: n
integer (C_tagint) :: id
integer (C_int) :: type
real (C_double), dimension(*) :: x, v
integer (C_imageint), dimension(*) :: image
integer (C_int), value :: shrinkexceed
end subroutine lammps_actual_create_atoms
#ifdef LAMMPS_EXCEPTIONS
function lammps_actual_has_error (ptr) result (C_has_it) &
bind (C, name='lammps_has_error')
import :: C_int, C_ptr
type (C_ptr), value :: ptr
integer (C_int) :: C_has_it
end function lammps_actual_has_error
function lammps_actual_get_last_error_message (ptr, buffer, &
buffer_size) result (error_type) &
bind (C, name='lammps_get_last_error_message')
import :: C_ptr, C_char, C_int
type (C_ptr), value :: ptr
integer (C_int), value :: buffer_size
character (len=1, kind=C_char), dimension(*) :: buffer
integer (C_int) :: error_type
end function lammps_actual_get_last_error_message
#endif
end interface end interface
! Generic functions for the wrappers below {{{1 ! Generic functions for the wrappers below {{{1
@ -256,10 +555,25 @@ module LAMMPS
module procedure lammps_gather_atoms_ia, lammps_gather_atoms_dpa module procedure lammps_gather_atoms_ia, lammps_gather_atoms_dpa
end interface lammps_gather_atoms end interface lammps_gather_atoms
interface lammps_gather_atoms_concat
module procedure lammps_gather_atoms_concat_ia, &
lammps_gather_atoms_concat_dpa
end interface lammps_gather_atoms_concat
interface lammps_gather_atoms_subset
module procedure lammps_gather_atoms_subset_ia, &
lammps_gather_atoms_subset_dpa
end interface lammps_gather_atoms_subset
interface lammps_scatter_atoms interface lammps_scatter_atoms
module procedure lammps_scatter_atoms_ia, lammps_scatter_atoms_dpa module procedure lammps_scatter_atoms_ia, lammps_scatter_atoms_dpa
end interface lammps_scatter_atoms end interface lammps_scatter_atoms
interface lammps_scatter_atoms_subset
module procedure lammps_scatter_atoms_subset_ia, &
lammps_scatter_atoms_subset_dpa
end interface lammps_scatter_atoms_subset
contains !! Wrapper functions local to this module {{{1 contains !! Wrapper functions local to this module {{{1
subroutine lammps_open (command_line, communicator, ptr) subroutine lammps_open (command_line, communicator, ptr)
@ -312,6 +626,53 @@ contains !! Wrapper functions local to this module {{{1
dummy = lammps_actual_command (ptr, Cstr) dummy = lammps_actual_command (ptr, Cstr)
end subroutine lammps_command end subroutine lammps_command
!-----------------------------------------------------------------------------
subroutine lammps_commands_list (ptr, cmds)
type (C_ptr), intent(in) :: ptr
character (len=*), dimension(:) :: cmds
integer (C_int) :: ncmd
! character (kind=C_char,len=1), dimension(size(cmds)) :: C_cmds
type (C_ptr), dimension(:), allocatable :: C_cmds
character (len=1, kind=C_char), allocatable, target :: C_strings(:,:)
integer :: i, max_len
ncmd = size(cmds)
allocate (C_cmds(ncmd))
max_len = 0
do i=1, size(cmds)
if ( len(cmds(i)) > max_len ) max_len = len(cmds(i))
end do
allocate (C_strings(max_len + 1, ncmd))
do i=1, size(cmds)
C_strings(:,i) = string2Cstring(cmds(i))
C_cmds(i) = C_loc(C_strings(1,i))
end do
call lammps_actual_commands_list (ptr, ncmd, C_cmds)
deallocate (C_strings)
deallocate (C_cmds)
end subroutine lammps_commands_list
!-----------------------------------------------------------------------------
subroutine lammps_commands_string (ptr, str)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: str
character (kind=C_char), dimension(len_trim(str)+1) :: C_str
C_str = string2Cstring (str)
call lammps_actual_commands_string (ptr, C_str)
end subroutine lammps_commands_string
!-----------------------------------------------------------------------------
function lammps_extract_setting (ptr, name) result (setting)
integer :: setting
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
character (kind=C_char), dimension(len_trim(name)+1) :: C_name
C_name = string2Cstring (name)
setting = lammps_actual_extract_setting (ptr, C_name)
end function lammps_extract_setting
!----------------------------------------------------------------------------- !-----------------------------------------------------------------------------
! lammps_extract_global {{{2 ! lammps_extract_global {{{2
@ -342,6 +703,28 @@ contains !! Wrapper functions local to this module {{{1
!----------------------------------------------------------------------------- !-----------------------------------------------------------------------------
! lammps_extract_box {{{2
subroutine lammps_extract_box (ptr, boxlo, boxhi, xy, yz, xz, &
periodicity, box_change)
type (C_ptr), intent(in) :: ptr
double precision, dimension(3), intent(out) :: boxlo, boxhi
double precision, intent(out) :: xy, yz, xz
logical, intent(out) :: periodicity(3), box_change
integer (kind=C_int) :: C_periodicity(3), C_box_change
real (C_double) :: C_boxlo(3), C_boxhi(3), C_xy, C_yz, C_xz
call lammps_actual_extract_box (ptr, C_boxlo, C_boxhi, C_xy, C_yz, &
C_xz, C_periodicity, C_box_change)
boxlo = C_boxlo
boxhi = C_boxhi
xy = C_xy
yz = C_yz
xz = C_xz
periodicity = (C_periodicity == 1)
box_change = (C_box_change == 1)
end subroutine
!-----------------------------------------------------------------------------
! lammps_extract_atom {{{2 ! lammps_extract_atom {{{2
function lammps_extract_atom_Cptr (ptr, name) result (atom) function lammps_extract_atom_Cptr (ptr, name) result (atom)
type (C_ptr) :: atom type (C_ptr) :: atom
@ -551,7 +934,6 @@ contains !! Wrapper functions local to this module {{{1
end if end if
Cptr = lammps_extract_fix_Cptr (ptr, id, style, type, i, j) Cptr = lammps_extract_fix_Cptr (ptr, id, style, type, i, j)
call C_F_pointer (Cptr, Fptr) call C_F_pointer (Cptr, Fptr)
fix = Fptr
nullify (Fptr) nullify (Fptr)
! Memory is only allocated for "global" fix variables ! Memory is only allocated for "global" fix variables
if ( style == 0 ) call lammps_free (Cptr) if ( style == 0 ) call lammps_free (Cptr)
@ -674,6 +1056,41 @@ contains !! Wrapper functions local to this module {{{1
!-------------------------------------------------------------------------2}}} !-------------------------------------------------------------------------2}}}
function lammps_get_thermo (ptr, name) result (dval)
double precision :: dval
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
Cname = string2Cstring (name)
dval = lammps_actual_get_thermo (ptr, Cname)
end function lammps_get_thermo
subroutine lammps_set_variable (ptr, name, str, err)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name, str
integer, optional :: err
integer (C_int) :: Cerr
character (kind=C_char) :: Cname(len_trim(name)+1), Cstr(len_trim(str)+1)
Cname = string2Cstring (name)
Cstr = string2Cstring (str)
Cerr = lammps_actual_set_variable (ptr, Cname, Cstr)
if ( present(err) ) err = Cerr
end subroutine lammps_set_variable
subroutine lammps_reset_box (ptr, boxlo, boxhi, xy, yz, xz)
type (C_ptr), intent(in) :: ptr
double precision, dimension(3), intent(in) :: boxlo, boxhi
double precision, intent(in) :: xy, yz, xz
real (C_double) :: C_boxlo(3), C_boxhi(3), C_xy, C_yz, C_xz
C_boxlo = boxlo
C_boxhi = boxhi
C_xy = xy
C_xz = xz
C_yz = yz
call lammps_actual_reset_box (ptr, C_boxlo, C_boxhi, C_xy, C_xz, C_yz)
end subroutine lammps_reset_box
! lammps_gather_atoms {{{2
subroutine lammps_gather_atoms_ia (ptr, name, count, data) subroutine lammps_gather_atoms_ia (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name character (len=*), intent(in) :: name
@ -727,8 +1144,123 @@ contains !! Wrapper functions local to this module {{{1
deallocate (Fdata) deallocate (Fdata)
end subroutine lammps_gather_atoms_dpa end subroutine lammps_gather_atoms_dpa
! lammps_gather_atoms_concat {{{2
subroutine lammps_gather_atoms_concat_ia (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count
integer, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
integer (C_int), dimension(:), pointer :: Fdata
integer (C_int) :: natoms
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
integer (C_int), parameter :: Ctype = 0_C_int
integer (C_int) :: Ccount
natoms = lammps_get_natoms (ptr)
Cname = string2Cstring (name)
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*natoms) )
allocate ( data(count*natoms) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms_concat (ptr, Cname, Ctype, Ccount, Cdata)
data = Fdata
deallocate (Fdata)
end subroutine lammps_gather_atoms_concat_ia
subroutine lammps_gather_atoms_concat_dpa (ptr, name, count, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count
double precision, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
real (C_double), dimension(:), pointer :: Fdata
integer (C_int) :: natoms
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
integer (C_int), parameter :: Ctype = 1_C_int
integer (C_int) :: Ccount
natoms = lammps_get_natoms (ptr)
Cname = string2Cstring (name)
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms_concat&
& requires count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*natoms) )
allocate ( data(count*natoms) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms_concat (ptr, Cname, Ctype, Ccount, Cdata)
data = Fdata(:)
deallocate (Fdata)
end subroutine lammps_gather_atoms_concat_dpa
!----------------------------------------------------------------------------- !-----------------------------------------------------------------------------
! lammps_gather_atoms_subset {{{2
subroutine lammps_gather_atoms_subset_ia (ptr,name,count,ids,data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count, ids(:)
integer, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
integer (C_int), dimension(:), pointer :: Fdata
integer (C_int) :: ndata, Cids(size(ids))
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
integer (C_int), parameter :: Ctype = 0_C_int
integer (C_int) :: Ccount
ndata = size(ids)
Cname = string2Cstring (name)
Cids = ids
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms_subset&
& requires count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*ndata) )
allocate ( data(count*ndata) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms_subset (ptr, Cname, Ctype, Ccount, &
ndata, Cids, Cdata)
data = Fdata
deallocate (Fdata)
end subroutine lammps_gather_atoms_subset_ia
subroutine lammps_gather_atoms_subset_dpa (ptr,name,count,ids,data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, intent(in) :: count, ids(:)
double precision, dimension(:), allocatable, intent(out) :: data
type (C_ptr) :: Cdata
real (C_double), dimension(:), pointer :: Fdata
integer (C_int) :: ndata, Cids(size(ids))
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
integer (C_int), parameter :: Ctype = 1_C_int
integer (C_int) :: Ccount
ndata = size(ids)
Cname = string2Cstring (name)
Cids = ids
if ( count /= 1 .and. count /= 3 ) then
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
else
Ccount = count
end if
allocate ( Fdata(count*ndata) )
allocate ( data(count*ndata) )
Cdata = C_loc (Fdata(1))
call lammps_actual_gather_atoms_subset (ptr, Cname, Ctype, Ccount, &
ndata, Cids, Cdata)
data = Fdata
deallocate (Fdata)
end subroutine lammps_gather_atoms_subset_dpa
!-----------------------------------------------------------------------------
! lammps_scatter_atoms {{{2
subroutine lammps_scatter_atoms_ia (ptr, name, data) subroutine lammps_scatter_atoms_ia (ptr, name, data)
type (C_ptr), intent(in) :: ptr type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name character (len=*), intent(in) :: name
@ -770,6 +1302,265 @@ contains !! Wrapper functions local to this module {{{1
!----------------------------------------------------------------------------- !-----------------------------------------------------------------------------
! lammps_scatter_atoms_subset {{{2
subroutine lammps_scatter_atoms_subset_ia (ptr, name, ids, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
integer, dimension(:), intent(in) :: data, ids
integer (kind=C_int) :: ndata, Ccount, Cids(size(ids))
integer (kind=C_int), parameter :: Ctype = 0_C_int
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
integer (C_int), dimension(size(data)), target :: Fdata
type (C_ptr) :: Cdata
ndata = size(ids)
Cname = string2Cstring (name)
Ccount = size(data) / ndata
if ( Ccount /= 1 .and. Ccount /= 3 ) &
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
Fdata = data
Cdata = C_loc (Fdata(1))
Cids = ids
call lammps_actual_scatter_atoms_subset (ptr, Cname, Ctype, Ccount, &
ndata, Cids, Cdata)
end subroutine lammps_scatter_atoms_subset_ia
subroutine lammps_scatter_atoms_subset_dpa (ptr, name, ids, data)
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: name
double precision, dimension(:), intent(in) :: data, ids
integer (kind=C_int) :: ndata, Ccount, Cids(size(ids))
integer (kind=C_int), parameter :: Ctype = 1_C_int
character (kind=C_char), dimension(len_trim(name)+1) :: Cname
real (C_double), dimension(size(data)), target :: Fdata
type (C_ptr) :: Cdata
ndata = size(ids)
Cname = string2Cstring (name)
Ccount = size(data) / ndata
if ( Ccount /= 1 .and. Ccount /= 3 ) &
call lammps_error_all (ptr, FLERR, 'lammps_gather_atoms requires&
& count to be either 1 or 3')
Fdata = data
Cdata = C_loc (Fdata(1))
call lammps_actual_scatter_atoms_subset (ptr, Cname, Ctype, Ccount, &
ndata, Cids, Cdata)
end subroutine lammps_scatter_atoms_subset_dpa
!-----------------------------------------------------------------------------
subroutine lammps_create_atoms (ptr, id, type, x, v, image, shrinkexceed)
type (C_ptr), intent(in) :: ptr
integer (kind=C_tagint), dimension(:), optional :: id
integer, dimension(:) :: type
double precision, dimension(:,:) :: x
double precision, dimension(:,:), optional :: v
integer (kind=C_imageint), dimension(:), target, optional :: image
logical, optional :: shrinkexceed
real (C_double), dimension(size(x)) :: C_x, C_v
integer (C_int) :: C_shrinkexceed, n
integer (kind=C_tagint) :: C_id
integer (C_imageint), dimension(size(x)/3) :: C_image
integer (C_int) :: C_type
if (shrinkexceed) then
C_shrinkexceed = 1_C_int
else
C_shrinkexceed = 0_C_int
end if
C_x = reshape(transpose(x), shape(C_x))
if ( present(v) ) then
C_v = reshape(transpose(v), shape(C_v))
else
C_v = 0.0_C_double
end if
if ( present(image) ) then
C_image = image
else
C_image = int(0,kind=C_imageint)
end if
n = size(type)
call lammps_actual_create_atoms (ptr, n, C_id, C_type, C_x, C_v, &
C_image, C_shrinkexceed)
end subroutine lammps_create_atoms
!-----------------------------------------------------------------------------
function lammps_config_has_package (package_name) result (has_it)
character (len=*), intent(in) :: package_name
character (len=1, kind=C_char), dimension(len_trim(package_name)+1) :: &
C_package_name
logical :: has_it
integer (C_int) :: C_has_it
C_package_name = string2Cstring (package_name)
C_has_it = lammps_actual_config_has_package (C_package_name)
has_it = (C_has_it == 1)
end function lammps_config_has_package
!-----------------------------------------------------------------------------
function lammps_config_package_name (index, buffer) result (installed)
character (len=*), intent(inout) :: buffer
integer, intent(in) :: index
logical :: installed
integer (kind=C_int) :: C_installed, C_index, max_size
character (len=1, kind=C_char), dimension(len_trim(buffer)+1) :: C_buffer
C_buffer = string2Cstring (buffer)
max_size = len(buffer)
C_index = index
C_installed = lammps_actual_config_package_name (C_index, C_buffer, &
max_size)
installed = (C_installed == 1_C_int)
buffer = Cstring2string (C_buffer)
end function lammps_config_package_name
!-----------------------------------------------------------------------------
logical function lammps_config_has_gzip_support () result (has_it)
integer (C_int) :: C_has_it
C_has_it = lammps_actual_config_has_gzip_support ()
has_it = (C_has_it == 1_C_int)
end function lammps_config_has_gzip_support
!-----------------------------------------------------------------------------
logical function lammps_config_has_png_support () result (has_it)
integer (C_int) :: C_has_it
C_has_it = lammps_actual_config_has_png_support ()
has_it = (C_has_it == 1_C_int)
end function lammps_config_has_png_support
!-----------------------------------------------------------------------------
logical function lammps_config_has_jpeg_support () result (has_it)
integer (C_int) :: C_has_it
C_has_it = lammps_actual_config_has_jpeg_support ()
has_it = (C_has_it == 1_C_int)
end function lammps_config_has_jpeg_support
!-----------------------------------------------------------------------------
logical function lammps_config_has_ffmpeg_support () result (has_it)
integer (C_int) :: C_has_it
C_has_it = lammps_actual_config_has_ffmpeg_support ()
has_it = (C_has_it == 1_C_int)
end function lammps_config_has_ffmpeg_support
!-----------------------------------------------------------------------------
logical function lammps_config_has_exceptions () result (has_it)
integer (C_int) :: C_has_it
C_has_it = lammps_actual_config_has_exceptions ()
has_it = (C_has_it == 1_C_int)
end function lammps_config_has_exceptions
!-----------------------------------------------------------------------------
function lammps_find_pair_neighlist (ptr, style, exact, nsub, request) &
result (neighlist)
integer :: neighlist
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: style
logical, intent(in) :: exact
integer, intent(in) :: nsub, request
integer (C_int) :: C_exact, C_nsub, C_neighlist, C_request
character (kind=C_char), dimension(len_trim(style)+1) :: C_style
if (exact) then
C_exact = 1_C_int
else
C_exact = 0_C_int
end if
C_nsub = nsub
C_request = request
C_style = string2Cstring (style)
C_neighlist = lammps_actual_find_pair_neighlist (ptr, C_style, C_exact, &
C_nsub, C_request)
neighlist = C_neighlist
end function lammps_find_pair_neighlist
!-----------------------------------------------------------------------------
function lammps_find_fix_neighlist (ptr, id, request) result (neighlist)
integer :: neighlist
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: id
integer, intent(in) :: request
integer (C_int) :: C_request, C_neighlist
character (kind=C_char), dimension(len_trim(id)+1) :: C_id
C_id = string2Cstring(id)
C_request = request
C_neighlist = lammps_actual_find_fix_neighlist (ptr, C_id, C_request)
neighlist = C_neighlist
end function lammps_find_fix_neighlist
!-----------------------------------------------------------------------------
function lammps_find_compute_neighlist (ptr, id, request) result (neighlist)
integer :: neighlist
type (C_ptr), intent(in) :: ptr
character (len=*), intent(in) :: id
integer, intent(in) :: request
integer (C_int) :: C_request
character (kind=C_char), dimension(len_trim(id)+1) :: C_id
C_id = string2Cstring(id)
C_request = request
neighlist = lammps_actual_find_compute_neighlist (ptr, C_id, C_request)
end function lammps_find_compute_neighlist
!-----------------------------------------------------------------------------
function lammps_neighlist_num_elements (ptr, idx) result (nelements)
integer :: nelements
type (C_ptr), intent(in) :: ptr
integer, intent(in) :: idx
integer (C_int) :: C_idx
C_idx = idx
nelements = lammps_actual_neighlist_num_elements (ptr, C_idx)
end function lammps_neighlist_num_elements
!-----------------------------------------------------------------------------
subroutine lammps_neighlist_element_neighbors (ptr, idx, element, iatom, &
numneigh, neighbors)
type (C_ptr), intent(in) :: ptr
integer, intent(in) :: idx, element
integer, intent(out) :: iatom, numneigh
integer (C_int), dimension(:), pointer, intent(out) :: neighbors
integer (C_int) :: C_idx, C_element, C_iatom, C_numneigh
type (C_ptr) :: C_neighbors
C_idx = idx
C_element = element
call lammps_actual_neighlist_element_neighbors (ptr, C_idx, C_element, &
C_iatom, C_numneigh, C_neighbors)
iatom = C_iatom
numneigh = C_numneigh
call C_F_pointer (C_neighbors, neighbors, [numneigh])
end subroutine lammps_neighlist_element_neighbors
!-----------------------------------------------------------------------------
! These are only defined if -DLAMMPS_EXCEPTIONS was issued
#ifdef LAMMPS_EXCEPTIONS
logical function lammps_has_error (ptr) result (has_it)
type (C_ptr), intent(in) :: ptr
integer (kind=C_int) :: C_has_it
C_has_it = lammps_actual_has_error (ptr)
has_it = (C_has_it == 1_C_int)
end function lammps_has_error
!-----------------------------------------------------------------------------
function lammps_get_last_error_message (ptr, buffer) result (error_type)
integer (C_int) :: error_type
type (C_ptr), intent(in) :: ptr
character (len=*), intent(out) :: buffer
integer (C_int) :: buffer_size
character (len=1, kind=C_char), dimension(len(buffer)+1) :: C_buffer
buffer_size = len(buffer)
error_type = lammps_actual_get_last_error_message (ptr, C_buffer, &
buffer_size)
buffer = Cstring2string (C_buffer)
end function lammps_get_last_error_message
#endif
!-------------------------------------------------------------------------2}}}
function lammps_extract_compute_vectorsize (ptr, id, style) & function lammps_extract_compute_vectorsize (ptr, id, style) &
result (vectorsize) result (vectorsize)
integer :: vectorsize integer :: vectorsize
@ -865,6 +1656,34 @@ contains !! Wrapper functions local to this module {{{1
C_string(n+1) = C_NULL_CHAR C_string(n+1) = C_NULL_CHAR
end function string2Cstring end function string2Cstring
!-----------------------------------------------------------------------------
pure function Cstrlen (Cstring) result (n)
character (len=1, kind=C_char), dimension(:), intent(in) :: Cstring
integer :: n, i
n = size(Cstring)
do i = 1, size(Cstring)
if ( Cstring(i) == C_NULL_CHAR ) then
n = i - 1
return
end if
end do
end function Cstrlen
!-----------------------------------------------------------------------------
pure function Cstring2string (Cstring) result (string)
!use, intrinsic :: ISO_C_binding, only : C_char, C_NULL_CHAR
character (len=1, kind=C_char), intent(in) :: Cstring (:)
character (len=Cstrlen(Cstring)) :: string
integer :: i, n
n = Cstrlen(Cstring)
string = ''
forall (i = 1:n)
string(i:i) = Cstring(i)
end forall
end function Cstring2string
!----------------------------------------------------------------------------- !-----------------------------------------------------------------------------
subroutine Cstring2argcargv (Cstring, argc, argv) subroutine Cstring2argcargv (Cstring, argc, argv)