[cig-commits] r22084 - seismo/3D/SPECFEM3D/trunk/src/specfem3D

xie.zhinan at geodynamics.org xie.zhinan at geodynamics.org
Thu May 16 11:22:56 PDT 2013


Author: xie.zhinan
Date: 2013-05-16 11:22:56 -0700 (Thu, 16 May 2013)
New Revision: 22084

Modified:
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_coupling_acoustic_el.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_calling_routine.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_noDev.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_noDev.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_allocate_arrays.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_accel_contribution.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_memory_variables.f90
   seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_par.f90
Log:
prepare the code for adjoint simulation with PML and reduce significantly the memory usage when using PML.


Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_coupling_acoustic_el.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_coupling_acoustic_el.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_coupling_acoustic_el.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -33,7 +33,8 @@
                         coupling_ac_el_normal, &
                         coupling_ac_el_jacobian2Dw, &
                         ispec_is_inner,phase_is_inner,& 
-                        PML_CONDITIONS,spec_to_CPML,is_CPML,potential_dot_dot_acoustic_interface) 
+                        PML_CONDITIONS,spec_to_CPML,is_CPML,&
+                        potential_dot_dot_acoustic_interface,veloc,rmemory_coupling_ac_el_displ) 
 
 ! returns the updated pressure array: potential_dot_dot_acoustic
 
@@ -43,9 +44,10 @@
   integer :: NSPEC_AB,NGLOB_AB
 
 ! displacement and pressure
-  real(kind=CUSTOM_REAL), dimension(NDIM,NGLOB_AB) :: displ 
+  real(kind=CUSTOM_REAL), dimension(NDIM,NGLOB_AB) :: displ,veloc
   real(kind=CUSTOM_REAL), dimension(NGLOB_AB) :: potential_dot_dot_acoustic,&
                                                  potential_dot_dot_acoustic_interface
+  real(kind=CUSTOM_REAL), dimension(3,NGLLX,NGLLY,NGLLZ,num_coupling_ac_el_faces,2) :: rmemory_coupling_ac_el_displ
 
 ! global indexing
   integer, dimension(NGLLX,NGLLY,NGLLZ,NSPEC_AB) :: ibool
@@ -96,7 +98,8 @@
            if(is_CPML(ispec))then
               ispec_CPML = spec_to_CPML(ispec)
               call pml_compute_memory_variables_acoustic_elastic(ispec_CPML,iface,iglob,i,j,k,&
-                                                                 displ_x,displ_y,displ_z)
+                                                                 displ_x,displ_y,displ_z,displ,veloc,&
+                                                                 num_coupling_ac_el_faces,rmemory_coupling_ac_el_displ)
            else
               displ_x = displ(1,iglob)
               displ_y = displ(2,iglob)

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_calling_routine.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_calling_routine.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_calling_routine.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -57,7 +57,8 @@
   use specfem_par_acoustic
   use specfem_par_elastic
   use specfem_par_poroelastic
-  use pml_par,only: spec_to_CPML,is_CPML
+  use pml_par,only: spec_to_CPML,is_CPML,rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl,&
+                    rmemory_potential_acoustic,rmemory_coupling_ac_el_displ
 
   implicit none
 
@@ -116,7 +117,9 @@
                         wgllwgll_xy,wgllwgll_xz,wgllwgll_yz, &
                         rhostore,jacobian,ibool,deltat, &
                         num_phase_ispec_acoustic,nspec_inner_acoustic,nspec_outer_acoustic,&
-                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,potential_dot_dot_acoustic_interface)
+                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,&
+                        rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl,&
+                        rmemory_potential_acoustic,potential_dot_dot_acoustic_interface) 
       endif
 
       ! adjoint simulations
@@ -140,7 +143,9 @@
                         wgllwgll_xy,wgllwgll_xz,wgllwgll_yz, &
                         rhostore,jacobian,ibool,deltat, &
                         num_phase_ispec_acoustic,nspec_inner_acoustic,nspec_outer_acoustic,&
-                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,potential_dot_dot_acoustic_interface)
+                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,&
+                        rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl,&
+                        rmemory_potential_acoustic,potential_dot_dot_acoustic_interface) 
         endif
       endif
 
@@ -177,7 +182,9 @@
                               coupling_ac_el_normal, &
                               coupling_ac_el_jacobian2Dw, &
                               ispec_is_inner,phase_is_inner,& 
-                              PML_CONDITIONS,spec_to_CPML,is_CPML,potential_dot_dot_acoustic_interface) 
+                              PML_CONDITIONS,spec_to_CPML,is_CPML,&
+                              potential_dot_dot_acoustic_interface,veloc,rmemory_coupling_ac_el_displ)
+
           else
             ! handles adjoint runs coupling between adjoint potential and adjoint elastic wavefield
             ! adjoint definition: \partial_t^2 \bfs^\dagger=-\frac{1}{\rho}\bfnabla\phi^\dagger
@@ -188,7 +195,8 @@
                               coupling_ac_el_normal, &
                               coupling_ac_el_jacobian2Dw, &
                               ispec_is_inner,phase_is_inner,& 
-                              PML_CONDITIONS,spec_to_CPML,is_CPML,potential_dot_dot_acoustic_interface) 
+                              PML_CONDITIONS,spec_to_CPML,is_CPML,&
+                              potential_dot_dot_acoustic_interface,veloc,rmemory_coupling_ac_el_displ)
           endif
           ! adjoint/kernel simulations
           if( SIMULATION_TYPE == 3 ) &
@@ -199,7 +207,8 @@
                             coupling_ac_el_normal, &
                             coupling_ac_el_jacobian2Dw, &
                             ispec_is_inner,phase_is_inner,& 
-                            PML_CONDITIONS,spec_to_CPML,is_CPML,potential_dot_dot_acoustic_interface) 
+                            PML_CONDITIONS,spec_to_CPML,is_CPML,&
+                            potential_dot_dot_acoustic_interface,veloc,rmemory_coupling_ac_el_displ) 
 
         else
           ! on GPU

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_noDev.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_noDev.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_acoustic_noDev.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -34,15 +34,22 @@
                         wgllwgll_xy,wgllwgll_xz,wgllwgll_yz, &
                         rhostore,jacobian,ibool,deltat, &
                         num_phase_ispec_acoustic,nspec_inner_acoustic,nspec_outer_acoustic,&
-                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,potential_dot_dot_acoustic_interface) 
+                        phase_ispec_inner_acoustic,ELASTIC_SIMULATION,&
+                        rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl,&
+                        rmemory_potential_acoustic,potential_dot_dot_acoustic_interface) 
 
 ! computes forces for acoustic elements
 !
 ! note that pressure is defined as:
 !     p = - Chi_dot_dot
 !
-  use specfem_par,only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,TINYVAL_SNGL,STACEY_ABSORBING_CONDITIONS,PML_CONDITIONS
-  use pml_par
+  use specfem_par,only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,TINYVAL_SNGL,&
+                        STACEY_ABSORBING_CONDITIONS,PML_CONDITIONS
+  use pml_par, only: ELASTIC_SIMULATION,NSPEC_CPML,is_CPML, spec_to_CPML, &
+                     k_store_x,k_store_y,k_store_z,d_store_x,d_store_y,d_store_z,alpha_store,&
+                     PML_dpotential_dxl,PML_dpotential_dyl,PML_dpotential_dzl,&
+                     PML_dpotential_dxl_new,PML_dpotential_dyl_new,PML_dpotential_dzl_new,&
+                     potential_dot_dot_acoustic_CPML
 
   implicit none
 
@@ -75,7 +82,12 @@
   integer :: num_phase_ispec_acoustic,nspec_inner_acoustic,nspec_outer_acoustic
   integer, dimension(num_phase_ispec_acoustic,2) :: phase_ispec_inner_acoustic
 
-!CPML fluid-solid interface
+! CPML 
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2) :: &
+                          rmemory_dpotential_dxl, rmemory_dpotential_dyl, rmemory_dpotential_dzl
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3) :: rmemory_potential_acoustic
+
+! CPML fluid-solid interface
   logical :: ELASTIC_SIMULATION
   real(kind=CUSTOM_REAL), dimension(NGLOB_AB) :: potential_dot_dot_acoustic_interface 
 
@@ -186,17 +198,17 @@
              if(is_CPML(ispec)) then
                 ispec_CPML = spec_to_CPML(ispec)
 
-                PML_dpotential_dxl(i,j,k,ispec_CPML) = dpotentialdxl
-                PML_dpotential_dyl(i,j,k,ispec_CPML) = dpotentialdyl
-                PML_dpotential_dzl(i,j,k,ispec_CPML) = dpotentialdzl
+                PML_dpotential_dxl(i,j,k) = dpotentialdxl
+                PML_dpotential_dyl(i,j,k) = dpotentialdyl
+                PML_dpotential_dzl(i,j,k) = dpotentialdzl
 
                 dpotentialdxl_new = xixl*temp1l_new + etaxl*temp2l_new + gammaxl*temp3l_new
                 dpotentialdyl_new = xiyl*temp1l_new + etayl*temp2l_new + gammayl*temp3l_new
                 dpotentialdzl_new = xizl*temp1l_new + etazl*temp2l_new + gammazl*temp3l_new
 
-                PML_dpotential_dxl_new(i,j,k,ispec_CPML) = dpotentialdxl_new
-                PML_dpotential_dyl_new(i,j,k,ispec_CPML) = dpotentialdyl_new
-                PML_dpotential_dzl_new(i,j,k,ispec_CPML) = dpotentialdzl_new
+                PML_dpotential_dxl_new(i,j,k) = dpotentialdxl_new
+                PML_dpotential_dyl_new(i,j,k) = dpotentialdyl_new
+                PML_dpotential_dzl_new(i,j,k) = dpotentialdzl_new
              endif
           endif
 
@@ -220,10 +232,12 @@
        ! because array is_CPML() is unallocated when PML_CONDITIONS is false
        if(is_CPML(ispec)) then
           ! sets C-PML elastic memory variables to compute stress sigma and form dot product with test vector
-          call pml_compute_memory_variables_acoustic(ispec,ispec_CPML,temp1,temp2,temp3)
+          call pml_compute_memory_variables_acoustic(ispec,ispec_CPML,temp1,temp2,temp3,&
+                                                     rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl)
 
           ! calculates contribution from each C-PML element to update acceleration
-          call pml_compute_accel_contribution_acoustic(ispec,ispec_CPML)
+          call pml_compute_accel_contribution_acoustic(ispec,ispec_CPML,potential_acoustic,&
+                                                       potential_dot_acoustic,rmemory_potential_acoustic)
        endif
     endif
 
@@ -259,7 +273,7 @@
                    potential_dot_dot_acoustic_interface(iglob) = potential_dot_dot_acoustic(iglob)
                 endif
                 potential_dot_dot_acoustic(iglob) = potential_dot_dot_acoustic(iglob) - &
-                     potential_dot_dot_acoustic_CPML(i,j,k,ispec_CPML)
+                     potential_dot_dot_acoustic_CPML(i,j,k)
              endif
           endif
 

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_calling_routine.F90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -90,7 +90,14 @@
                         dsdx_top,dsdx_bot, &
                         ispec2D_moho_top,ispec2D_moho_bot, &
                         num_phase_ispec_elastic,nspec_inner_elastic,nspec_outer_elastic, &
-                        phase_ispec_inner_elastic)
+                        phase_ispec_inner_elastic, &
+                        rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                        rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                        rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                        rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                        rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                        rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z, &
+                        rmemory_displ_elastic)
 
         ! adjoint simulations: backward/reconstructed wavefield
         if( SIMULATION_TYPE == 3 ) &
@@ -120,7 +127,14 @@
                         b_dsdx_top,b_dsdx_bot, &
                         ispec2D_moho_top,ispec2D_moho_bot, &
                         num_phase_ispec_elastic,nspec_inner_elastic,nspec_outer_elastic, &
-                        phase_ispec_inner_elastic)
+                        phase_ispec_inner_elastic, &
+                        rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                        rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                        rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                        rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                        rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                        rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z, &
+                        rmemory_displ_elastic)
 
       endif
 

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_noDev.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_noDev.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/compute_forces_viscoelastic_noDev.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -50,10 +50,23 @@
                         dsdx_top,dsdx_bot, &
                         ispec2D_moho_top,ispec2D_moho_bot, &
                         num_phase_ispec_elastic,nspec_inner_elastic,nspec_outer_elastic, &
-                        phase_ispec_inner_elastic)
+                        phase_ispec_inner_elastic, &
+                        rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                        rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                        rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                        rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                        rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                        rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z, &
+                        rmemory_displ_elastic)
 
-  use constants, only: NGLLX,NGLLY,NGLLZ,NDIM,N_SLS,SAVE_MOHO_MESH,ONE_THIRD,FOUR_THIRDS
-  use pml_par
+  use constants, only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,NDIM,N_SLS,SAVE_MOHO_MESH,ONE_THIRD,FOUR_THIRDS
+  use pml_par, only: NSPEC_CPML,is_CPML, spec_to_CPML, accel_elastic_CPML, &
+                     k_store_x,k_store_y,k_store_z,d_store_x,d_store_y,d_store_z,alpha_store, &
+                     PML_dux_dxl, PML_dux_dyl, PML_dux_dzl, PML_duy_dxl, PML_duy_dyl, PML_duy_dzl, &
+                     PML_duz_dxl, PML_duz_dyl, PML_duz_dzl, &
+                     PML_dux_dxl_new, PML_dux_dyl_new, PML_dux_dzl_new, &
+                     PML_duy_dxl_new, PML_duy_dyl_new, PML_duy_dzl_new, &
+                     PML_duz_dxl_new, PML_duz_dyl_new, PML_duz_dzl_new
   use fault_solver_dynamic, only : Kelvin_Voigt_eta
   use specfem_par, only : FULL_ATTENUATION_SOLID
 
@@ -126,6 +139,14 @@
 
 ! C-PML absorbing boundary conditions
   logical :: PML_CONDITIONS
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2) ::  &
+                          rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                          rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                          rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                          rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                          rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                          rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z
+  real(kind=CUSTOM_REAL), dimension(NDIM,NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3) :: rmemory_displ_elastic
 
 ! local parameters
   integer :: i_SLS,imodulo_N_SLS
@@ -399,17 +420,17 @@
                  if(is_CPML(ispec)) then
                     ispec_CPML = spec_to_CPML(ispec)
 
-                    PML_dux_dxl(i,j,k,ispec_CPML) = duxdxl
-                    PML_dux_dyl(i,j,k,ispec_CPML) = duxdyl
-                    PML_dux_dzl(i,j,k,ispec_CPML) = duxdzl
+                    PML_dux_dxl(i,j,k) = duxdxl
+                    PML_dux_dyl(i,j,k) = duxdyl
+                    PML_dux_dzl(i,j,k) = duxdzl
 
-                    PML_duy_dxl(i,j,k,ispec_CPML) = duydxl
-                    PML_duy_dyl(i,j,k,ispec_CPML) = duydyl
-                    PML_duy_dzl(i,j,k,ispec_CPML) = duydzl
+                    PML_duy_dxl(i,j,k) = duydxl
+                    PML_duy_dyl(i,j,k) = duydyl
+                    PML_duy_dzl(i,j,k) = duydzl
 
-                    PML_duz_dxl(i,j,k,ispec_CPML) = duzdxl
-                    PML_duz_dyl(i,j,k,ispec_CPML) = duzdyl
-                    PML_duz_dzl(i,j,k,ispec_CPML) = duzdzl
+                    PML_duz_dxl(i,j,k) = duzdxl
+                    PML_duz_dyl(i,j,k) = duzdyl
+                    PML_duz_dzl(i,j,k) = duzdzl
                  endif
               endif
 
@@ -479,25 +500,25 @@
                     ! do not merge this second line with the first using an ".and." statement
                     ! because array is_CPML() is unallocated when PML_CONDITIONS is false
                     if(is_CPML(ispec)) then
-                       PML_dux_dxl_new(i,j,k,ispec_CPML) = &
+                       PML_dux_dxl_new(i,j,k) = &
                             xixl*tempx1_att(i,j,k) + etaxl*tempx2_att(i,j,k) + gammaxl*tempx3_att(i,j,k)
-                       PML_dux_dyl_new(i,j,k,ispec_CPML) = &
+                       PML_dux_dyl_new(i,j,k) = &
                             xiyl*tempx1_att(i,j,k) + etayl*tempx2_att(i,j,k) + gammayl*tempx3_att(i,j,k)
-                       PML_dux_dzl_new(i,j,k,ispec_CPML) = &
+                       PML_dux_dzl_new(i,j,k) = &
                             xizl*tempx1_att(i,j,k) + etazl*tempx2_att(i,j,k) + gammazl*tempx3_att(i,j,k)
 
-                       PML_duy_dxl_new(i,j,k,ispec_CPML) = &
+                       PML_duy_dxl_new(i,j,k) = &
                             xixl*tempy1_att(i,j,k) + etaxl*tempy2_att(i,j,k) + gammaxl*tempy3_att(i,j,k)
-                       PML_duy_dyl_new(i,j,k,ispec_CPML) = &
+                       PML_duy_dyl_new(i,j,k) = &
                             xiyl*tempy1_att(i,j,k) + etayl*tempy2_att(i,j,k) + gammayl*tempy3_att(i,j,k)
