!===============================================================================
!
! module_action.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 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/>.
!
!-------------------------------------------------------------------------------
! Added extra indices to accomodate PF and tRHMC
!
! Author: Taylor Haar
! Last modified: 17/03/2017
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
module module_action_type
  use typedef

  type :: type_plaq
     integer :: aid ! action    id
     integer :: fid ! force     id
     integer :: sid ! smearing  id
     REAL    :: beta
  end type type_plaq

  type :: type_impg
     integer :: aid ! action    id
     integer :: fid ! force     id
     integer :: sid ! smearing  id
     REAL    :: beta1, beta2, beta3
  end type type_impg

  type :: type_mtilde
     integer :: cid ! clover    id
     integer :: did ! dslash    id
     REAL :: rho, kappa, cswkappa, h, b, lambda, em_charge
  end type type_mtilde

  type :: type_pfermi
     integer :: pid ! my id of pfermi
     integer :: aid ! id of action
     integer :: fid ! id of force
     integer :: rid ! id of rational approx
     integer :: mid1 ! mtilde   id denominator (hasenbusch heavy)
     integer :: mid2 ! mtilde   id numerator   (hasenbusch light)
     integer :: type ! EO_NORMAL,EO_RATIONAL
     REAL    :: factor
     integer :: nth  ! nth rooted 
     integer :: npf  ! number of pseudo fermion
     integer :: mts  ! multiple time scale 
     logical :: gencoef
     type(sc_field), dimension(:), pointer :: mpf
     REAL    :: sf   ! action
     integer :: polyid ! id of polynomial for PFHMC
     integer :: truncid ! id of truncation data for tRHMC
  end type type_pfermi

  type :: type_logdet
     integer :: aid ! action id
     integer :: fid ! force  id
     integer :: cid ! clover id
  end type type_logdet

  type :: type_ffd
     integer :: aid ! action id
     integer :: fid ! force  id
     integer :: sid ! smearing  id
     REAL    :: theta
  end type type_ffd

  !! all colover terms
  type :: type_clover
     integer :: nf
     REAL    :: kappa, csw, cswkappa, lambda, lambdakappa
  end type type_clover

end module module_action_type

!-------------------------------------------------------------------------------
module module_action
  use module_action_type

  !-----------------------------------------------------------------------------
  ! gauge action
  !-----------------------------------------------------------------------------
  character(len = 10), save :: gauge_action

  REAL, save :: c0, c1, c2, c3

  !
  ! for tadpole improvement
  !
  REAL, save :: last_plaq, plaq_ave, g2
  REAL, dimension(:),pointer, save  :: plaq_hist
  integer, dimension(:),pointer, save  :: n_ave_plaq
  integer, save :: last_n_ave_plaq, plaq_start
  character(len = 14), save:: plaq_file

  !-----------------------------------------------------------------------------
  ! fermi action
  !-----------------------------------------------------------------------------
  character(len = 10), save :: fermi_action
  
  !                  6 of all fermionic type
  integer, dimension(6) :: accumulated_num_mpf, num_mpf


  !-----------------------------------------------------------------------------
  ! action infos
  !-----------------------------------------------------------------------------
  integer, save :: n_dslash = 0
  integer, save :: n_pfermi = 0
  integer, save :: n_clover = 0
  integer, save :: n_mtilde = 0
  integer, save :: n_logdet = 0
  integer, save :: n_ratapp = 0

  type :: type_action
     type(type_plaq)  :: plaq
     type(type_impg)  :: impg
     type(type_ffd)   :: ffd
     type(type_logdet) :: logdet(30)
     type(type_mtilde) :: mtilde(30)
     type(type_pfermi) :: pfermi(30)
  end type type_action

  type(type_action), save :: action
  type(type_clover), save :: clvpar(30)


  ! even-odd precnditioning notation
#ifdef DOEDEO
  integer, parameter :: se = 1
  integer, parameter :: so = 0
#else
  integer, parameter :: se = 0
  integer, parameter :: so = 1
#endif

  REAL, save :: chemi, chemi_i
  REAL, save :: kappa_axion, finv_axion

  COMPLEX, save :: breaking_term(4,4)=ZERO
end

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