swap rows/cols for less confusion

This commit is contained in:
Axel Kohlmeyer
2024-08-30 23:16:37 -04:00
parent b426556632
commit 0cdf8f2658
2 changed files with 8 additions and 10 deletions

View File

@ -1469,9 +1469,8 @@ CONTAINS
ntypes = lmp_extract_setting(self, 'ntypes') ntypes = lmp_extract_setting(self, 'ntypes')
Cname = f2c_string(name) Cname = f2c_string(name)
datatype = lammps_extract_atom_datatype(self%handle, Cname) datatype = lammps_extract_atom_datatype(self%handle, Cname)
! Fortran and C/C++ have rows and columns switched nrows = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_ROWS)
ncols = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_ROWS) ncols = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_COLS)
nrows = lammps_extract_atom_size(self%handle, Cname, LMP_SIZE_COLS)
Cptr = lammps_extract_atom(self%handle, Cname) Cptr = lammps_extract_atom(self%handle, Cname)
CALL lammps_free(Cname) CALL lammps_free(Cname)
@ -1479,25 +1478,25 @@ CONTAINS
SELECT CASE (datatype) SELECT CASE (datatype)
CASE (LAMMPS_INT) CASE (LAMMPS_INT)
peratom_data%datatype = DATA_INT_1D peratom_data%datatype = DATA_INT_1D
CALL C_F_POINTER(Cptr, peratom_data%i32_vec, [ncols]) CALL C_F_POINTER(Cptr, peratom_data%i32_vec, [nrows])
CASE (LAMMPS_INT64) CASE (LAMMPS_INT64)
peratom_data%datatype = DATA_INT64_1D peratom_data%datatype = DATA_INT64_1D
CALL C_F_POINTER(Cptr, peratom_data%i64_vec, [ncols]) CALL C_F_POINTER(Cptr, peratom_data%i64_vec, [nrows])
CASE (LAMMPS_DOUBLE) CASE (LAMMPS_DOUBLE)
peratom_data%datatype = DATA_DOUBLE_1D peratom_data%datatype = DATA_DOUBLE_1D
! The mass array is allocated from 0, but only used from 1. We also want to use it from 1. ! The mass array is allocated from 0, but only used from 1. We also want to use it from 1.
IF (name == 'mass') THEN IF (name == 'mass') THEN
CALL C_F_POINTER(Cptr, dummy, [ncols]) CALL C_F_POINTER(Cptr, dummy, [nrows])
peratom_data%r64_vec(0:) => dummy peratom_data%r64_vec(0:) => dummy
ELSE ELSE
CALL C_F_POINTER(Cptr, peratom_data%r64_vec, [ncols]) CALL C_F_POINTER(Cptr, peratom_data%r64_vec, [nrows])
END IF END IF
CASE (LAMMPS_DOUBLE_2D) CASE (LAMMPS_DOUBLE_2D)
peratom_data%datatype = DATA_DOUBLE_2D peratom_data%datatype = DATA_DOUBLE_2D
! First, we dereference the void** pointer to point to the void* ! First, we dereference the void** pointer to point to the void*
CALL C_F_POINTER(Cptr, Catomptr, [ncols]) CALL C_F_POINTER(Cptr, Catomptr, [nrows])
! Catomptr(1) now points to the first element of the array ! Catomptr(1) now points to the first element of the array
CALL C_F_POINTER(Catomptr(1), peratom_data%r64_mat, [nrows,ncols]) CALL C_F_POINTER(Catomptr(1), peratom_data%r64_mat, [ncols,nrows])
CASE (-1) CASE (-1)
CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, & CALL lmp_error(self, LMP_ERROR_ALL + LMP_ERROR_WORLD, &
'per-atom property ' // name // ' not found in extract_setting') 'per-atom property ' // name // ' not found in extract_setting')

View File

@ -2557,4 +2557,3 @@ class lammps(object):
# Local Variables: # Local Variables:
# fill-column: 80 # fill-column: 80
# End: # End: