Skip to content

Commit 68a8f50

Browse files
committed
moves mass matrix allocations to create_mass_matrices() routine; updates usage of nglob_xy (for absorbing boundary cases)
1 parent 7dd0eb8 commit 68a8f50

File tree

7 files changed

+100
-126
lines changed

7 files changed

+100
-126
lines changed

src/meshfem3D/create_mass_matrices.f90

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ subroutine create_mass_matrices(idoubling,ibool, &
5656
use regions_mesh_par2, only: &
5757
xixstore,xiystore,xizstore,etaxstore,etaystore,etazstore, &
5858
gammaxstore,gammaystore,gammazstore,rhostore,kappavstore, &
59-
rmassx,rmassy,rmassz,b_rmassx,b_rmassy, &
60-
nglob_xy
59+
rmassx,rmassy,rmassz,b_rmassx,b_rmassy,rmass_ocean_load, &
60+
nglob_xy,nglob_oceans
6161

6262
implicit none
6363

@@ -75,10 +75,61 @@ subroutine create_mass_matrices(idoubling,ibool, &
7575
! local parameters
7676
double precision :: weight
7777
real(kind=CUSTOM_REAL) :: xixl,xiyl,xizl,etaxl,etayl,etazl,gammaxl,gammayl,gammazl,jacobianl
78+
integer :: ispec,i,j,k,iglob,ier
7879

79-
integer :: ispec,i,j,k,iglob
80+
! initializes
81+
nglob_xy = 0 ! for rmassx/rmassy
82+
nglob_oceans = 0 ! for ocean load mass matrix
83+
84+
! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix is needed
85+
! for the sake of performance, only "rmassz" array will be filled and "rmassx" & "rmassy" will be obsolete
86+
if (NCHUNKS /= 6 .and. ABSORBING_CONDITIONS) then
87+
! crust/mantle region uses different rmassx/rmassy/rmassz for absorbing boundary
88+
if (iregion_code == IREGION_CRUST_MANTLE) nglob_xy = nglob
89+
endif
90+
91+
if (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION) then
92+
! rotation in solid domains uses different rmassx/rmassy/rmassz
93+
if (iregion_code == IREGION_CRUST_MANTLE .or. &
94+
iregion_code == IREGION_INNER_CORE) nglob_xy = nglob
95+
endif
96+
97+
! ocean load mass matrix
98+
if (OCEANS) then
99+
! ocean load only applies in crust/mantle region
100+
if (iregion_code == IREGION_CRUST_MANTLE) nglob_oceans = nglob
101+
endif
102+
103+
! allocates mass matrices in this slice (will be fully assembled in the solver)
104+
allocate(rmassz(nglob),stat=ier)
105+
if (ier /= 0) stop 'Error in allocate 22'
106+
rmassz(:) = 0.0_CUSTOM_REAL
107+
108+
allocate(rmassx(nglob_xy), &
109+
rmassy(nglob_xy), &
110+
stat=ier)
111+
if (ier /= 0) stop 'Error in allocate 21'
112+
rmassx(:) = 0.0_CUSTOM_REAL
113+
rmassy(:) = 0.0_CUSTOM_REAL
114+
115+
allocate(b_rmassx(nglob_xy), &
116+
b_rmassy(nglob_xy),stat=ier)
117+
if (ier /= 0) stop 'Error in allocate b_21'
118+
b_rmassx(:) = 0.0_CUSTOM_REAL
119+
b_rmassy(:) = 0.0_CUSTOM_REAL
120+
121+
! allocates ocean load mass matrix as well if oceans
122+
allocate(rmass_ocean_load(nglob_oceans),stat=ier)
123+
if (ier /= 0) stop 'Error in allocate 22'
124+
rmass_ocean_load(:) = 0.0_CUSTOM_REAL
80125

81-
! initializes matrices
126+
! checks if anything to do
127+
if (iregion_code == IREGION_TRINFINITE .or. iregion_code == IREGION_INFINITE) return
128+
129+
! check if anything to do (must have region domain points)
130+
if (nglob == 0) return
131+
132+
! setup matrices
82133
!
83134
! in the case of Stacey boundary conditions, add C*delta/2 contribution to the mass matrix
84135
! on the Stacey edges for the crust_mantle and outer_core regions but not for the inner_core region
@@ -89,18 +140,7 @@ subroutine create_mass_matrices(idoubling,ibool, &
89140
!
90141
! Now also handle EXACT_MASS_MATRIX_FOR_ROTATION, which requires similar corrections
91142

92-
rmassx(:) = 0._CUSTOM_REAL
93-
rmassy(:) = 0._CUSTOM_REAL
94-
rmassz(:) = 0._CUSTOM_REAL
95-
96-
b_rmassx(:) = 0._CUSTOM_REAL
97-
b_rmassy(:) = 0._CUSTOM_REAL
98-
99-
! checks if anything to do
100-
if (iregion_code == IREGION_TRINFINITE .or. iregion_code == IREGION_INFINITE) return
101-
102143
! first create the main standard mass matrix with no corrections
103-
104144
! openmp mesher
105145
!$OMP PARALLEL DEFAULT(SHARED) &
106146
!$OMP PRIVATE(ispec,i,j,k,iglob,weight, &
@@ -427,6 +467,14 @@ subroutine create_mass_matrices_Stacey(ibool,iregion_code)
427467
! adds contributions to mass matrix to stabilize Stacey conditions
428468
select case (iregion_code)
429469
case (IREGION_CRUST_MANTLE)
470+
471+
! compatibility with old versions (6.x, 7.x)
472+
if (USE_OLD_VERSION_FORMAT) then
473+
! note: this will override the rotation contributions added in case before this routine call
474+
rmassx(:) = rmassz(:)
475+
rmassy(:) = rmassz(:)
476+
endif
477+
430478
do iface = 1,num_abs_boundary_faces
431479

432480
ispec = abs_boundary_ispec(iface)

src/meshfem3D/create_regions_mesh.F90

Lines changed: 23 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,19 @@ subroutine create_regions_mesh(npointot, &
5555
HDF5_ENABLED
5656

5757
use meshfem_par, only: &
58-
myrank,nspec,nglob,iregion_code, &
58+
myrank,nspec,iregion_code, &
5959
ibool,idoubling,xstore,ystore,zstore, &
6060
xstore_glob,ystore_glob,zstore_glob
6161

6262
use meshfem_par, only: &
6363
NCHUNKS,SAVE_MESH_FILES,ABSORBING_CONDITIONS,LOCAL_PATH, &
6464
ADIOS_FOR_ARRAYS_SOLVER,ADIOS_FOR_SOLVER_MESHFILES, &
65-
ROTATION,EXACT_MASS_MATRIX_FOR_ROTATION,GRAVITY_INTEGRALS, &
65+
GRAVITY_INTEGRALS, &
6666
FULL_GRAVITY, &
6767
NGLOB1D_RADIAL_CORNER, &
6868
NGLOB2DMAX_XMIN_XMAX,NGLOB2DMAX_YMIN_YMAX, &
6969
volume_total,Earth_mass_total,Earth_center_of_mass_x_total,Earth_center_of_mass_y_total,Earth_center_of_mass_z_total
7070

71-
use meshfem_models_par, only: &
72-
OCEANS
73-
7471
#ifdef USE_CEM
7572
use meshfem_models_par, only: CEM_REQUEST
7673
#endif
@@ -96,8 +93,8 @@ subroutine create_regions_mesh(npointot, &
9693
mu0store,Gc_prime_store,Gs_prime_store, &
9794
rho_vp,rho_vs, &
9895
Qmu_store,tau_e_store, &
99-
nglob_xy,rmassx,rmassy,rmassz,b_rmassx,b_rmassy, &
100-
nglob_oceans,rmass_ocean_load, &
96+
rmassx,rmassy,rmassz,b_rmassx,b_rmassy, &
97+
rmass_ocean_load, &
10198
iMPIcut_xi,iMPIcut_eta, &
10299
ispec_is_tiso
103100

@@ -129,9 +126,6 @@ subroutine create_regions_mesh(npointot, &
129126
! now perform two passes in this part to be able to save memory
130127
integer,intent(in) :: ipass
131128

132-
! local parameters
133-
integer :: ier
134-
135129
! user output
136130
if (myrank == 0) then
137131
write(IMAIN,*)
@@ -374,71 +368,6 @@ subroutine create_regions_mesh(npointot, &
374368
write(IMAIN,*) ' ...creating mass matrix'
375369
call flush_IMAIN()
376370
endif
377-
378-
! allocates mass matrices in this slice (will be fully assembled in the solver)
379-
!
380-
! in the case of Stacey boundary conditions, add C*deltat/2 contribution to the mass matrix
381-
! on Stacey edges for the crust_mantle and outer_core regions but not for the inner_core region
382-
! thus the mass matrix must be replaced by three mass matrices including the "C" damping matrix
383-
!
384-
! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix is needed
385-
! for the sake of performance, only "rmassz" array will be filled and "rmassx" & "rmassy" will be obsolete
386-
if (NCHUNKS /= 6 .and. ABSORBING_CONDITIONS) then
387-
select case (iregion_code)
388-
case (IREGION_CRUST_MANTLE)
389-
nglob_xy = nglob
390-
case (IREGION_INNER_CORE, IREGION_OUTER_CORE)
391-
nglob_xy = 1
392-
case (IREGION_TRINFINITE, IREGION_INFINITE)
393-
nglob_xy = 1
394-
case default
395-
call exit_mpi(myrank,'Invalid region code for nglob_xy')
396-
end select
397-
else
398-
nglob_xy = 1
399-
endif
400-
401-
if (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION) then
402-
select case (iregion_code)
403-
case (IREGION_CRUST_MANTLE,IREGION_INNER_CORE)
404-
nglob_xy = nglob
405-
case (IREGION_OUTER_CORE)
406-
nglob_xy = 1
407-
case (IREGION_TRINFINITE, IREGION_INFINITE)
408-
nglob_xy = 1
409-
case default
410-
call exit_mpi(myrank,'Invalid region code for nglob_xy with EXACT_MASS_MATRIX_FOR_ROTATION')
411-
end select
412-
endif
413-
414-
allocate(rmassx(nglob_xy), &
415-
rmassy(nglob_xy), &
416-
stat=ier)
417-
if (ier /= 0) stop 'Error in allocate 21'
418-
rmassx(:) = 0.0_CUSTOM_REAL
419-
rmassy(:) = 0.0_CUSTOM_REAL
420-
421-
allocate(b_rmassx(nglob_xy), &
422-
b_rmassy(nglob_xy),stat=ier)
423-
if (ier /= 0) stop 'Error in allocate b_21'
424-
b_rmassx(:) = 0.0_CUSTOM_REAL
425-
b_rmassy(:) = 0.0_CUSTOM_REAL
426-
427-
allocate(rmassz(nglob),stat=ier)
428-
if (ier /= 0) stop 'Error in allocate 22'
429-
rmassz(:) = 0.0_CUSTOM_REAL
430-
431-
! allocates ocean load mass matrix as well if oceans
432-
if (OCEANS .and. iregion_code == IREGION_CRUST_MANTLE) then
433-
nglob_oceans = nglob
434-
else
435-
! allocate dummy array if no oceans
436-
nglob_oceans = 1
437-
endif
438-
allocate(rmass_ocean_load(nglob_oceans),stat=ier)
439-
if (ier /= 0) stop 'Error in allocate 22'
440-
rmass_ocean_load(:) = 0.0_CUSTOM_REAL
441-
442371
! creating mass matrices in this slice (will be fully assembled in the solver)
443372
! note: for Stacey boundaries, needs indexing nimin,.. filled in the first pass
444373
call create_mass_matrices(idoubling,ibool, &
@@ -522,25 +451,6 @@ subroutine create_regions_mesh(npointot, &
522451

523452
endif ! .not. GRAVITY_INTEGRALS
524453

525-
! synchronizes processes before clean up memory
526-
call synchronize_all()
527-
528-
! frees memory
529-
deallocate(rmassx,rmassy,rmassz)
530-
deallocate(b_rmassx,b_rmassy)
531-
deallocate(rmass_ocean_load)
532-
! frees allocated mesh memory
533-
deallocate(xstore_glob,ystore_glob,zstore_glob)
534-
! frees MPI arrays memory
535-
call crm_free_MPI_arrays()
536-
! free Stacey helper arrays (not needed anymore)
537-
if (allocated(nimin)) deallocate(nimin,nimax,njmin,njmax,nkmin_xi,nkmin_eta)
538-
if (allocated(abs_boundary_ispec)) then
539-
deallocate(abs_boundary_ispec,abs_boundary_npoin,abs_boundary_ijk)
540-
deallocate(abs_boundary_jacobian2Dw)
541-
deallocate(abs_boundary_normal)
542-
endif
543-
544454
! compute volume, bottom and top area of that part of the slice, and then the total
545455
call compute_volumes_and_areas(NCHUNKS,iregion_code,nspec,wxgll,wygll,wzgll, &
546456
xixstore,xiystore,xizstore,etaxstore,etaystore,etazstore,gammaxstore,gammaystore,gammazstore, &
@@ -569,6 +479,25 @@ subroutine create_regions_mesh(npointot, &
569479

570480
endif
571481

482+
! synchronizes processes before clean up memory
483+
call synchronize_all()
484+
485+
! frees memory
486+
deallocate(rmassx,rmassy,rmassz)
487+
deallocate(b_rmassx,b_rmassy)
488+
deallocate(rmass_ocean_load)
489+
! frees allocated mesh memory
490+
deallocate(xstore_glob,ystore_glob,zstore_glob)
491+
! frees MPI arrays memory
492+
call crm_free_MPI_arrays()
493+
! free Stacey helper arrays (not needed anymore)
494+
if (allocated(nimin)) deallocate(nimin,nimax,njmin,njmax,nkmin_xi,nkmin_eta)
495+
if (allocated(abs_boundary_ispec)) then
496+
deallocate(abs_boundary_ispec,abs_boundary_npoin,abs_boundary_ijk)
497+
deallocate(abs_boundary_jacobian2Dw)
498+
deallocate(abs_boundary_normal)
499+
endif
500+
572501
case default
573502
stop 'there cannot be more than two passes in mesh creation'
574503

src/meshfem3D/save_arrays_solver.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,13 @@ subroutine save_arrays_mesh_parameters()
773773
!
774774
! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix is needed
775775
! for the sake of performance, only "rmassz" array will be filled and "rmassx" & "rmassy" will be fictitious / unused
776+
NGLOB_XY_CM = 0
777+
NGLOB_XY_IC = 0
776778

777779
if (NCHUNKS /= 6 .and. ABSORBING_CONDITIONS) then
778-
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
779-
else
780-
NGLOB_XY_CM = 0
780+
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
781781
endif
782-
NGLOB_XY_IC = 0
782+
783783
if (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION) then
784784
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
785785
NGLOB_XY_IC = NGLOB_REGIONS(IREGION_INNER_CORE)

src/shared/memory_eval.f90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -555,12 +555,12 @@ subroutine memory_eval(NEX_PER_PROC_XI,NEX_PER_PROC_ETA, &
555555
!
556556
! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix is needed
557557
! for the sake of performance, only "rmassz" array will be filled and "rmassx" & "rmassy" will be fictitious / unused
558+
NGLOB_XY_CM = 0
559+
NGLOB_XY_IC = 0
560+
558561
if (NCHUNKS /= 6 .and. ABSORBING_CONDITIONS) then
559-
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
560-
else
561-
NGLOB_XY_CM = 0
562+
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
562563
endif
563-
NGLOB_XY_IC = 0
564564

565565
if (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION) then
566566
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)

src/shared/save_header_file.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,18 @@ subroutine save_header_file(NSPEC_REGIONS,NGLOB_REGIONS,NPROC,NPROCTOT, &
745745
!
746746
! if absorbing_conditions are not set or if NCHUNKS=6, only one mass matrix is needed
747747
! for the sake of performance, only "rmassz" array will be filled and "rmassx" & "rmassy" will be fictitious / unused
748+
NGLOB_XY_CM = 0
749+
NGLOB_XY_IC = 0
748750

749751
if (NCHUNKS /= 6 .and. ABSORBING_CONDITIONS) then
750-
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
751-
else
752-
NGLOB_XY_CM = 0
752+
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
753753
endif
754-
NGLOB_XY_IC = 0
755754

756755
if (ROTATION .and. EXACT_MASS_MATRIX_FOR_ROTATION) then
757756
NGLOB_XY_CM = NGLOB_REGIONS(IREGION_CRUST_MANTLE)
758757
NGLOB_XY_IC = NGLOB_REGIONS(IREGION_INNER_CORE)
759758
endif
759+
760760
write(IOUT,*) 'integer, parameter :: NGLOB_XY_CM = ',NGLOB_XY_CM
761761
write(IOUT,*) 'integer, parameter :: NGLOB_XY_IC = ',NGLOB_XY_IC
762762
write(IOUT,*)

src/specfem3D/compute_forces_viscoelastic_calling_routine.F90

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,7 @@ subroutine compute_forces_inner_core( NSPEC_STR_OR_ATT,NGLOB,NSPEC_ATT, &
850850
! (left in this file to let compiler decide about inlining)
851851

852852
use constants_solver, only: CUSTOM_REAL,NDIM,NGLLX,NGLLY,NGLLZ,USE_DEVILLE_PRODUCTS_VAL, &
853-
ATT5_VAL,N_SLS,NSPEC_INNER_CORE_STRAIN_ONLY,NCHUNKS_VAL
854-
855-
use shared_parameters, only: ABSORBING_CONDITIONS
853+
ATT5_VAL,N_SLS,NSPEC_INNER_CORE_STRAIN_ONLY
856854

857855
! note: passes sum_terms array as subroutine argument which will help for performance (better than use-statement)
858856
use specfem_par_innercore, only: sum_terms_inner_core,factor_common_inner_core,NSPEC_INNER_CORE
@@ -891,8 +889,6 @@ subroutine compute_forces_inner_core( NSPEC_STR_OR_ATT,NGLOB,NSPEC_ATT, &
891889
real(kind=CUSTOM_REAL), dimension(NGLOB),intent(in) :: pgrav_inner_core
892890

893891
! checks if anything to
894-
! no need for inner core, absorbing boundaries placed at outer core bottom surface
895-
if (NCHUNKS_VAL /= 6 .and. ABSORBING_CONDITIONS) return
896892
! for regional mesh cut-offs, there are no inner core elements
897893
if (NSPEC_INNER_CORE == 0) return
898894

src/specfem3D/prepare_timerun.F90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ subroutine prepare_timerun_mass_matrices()
336336
endif
337337
endif
338338
rmassz_inner_core = 1._CUSTOM_REAL / rmassz_inner_core
339+
339340
! outer core
340341
rmass_outer_core = 1._CUSTOM_REAL / rmass_outer_core
341342

0 commit comments

Comments
 (0)