!===============================================================================
!
! w_mult.F90  -  W := M~ + rho (Hasenbusch improvement)
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2006-2008 Yoshifumi Nakamura
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! BQCD is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------
# include "defs.h"
 
!-------------------------------------------------------------------------------
subroutine wdagw_r8(out, in, id)  ! out = (W+ W) in
  use module_vol
  use module_p_interface
  implicit none
  SPINCOL_FIELD, intent(out) :: out
  SPINCOL_FIELD, intent(in)  :: in
  P_SPINCOL_FIELD, save :: tmp
  integer,intent(in) :: id

  TIMING_START(timing_bin_mtdagmt)
  ALLOCATE_SC_FIELD(tmp)
  call wmul_r8(tmp(1,1,1), in,  id)
  call wdag_r8(out, tmp(1,1,1), id)
  TIMING_STOP(timing_bin_mtdagmt)
end

!-------------------------------------------------------------------------------
subroutine wmul_r8(out, in, id)  ! out = W in
  use module_vol
  use module_action
  implicit none
  integer,intent(in) :: id
  SPINCOL_FIELD, intent(out) :: out
  SPINCOL_FIELD, intent(in)  :: in
  REAL :: rho

  call mtil_r8(out, in, id)
  if(action%mtilde(id)%rho /= ZERO) then
     rho = action%mtilde(id)%rho
     call sc_axpy(out, in, rho)
  endif
end

!-------------------------------------------------------------------------------
subroutine wdag_r8(out, in, id)  ! out = W in
  use module_vol
  use module_action
  implicit none
  integer,intent(in) :: id
  SPINCOL_FIELD, intent(out) :: out
  SPINCOL_FIELD, intent(in)  :: in
  REAL :: rho

  call mtil_dag_r8(out, in, id)
  if(action%mtilde(id)%rho /= ZERO) then
     rho = action%mtilde(id)%rho
     call sc_axpy(out, in, rho)
  endif
end

!===============================================================================
