Skip to content

Commit f445866

Browse files
committed
updates boundary flags in mesher when extending mesh with CPML elements
1 parent 0533bba commit f445866

File tree

1 file changed

+104
-30
lines changed

1 file changed

+104
-30
lines changed

src/meshfem3D/create_CPML_regions.f90

Lines changed: 104 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -533,8 +533,10 @@ subroutine add_CPML_region_as_extra_layers(nglob)
533533
use constants_meshfem, only: NGLLX_M,NGLLY_M,NGLLZ_M
534534

535535
use meshfem_par, only: nspec
536+
536537
use create_meshfem_par, only: nodes_coords,ispec_material_id, &
537-
iboun,iMPIcut_xi,iMPIcut_eta
538+
iboun,iMPIcut_xi,iMPIcut_eta, &
539+
ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top
538540

539541
use shared_parameters, only: NGNOD
540542

@@ -545,6 +547,9 @@ subroutine add_CPML_region_as_extra_layers(nglob)
545547
THICKNESS_OF_X_PML,THICKNESS_OF_Y_PML,THICKNESS_OF_Z_PML, &
546548
ADD_PML_AS_EXTRA_MESH_LAYERS,NUMBER_OF_PML_LAYERS_TO_ADD
547549

550+
! boun
551+
use meshfem_par, only: NSPEC2DMAX_XMIN_XMAX,NSPEC2DMAX_YMIN_YMAX,NSPEC2D_BOTTOM,NSPEC2D_TOP
552+
548553
implicit none
549554

550555
integer,intent(inout) :: nglob
@@ -633,9 +638,9 @@ subroutine add_CPML_region_as_extra_layers(nglob)
633638
logical, dimension(:), allocatable :: ifseg
634639
double precision, dimension(:), allocatable :: xp,yp,zp
635640

636-
! (optional) updates absorbing boundary (iboun) array to move to outermost PML boundary elements
637-
! if .false. then Stacey boundary stays at original mesh boundary
638-
logical, parameter :: MOVE_STACEY_ABSORBING_BOUNDARY = .false.
641+
! updates absorbing/free-surface boundary (iboun) array to move to outermost PML boundary elements
642+
! (if .false. then boundary stays at original mesh boundary)
643+
logical, parameter :: UPDATE_BOUNDARY_FLAGS = .true.
639644
! sort and re-order new global nodes
640645
logical, parameter :: DO_MESH_SORTING = .true.
641646

@@ -1391,47 +1396,88 @@ subroutine add_CPML_region_as_extra_layers(nglob)
13911396
! create the material property for the extended elements
13921397
ispec_material_id_new(elem_counter) = ispec_material_id(ispec)
13931398

1394-
! boundary & MPI
1395-
iboun_new(:,elem_counter) = .false. ! absorbing boundary for Stacey, can be left at original mesh boundary
1396-
! (optional) move absorbing boundary to outermost PML layer
1397-
if (MOVE_STACEY_ABSORBING_BOUNDARY) then
1398-
iboun(:,ispec) = .false. ! reset as old boundary element is inside mesh now
1399-
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
1400-
! extended element is outer most element
1401-
if (iloop_on_X_Y_Z_faces == 1) then
1402-
! X-faces
1403-
if (iloop_on_min_face_then_max_face == 1) then
1404-
! xmin
1399+
! boundary
1400+
! updates absorbing/free-surface boundary flags to outermost PML layer
1401+
if (UPDATE_BOUNDARY_FLAGS) then
1402+
! extend (old) boundary flags
1403+
iboun_new(:,elem_counter) = iboun(:,ispec)
1404+
! extended element is outer most element
1405+
if (iloop_on_X_Y_Z_faces == 1) then
1406+
! X-faces
1407+
if (iloop_on_min_face_then_max_face == 1) then
1408+
! xmin
1409+
! reset as old boundary element is inside mesh now
1410+
iboun(1,ispec) = .false.
1411+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
14051412
iboun_new(1,elem_counter) = .true.
14061413
else
1407-
! xmax
1414+
! extended element is still inside mesh
1415+
iboun_new(1,elem_counter) = .false.
1416+
endif
1417+
else
1418+
! xmax
1419+
! reset as old boundary element is inside mesh now
1420+
iboun(2,ispec) = .false.
1421+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
14081422
iboun_new(2,elem_counter) = .true.
1423+
else
1424+
! extended element is still inside mesh
1425+
iboun_new(2,elem_counter) = .false.
14091426
endif
1410-
else if (iloop_on_X_Y_Z_faces == 2) then
1411-
! Y-faces
1412-
if (iloop_on_min_face_then_max_face == 1) then
1413-
! ymin
1427+
endif
1428+
else if (iloop_on_X_Y_Z_faces == 2) then
1429+
! Y-faces
1430+
if (iloop_on_min_face_then_max_face == 1) then
1431+
! ymin
1432+
! reset as old boundary element is inside mesh now
1433+
iboun(3,ispec) = .false.
1434+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
14141435
iboun_new(3,elem_counter) = .true.
14151436
else
1416-
! ymax
1417-
iboun_new(4,elem_counter) = .true.
1437+
! extended element is still inside mesh
1438+
iboun_new(3,elem_counter) = .false.
14181439
endif
14191440
else
1420-
! Z-faces
1421-
if (iloop_on_min_face_then_max_face == 1) then
1422-
! zmin
1441+
! ymax
1442+
! reset as old boundary element is inside mesh now
1443+
iboun(4,ispec) = .false.
1444+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
1445+
iboun_new(4,elem_counter) = .true.
1446+
else
1447+
! extended element is still inside mesh
1448+
iboun_new(4,elem_counter) = .false.
1449+
endif
1450+
endif
1451+
else
1452+
! Z-faces
1453+
if (iloop_on_min_face_then_max_face == 1) then
1454+
! zmin
1455+
! reset as old boundary element is inside mesh now
1456+
iboun(5,ispec) = .false.
1457+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
14231458
iboun_new(5,elem_counter) = .true.
14241459
else
1425-
! zmax
1460+
! extended element is still inside mesh
1461+
iboun_new(5,elem_counter) = .false.
1462+
endif
1463+
else
1464+
! zmax
1465+
! reset as old boundary element is inside mesh now
1466+
iboun(6,ispec) = .false.
1467+
if (iextend == NUMBER_OF_PML_LAYERS_TO_ADD) then
14261468
iboun_new(6,elem_counter) = .true.
1469+
else
1470+
! extended element is still inside mesh
1471+
iboun_new(6,elem_counter) = .false.
14271472
endif
14281473
endif
1429-
else
1430-
! extended element is still inside mesh
1431-
iboun_new(:,elem_counter) = .false.
14321474
endif
1475+
else
1476+
! boundary flags left at original mesh boundary
1477+
iboun_new(:,elem_counter) = .false.
14331478
endif
14341479