-                       PML_duy_dzl_new(i,j,k,ispec_CPML) = &
+                       PML_duy_dzl_new(i,j,k) = &
                             xizl*tempy1_att(i,j,k) + etazl*tempy2_att(i,j,k) + gammazl*tempy3_att(i,j,k)
 
-                       PML_duz_dxl_new(i,j,k,ispec_CPML) = &
+                       PML_duz_dxl_new(i,j,k) = &
                             xixl*tempz1_att(i,j,k) + etaxl*tempz2_att(i,j,k) + gammaxl*tempz3_att(i,j,k)
-                       PML_duz_dyl_new(i,j,k,ispec_CPML) = &
+                       PML_duz_dyl_new(i,j,k) = &
                             xiyl*tempz1_att(i,j,k) + etayl*tempz2_att(i,j,k) + gammayl*tempz3_att(i,j,k)
-                       PML_duz_dzl_new(i,j,k,ispec_CPML) = &
+                       PML_duz_dzl_new(i,j,k) = &
                             xizl*tempz1_att(i,j,k) + etazl*tempz2_att(i,j,k) + gammazl*tempz3_att(i,j,k)
                     endif
 
@@ -719,11 +740,17 @@
        ! because array is_CPML() is unallocated when PML_CONDITIONS is false
        if(is_CPML(ispec)) then
           ! sets C-PML elastic memory variables to compute stress sigma and form dot product with test vector
-          call pml_compute_memory_variables_elastic(ispec,ispec_CPML,tempx1,tempy1,tempz1,tempx2,tempy2,tempz2, &
-                                                    tempx3,tempy3,tempz3)
+          call pml_compute_memory_variables_elastic(ispec,ispec_CPML,tempx1,tempy1,tempz1,tempx2,tempy2,tempz2, & 
+                                    tempx3,tempy3,tempz3, &
+                                    rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                                    rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                                    rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                                    rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                                    rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                                    rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z)
 
           ! calculates contribution from each C-PML element to update acceleration
-          call pml_compute_accel_contribution_elastic(ispec,ispec_CPML)
+          call pml_compute_accel_contribution_elastic(ispec,ispec_CPML,displ,veloc,rmemory_displ_elastic)
        endif
     endif
 
@@ -781,9 +808,9 @@
              ! do not merge this second line with the first using an ".and." statement
              ! because array is_CPML() is unallocated when PML_CONDITIONS is false
              if(is_CPML(ispec)) then
-                accel(1,iglob) = accel(1,iglob) - accel_elastic_CPML(1,i,j,k,ispec_CPML)
-                accel(2,iglob) = accel(2,iglob) - accel_elastic_CPML(2,i,j,k,ispec_CPML)
-                accel(3,iglob) = accel(3,iglob) - accel_elastic_CPML(3,i,j,k,ispec_CPML)
+                accel(1,iglob) = accel(1,iglob) - accel_elastic_CPML(1,i,j,k)
+                accel(2,iglob) = accel(2,iglob) - accel_elastic_CPML(2,i,j,k)
+                accel(3,iglob) = accel(3,iglob) - accel_elastic_CPML(3,i,j,k)
              endif
           endif
 

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_allocate_arrays.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_allocate_arrays.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_allocate_arrays.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -48,110 +48,110 @@
   if(ier /= 0) stop 'error allocating array CPML_type'
 
   ! stores derivatives of ux, uy and uz with respect to x, y and z
