mirror of https://github.com/phonopy/phono3py.git
Update of fortran wrapper
This commit is contained in:
parent
e8cb099ae2
commit
c52857468b
|
@ -192,7 +192,7 @@ long gridsys_get_triplets_at_q(long *map_triplets, long *map_q,
|
|||
rec_rotations, swappable);
|
||||
}
|
||||
|
||||
long gridsys_get_BZ_triplets_at_q(long (*triplets)[3], const long grid_point,
|
||||
long gridsys_get_bz_triplets_at_q(long (*triplets)[3], const long grid_point,
|
||||
const long (*bz_grid_addresses)[3],
|
||||
const long *bz_map, const long *map_triplets,
|
||||
const long num_map_triplets,
|
||||
|
|
|
@ -274,7 +274,7 @@ long gridsys_get_triplets_at_q(long *map_triplets, long *map_q,
|
|||
* dense, recommended) of bz_map
|
||||
* @return long
|
||||
*/
|
||||
long gridsys_get_BZ_triplets_at_q(long (*triplets)[3], const long grid_point,
|
||||
long gridsys_get_bz_triplets_at_q(long (*triplets)[3], const long grid_point,
|
||||
const long (*bz_grid_addresses)[3],
|
||||
const long *bz_map, const long *map_triplets,
|
||||
const long num_map_triplets,
|
||||
|
|
|
@ -20,8 +20,8 @@ if(NOT GTest_FOUND)
|
|||
# cmake-lint: disable=C0301
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz
|
||||
URL_HASH MD5=e82199374acdfda3f425331028eb4e2a)
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a)
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
program test_gridsysf
|
||||
use, intrinsic :: iso_c_binding
|
||||
use gridsysf, only: gridsys_get_bz_grid_addresses
|
||||
use gridsysf, only: &
|
||||
gridsys_get_bz_grid_addresses, &
|
||||
gridsys_get_triplets_at_q
|
||||
implicit none
|
||||
|
||||
integer(c_long) :: wurtzite_rec_rotations_without_time_reversal(3, 3, 12)
|
||||
|
||||
wurtzite_rec_rotations_without_time_reversal(:, :, :) = &
|
||||
reshape([1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, -1, 0, 0, 0, 0, 1, &
|
||||
0, 1, 0, -1, -1, 0, 0, 0, 1, -1, 0, 0, 0, -1, 0, 0, 0, 1, &
|
||||
-1, -1, 0, 1, 0, 0, 0, 0, 1, 0, -1, 0, 1, 1, 0, 0, 0, 1, &
|
||||
0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, -1, 0, 0, 0, 1, &
|
||||
1, 0, 0, -1, -1, 0, 0, 0, 1, 0, -1, 0, -1, 0, 0, 0, 0, 1, &
|
||||
-1, -1, 0, 0, 1, 0, 0, 0, 1, -1, 0, 0, 1, 1, 0, 0, 0, 1], [3, 3, 12])
|
||||
|
||||
write (*, '("[test_gridsys_get_bz_grid_addresses]")')
|
||||
call test_gridsys_get_bz_grid_addresses()
|
||||
write (*, '("[test_gridsys_get_triplets_at_q]")')
|
||||
call test_gridsys_get_triplets_at_q()
|
||||
|
||||
contains
|
||||
subroutine test_gridsys_get_bz_grid_addresses() bind(C)
|
||||
|
@ -14,12 +28,12 @@ contains
|
|||
real(c_double) :: rec_lattice(3, 3)
|
||||
integer :: i, j
|
||||
|
||||
integer :: ref_bz_addresses(3, 93)
|
||||
integer :: ref_bz_map(76)
|
||||
integer :: ref_bzg2grg(93)
|
||||
integer(c_long) :: ref_bz_grid_addresses(3, 93)
|
||||
integer(c_long) :: ref_bz_map(76)
|
||||
integer(c_long) :: ref_bzg2grg(93)
|
||||
|
||||
ref_bz_addresses(:, :) = reshape([ &
|
||||
0, 0, 0, 1, 0, 0, 2, 0, 0, -2, 0, 0, -1, 0, 0, &
|
||||
ref_bz_grid_addresses(:, :) = &
|
||||
reshape([0, 0, 0, 1, 0, 0, 2, 0, 0, -2, 0, 0, -1, 0, 0, &
|
||||
0, 1, 0, 1, 1, 0, 2, 1, 0, -3, 1, 0, -2, 1, 0, &
|
||||
-1, 1, 0, 0, 2, 0, 1, 2, 0, 1, -3, 0, 2, -3, 0, &
|
||||
-3, 2, 0, -2, 2, 0, -1, 2, 0, 0, -2, 0, 1, -2, 0, &
|
||||
|
@ -42,7 +56,8 @@ contains
|
|||
17, 18, 19, 20, 21, 23, 25, 26, 27, 28, 30, 31, 32, 33, &
|
||||
34, 35, 36, 37, 38, 40, 41, 42, 43, 45, 47, 48, 49, 50, &
|
||||
51, 52, 54, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, &
|
||||
68, 69, 71, 72, 73, 74, 76, 78, 79, 80, 81, 82, 83, 85, 87, 88, 89, 90, 92, 93]
|
||||
68, 69, 71, 72, 73, 74, 76, 78, 79, 80, 81, 82, 83, 85, &
|
||||
87, 88, 89, 90, 92, 93]
|
||||
ref_bzg2grg(:) = [ &
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11, 12, 12, &
|
||||
13, 14, 15, 16, 17, 18, 18, 19, 19, 20, 21, 22, 23, 23, 24, 25, &
|
||||
|
@ -61,36 +76,123 @@ contains
|
|||
bz_size = gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, &
|
||||
D_diag, Q, PS, rec_lattice, int(2, c_long))
|
||||
|
||||
! check bz_grid_addresses
|
||||
write (*, '("check bz_grid_addresses")', advance='no')
|
||||
do i = 1, 93
|
||||
do j = 1, 3
|
||||
if (bz_grid_addresses(j, i) /= ref_bz_addresses(j, i)) then
|
||||
print '("(", i0, ",", i0, "):", i0, " ", i0)', i, j, bz_grid_addresses(j, i), ref_bz_addresses(j, i)
|
||||
error stop
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
call assert_2D_array_c_long(bz_grid_addresses, ref_bz_grid_addresses, &
|
||||
shape(ref_bz_grid_addresses))
|
||||
write (*, '(" OK")')
|
||||
|
||||
! check bz_map
|
||||
write (*, '("check bz_map")', advance='no')
|
||||
do i = 1, 76
|
||||
if (bz_map(i) /= ref_bz_map(i)) then
|
||||
print '(i0, ":", i0, " ", i0)', i, bz_map(i), ref_bz_map(i)
|
||||
error stop
|
||||
end if
|
||||
end do
|
||||
call assert_1D_array_c_long(bz_map, ref_bz_map, 76)
|
||||
write (*, '(" OK")')
|
||||
|
||||
! check bz_map
|
||||
write (*, '("check bzg2grg")', advance='no')
|
||||
do i = 1, 93
|
||||
if (bzg2grg(i) /= ref_bzg2grg(i)) then
|
||||
print '(i0, ":", i0, " ", i0)', i, bzg2grg(i), ref_bzg2grg(i)
|
||||
error stop
|
||||
end if
|
||||
end do
|
||||
call assert_1D_array_c_long(bzg2grg, ref_bzg2grg, 93)
|
||||
write (*, '(" OK")')
|
||||
end subroutine test_gridsys_get_bz_grid_addresses
|
||||
|
||||
subroutine test_gridsys_get_triplets_at_q() bind(C)
|
||||
integer(c_long) :: D_diag(3)
|
||||
integer(c_long) :: map_triplets(36), map_q(36)
|
||||
integer(c_long) :: rec_rotations(3, 3, 12)
|
||||
integer(c_long) :: grid_point, is_time_reversal, num_rot, swappable
|
||||
integer :: i, j, k, n_ir_triplets
|
||||
|
||||
integer :: ref_num_triplets(4)
|
||||
integer(c_long) :: ref_map_triplets(36, 4), ref_map_q(36, 4)
|
||||
|
||||
grid_point = 1
|
||||
D_diag(:) = [3, 3, 4]
|
||||
num_rot = 12
|
||||
ref_num_triplets(:) = [12, 18, 14, 24]
|
||||
ref_map_triplets(:, :) = &
|
||||
reshape([ &
|
||||
0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 9, 12, 12, 14, 14, 12, 12, &
|
||||
18, 19, 18, 21, 21, 23, 23, 21, 21, 9, 10, 9, 12, 12, 14, 14, 12, 12, &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
0, 1, 0, 3, 3, 5, 5, 3, 3, 9, 10, 11, &
|
||||
12, 13, 14, 14, 12, 13, 18, 19, 18, 21, 21, 23, &
|
||||
23, 21, 21, 11, 10, 9, 13, 12, 14, 14, 13, 12, &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, &
|
||||
12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, &
|
||||
23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31 &
|
||||
], [36, 4])
|
||||
ref_map_q(:, :) = &
|
||||
reshape([ &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
18, 19, 20, 21, 22, 23, 23, 21, 22, 9, 10, 11, 12, 13, 14, 14, 12, 13, &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, &
|
||||
12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, &
|
||||
23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31, &
|
||||
0, 1, 2, 3, 4, 5, 5, 3, 4, 9, 10, 11, &
|
||||
12, 13, 14, 14, 12, 13, 18, 19, 20, 21, 22, 23, &
|
||||
23, 21, 22, 27, 28, 29, 30, 31, 32, 32, 30, 31], &
|
||||
[36, 4])
|
||||
|
||||
k = 1
|
||||
do i = 0, 1
|
||||
do j = 0, 1
|
||||
is_time_reversal = 1 - i
|
||||
swappable = 1 - j
|
||||
n_ir_triplets = gridsys_get_triplets_at_q( &
|
||||
map_triplets, map_q, grid_point, &
|
||||
D_diag, is_time_reversal, num_rot, &
|
||||
wurtzite_rec_rotations_without_time_reversal, &
|
||||
swappable)
|
||||
|
||||
call assert_int(n_ir_triplets, ref_num_triplets(k))
|
||||
write (*, '("check map_triplets")', advance='no')
|
||||
call assert_1D_array_c_long(map_triplets, ref_map_triplets(:, k), 36)
|
||||
write (*, '(" OK")')
|
||||
write (*, '("check map_q")', advance='no')
|
||||
call assert_1D_array_c_long(map_q, ref_map_q(:, k), 36)
|
||||
write (*, '(" OK")')
|
||||
k = k + 1
|
||||
end do
|
||||
end do
|
||||
end subroutine test_gridsys_get_triplets_at_q
|
||||
|
||||
subroutine assert_int(val, ref_val)
|
||||
integer, intent(in) :: val, ref_val
|
||||
if (val /= ref_val) then
|
||||
print '()'
|
||||
print '(i0, "/=", i0)', val, ref_val
|
||||
error stop
|
||||
end if
|
||||
end subroutine assert_int
|
||||
|
||||
subroutine assert_1D_array_c_long(vals, ref_vals, size_of_array)
|
||||
integer(c_long), intent(in) :: vals(:)
|
||||
integer(c_long), intent(in) :: ref_vals(:)
|
||||
integer, intent(in) :: size_of_array
|
||||
integer :: i
|
||||
|
||||
do i = 1, size_of_array
|
||||
if (vals(i) /= ref_vals(i)) then
|
||||
print '()'
|
||||
print '(i0, ":", i0, " ", i0)', i, vals(i), ref_vals(i)
|
||||
error stop
|
||||
end if
|
||||
end do
|
||||
end subroutine assert_1D_array_c_long
|
||||
|
||||
subroutine assert_2D_array_c_long(vals, ref_vals, shape_of_array)
|
||||
integer(c_long), intent(in) :: vals(:, :)
|
||||
integer(c_long), intent(in) :: ref_vals(:, :)
|
||||
integer, intent(in) :: shape_of_array(:)
|
||||
integer :: i, j
|
||||
|
||||
do i = 1, shape_of_array(1)
|
||||
do j = 1, shape_of_array(2)
|
||||
if (vals(j, i) /= ref_vals(j, i)) then
|
||||
print '()'
|
||||
print '("(", i0, ",", i0, "):", i0, " ", i0)', i, j, vals(j, i), ref_vals(j, i)
|
||||
error stop
|
||||
end if
|
||||
end do
|
||||
end do
|
||||
end subroutine assert_2D_array_c_long
|
||||
|
||||
end program test_gridsysf
|
||||
|
|
|
@ -983,7 +983,7 @@ TEST(test_gridsys, test_gridsys_get_triplets_at_q_wurtzite_force_SNF) {
|
|||
* The lattices generated with and without force_SNF are the same.
|
||||
* Therefore numbers of unique triplets should agree, which is this test.
|
||||
*/
|
||||
TEST(test_gridsys, test_gridsys_get_BZ_triplets_at_q_wurtzite_force_SNF) {
|
||||
TEST(test_gridsys, test_gridsys_get_bz_triplets_at_q_wurtzite_force_SNF) {
|
||||
long D_diag[2][3] = {{1, 5, 15}, {5, 5, 3}};
|
||||
long PS[3] = {0, 0, 0};
|
||||
long Q[2][3][3] = {{{-1, 0, -6}, {0, -1, 0}, {-1, 0, -5}},
|
||||
|
@ -1030,7 +1030,7 @@ TEST(test_gridsys, test_gridsys_get_BZ_triplets_at_q_wurtzite_force_SNF) {
|
|||
num_triplets_1 = gridsys_get_triplets_at_q(
|
||||
map_triplets, map_q, grid_point, D_diag[i],
|
||||
is_time_reversal[k], 12, rec_rotations[i], swappable[j]);
|
||||
num_triplets_2 = gridsys_get_BZ_triplets_at_q(
|
||||
num_triplets_2 = gridsys_get_bz_triplets_at_q(
|
||||
triplets, grid_point, bz_grid_addresses, bz_map,
|
||||
map_triplets, 75, D_diag[i], Q[i], 2);
|
||||
ASSERT_EQ(num_triplets_1, num_triplets_2);
|
||||
|
|
|
@ -48,7 +48,6 @@ module gridsysf
|
|||
integer(c_long), intent(inout) :: gr_grid_addresses(3, *)
|
||||
end subroutine gridsys_get_all_grid_addresses
|
||||
|
||||
|
||||
subroutine gridsys_get_double_grid_address(address_double, address, &
|
||||
PS) bind(c)
|
||||
import c_long
|
||||
|
@ -57,7 +56,6 @@ module gridsysf
|
|||
integer(c_long), intent(in) :: PS(3)
|
||||
end subroutine gridsys_get_double_grid_address
|
||||
|
||||
|
||||
subroutine gridsys_get_grid_address_from_index(address, grid_index, D_diag) &
|
||||
bind(c)
|
||||
import c_long
|
||||
|
@ -66,7 +64,6 @@ module gridsysf
|
|||
integer(c_long), intent(in) :: D_diag(3)
|
||||
end subroutine gridsys_get_grid_address_from_index
|
||||
|
||||
|
||||
function gridsys_rotate_grid_index(grid_index, rotation, D_diag, PS) &
|
||||
bind(c)
|
||||
import c_long
|
||||
|
@ -77,7 +74,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_rotate_grid_index
|
||||
end function gridsys_rotate_grid_index
|
||||
|
||||
|
||||
function gridsys_get_double_grid_index(address_double, D_diag, PS) bind(c)
|
||||
import c_long
|
||||
integer(c_long), intent(in) :: address_double(3)
|
||||
|
@ -86,7 +82,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_get_double_grid_index
|
||||
end function gridsys_get_double_grid_index
|
||||
|
||||
|
||||
function gridsys_get_reciprocal_point_group(rec_rotations, rotations, &
|
||||
num_rot, is_time_reversal) bind(c)
|
||||
import c_long
|
||||
|
@ -97,7 +92,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_get_reciprocal_point_group
|
||||
end function gridsys_get_reciprocal_point_group
|
||||
|
||||
|
||||
function gridsys_get_snf3x3(D_diag, P, Q, A) bind(c)
|
||||
import c_long
|
||||
integer(c_long), intent(inout) :: D_diag(3)
|
||||
|
@ -107,7 +101,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_get_snf3x3
|
||||
end function gridsys_get_snf3x3
|
||||
|
||||
|
||||
function gridsys_transform_rotations(transformed_rots, &
|
||||
rotations, num_rot, D_diag, Q) bind(c)
|
||||
import c_long
|
||||
|
@ -119,7 +112,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_transform_rotations
|
||||
end function gridsys_transform_rotations
|
||||
|
||||
|
||||
function gridsys_get_thm_integration_weight(omega, &
|
||||
tetrahedra_omegas, function_char) bind(c)
|
||||
import c_char, c_double
|
||||
|
@ -129,7 +121,6 @@ module gridsysf
|
|||
real(c_double) :: gridsys_get_thm_integration_weight
|
||||
end function gridsys_get_thm_integration_weight
|
||||
|
||||
|
||||
subroutine gridsys_get_thm_relative_grid_address(relative_grid_addresses, &
|
||||
rec_lattice) bind(c)
|
||||
import c_long, c_double
|
||||
|
@ -137,7 +128,6 @@ module gridsysf
|
|||
real(c_double), intent(in) :: rec_lattice(3, 3)
|
||||
end subroutine gridsys_get_thm_relative_grid_address
|
||||
|
||||
|
||||
subroutine gridsys_get_ir_grid_map(ir_grid_map, rotations, num_rot, &
|
||||
D_diag, PS) bind(c)
|
||||
import c_long
|
||||
|
@ -148,7 +138,6 @@ module gridsysf
|
|||
integer(c_long), intent(in) :: PS(3)
|
||||
end subroutine gridsys_get_ir_grid_map
|
||||
|
||||
|
||||
function gridsys_get_bz_grid_addresses(bz_grid_addresses, bz_map, &
|
||||
bzg2grg, D_diag, Q, PS, rec_lattice, type) bind(c)
|
||||
import c_long, c_double
|
||||
|
@ -163,7 +152,6 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_get_bz_grid_addresses
|
||||
end function gridsys_get_bz_grid_addresses
|
||||
|
||||
|
||||
function gridsys_get_triplets_at_q(map_triplets, map_q, grid_point, &
|
||||
D_diag, is_time_reversal, num_rot, rec_rotations, swappable) bind(c)
|
||||
import c_long
|
||||
|
@ -178,8 +166,22 @@ module gridsysf
|
|||
integer(c_long) :: gridsys_get_triplets_at_q
|
||||
end function gridsys_get_triplets_at_q
|
||||
|
||||
end interface
|
||||
function gridsys_get_bz_triplets_at_q(triplets, grid_point, bz_grid_addresses, &
|
||||
bz_map, map_triplets, num_map_triplets, D_diag, Q, bz_grid_type) bind(c)
|
||||
import c_long
|
||||
integer(c_long), intent(inout) :: triplets(3, *)
|
||||
integer(c_long), intent(in), value :: grid_point
|
||||
integer(c_long), intent(in) :: bz_grid_addresses(3, *)
|
||||
integer(c_long), intent(in) :: bz_map(*)
|
||||
integer(c_long), intent(in) :: map_triplets(*)
|
||||
integer(c_long), intent(in), value :: num_map_triplets
|
||||
integer(c_long), intent(in) :: D_diag(3)
|
||||
integer(c_long), intent(in) :: Q(3, 3)
|
||||
integer(c_long), intent(in), value :: bz_grid_type
|
||||
integer(c_long) :: gridsys_get_bz_triplets_at_q
|
||||
end function gridsys_get_bz_triplets_at_q
|
||||
|
||||
end interface
|
||||
|
||||
public :: gridsys_get_all_grid_addresses, &
|
||||
gridsys_get_double_grid_address, &
|
||||
|
@ -193,6 +195,7 @@ module gridsysf
|
|||
gridsys_get_thm_integration_weight, &
|
||||
gridsys_get_ir_grid_map, &
|
||||
gridsys_get_bz_grid_addresses, &
|
||||
gridsys_get_triplets_at_q
|
||||
gridsys_get_triplets_at_q, &
|
||||
gridsys_get_bz_triplets_at_q
|
||||
|
||||
end module gridsysf
|
||||
|
|
Loading…
Reference in New Issue