1480+
! MPI
14351481
! extend (old) MPI-cut flags
14361482
iMPIcut_xi_new(:,elem_counter) = iMPIcut_xi(:,ispec)
14371483
iMPIcut_eta_new(:,elem_counter) = iMPIcut_eta(:,ispec)
@@ -1705,8 +1751,10 @@ subroutine add_CPML_region_as_extra_layers(nglob)
17051751
ispec_material_id(:) = ispec_material_id_new(:)
17061752
ibool(:,:,:,:) = ibool_new(:,:,:,:)
17071753

1708-
! boundary & MPI
1754+
! boundary (absorbing / free surface)
17091755
iboun(:,:) = iboun_new(:,:)
1756+
1757+
! MPI
17101758
iMPIcut_xi(:,:) = iMPIcut_xi_new(:,:)
17111759
iMPIcut_eta(:,:) = iMPIcut_eta_new(:,:)
17121760

@@ -1715,6 +1763,32 @@ subroutine add_CPML_region_as_extra_layers(nglob)
17151763
is_Y_CPML(:) = is_Y_CPML_new(:)
17161764
is_Z_CPML(:) = is_Z_CPML_new(:)
17171765

1766+
! updates boundary arrays
1767+
if (UPDATE_BOUNDARY_FLAGS) then
1768+
! updates counts
1769+
NSPEC2DMAX_XMIN_XMAX = max(NSPEC2DMAX_XMIN_XMAX,count(iboun(1,:) .eqv. .true.))
1770+
NSPEC2DMAX_XMIN_XMAX = max(NSPEC2DMAX_XMIN_XMAX,count(iboun(2,:) .eqv. .true.))
1771+
1772+
NSPEC2DMAX_YMIN_YMAX = max(NSPEC2DMAX_YMIN_YMAX,count(iboun(3,:) .eqv. .true.))
1773+
NSPEC2DMAX_YMIN_YMAX = max(NSPEC2DMAX_YMIN_YMAX,count(iboun(4,:) .eqv. .true.))
1774+
1775+
NSPEC2D_BOTTOM = count(iboun(5,:) .eqv. .true.)
1776+
NSPEC2D_TOP = count(iboun(6,:) .eqv. .true.)
1777+
1778+
! re-allocates boundary parameters locator
1779+
deallocate(ibelm_xmin,ibelm_xmax,ibelm_ymin,ibelm_ymax,ibelm_bottom,ibelm_top)
1780+
allocate(ibelm_xmin(NSPEC2DMAX_XMIN_XMAX), &
1781+
ibelm_xmax(NSPEC2DMAX_XMIN_XMAX), &
1782+
ibelm_ymin(NSPEC2DMAX_YMIN_YMAX), &
1783+
ibelm_ymax(NSPEC2DMAX_YMIN_YMAX), &
1784+
ibelm_bottom(NSPEC2D_BOTTOM), &
1785+
ibelm_top(NSPEC2D_TOP),stat=ier)
1786+
if (ier /= 0) stop 'Error allocating new ibelm arrays'
1787+
! initializes - values will be determined later on when calling store_boundaries() routine
1788+
ibelm_xmin(:) = 0; ibelm_xmax(:) = 0; ibelm_ymin(:) = 0; ibelm_ymax(:) = 0
1789+
ibelm_bottom(:) = 0; ibelm_top(:) = 0
1790+
endif
1791+
17181792
! the new number of elements and points becomes the old one, for the same reason
17191793
nspec = nspec_new
17201794
npoin = npoin_new_real

0 commit comments

Comments
 (0)