From d3ed99c7f86efad995454c0a780a425df949e964 Mon Sep 17 00:00:00 2001 From: Karl Hammond Date: Fri, 28 Oct 2022 21:01:12 -0500 Subject: [PATCH] Optional arguments for find_*_neighlist --- doc/src/Fortran.rst | 16 ++++++++-------- fortran/lammps.f90 | 20 ++++++++++++++++---- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/doc/src/Fortran.rst b/doc/src/Fortran.rst index bda059432f..8e76955c6d 100644 --- a/doc/src/Fortran.rst +++ b/doc/src/Fortran.rst @@ -1553,7 +1553,7 @@ Procedures Bound to the :f:type:`lammps` Derived Type -------- -.. f:function:: find_fix_neighlist() +.. f:function:: find_fix_neighlist(id[, reqid]) Find index of a neighbor list requested by a fix. @@ -1564,15 +1564,15 @@ Procedures Bound to the :f:type:`lammps` Derived Type fixes with multiple neighbor list requests. :p character(len=\*) id: Identifier of fix instance - :p integer(c_int) reqid: request ID to identify the neighbor list in cases - in which there are multiple requests from the same fix. + :o integer(c_int) reqid: request ID to identify the neighbor list in cases + in which there are multiple requests from the same fix. Default: 0. :to: :cpp:func:`lammps_find_fix_neighlist` :r index: neighbor list index if found, otherwise :math:`-1` :rtype index: integer(c_int) -------- -.. f:function:: find_compute_neighlist() +.. f:function:: find_compute_neighlist(id[, reqid]) Find index of a neighbor list requested by a compute. @@ -1582,11 +1582,11 @@ Procedures Bound to the :f:type:`lammps` Derived Type the request ID. The request ID is typically zero, but will be :math:`> 0` in case a compute has multiple neighbor list requests. - :p character(len=\*) id: Identifier of compute instance - :p integer(c_int) reqid: request ID to identify the neighbor list in cases - in which there are multiple requests from the same compute + :p character(len=\*) id: Identifier of compute instance. + :o integer(c_int) reqid: request ID to identify the neighbor list in cases + in which there are multiple requests from the same compute. Default: 0. :to: :cpp:func:`lammps_find_compute_neighlist` - :r index: neighbor list index if found, otherwise :math:`-1` + :r index: neighbor list index if found, otherwise :math:`-1`. :rtype index: integer(c_int) -------- diff --git a/fortran/lammps.f90 b/fortran/lammps.f90 index ca065384b5..6899245ba3 100644 --- a/fortran/lammps.f90 +++ b/fortran/lammps.f90 @@ -1892,11 +1892,17 @@ CONTAINS INTEGER(c_int) FUNCTION lmp_find_fix_neighlist(self, id, reqid) RESULT(idx) CLASS(lammps), INTENT(IN) :: self CHARACTER(LEN=*), INTENT(IN) :: id - INTEGER(c_int), INTENT(IN) :: reqid + INTEGER(c_int), INTENT(IN), OPTIONAL :: reqid TYPE(c_ptr) :: Cid + INTEGER(c_int) :: Creqid + IF (PRESENT(reqid)) THEN + Creqid = reqid + ELSE + Creqid = 0_c_int + END IF Cid = f2c_string(id) - idx = lammps_find_fix_neighlist(self%handle, Cid, reqid) + idx = lammps_find_fix_neighlist(self%handle, Cid, Creqid) IF (idx < 0) THEN CALL lmp_error(self, LMP_ERROR_WARNING + LMP_ERROR_WORLD, & 'neighbor list not found [Fortran/find_fix_neighlist]') @@ -1909,11 +1915,17 @@ CONTAINS RESULT(idx) CLASS(lammps), INTENT(IN) :: self CHARACTER(LEN=*), INTENT(IN) :: id - INTEGER(c_int), INTENT(IN) :: reqid + INTEGER(c_int), INTENT(IN), OPTIONAL :: reqid TYPE(c_ptr) :: Cid + INTEGER(c_int) :: Creqid + IF (PRESENT(reqid)) THEN + Creqid = reqid + ELSE + Creqid = 0_c_int + END IF Cid = f2c_string(id) - idx = lammps_find_compute_neighlist(self%handle, Cid, reqid) + idx = lammps_find_compute_neighlist(self%handle, Cid, Creqid) IF (idx < 0) THEN CALL lmp_error(self, LMP_ERROR_WARNING + LMP_ERROR_WORLD, & 'neighbor list not found [Fortran/find_compute_neighlist]')