[cig-commits] r21838 - seismo/3D/SPECFEM3D/trunk/src/generate_databases

xie.zhinan at geodynamics.org xie.zhinan at geodynamics.org
Fri Apr 12 08:54:32 PDT 2013


Author: xie.zhinan
Date: 2013-04-12 08:54:31 -0700 (Fri, 12 Apr 2013)
New Revision: 21838

Modified:
   seismo/3D/SPECFEM3D/trunk/src/generate_databases/pml_set_local_dampingcoeff.f90
Log:
commit Dimitri's way to avoid errors in computing damping parameters in CPML


Modified: seismo/3D/SPECFEM3D/trunk/src/generate_databases/pml_set_local_dampingcoeff.f90
===================================================================
--- seismo/3D/SPECFEM3D/trunk/src/generate_databases/pml_set_local_dampingcoeff.f90	2013-04-12 12:31:01 UTC (rev 21837)
+++ seismo/3D/SPECFEM3D/trunk/src/generate_databases/pml_set_local_dampingcoeff.f90	2013-04-12 15:54:31 UTC (rev 21838)
@@ -99,7 +99,7 @@
   alpha_store = 0._CUSTOM_REAL
 
   if(ELASTIC_SIMULATION .and. .not. ACOUSTIC_SIMULATION)then
-    ALPHA_MAX_PML = PI*f0_FOR_PML  ! from Festa and Vilotte (2005)
+    ALPHA_MAX_PML = PI*f0_FOR_PML*1.0  ! from Festa and Vilotte (2005)
   elseif(ACOUSTIC_SIMULATION .and. .not. ELASTIC_SIMULATION)then
     ALPHA_MAX_PML = PI*f0_FOR_PML*2.0
   elseif(ELASTIC_SIMULATION .and. ACOUSTIC_SIMULATION)then