-  allocate(PML_dux_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dxl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dxl array'
-  allocate(PML_dux_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dyl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dyl array'
-  allocate(PML_dux_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dzl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dzl array'
-  allocate(PML_duy_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dxl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dxl array'
-  allocate(PML_duy_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dyl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dyl array'
-  allocate(PML_duy_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dzl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dzl array'
-  allocate(PML_duz_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dxl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dxl array'
-  allocate(PML_duz_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dyl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dyl array'
-  allocate(PML_duz_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dzl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dzl array'
 
-  allocate(PML_dux_dxl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dxl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dxl_new array'
-  allocate(PML_dux_dyl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dyl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dyl_new array'
-  allocate(PML_dux_dzl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dux_dzl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dux_dzl_new array'
-  allocate(PML_duy_dxl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dxl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dxl_new array'
-  allocate(PML_duy_dyl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dyl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dyl_new array'
-  allocate(PML_duy_dzl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duy_dzl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duy_dzl_new array'
-  allocate(PML_duz_dxl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dxl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dxl_new array'
-  allocate(PML_duz_dyl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dyl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dyl_new array'
-  allocate(PML_duz_dzl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_duz_dzl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_duz_dzl_new array'
 
   ! stores derivatives of potential with respect to x, y and z
-  allocate(PML_dpotential_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dxl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl array'
-  allocate(PML_dpotential_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dyl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl array'
-  allocate(PML_dpotential_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dzl(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl array'
 
-  allocate(PML_dpotential_dxl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dxl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl_new array'
-  allocate(PML_dpotential_dyl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dyl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl_new array'
-  allocate(PML_dpotential_dzl_new(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(PML_dpotential_dzl_new(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating PML_dpotential_dxl_new array'
 
   ! stores C-PML memory variables
-  allocate(rmemory_dux_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dxl_x array'
-  allocate(rmemory_dux_dyl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dyl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dyl_x array'
-  allocate(rmemory_dux_dzl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dzl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dzl_x array'
-  allocate(rmemory_duy_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dxl_x array'
-  allocate(rmemory_duy_dyl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dyl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dyl_x array'
-  allocate(rmemory_duz_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dxl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dxl_x array'
-  allocate(rmemory_duz_dzl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dzl_x(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dzl_x array'
 
-  allocate(rmemory_dux_dxl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dxl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dxl_y array'
-  allocate(rmemory_dux_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dyl_y array'
-  allocate(rmemory_duy_dxl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dxl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dxl_y array'
-  allocate(rmemory_duy_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dyl_y array'
-  allocate(rmemory_duy_dzl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dzl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dzl_y array'
-  allocate(rmemory_duz_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dyl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dyl_y array'
-  allocate(rmemory_duz_dzl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dzl_y(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dzl_y array'
 
-  allocate(rmemory_dux_dxl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dxl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dxl_z array'
-  allocate(rmemory_dux_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dux_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dux_dzl_z array'
-  allocate(rmemory_duy_dyl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dyl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dyl_z array'
-  allocate(rmemory_duy_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duy_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duy_dzl_z array'
-  allocate(rmemory_duz_dxl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dxl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dxl_z array'
-  allocate(rmemory_duz_dyl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dyl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dyl_z array'
-  allocate(rmemory_duz_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_duz_dzl_z(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_duz_dzl_z array'
 
-  allocate(rmemory_dpotential_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dpotential_dxl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dpotential_dxl array'
-  allocate(rmemory_dpotential_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dpotential_dyl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dpotential_dyl array'
-  allocate(rmemory_dpotential_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3),stat=ier)
+  allocate(rmemory_dpotential_dzl(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2),stat=ier)
   if(ier /= 0) stop 'error allocating rmemory_dpotential_dzl array'
 
   ! stores C-PML memory variables needed for displacement
@@ -163,11 +163,11 @@
   if(ier /= 0) stop 'error allocating rmemory_potential_acoustic array'
 
   ! stores C-PML contribution to update acceleration to the global mesh
-  allocate(accel_elastic_CPML(NDIM,NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(accel_elastic_CPML(NDIM,NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating accel_elastic_CPML array'
 
   ! stores C-PML contribution to update the second derivative of the potential to the global mesh
-  allocate(potential_dot_dot_acoustic_CPML(NGLLX,NGLLY,NGLLZ,NSPEC_CPML),stat=ier)
+  allocate(potential_dot_dot_acoustic_CPML(NGLLX,NGLLY,NGLLZ),stat=ier)
   if(ier /= 0) stop 'error allocating potential_dot_dot_acoustic_CPML array'
 
   ! stores C-PML contribution on elastic/acoustic interface
@@ -180,33 +180,33 @@
 
   CPML_type(:) = 0
 
-  PML_dux_dxl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dux_dyl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dux_dzl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dxl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dyl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dzl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dxl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dyl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dzl(:,:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dxl(:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dyl(:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dzl(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dxl(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dyl(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dzl(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dxl(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dyl(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dzl(:,:,:) = 0._CUSTOM_REAL
 
-  PML_dux_dxl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dux_dyl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dux_dzl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dxl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dyl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duy_dzl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dxl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dyl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_duz_dzl_new(:,:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dxl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dyl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_dux_dzl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dxl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dyl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duy_dzl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dxl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dyl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_duz_dzl_new(:,:,:) = 0._CUSTOM_REAL
 
-  PML_dpotential_dxl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dpotential_dyl(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dpotential_dzl(:,:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dxl(:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dyl(:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dzl(:,:,:) = 0._CUSTOM_REAL
 
-  PML_dpotential_dxl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dpotential_dyl_new(:,:,:,:) = 0._CUSTOM_REAL
-  PML_dpotential_dzl_new(:,:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dxl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dyl_new(:,:,:) = 0._CUSTOM_REAL
+  PML_dpotential_dzl_new(:,:,:) = 0._CUSTOM_REAL
 
   rmemory_dux_dxl_x(:,:,:,:,:) = 0._CUSTOM_REAL
   rmemory_dux_dyl_x(:,:,:,:,:) = 0._CUSTOM_REAL
@@ -240,9 +240,9 @@
 
   rmemory_potential_acoustic(:,:,:,:,:) = 0._CUSTOM_REAL
 
-  accel_elastic_CPML(:,:,:,:,:) = 0._CUSTOM_REAL
+  accel_elastic_CPML(:,:,:,:) = 0._CUSTOM_REAL
 
-  potential_dot_dot_acoustic_CPML(:,:,:,:) = 0._CUSTOM_REAL
+  potential_dot_dot_acoustic_CPML(:,:,:) = 0._CUSTOM_REAL
 
   if(ACOUSTIC_SIMULATION .and. ELASTIC_SIMULATION)then 
      rmemory_coupling_ac_el_displ(:,:,:,:,:,:) = 0._CUSTOM_REAL 

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_accel_contribution.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_accel_contribution.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_accel_contribution.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -26,7 +26,7 @@
 !
 ! United States and French Government Sponsorship Acknowledged.
 
-subroutine pml_compute_accel_contribution_elastic(ispec,ispec_CPML)
+subroutine pml_compute_accel_contribution_elastic(ispec,ispec_CPML,displ,veloc,rmemory_displ_elastic)
 
   ! calculates contribution from each C-PML element to update acceleration to the global mesh
 
@@ -35,16 +35,17 @@
   ! Anisotropic-Medium PML for Vector FETD With Modified Basis Functions,
   ! IEEE Transactions on Antennas and Propagation, vol. 54, no. 1, (2006)
 
-  use specfem_par, only: it,deltat,wgll_cube,jacobian,ibool,rhostore
-  use specfem_par_elastic, only: displ,veloc
+  use specfem_par, only: NGLOB_AB,it,deltat,wgll_cube,jacobian,ibool,rhostore
   use pml_par, only: CPML_regions,d_store_x,d_store_y,d_store_z,K_store_x,K_store_y,K_store_z,&
-                     alpha_store,rmemory_displ_elastic,accel_elastic_CPML                    
-  use constants, only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY, &
+                     alpha_store,NSPEC_CPML,accel_elastic_CPML                 
+  use constants, only: CUSTOM_REAL,NDIM,NGLLX,NGLLY,NGLLZ,CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY, &
                        CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ
 
   implicit none
 
   integer, intent(in) :: ispec,ispec_CPML
+  real(kind=CUSTOM_REAL), dimension(NDIM,NGLOB_AB), intent(in) :: displ,veloc
+  real(kind=CUSTOM_REAL), dimension(NDIM,NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3) :: rmemory_displ_elastic
 
   ! local parameters
   integer :: i,j,k,iglob
@@ -434,21 +435,21 @@
 
            endif
 
-           accel_elastic_CPML(1,i,j,k,ispec_CPML) =  wgllcube * rhol * jacobianl * &
+           accel_elastic_CPML(1,i,j,k) =  wgllcube * rhol * jacobianl * &
                 ( A1 * veloc(1,iglob) + A2 * displ(1,iglob) + &
                   A3 * rmemory_displ_elastic(1,i,j,k,ispec_CPML,1) + &
                   A4 * rmemory_displ_elastic(1,i,j,k,ispec_CPML,2) + &
                   A5 * rmemory_displ_elastic(1,i,j,k,ispec_CPML,3)  &
                 )
 
-           accel_elastic_CPML(2,i,j,k,ispec_CPML) =  wgllcube * rhol * jacobianl * &
+           accel_elastic_CPML(2,i,j,k) =  wgllcube * rhol * jacobianl * &
                 ( A1 * veloc(2,iglob) + A2 * displ(2,iglob) + &
                   A3 * rmemory_displ_elastic(2,i,j,k,ispec_CPML,1) + &
                   A4 * rmemory_displ_elastic(2,i,j,k,ispec_CPML,2) + &
                   A5 * rmemory_displ_elastic(2,i,j,k,ispec_CPML,3)  &
                 )
 
-           accel_elastic_CPML(3,i,j,k,ispec_CPML) =  wgllcube * rhol * jacobianl * &
+           accel_elastic_CPML(3,i,j,k) =  wgllcube * rhol * jacobianl * &
                 ( A1 * veloc(3,iglob) + A2 * displ(3,iglob) + &
                   A3 * rmemory_displ_elastic(3,i,j,k,ispec_CPML,1) + &
                   A4 * rmemory_displ_elastic(3,i,j,k,ispec_CPML,2) + &
@@ -465,7 +466,8 @@
 !
 ! 
 
-subroutine pml_compute_accel_contribution_acoustic(ispec,ispec_CPML)
+subroutine pml_compute_accel_contribution_acoustic(ispec,ispec_CPML,potential_acoustic,&
+                                                   potential_dot_acoustic,rmemory_potential_acoustic)
 
   ! calculates contribution from each C-PML element to update acceleration to the global mesh
 
@@ -474,17 +476,19 @@
   ! Anisotropic-Medium PML for Vector FETD With Modified Basis Functions,
   ! IEEE Transactions on Antennas and Propagation, vol. 54, no. 1, (2006)
 
-  use specfem_par, only: it,deltat,wgll_cube,jacobian,ibool,kappastore
-  use specfem_par_acoustic, only: potential_acoustic,potential_dot_acoustic
-  use pml_par, only: CPML_regions,d_store_x,d_store_y,d_store_z,K_store_x,K_store_y,K_store_z,&
-                     alpha_store,rmemory_potential_acoustic, potential_dot_dot_acoustic_CPML
+  use specfem_par, only: NGLOB_AB,it,deltat,wgll_cube,jacobian,ibool,kappastore
+  use pml_par, only: CPML_regions,NSPEC_CPML,d_store_x,d_store_y,d_store_z,K_store_x,K_store_y,K_store_z,&
+                     alpha_store, potential_dot_dot_acoustic_CPML
   use constants, only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY, &
                        CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ
 
   implicit none
 
   integer, intent(in) :: ispec,ispec_CPML
+  real(kind=CUSTOM_REAL), dimension(NGLOB_AB), intent(in) :: potential_acoustic,potential_dot_acoustic 
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,3) :: rmemory_potential_acoustic
 
+
   ! local parameters
   integer :: i,j,k,iglob
   real(kind=CUSTOM_REAL) :: wgllcube,kappal_inv,jacobianl
@@ -791,7 +795,7 @@
 
            endif
 
-           potential_dot_dot_acoustic_CPML(i,j,k,ispec_CPML) =  wgllcube * kappal_inv *jacobianl * &
+           potential_dot_dot_acoustic_CPML(i,j,k) =  wgllcube * kappal_inv *jacobianl * &
                  ( A1 * potential_dot_acoustic(iglob) + A2 * potential_acoustic(iglob) + &
                    A3 * rmemory_potential_acoustic(i,j,k,ispec_CPML,1)+ &
                    A4 * rmemory_potential_acoustic(i,j,k,ispec_CPML,2)+ &

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_memory_variables.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_memory_variables.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_compute_memory_variables.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -27,7 +27,13 @@
 ! United States and French Government Sponsorship Acknowledged.
 
 subroutine pml_compute_memory_variables_elastic(ispec,ispec_CPML,tempx1,tempy1,tempz1,tempx2,tempy2,tempz2, &
-                                    tempx3,tempy3,tempz3)
+                                    tempx3,tempy3,tempz3, &
+                                    rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                                    rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                                    rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                                    rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                                    rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                                    rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z)
   ! calculates C-PML elastic memory variables and computes stress sigma
 
   ! second-order accurate convolution term calculation from equation (21) of
@@ -38,8 +44,14 @@
   use specfem_par, only: wgllwgll_xy,wgllwgll_xz,wgllwgll_yz,it,deltat, &
                          xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz,jacobian, &
                          kappastore,mustore
-  use pml_par
-  use constants, only: NGLLX,NGLLY,NGLLZ,FOUR_THIRDS, &
+  use pml_par, only: NSPEC_CPML,CPML_regions,k_store_x,k_store_y,k_store_z,&
+                     d_store_x,d_store_y,d_store_z,alpha_store, &
+                     PML_dux_dxl, PML_dux_dyl, PML_dux_dzl, PML_duy_dxl, PML_duy_dyl, PML_duy_dzl, &
+                     PML_duz_dxl, PML_duz_dyl, PML_duz_dzl, &
+                     PML_dux_dxl_new, PML_dux_dyl_new, PML_dux_dzl_new, &
+                     PML_duy_dxl_new, PML_duy_dyl_new, PML_duy_dzl_new, &
+                     PML_duz_dxl_new, PML_duz_dyl_new, PML_duz_dzl_new
+  use constants, only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,FOUR_THIRDS, &
                        CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY,CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ
 
   implicit none
@@ -48,6 +60,13 @@
   real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ), intent(out) :: tempx1,tempx2,tempx3
   real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ), intent(out) :: tempy1,tempy2,tempy3
   real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ), intent(out) :: tempz1,tempz2,tempz3
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2) ::  &
+                          rmemory_dux_dxl_x, rmemory_duy_dyl_x, rmemory_duz_dzl_x, &
+                          rmemory_dux_dyl_x, rmemory_dux_dzl_x, rmemory_duz_dxl_x, rmemory_duy_dxl_x, &
+                          rmemory_dux_dxl_y, rmemory_duz_dzl_y, rmemory_duy_dyl_y, &
+                          rmemory_duy_dxl_y, rmemory_duy_dzl_y, rmemory_duz_dyl_y, rmemory_dux_dyl_y, &
+                          rmemory_dux_dxl_z, rmemory_duy_dyl_z, rmemory_duz_dzl_z, &
+                          rmemory_duz_dxl_z, rmemory_duz_dyl_z, rmemory_duy_dzl_z, rmemory_dux_dzl_z
 
   ! local parameters
   integer :: i,j,k
@@ -103,15 +122,15 @@
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dxl_new(i,j,k) * coef1_2 + PML_dux_dxl(i,j,k) * coef2_2
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dxl_new(i,j,k) * coef1_2 + PML_duy_dxl(i,j,k) * coef2_2
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dxl_new(i,j,k) * coef1_2 + PML_duz_dxl(i,j,k) * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9  = k_store_x(i,j,k,ispec_CPML)
@@ -130,15 +149,15 @@
               endif
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -158,15 +177,15 @@
               endif
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A15 and A16 --------------------------
@@ -185,19 +204,19 @@
               endif
 
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A17 and A18 --------------------------
@@ -254,15 +273,15 @@
               endif
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -283,15 +302,15 @@
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dyl_new(i,j,k) * coef1_2 + PML_dux_dyl(i,j,k) * coef2_2
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dyl_new(i,j,k) * coef1_2 + PML_duy_dyl(i,j,k) * coef2_2
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dyl_new(i,j,k) * coef1_2 + PML_duz_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_y(i,j,k,ispec_CPML)
@@ -310,15 +329,15 @@
               endif
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A15 and A16 --------------------------
@@ -353,19 +372,19 @@
               endif
 
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A19 and A20--------------------------
@@ -407,15 +426,15 @@
               endif
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -435,15 +454,15 @@
               endif
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -464,15 +483,15 @@
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dzl_new(i,j,k) * coef1_2 + PML_dux_dzl(i,j,k) * coef2_2
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dzl_new(i,j,k) * coef1_2 + PML_duy_dzl(i,j,k) * coef2_2
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dzl_new(i,j,k) * coef1_2 + PML_duz_dzl(i,j,k) * coef2_2
 
               !---------------------- A15 and A16 --------------------------
               A15 = 1.d0
@@ -522,19 +541,19 @@
               endif
 
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
             else if( CPML_regions(ispec_CPML) == CPML_XY_ONLY ) then
@@ -562,15 +581,15 @@
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dxl_new(i,j,k) * coef1_2 + PML_dux_dxl(i,j,k) * coef2_2
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dxl_new(i,j,k) * coef1_2 + PML_duy_dxl(i,j,k) * coef2_2
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dxl_new(i,j,k) * coef1_2 + PML_duz_dxl(i,j,k) * coef2_2
 
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -592,15 +611,15 @@
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dyl_new(i,j,k) * coef1_2 + PML_dux_dyl(i,j,k) * coef2_2
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dyl_new(i,j,k) * coef1_2 + PML_duy_dyl(i,j,k) * coef2_2
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dyl_new(i,j,k) * coef1_2 + PML_duz_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_x(i,j,k,ispec_CPML) * k_store_y(i,j,k,ispec_CPML)
@@ -625,22 +644,19 @@
               coef2_2 = coef2_1
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dux_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dux_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dzl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duy_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duy_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dzl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duz_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duz_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dzl(i,j,k) * it*deltat * coef2_2
 
               !---------------------- A15 and A16 --------------------------
               A15 = k_store_x(i,j,k,ispec_CPML)
@@ -658,19 +674,19 @@
               endif
 
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A17 and A18 --------------------------
@@ -689,19 +705,19 @@
               endif
 
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A19 and A20--------------------------
@@ -745,15 +761,15 @@
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dxl_new(i,j,k) * coef1_2 + PML_dux_dxl(i,j,k) * coef2_2
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dxl_new(i,j,k) * coef1_2 + PML_duy_dxl(i,j,k) * coef2_2
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dxl_new(i,j,k) * coef1_2 + PML_duz_dxl(i,j,k) * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9 = k_store_x(i,j,k,ispec_CPML) * k_store_z(i,j,k,ispec_CPML)
@@ -778,22 +794,19 @@
               coef2_2 = coef2_1
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dux_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dux_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dyl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duy_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duy_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dyl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duz_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duz_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dyl(i,j,k) * it*deltat * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_x(i,j,k,ispec_CPML) / k_store_z(i,j,k,ispec_CPML)
@@ -814,15 +827,15 @@
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dzl_new(i,j,k) * coef1_2 + PML_dux_dzl(i,j,k) * coef2_2
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dzl_new(i,j,k) * coef1_2 + PML_duy_dzl(i,j,k) * coef2_2
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dzl_new(i,j,k) * coef1_2 + PML_duz_dzl(i,j,k) * coef2_2
 
               !---------------------- A15 and A16 --------------------------
               A15 = k_store_x(i,j,k,ispec_CPML)
@@ -840,19 +853,19 @@
               endif
 
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A17 and A18 --------------------------
@@ -887,19 +900,19 @@
               endif
 
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
             else if( CPML_regions(ispec_CPML) == CPML_YZ_ONLY ) then
@@ -931,22 +944,19 @@
               coef2_2 = coef2_1
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dux_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dux_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dxl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duy_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duy_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dxl(i,j,k) * it*deltat * coef2_2
 
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_duz_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_duz_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dxl(i,j,k) * it*deltat * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9 = k_store_z(i,j,k,ispec_CPML) / k_store_y(i,j,k,ispec_CPML)
@@ -967,15 +977,15 @@
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dyl_new(i,j,k) * coef1_2 + PML_dux_dyl(i,j,k) * coef2_2
 
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dyl_new(i,j,k) * coef1_2 + PML_duy_dyl(i,j,k) * coef2_2
 
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dyl_new(i,j,k) * coef1_2 + PML_duz_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_y(i,j,k,ispec_CPML) / k_store_z(i,j,k,ispec_CPML)
@@ -996,15 +1006,15 @@
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dux_dzl_new(i,j,k) * coef1_2 + PML_dux_dzl(i,j,k) * coef2_2
 
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duy_dzl_new(i,j,k) * coef1_2 + PML_duy_dzl(i,j,k) * coef2_2
 
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_duz_dzl_new(i,j,k) * coef1_2 + PML_duz_dzl(i,j,k) * coef2_2
 
               !---------------------- A15 and A16 --------------------------
               A15 = 1.0d0
@@ -1038,19 +1048,19 @@
               endif
 
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_x(i,j,k,ispec_CPML,2) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A19 and A20--------------------------
@@ -1069,19 +1079,19 @@
               endif
 
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
             else if( CPML_regions(ispec_CPML) == CPML_XYZ ) then
@@ -1130,29 +1140,26 @@
               endif
 
               rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
 
               if( abs(d_store_x(i,j,k,ispec_CPML)) > 1.d-5 ) then
                  rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dux_dxl_new(i,j,k) * coef1_2 + PML_dux_dxl(i,j,k) * coef2_2
                  rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duy_dxl_new(i,j,k) * coef1_2 + PML_duy_dxl(i,j,k) * coef2_2
                  rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duz_dxl_new(i,j,k) * coef1_2 + PML_duz_dxl(i,j,k) * coef2_2
               else
                  rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dux_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dux_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dxl(i,j,k) * it*deltat * coef2_2
                  rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duy_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duy_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dxl(i,j,k) * it*deltat * coef2_2
                  rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duz_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duz_dxl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dxl(i,j,k) * it*deltat * coef2_2
               endif
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -1195,29 +1202,26 @@
               endif
 
               rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
 
               if( abs(d_store_y(i,j,k,ispec_CPML)) > 1.d-5 ) then
                  rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dux_dyl_new(i,j,k) * coef1_2 + PML_dux_dyl(i,j,k) * coef2_2
                  rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duy_dyl_new(i,j,k) * coef1_2 + PML_duy_dyl(i,j,k) * coef2_2
                  rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duz_dyl_new(i,j,k) * coef1_2 + PML_duz_dyl(i,j,k) * coef2_2
               else
                  rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dux_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dux_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dyl(i,j,k) * it*deltat * coef2_2
                  rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duy_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duy_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dyl(i,j,k) * it*deltat * coef2_2
                  rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duz_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duz_dyl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dyl(i,j,k) * it*deltat * coef2_2
               endif
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -1261,29 +1265,26 @@
               endif
 
               rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
 
               if( abs(d_store_z(i,j,k,ispec_CPML)) > 1.d-5 ) then
                  rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dux_dzl_new(i,j,k) * coef1_2 + PML_dux_dzl(i,j,k) * coef2_2
                  rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duy_dzl_new(i,j,k) * coef1_2 + PML_duy_dzl(i,j,k) * coef2_2
                  rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_duz_dzl_new(i,j,k) * coef1_2 + PML_duz_dzl(i,j,k) * coef2_2
               else
                  rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2) &
-                      + PML_dux_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dux_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dux_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_dux_dzl(i,j,k) * it*deltat * coef2_2
                  rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2) &
-                      + PML_duy_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duy_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duy_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_duy_dzl(i,j,k) * it*deltat * coef2_2
                  rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2) &
-                      + PML_duz_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_duz_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_duz_dzl_new(i,j,k) * it*deltat * coef1_2 + PML_duz_dzl(i,j,k) * it*deltat * coef2_2
               endif
 
               !---------------------- A15 and A16 --------------------------
@@ -1302,19 +1303,19 @@
               endif
 
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dyl_new(i,j,k) * coef1_1 + PML_duz_dyl(i,j,k) * coef2_1
               rmemory_duz_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dzl_new(i,j,k) * coef1_1 + PML_duy_dzl(i,j,k) * coef2_1
               rmemory_duy_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A17 and A18 --------------------------
@@ -1333,19 +1334,19 @@
               endif
 
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dzl_new(i,j,k) * coef1_1 + PML_duz_dzl(i,j,k) * coef2_1
               rmemory_duz_dzl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duz_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duz_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duz_dxl_new(i,j,k) * coef1_1 + PML_duz_dxl(i,j,k) * coef2_1
               rmemory_duz_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dzl_new(i,j,k) * coef1_1 + PML_dux_dzl(i,j,k) * coef2_1
               rmemory_dux_dzl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_z(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A19 and A20 --------------------------
@@ -1364,68 +1365,68 @@
               endif
 
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dyl_new(i,j,k) * coef1_1 + PML_duy_dyl(i,j,k) * coef2_1
               rmemory_duy_dyl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) &
-                   + PML_duy_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_duy_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_duy_dxl_new(i,j,k) * coef1_1 + PML_duy_dxl(i,j,k) * coef2_1
               rmemory_duy_dxl_x(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dyl_new(i,j,k) * coef1_1 + PML_dux_dyl(i,j,k) * coef2_1
               rmemory_dux_dyl_y(i,j,k,ispec_CPML,2) = 0.d0
 
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) &
-                   + PML_dux_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dux_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dux_dxl_new(i,j,k) * coef1_1 + PML_dux_dxl(i,j,k) * coef2_1
               rmemory_dux_dxl_y(i,j,k,ispec_CPML,2) = 0.d0
 
             else
               stop 'wrong PML flag in PML memory variable calculation routine'
             endif
 
-            duxdxl_x = A6 * PML_dux_dxl(i,j,k,ispec_CPML)  &
+            duxdxl_x = A6 * PML_dux_dxl(i,j,k)  &
                  + A7 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,1) + A8 * rmemory_dux_dxl_x(i,j,k,ispec_CPML,2)
-            duxdyl_x = A9 * PML_dux_dyl(i,j,k,ispec_CPML)  &
+            duxdyl_x = A9 * PML_dux_dyl(i,j,k)  &
                  + A10 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,1) + A11 * rmemory_dux_dyl_x(i,j,k,ispec_CPML,2)
-            duxdzl_x = A12 * PML_dux_dzl(i,j,k,ispec_CPML)  &
+            duxdzl_x = A12 * PML_dux_dzl(i,j,k)  &
                  + A13 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,1) + A14 * rmemory_dux_dzl_x(i,j,k,ispec_CPML,2)
-            duzdzl_x = A17 * PML_duz_dzl(i,j,k,ispec_CPML)  &
+            duzdzl_x = A17 * PML_duz_dzl(i,j,k)  &
                  + A18 * rmemory_duz_dzl_x(i,j,k,ispec_CPML,1) + rmemory_duz_dzl_x(i,j,k,ispec_CPML,2)
-            duzdxl_x = A17 * PML_duz_dxl(i,j,k,ispec_CPML)  &
+            duzdxl_x = A17 * PML_duz_dxl(i,j,k)  &
                  + A18 * rmemory_duz_dxl_x(i,j,k,ispec_CPML,1) + rmemory_duz_dxl_x(i,j,k,ispec_CPML,2)
-            duydyl_x = A19 * PML_duy_dyl(i,j,k,ispec_CPML)  &
+            duydyl_x = A19 * PML_duy_dyl(i,j,k)  &
                  + A20 * rmemory_duy_dyl_x(i,j,k,ispec_CPML,1) + rmemory_duy_dyl_x(i,j,k,ispec_CPML,2)
-            duydxl_x = A19 * PML_duy_dxl(i,j,k,ispec_CPML)  &
+            duydxl_x = A19 * PML_duy_dxl(i,j,k)  &
                  + A20 * rmemory_duy_dxl_x(i,j,k,ispec_CPML,1) + rmemory_duy_dxl_x(i,j,k,ispec_CPML,2)
 
-            duydxl_y = A6 * PML_duy_dxl(i,j,k,ispec_CPML)  &
+            duydxl_y = A6 * PML_duy_dxl(i,j,k)  &
                  + A7 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,1) + A8 * rmemory_duy_dxl_y(i,j,k,ispec_CPML,2)
-            duydyl_y = A9 * PML_duy_dyl(i,j,k,ispec_CPML)  &
+            duydyl_y = A9 * PML_duy_dyl(i,j,k)  &
                  + A10 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,1) + A11 * rmemory_duy_dyl_y(i,j,k,ispec_CPML,2)
-            duydzl_y = A12 * PML_duy_dzl(i,j,k,ispec_CPML)  &
+            duydzl_y = A12 * PML_duy_dzl(i,j,k)  &
                  + A13 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,1) + A14 * rmemory_duy_dzl_y(i,j,k,ispec_CPML,2)
-            duzdzl_y = A15 * PML_duz_dzl(i,j,k,ispec_CPML)  &
+            duzdzl_y = A15 * PML_duz_dzl(i,j,k)  &
                  + A16 * rmemory_duz_dzl_y(i,j,k,ispec_CPML,1) + rmemory_duz_dzl_y(i,j,k,ispec_CPML,2)
-            duzdyl_y = A15 * PML_duz_dyl(i,j,k,ispec_CPML)  &
+            duzdyl_y = A15 * PML_duz_dyl(i,j,k)  &
                  + A16 * rmemory_duz_dyl_y(i,j,k,ispec_CPML,1) + rmemory_duz_dyl_y(i,j,k,ispec_CPML,2)
-            duxdyl_y = A19 * PML_dux_dyl(i,j,k,ispec_CPML)  &
+            duxdyl_y = A19 * PML_dux_dyl(i,j,k)  &
                  + A20 * rmemory_dux_dyl_y(i,j,k,ispec_CPML,1) + rmemory_dux_dyl_y(i,j,k,ispec_CPML,2)
-            duxdxl_y = A19 * PML_dux_dxl(i,j,k,ispec_CPML)  &
+            duxdxl_y = A19 * PML_dux_dxl(i,j,k)  &
                  + A20 * rmemory_dux_dxl_y(i,j,k,ispec_CPML,1) + rmemory_dux_dxl_y(i,j,k,ispec_CPML,2)
 
-            duzdxl_z = A6 * PML_duz_dxl(i,j,k,ispec_CPML)  &
+            duzdxl_z = A6 * PML_duz_dxl(i,j,k)  &
                  + A7 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,1) + A8 * rmemory_duz_dxl_z(i,j,k,ispec_CPML,2)
-            duzdyl_z = A9 * PML_duz_dyl(i,j,k,ispec_CPML)  &
+            duzdyl_z = A9 * PML_duz_dyl(i,j,k)  &
                  + A10 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,1) + A11 * rmemory_duz_dyl_z(i,j,k,ispec_CPML,2)
-            duzdzl_z = A12 * PML_duz_dzl(i,j,k,ispec_CPML)  &
+            duzdzl_z = A12 * PML_duz_dzl(i,j,k)  &
                  + A13 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,1) + A14 * rmemory_duz_dzl_z(i,j,k,ispec_CPML,2)
-            duydzl_z = A15 * PML_duy_dzl(i,j,k,ispec_CPML)  &
+            duydzl_z = A15 * PML_duy_dzl(i,j,k)  &
                  + A16 * rmemory_duy_dzl_z(i,j,k,ispec_CPML,1) + rmemory_duy_dzl_z(i,j,k,ispec_CPML,2)
-            duydyl_z = A15 * PML_duy_dyl(i,j,k,ispec_CPML)  &
+            duydyl_z = A15 * PML_duy_dyl(i,j,k)  &
                  + A16 * rmemory_duy_dyl_z(i,j,k,ispec_CPML,1) + rmemory_duy_dyl_z(i,j,k,ispec_CPML,2)
-            duxdzl_z = A17 * PML_dux_dzl(i,j,k,ispec_CPML)  &
+            duxdzl_z = A17 * PML_dux_dzl(i,j,k)  &
                  + A18 * rmemory_dux_dzl_z(i,j,k,ispec_CPML,1) + rmemory_dux_dzl_z(i,j,k,ispec_CPML,2)
-            duxdxl_z = A17 * PML_dux_dxl(i,j,k,ispec_CPML)  &
+            duxdxl_z = A17 * PML_dux_dxl(i,j,k)  &
                  + A18 * rmemory_dux_dxl_z(i,j,k,ispec_CPML,1) + rmemory_dux_dxl_z(i,j,k,ispec_CPML,2)
 
             ! compute stress sigma
@@ -1465,7 +1466,8 @@
 !
 !
 
-subroutine pml_compute_memory_variables_acoustic(ispec,ispec_CPML,temp1,temp2,temp3)
+subroutine pml_compute_memory_variables_acoustic(ispec,ispec_CPML,temp1,temp2,temp3,&
+                                                 rmemory_dpotential_dxl,rmemory_dpotential_dyl,rmemory_dpotential_dzl)
   ! calculates C-PML elastic memory variables and computes stress sigma
 
   ! second-order accurate convolution term calculation from equation (21) of
@@ -1476,14 +1478,19 @@
   use specfem_par, only: NSPEC_AB,wgllwgll_xy,wgllwgll_xz,wgllwgll_yz,&
                          xix,xiy,xiz,etax,etay,etaz,gammax,gammay,gammaz,jacobian,&
                          it,deltat,rhostore
-  use pml_par
-  use constants, only: NGLLX,NGLLY,NGLLZ,FOUR_THIRDS, &
+  use pml_par, only: NSPEC_CPML,CPML_regions,k_store_x,k_store_y,k_store_z,&
+                     d_store_x,d_store_y,d_store_z,alpha_store,&
+                     PML_dpotential_dxl,PML_dpotential_dyl,PML_dpotential_dzl,&
+                     PML_dpotential_dxl_new,PML_dpotential_dyl_new,PML_dpotential_dzl_new
+  use constants, only: CUSTOM_REAL,NGLLX,NGLLY,NGLLZ,FOUR_THIRDS, &
                        CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY,CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ
 
   implicit none
 
   integer, intent(in) :: ispec,ispec_CPML
   real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ), intent(out) :: temp1,temp2,temp3
+  real(kind=CUSTOM_REAL), dimension(NGLLX,NGLLY,NGLLZ,NSPEC_CPML,2) :: &
+                               rmemory_dpotential_dxl, rmemory_dpotential_dyl, rmemory_dpotential_dzl
 
   ! local parameters
   integer :: i,j,k
@@ -1535,7 +1542,7 @@
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_2 + PML_dpotential_dxl(i,j,k) * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9  = k_store_x(i,j,k,ispec_CPML)
@@ -1554,7 +1561,7 @@
               endif
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_1 + PML_dpotential_dyl(i,j,k) * coef2_1
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -1574,7 +1581,7 @@
               endif
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_1 + PML_dpotential_dzl(i,j,k) * coef2_1
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = 0.d0
 
             else if( CPML_regions(ispec_CPML) == CPML_Y_ONLY ) then
@@ -1599,7 +1606,7 @@
               endif
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_1 + PML_dpotential_dxl(i,j,k) * coef2_1
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -1620,7 +1627,7 @@
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_2 + PML_dpotential_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_y(i,j,k,ispec_CPML)
@@ -1639,7 +1646,7 @@
               endif
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_1 + PML_dpotential_dzl(i,j,k) * coef2_1
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = 0.d0
 
             else if( CPML_regions(ispec_CPML) == CPML_Z_ONLY ) then
@@ -1665,7 +1672,7 @@
               endif
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_1 + PML_dpotential_dxl(i,j,k) * coef2_1
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -1685,7 +1692,7 @@
               endif
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_1 + PML_dpotential_dyl(i,j,k) * coef2_1
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = 0.d0
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -1706,7 +1713,7 @@
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_2 + PML_dpotential_dzl(i,j,k) * coef2_2
 
             else if( CPML_regions(ispec_CPML) == CPML_XY_ONLY ) then
 
@@ -1733,7 +1740,7 @@
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_2 + PML_dpotential_dxl(i,j,k) * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9 = k_store_x(i,j,k,ispec_CPML) / k_store_y(i,j,k,ispec_CPML)
@@ -1754,7 +1761,7 @@
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_2 + PML_dpotential_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_x(i,j,k,ispec_CPML) * k_store_y(i,j,k,ispec_CPML)
@@ -1779,10 +1786,10 @@
               coef2_2 = coef2_1
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_1 + PML_dpotential_dzl(i,j,k) * coef2_1
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dpotential_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dpotential_dzl_new(i,j,k) * it*deltat * coef1_2 &
+                   + PML_dpotential_dzl(i,j,k) * it*deltat * coef2_2
 
             else if( CPML_regions(ispec_CPML) == CPML_XZ_ONLY ) then
 
@@ -1809,7 +1816,7 @@
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_2 + PML_dpotential_dxl(i,j,k) * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9 = k_store_x(i,j,k,ispec_CPML) * k_store_z(i,j,k,ispec_CPML)
@@ -1834,10 +1841,10 @@
               coef2_2 = coef2_1
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_1 + PML_dpotential_dyl(i,j,k) * coef2_1
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dpotential_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dpotential_dyl_new(i,j,k) * it*deltat * coef1_2 &
+                   + PML_dpotential_dyl(i,j,k) * it*deltat * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_x(i,j,k,ispec_CPML) / k_store_z(i,j,k,ispec_CPML)
@@ -1858,7 +1865,7 @@
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_2 + PML_dpotential_dzl(i,j,k) * coef2_2
 
             else if( CPML_regions(ispec_CPML) == CPML_YZ_ONLY ) then
 
@@ -1889,10 +1896,10 @@
               coef2_2 = coef2_1
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_1 + PML_dpotential_dxl(i,j,k) * coef2_1
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                   + PML_dpotential_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                   + PML_dpotential_dxl_new(i,j,k) * it*deltat * coef1_2 &
+                   + PML_dpotential_dxl(i,j,k) * it*deltat * coef2_2
 
               !---------------------- A9, A10 and A11 --------------------------
               A9 = k_store_z(i,j,k,ispec_CPML) / k_store_y(i,j,k,ispec_CPML)
@@ -1913,7 +1920,7 @@
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_2 + PML_dpotential_dyl(i,j,k) * coef2_2
 
               !---------------------- A12, A13 and A14 --------------------------
               A12 = k_store_y(i,j,k,ispec_CPML) / k_store_z(i,j,k,ispec_CPML)
@@ -1934,7 +1941,7 @@
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = 0.d0
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_2
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_2 + PML_dpotential_dzl(i,j,k) * coef2_2
 
             else if( CPML_regions(ispec_CPML) == CPML_XYZ ) then
 
@@ -1982,15 +1989,15 @@
               endif
 
               rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dxl_new(i,j,k) * coef1_1 + PML_dpotential_dxl(i,j,k) * coef2_1
 
               if(abs(d_store_x(i,j,k,ispec_CPML))> 1.d-5)then
                  rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dxl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dpotential_dxl_new(i,j,k) * coef1_2 + PML_dpotential_dxl(i,j,k) * coef2_2
               else
                  rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dxl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dpotential_dxl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dpotential_dxl_new(i,j,k) * it*deltat * coef1_2 &
+                      + PML_dpotential_dxl(i,j,k) * it*deltat * coef2_2
               endif
 
               !---------------------- A9, A10 and A11 --------------------------
@@ -2033,15 +2040,15 @@
               endif
 
               rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dyl_new(i,j,k) * coef1_1 + PML_dpotential_dyl(i,j,k) * coef2_1
 
               if(abs(d_store_y(i,j,k,ispec_CPML))> 1.d-5)then
                  rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dyl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dpotential_dyl_new(i,j,k) * coef1_2 + PML_dpotential_dyl(i,j,k) * coef2_2
               else
                  rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dyl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dpotential_dyl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dpotential_dyl_new(i,j,k) * it*deltat * coef1_2 &
+                      + PML_dpotential_dyl(i,j,k) * it*deltat * coef2_2
               endif
 
               !---------------------- A12, A13 and A14 --------------------------
@@ -2084,26 +2091,26 @@
               endif
 
               rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) = coef0_1 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) &
-                   + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_1 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_1
+                   + PML_dpotential_dzl_new(i,j,k) * coef1_1 + PML_dpotential_dzl(i,j,k) * coef2_1
 
               if(abs(d_store_z(i,j,k,ispec_CPML))> 1.d-5)then
                  rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * coef1_2 + PML_dpotential_dzl(i,j,k,ispec_CPML) * coef2_2
+                      + PML_dpotential_dzl_new(i,j,k) * coef1_2 + PML_dpotential_dzl(i,j,k) * coef2_2
               else
                  rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) = coef0_2 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2) &
-                      + PML_dpotential_dzl_new(i,j,k,ispec_CPML) * it*deltat * coef1_2 &
-                      + PML_dpotential_dzl(i,j,k,ispec_CPML) * it*deltat * coef2_2
+                      + PML_dpotential_dzl_new(i,j,k) * it*deltat * coef1_2 &
+                      + PML_dpotential_dzl(i,j,k) * it*deltat * coef2_2
               endif
 
             else
               stop 'wrong PML flag in PML memory variable calculation routine'
             endif
 
-            dpotentialdxl = A6 * PML_dpotential_dxl(i,j,k,ispec_CPML)  &
+            dpotentialdxl = A6 * PML_dpotential_dxl(i,j,k)  &
                  + A7 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,1) + A8 * rmemory_dpotential_dxl(i,j,k,ispec_CPML,2)
-            dpotentialdyl = A9 * PML_dpotential_dyl(i,j,k,ispec_CPML)  &
+            dpotentialdyl = A9 * PML_dpotential_dyl(i,j,k)  &
                  + A10 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,1) + A11 * rmemory_dpotential_dyl(i,j,k,ispec_CPML,2)
-            dpotentialdzl = A12 * PML_dpotential_dzl(i,j,k,ispec_CPML)  &
+            dpotentialdzl = A12 * PML_dpotential_dzl(i,j,k)  &
                  + A13 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,1) + A14 * rmemory_dpotential_dzl(i,j,k,ispec_CPML,2)
             temp1(i,j,k) = rhoin_jacob_jk * (xixl*dpotentialdxl + xiyl*dpotentialdyl + xizl*dpotentialdzl)
             temp2(i,j,k) = rhoin_jacob_ik * (etaxl*dpotentialdxl + etayl*dpotentialdyl + etazl*dpotentialdzl)
@@ -2121,7 +2128,8 @@
 !
 
 subroutine pml_compute_memory_variables_acoustic_elastic(ispec_CPML,iface,iglob,i,j,k,&
-                                                         displ_x,displ_y,displ_z)
+                                                         displ_x,displ_y,displ_z,displ,veloc,&
+                                                         num_coupling_ac_el_faces,rmemory_coupling_ac_el_displ)
   ! calculates C-PML elastic memory variables and computes stress sigma
 
   ! second-order accurate convolution term calculation from equation (21) of
@@ -2129,20 +2137,23 @@
   ! Anisotropic-Medium PML for Vector FETD With Modified Basis Functions,
   ! IEEE Transactions on Antennas and Propagation, vol. 54, no. 1, (2006)
 
-  use specfem_par, only: it,deltat
-  use specfem_par_elastic, only: displ,veloc
-  use pml_par
-  use constants, only: CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY,CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ,NDIM
+  use specfem_par, only: NGLOB_AB,it,deltat
+  use pml_par,only : CPML_regions,k_store_x,k_store_y,k_store_z,d_store_x,d_store_y,d_store_z,alpha_store
+  use constants, only: CUSTOM_REAL,NDIM,NGLLX,NGLLY,NGLLZ,&
+                       CPML_X_ONLY,CPML_Y_ONLY,CPML_Z_ONLY,CPML_XY_ONLY,CPML_XZ_ONLY,CPML_YZ_ONLY,CPML_XYZ
 
   implicit none
 
-  integer, intent(in) :: ispec_CPML,iface,iglob
+  integer, intent(in) :: ispec_CPML,iface,iglob,num_coupling_ac_el_faces
+  real(kind=CUSTOM_REAL) :: displ_x,displ_y,displ_z
+  real(kind=CUSTOM_REAL), dimension(NDIM,NGLOB_AB), intent(in) :: displ,veloc
+  real(kind=CUSTOM_REAL), dimension(3,NGLLX,NGLLY,NGLLZ,num_coupling_ac_el_faces,2) :: & 
+                                    rmemory_coupling_ac_el_displ
 
   ! local parameters
   integer :: i,j,k
   real(kind=CUSTOM_REAL) :: bb,coef0_1,coef1_1,coef2_1,coef0_2,coef1_2,coef2_2
   real(kind=CUSTOM_REAL) :: A6,A7,A8,A9,A10,A11,A12,A13,A14
-  real(kind=CUSTOM_REAL) :: displ_x,displ_y,displ_z
 
 
   if( CPML_regions(ispec_CPML) == CPML_X_ONLY ) then

Modified: seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_par.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_par.f90	2013-05-16 15:58:48 UTC (rev 22083)
+++ seismo/3D/SPECFEM3D/trunk/src/specfem3D/pml_par.f90	2013-05-16 18:22:56 UTC (rev 22084)
@@ -63,18 +63,18 @@
   real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: alpha_store
 
   ! derivatives of ux, uy and uz with respect to x, y and z
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_dux_dxl,PML_dux_dyl,PML_dux_dzl
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_duy_dxl,PML_duy_dyl,PML_duy_dzl
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_duz_dxl,PML_duz_dyl,PML_duz_dzl
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_dux_dxl,PML_dux_dyl,PML_dux_dzl
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_duy_dxl,PML_duy_dyl,PML_duy_dzl
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_duz_dxl,PML_duz_dyl,PML_duz_dzl
 
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_dux_dxl_new,PML_dux_dyl_new,PML_dux_dzl_new
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_duy_dxl_new,PML_duy_dyl_new,PML_duy_dzl_new
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_duz_dxl_new,PML_duz_dyl_new,PML_duz_dzl_new
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_dux_dxl_new,PML_dux_dyl_new,PML_dux_dzl_new
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_duy_dxl_new,PML_duy_dyl_new,PML_duy_dzl_new
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_duz_dxl_new,PML_duz_dyl_new,PML_duz_dzl_new
 
   ! derivatives of potential with respect to x, y and z
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_dpotential_dxl,PML_dpotential_dyl,PML_dpotential_dzl
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_dpotential_dxl,PML_dpotential_dyl,PML_dpotential_dzl
 
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: PML_dpotential_dxl_new,PML_dpotential_dyl_new,PML_dpotential_dzl_new
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: PML_dpotential_dxl_new,PML_dpotential_dyl_new,PML_dpotential_dzl_new
 
   ! C-PML memory variables
   real(kind=CUSTOM_REAL), dimension(:,:,:,:,:), allocatable :: rmemory_dux_dxl_x,rmemory_dux_dyl_x,rmemory_dux_dzl_x
@@ -100,10 +100,10 @@
   real(kind=CUSTOM_REAL), dimension(:,:,:,:,:), allocatable :: rmemory_potential_acoustic
 
   ! C-PML contribution to update acceleration to the global mesh
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:,:), allocatable :: accel_elastic_CPML
+  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: accel_elastic_CPML
 
   ! C-PML contribution to update the second derivative of the potential to the global mesh
-  real(kind=CUSTOM_REAL), dimension(:,:,:,:), allocatable :: potential_dot_dot_acoustic_CPML
+  real(kind=CUSTOM_REAL), dimension(:,:,:), allocatable :: potential_dot_dot_acoustic_CPML
 
   ! C-PML contribution to update displacement on elastic/acoustic interface
   real(kind=CUSTOM_REAL), dimension(:,:,:,:,:,:), allocatable :: rmemory_coupling_ac_el_displ



More information about the CIG-COMMITS mailing list