Skip to content

Commit

Permalink
[WIP] Fix demo.F90
Browse files Browse the repository at this point in the history
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Feb 22, 2024
1 parent af05b60 commit 1167f3c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion test-suite/libv2-demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set_property(DIRECTORY APPEND
)

set(test_names
lib-gas-opt-pllel
lib-gas-opt
libc-gas-mix-serial
libc-gas-mix-serial-clash
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ project(demo_Wannier90 LANGUAGES Fortran)

find_package(Wannier90 REQUIRED)

add_executable(demo demo.f90)
add_executable(demo demo.F90)
if (Wannier90_MPI)
target_compile_definitions(demo PRIVATE Wannier90_MPI)
endif ()
target_link_libraries(demo PRIVATE Wannier90::wannier90)
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
program ok
#ifdef Wannier90_MPI
use mpi_f08
#endif
use w90_library

implicit none
Expand All @@ -18,6 +20,11 @@ program ok
real(8) :: uccart(3, 3) ! cartesian unit cell
type(lib_common_type), target :: w90main

#ifndef Wannier90_MPI
! MPI dummy
integer :: mpi_comm_world = 0
#endif

! collect data
nb = 12
nw = 8
Expand Down Expand Up @@ -58,10 +65,12 @@ program ok
enddo
enddo

#ifdef Wannier90_MPI
! setup MPI
call mpi_init(ierr)
call mpi_comm_size(mpi_comm_world, mpisize, ierr)
call mpi_comm_rank(mpi_comm_world, mpirank, ierr)
#endif

! crude k distribution
allocate (distk(nk))
Expand All @@ -73,57 +82,60 @@ program ok

! wannier interface starts
! stdout/err
call get_fortran_stdout(stdout)
call get_fortran_stderr(stderr)
call w90_get_fortran_stdout(stdout)
call w90_get_fortran_stderr(stderr)

! required settings
call set_option(w90main, 'kpoints', kpt)
call set_option(w90main, 'mp_grid', nkabc)
call set_option(w90main, 'num_bands', nb)
call set_option(w90main, 'num_kpts', nk)
call set_option(w90main, 'num_wann', nw)
call set_option(w90main, 'unit_cell_cart', uccart)
call w90_set_option(w90main, 'kpoints', kpt)
call w90_set_option(w90main, 'mp_grid', nkabc)
call w90_set_option(w90main, 'num_bands', nb)
call w90_set_option(w90main, 'num_kpts', nk)
call w90_set_option(w90main, 'num_wann', nw)
call w90_set_option(w90main, 'unit_cell_cart', uccart)

! optional settings
call set_option(w90main, 'conv_tol', 1.d-13)
call set_option(w90main, 'conv_window', 3)
call set_option(w90main, 'dis_froz_max', 14.0d0)
call set_option(w90main, 'dis_mix_ratio', 1.d0)
call set_option(w90main, 'dis_num_iter', 1200)
call set_option(w90main, 'distk', distk)
call set_option(w90main, 'dis_win_max', 24.d0)
call set_option(w90main, 'exclude_bands', exclude)
call set_option(w90main, 'fixed_step', 50.d0)
call set_option(w90main, 'iprint', 0)
call set_option(w90main, 'num_iter', 1000)

call input_setopt(w90main, 'gaas', mpi_comm_world, stdout, stderr, ierr) ! apply settings

call get_nn(w90main, nn, stdout, stderr, ierr);
call w90_set_option(w90main, 'conv_tol', 1.d-13)
call w90_set_option(w90main, 'conv_window', 3)
call w90_set_option(w90main, 'dis_froz_max', 14.0d0)
call w90_set_option(w90main, 'dis_mix_ratio', 1.d0)
call w90_set_option(w90main, 'dis_num_iter', 1200)
call w90_set_option(w90main, 'distk', distk)
call w90_set_option(w90main, 'dis_win_max', 24.d0)
call w90_set_option(w90main, 'exclude_bands', exclude)
call w90_set_option(w90main, 'fixed_step', 50.d0)
call w90_set_option(w90main, 'iprint', 0)
call w90_set_option(w90main, 'num_iter', 1000)

call w90_input_setopt(w90main, 'gaas', mpi_comm_world, stdout, stderr, ierr) ! apply settings

call w90_get_nn(w90main, nn, stdout, stderr, ierr);
allocate (nnkp(nk, nn))
call get_nnkp(w90main, nnkp, stdout, stderr, ierr);
call w90_get_nnkp(w90main, nnkp, stdout, stderr, ierr);
allocate (m_matrix(nb, nb, nn, nk))
allocate (u_matrix_opt(nb, nw, nk))
call set_m_local(w90main, m_matrix) ! m_matrix_local_orig
call set_u_opt(w90main, u_matrix_opt)
call w90_set_m_local(w90main, m_matrix) ! m_matrix_local_orig
call w90_set_u_opt(w90main, u_matrix_opt)

! read from ".mmn" and ".amn"
! and assign to m and a (now called u)
! a dft code would calculate the overlaps here instead
call overlaps(w90main, stdout, stderr, ierr)
! TODO: Correct this reference
! call overlaps(w90main, stdout, stderr, ierr)

! final u matrix
allocate (u_matrix(nw, nw, nk))
call set_u_matrix(w90main, u_matrix)
call w90_set_u_matrix(w90main, u_matrix)

call set_eigval(w90main, eval)
call disentangle(w90main, stdout, stderr, ierr)
call wannierise(w90main, stdout, stderr, ierr)
call w90_set_eigval(w90main, eval)
call w90_disentangle(w90main, stdout, stderr, ierr)
call w90_wannierise(w90main, stdout, stderr, ierr)

if (mpirank == 0) then
do ib = 1, nw
write (stdout, '(4f20.10)') (w90main%wannier_data%centres(ic, ib), ic=1, 3), w90main%wannier_data%spreads(ib)
enddo
endif
#ifdef Wannier90_MPI
call mpi_finalize()
#endif
end program
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ XLIBS=$(ROOT)/libwan2.a
a.out: demo.o
$(MPIF90) demo.o $(LIBS) $(XLIBS)
demo.o: demo.f90
$(MPIF90) $(FCOPTS) $(XINCS) -c $<
$(MPIF90) $(FCOPTS) -DWannier90_MPI $(XINCS) -c $<

0 comments on commit 1167f3c

Please sign in to comment.