@@ -278,38 +278,46 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
                  elseif( xstore(iglob) - x_origin < 0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! gets damping profile at the C-PML grid point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
 
-                       ! gets damping profile at the C-PML grid point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
+
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
                  else
                     stop "there is error in mesh of CPML-layer x"
                  endif
@@ -336,37 +344,46 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_y = ystore(iglob) - yoriginfront
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_y < 0.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
                  elseif( ystore(iglob) - y_origin < 0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_y = yoriginback - ystore(iglob)
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_y < 0.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
+
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
                  else
                     stop "there is error in mesh of  CPML-layer y"
 
@@ -395,37 +412,46 @@
                        ! gets abscissa of current grid point along the damping profile
                        abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_z / CPML_width_z
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                       alpha_z = ALPHA_MAX_PML / 2.d0
+                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       if( d_z < 0.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
+                       if( K_z < 1.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
                     endif
                  elseif( zstore(iglob) - z_origin < 0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_z = zoriginbottom - zstore(iglob)
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_z / CPML_width_z
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                       alpha_z = ALPHA_MAX_PML / 2.d0
-                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_z < 0.d0 ) then
                        d_z = 0.d0
-                       alpha_z = 0.d0
                        K_z = 1.d0
                     endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
                  else
                     stop "there is error in mesh of CPML-layer z"
                  endif
@@ -452,34 +478,42 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_y < 1.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
@@ -487,34 +521,42 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_y < 1.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
@@ -522,34 +564,42 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_y < 1.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
@@ -557,36 +607,45 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_y < 1.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
+
                  else
                     stop "there is error in mesh of CPML-layer xy"
                  endif
@@ -615,43 +674,95 @@
                        ! gets abscissa of current grid point along the damping profile
                        abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_x / CPML_width_x
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                       alpha_x = ALPHA_MAX_PML / 2.d0
+                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_z / CPML_width_z
+
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                       alpha_z = ALPHA_MAX_PML / 2.d0
+                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       if( d_x < 0.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( K_x < 1.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( xstore(iglob) - x_origin>0.d0 .and. zstore(iglob) - z_origin<0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                 elseif( xstore(iglob) - x_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
+                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_x / CPML_width_x
 
@@ -659,16 +770,10 @@
                        d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
                        alpha_x = ALPHA_MAX_PML / 2.d0
                        K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_x = 0.d0
-                       alpha_x = 0.d0
-                       K_x = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_z / CPML_width_z
 
@@ -676,83 +781,72 @@
                        d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
                        alpha_z = ALPHA_MAX_PML / 2.d0
                        K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_z = 0.d0
-                       alpha_z = 0.d0
-                       K_z = 1.d0
-                    endif
 
-                 elseif( xstore(iglob) - x_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
-                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+                       if( d_x < 0.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_x < 1.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( xstore(iglob) - x_origin<0.d0 .and. zstore(iglob) - z_origin<0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_z / CPML_width_z
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                       alpha_z = ALPHA_MAX_PML / 2.d0
-                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_z < 1.d0 ) then
                        d_z = 0.d0
-                       alpha_z = 0.d0
                        K_z = 1.d0
                     endif
+
                  else
                     stop "there is error in mesh of CPML-layer xz"
                  endif
@@ -780,43 +874,94 @@
                        ! gets abscissa of current grid point along the damping profile
                        abscissa_in_PML_y = ystore(iglob) - yoriginfront
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_y / CPML_width_y
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
-                          d_y = 0.d0
-                          alpha_y = 0.d0
-                          K_y = 1.d0
-                       endif
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                       alpha_y = ALPHA_MAX_PML / 2.d0
+                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
 
                        ! gets abscissa of current grid point along the damping profile
                        abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_z / CPML_width_z
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                       alpha_z = ALPHA_MAX_PML / 2.d0
+                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
+
+                       if( K_y < 1.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
+ 
+                       if( d_z < 0.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
+                       if( K_z < 1.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
                     endif
 
                  elseif( ystore(iglob) - y_origin>0.d0 .and. zstore(iglob) - z_origin<0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_y = ystore(iglob) - yoriginfront
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                 elseif( ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
+                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_y = yoriginback - ystore(iglob)
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_y / CPML_width_y
 
@@ -824,16 +969,10 @@
                        d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
                        alpha_y = ALPHA_MAX_PML / 2.d0
                        K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_y = 0.d0
-                       alpha_y = 0.d0
-                       K_y = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_z / CPML_width_z
 
@@ -841,83 +980,72 @@
                        d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
                        alpha_z = ALPHA_MAX_PML / 2.d0
                        K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_z = 0.d0
-                       alpha_z = 0.d0
-                       K_z = 1.d0
-                    endif
 
-                 elseif( ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
-                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_y = yoriginback - ystore(iglob)
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_y < 1.d0 ) then
                           d_y = 0.d0
-                          alpha_y = 0.d0
                           K_y = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin<0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_y = yoriginback - ystore(iglob)
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_y < 0.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_z / CPML_width_z
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                       alpha_z = ALPHA_MAX_PML / 2.d0
-                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_z < 1.d0 ) then
                        d_z = 0.d0
-                       alpha_z = 0.d0
                        K_z = 1.d0
                     endif
+
                  else
                     stop "there is error in mesh of CPML-layer yz"
                  endif
@@ -944,51 +1072,63 @@
                        ! gets abscissa of current grid point along the damping profile
                        abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_x / CPML_width_x
 
-                          ! gets damping profile at the C-PML grid point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       ! gets damping profile at the C-PML grid point
+                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                       alpha_x = ALPHA_MAX_PML / 2.d0
+                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_y = ystore(iglob) - yoriginfront
+
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_y / CPML_width_y
+
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                       alpha_y = ALPHA_MAX_PML / 2.d0
+                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+
+                       ! determines distance to C-PML/mesh interface
+                       dist = abscissa_in_PML_z / CPML_width_z
+
+                       ! gets damping profile at the C-PML element's GLL point
+                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                       alpha_z = ALPHA_MAX_PML / 2.d0
+                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                       if( d_x < 0.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                       if( K_x < 1.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
 
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_y < 1.d0 ) then
                           d_y = 0.d0
-                          alpha_y = 0.d0
                           K_y = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
                     endif
@@ -997,24 +1137,83 @@
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
+
+                    ! gets damping profile at the C-PML grid point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+
+                 elseif( xstore(iglob) - x_origin>0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
+                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_x = xstore(iglob) - xoriginright
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML grid point
+                       ! gets damping profile at the C-PML element's GLL point
                        d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
                        alpha_x = ALPHA_MAX_PML / 2.d0
                        K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_x = 0.d0
-                       alpha_x = 0.d0
-                       K_x = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_y = yoriginback - ystore(iglob)
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_y / CPML_width_y
 
@@ -1022,16 +1221,11 @@
                        d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
                        alpha_y = ALPHA_MAX_PML / 2.d0
                        K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_y = 0.d0
-                       alpha_y = 0.d0
-                       K_y = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_z / CPML_width_z
 
@@ -1039,88 +1233,121 @@
                        d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
                        alpha_z = ALPHA_MAX_PML / 2.d0
                        K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_z = 0.d0
-                       alpha_z = 0.d0
-                       K_z = 1.d0
-                    endif
 
-                 elseif( xstore(iglob) - x_origin>0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
-                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_x = xstore(iglob) - xoriginright
+                       if( d_x < 0.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_x < 1.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_y = yoriginback - ystore(iglob)
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_y < 1.d0 ) then
                           d_y = 0.d0
-                          alpha_y = 0.d0
                           K_y = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( xstore(iglob) - x_origin>0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin < 0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xstore(iglob) - xoriginright
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                 elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin>0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
+                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
+                       ! gets damping profile at the C-PML grid point
                        d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
                        alpha_x = ALPHA_MAX_PML / 2.d0
                        K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_x = 0.d0
-                       alpha_x = 0.d0
-                       K_x = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_y = ystore(iglob) - yoriginfront
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_y / CPML_width_y
 
@@ -1128,16 +1355,10 @@
                        d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
                        alpha_y = ALPHA_MAX_PML / 2.d0
                        K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_y = 0.d0
-                       alpha_y = 0.d0
-                       K_y = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_z / CPML_width_z
 
@@ -1145,88 +1366,119 @@
                        d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
                        alpha_z = ALPHA_MAX_PML / 2.d0
                        K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_z = 0.d0
-                       alpha_z = 0.d0
-                       K_z = 1.d0
-                    endif
 
-                 elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin>0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
-                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+                       if( d_x < 0.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
-
-                          ! gets damping profile at the C-PML grid point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_x < 1.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_y < 1.d0 ) then
                           d_y = 0.d0
-                          alpha_y = 0.d0
                           K_y = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin>0.d0 .and. zstore(iglob) - z_origin<0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
+
+                    ! gets damping profile at the C-PML grid point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
+
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( K_y < 1.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
+
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                    if( K_z < 1.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
+
+                 elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
+                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML grid point
+                       ! gets damping profile at the C-PML element's GLL point
                        d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
                        alpha_x = ALPHA_MAX_PML / 2.d0
                        K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_x = 0.d0
-                       alpha_x = 0.d0
-                       K_x = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = ystore(iglob) - yoriginfront
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_y = yoriginback - ystore(iglob)
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_y / CPML_width_y
 
@@ -1234,16 +1486,10 @@
                        d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
                        alpha_y = ALPHA_MAX_PML / 2.d0
                        K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_y = 0.d0
-                       alpha_y = 0.d0
-                       K_y = 1.d0
-                    endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                       ! gets abscissa of current grid point along the damping profile
+                       abscissa_in_PML_z = zstore(iglob) - zorigintop
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
                        ! determines distance to C-PML/mesh interface
                        dist = abscissa_in_PML_z / CPML_width_z
 
@@ -1251,117 +1497,103 @@
                        d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
                        alpha_z = ALPHA_MAX_PML / 2.d0
                        K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
-                       d_z = 0.d0
-                       alpha_z = 0.d0
-                       K_z = 1.d0
-                    endif
 
-                 elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin>0.d0 ) then
-                    if( PML_INSTEAD_OF_FREE_SURFACE ) then
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_x = xoriginleft - xstore(iglob)
+                       if( d_x < 0.d0 ) then
+                          d_x = 0.d0
+                          K_x = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_x >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_x / CPML_width_x
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                          alpha_x = ALPHA_MAX_PML / 2.d0
-                          K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_x < 1.d0 ) then
                           d_x = 0.d0
-                          alpha_x = 0.d0
                           K_x = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_y = yoriginback - ystore(iglob)
+                       if( d_y < 0.d0 ) then
+                          d_y = 0.d0
+                          K_y = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_y >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_y / CPML_width_y
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                          alpha_y = ALPHA_MAX_PML / 2.d0
-                          K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_y < 1.d0 ) then
                           d_y = 0.d0
-                          alpha_y = 0.d0
                           K_y = 1.d0
                        endif
 
-                       ! gets abscissa of current grid point along the damping profile
-                       abscissa_in_PML_z = zstore(iglob) - zorigintop
+                       if( d_z < 0.d0 ) then
+                          d_z = 0.d0
+                          K_z = 1.d0
+                       endif
 
-                       if( abscissa_in_PML_z >= -0.1d0 ) then
-                          ! determines distance to C-PML/mesh interface
-                          dist = abscissa_in_PML_z / CPML_width_z
-
-                          ! gets damping profile at the C-PML element's GLL point
-                          d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                          alpha_z = ALPHA_MAX_PML / 2.d0
-                          K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                       else
+                       if( K_z < 1.d0 ) then
                           d_z = 0.d0
-                          alpha_z = 0.d0
                           K_z = 1.d0
                        endif
+
                     endif
 
                  elseif( xstore(iglob) - x_origin<0.d0 .and. ystore(iglob) - y_origin<0.d0 .and. zstore(iglob) - z_origin < 0.d0 ) then
                     ! gets abscissa of current grid point along the damping profile
                     abscissa_in_PML_x = xoriginleft - xstore(iglob)
 
-                    if( abscissa_in_PML_x >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_x / CPML_width_x
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_x / CPML_width_x
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
-                       alpha_x = ALPHA_MAX_PML / 2.d0
-                       K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_x = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_x)
+                    alpha_x = ALPHA_MAX_PML / 2.d0
+                    K_x = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_y / CPML_width_y
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
+                    alpha_y = ALPHA_MAX_PML / 2.d0
+                    K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    ! gets abscissa of current grid point along the damping profile
+                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+
+                    ! determines distance to C-PML/mesh interface
+                    dist = abscissa_in_PML_z / CPML_width_z
+
+                    ! gets damping profile at the C-PML element's GLL point
+                    d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
+                    alpha_z = ALPHA_MAX_PML / 2.d0
+                    K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
+
+                    if( d_x < 0.d0 ) then
                        d_x = 0.d0
-                       alpha_x = 0.d0
                        K_x = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_y = yoriginback - ystore(iglob)
+                    if( K_x < 1.d0 ) then
+                       d_x = 0.d0
+                       K_x = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_y >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_y / CPML_width_y
+                    if( d_y < 0.d0 ) then
+                       d_y = 0.d0
+                       K_y = 1.d0
+                    endif
 
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_y = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_y)
-                       alpha_y = ALPHA_MAX_PML / 2.d0
-                       K_y = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_y < 1.d0 ) then
                        d_y = 0.d0
-                       alpha_y = 0.d0
                        K_y = 1.d0
                     endif
 
-                    ! gets abscissa of current grid point along the damping profile
-                    abscissa_in_PML_z = zoriginbottom - zstore(iglob)
+                    if( d_z < 0.d0 ) then
+                       d_z = 0.d0
+                       K_z = 1.d0
+                    endif
 
-                    if( abscissa_in_PML_z >= -0.1d0 ) then
-                       ! determines distance to C-PML/mesh interface
-                       dist = abscissa_in_PML_z / CPML_width_z
-
-                       ! gets damping profile at the C-PML element's GLL point
-                       d_z = pml_damping_profile_l(myrank,iglob,dist,vp,CPML_width_z)
-                       alpha_z = ALPHA_MAX_PML / 2.d0
-                       K_z = 1.d0 + (K_MAX_PML - 1.d0) * dist**NPOWER
-                    else
+                    if( K_z < 1.d0 ) then
                        d_z = 0.d0
-                       alpha_z = 0.d0
                        K_z = 1.d0
                     endif
+
                  else
                     stop "there is error in mesh of CPML-layer xyz"
                  endif



More information about the CIG-COMMITS mailing list