Fix the behavior of the code for electric field and copy to GPU, as the...

Fix the behavior of the code for electric field and copy to GPU, as the previous commit was introducing a wrong behavior in the code.
parent 63f0ccbd
Pipeline #147438631 failed with stage
in 0 seconds
......@@ -817,7 +817,7 @@ contains
call hamiltonian_elec_base_allocate(this%hm_base, mesh, FIELD_POTENTIAL, &
complex_potential = this%bc%abtype == IMAGINARY_ABSORBING)
call hamiltonian_elec_update_pot(this, mesh)
call hamiltonian_elec_update_pot(this, mesh, accel_copy=.false.)
! the lasers
if (present(time) .or. this%time_zero) then
......@@ -881,6 +881,9 @@ contains
end do
end if
!The electric field was added to the KS potential
call hamiltonian_elec_base_accel_copy(this%hm_base, mesh)
! and the static magnetic field
if(associated(this%ep%b_field)) then
call hamiltonian_elec_base_allocate(this%hm_base, mesh, FIELD_UNIFORM_MAGNETIC_FIELD, .false.)
......@@ -1021,9 +1024,10 @@ contains
!----------------------------------------------------------------
! Update the KS potential of the electronic Hamiltonian
subroutine hamiltonian_elec_update_pot(this, mesh)
subroutine hamiltonian_elec_update_pot(this, mesh, accel_copy)
type(hamiltonian_elec_t), intent(inout) :: this
type(mesh_t), intent(in) :: mesh
logical, intent(in) :: accel_copy
integer :: ispin, ip, offset
......@@ -1071,12 +1075,8 @@ contains
end do
if(allocated(this%hm_base%potential) .and. accel_is_enabled()) then
offset = 0
do ispin = 1, this%d%nspin
call accel_write_buffer(this%hm_base%potential_opencl, mesh%np, this%hm_base%potential(:, ispin), offset = offset)
offset = offset + accel_padded_size(mesh%np)
end do
if(accel_copy) then
call hamiltonian_elec_base_accel_copy(this%hm_base, mesh)
end if
POP_SUB(hamiltonian_elec_update_pot)
......@@ -1370,7 +1370,7 @@ contains
call hamiltonian_elec_base_allocate(this%hm_base, mesh, FIELD_POTENTIAL, &
complex_potential = this%bc%abtype == IMAGINARY_ABSORBING)
call hamiltonian_elec_update_pot(this, mesh)
call hamiltonian_elec_update_pot(this, mesh, accel_copy=.false.)
do itime = 1, 2
time_ = time(itime)
......@@ -1441,6 +1441,9 @@ contains
end do
end if
!The electric field is added to the KS potential
call hamiltonian_elec_base_accel_copy(this%hm_base, mesh)
! and the static magnetic field
if(associated(this%ep%b_field)) then
call hamiltonian_elec_base_allocate(this%hm_base, mesh, FIELD_UNIFORM_MAGNETIC_FIELD, .false.)
......
......@@ -75,6 +75,7 @@ module hamiltonian_elec_base_oct_m
hamiltonian_elec_base_clear, &
hamiltonian_elec_base_build_proj, &
hamiltonian_elec_base_update, &
hamiltonian_elec_base_accel_copy, &
dhamiltonian_elec_base_phase, &
zhamiltonian_elec_base_phase, &
dhamiltonian_elec_base_phase_spiral, &
......@@ -112,7 +113,7 @@ module hamiltonian_elec_base_oct_m
integer, allocatable, public :: projector_to_atom(:)
integer :: nregions
integer, allocatable :: regions(:)
type(accel_mem_t) , public :: potential_opencl
type(accel_mem_t) :: potential_opencl
type(accel_mem_t) :: buff_offsets
type(accel_mem_t) :: buff_matrices
type(accel_mem_t) :: buff_maps
......@@ -301,6 +302,29 @@ contains
POP_SUB(hamiltonian_elec_base_update)
end subroutine hamiltonian_elec_base_update
!--------------------------------------------------------
subroutine hamiltonian_elec_base_accel_copy(this, mesh)
type(hamiltonian_elec_base_t), intent(inout) :: this
type(mesh_t), intent(in) :: mesh
integer :: offset, ispin
PUSH_SUB(hamiltonian_elec_base_accel_copy)
if(allocated(this%potential) .and. accel_is_enabled()) then
offset = 0
do ispin = 1, this%nspin
call accel_write_buffer(this%potential_opencl, mesh%np, this%potential(:, ispin), offset = offset)
offset = offset + accel_padded_size(mesh%np)
end do
end if
POP_SUB(hamiltonian_elec_base_accel_copy)
end subroutine hamiltonian_elec_base_accel_copy
!--------------------------------------------------------
......
......@@ -883,7 +883,7 @@ contains
call mixing(scf%smix)
call mixfield_get_vnew(scf%mixfield, hm%vhxc)
call lda_u_mixer_get_vnew(hm%lda_u, scf%lda_u_mix, st)
call hamiltonian_elec_update_pot(hm, gr%mesh)
call hamiltonian_elec_update_pot(hm, gr%mesh, accel_copy=.true.)
case(OPTION__MIXFIELD__STATES)
......
......@@ -1239,7 +1239,7 @@ contains
if(ks%calc%time_present .or. hm%time_zero) then
call hamiltonian_elec_update(hm, ks%gr%mesh, namespace, time = ks%calc%time)
else
call hamiltonian_elec_update_pot(hm, ks%gr%mesh)
call hamiltonian_elec_update_pot(hm, ks%gr%mesh, accel_copy=.true.)
end if
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment