Skip to content

Commit 8bd3f5a

Browse files
authored
Merge pull request #1836 from danielpeter/devel
updates scripts; code cleaning
2 parents 3d986bd + 9103a9e commit 8bd3f5a

23 files changed

+410
-309
lines changed

EXAMPLES/applications/Gmsh_simple_box_hex27/mesh_example_with_Gmsh.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import gmsh
3737

3838
# from python file import
39-
sys.path.append('../../utils/Cubit_or_Gmsh/')
39+
sys.path.append('../../../utils/Cubit_or_Gmsh/')
4040
from Gmsh2specfem import export2SPECFEM3D
4141

4242

@@ -717,6 +717,24 @@ def mesh_3D():
717717
meshio.write(filename, mesh)
718718
print("VTK file written to : ",filename)
719719

720+
# cleans out unnecessary cell data
721+
# to avoid issues when storing/reading mesh in older Gmsh format (legacy) 2.2
722+
if pygmsh_major_version >= 7:
723+
print("")
724+
print("mesh items:")
725+
keys_to_clean = []
726+
for key, d in mesh.cell_data.items():
727+
print(" key: ",key)
728+
if key in ["gmsh:physical", "gmsh:geometrical", "cell_tags"]:
729+
continue
730+
else:
731+
# delete key
732+
print(" will be cleaned out...")
733+
keys_to_clean.append(key)
734+
# clean out element data
735+
for key in keys_to_clean: del mesh.cell_data[key]
736+
print("")
737+
720738
# saves as Gmsh-file
721739
filename = "MESH/box.msh"
722740
if pygmsh_major_version >= 7:
@@ -761,12 +779,19 @@ def create_mesh():
761779
print("pygmsh version: ",version)
762780

763781
# Gmsh version
782+
# try to get Gmsh version also through pygmsh and compare against loaded gmsh module
764783
if pygmsh_major_version >= 7:
765784
# pygmsh version >= 7.x
766-
version = pygmsh.__gmsh_version__
785+
try:
786+
version = pygmsh.__gmsh_version__
787+
except:
788+
version = gmsh.__version__
767789
else:
768790
# pygmsh version 6.x
769-
version = pygmsh.get_gmsh_major_version()
791+
try:
792+
version = pygmsh.get_gmsh_major_version()
793+
except:
794+
version = gmsh.__version__
770795
print("Gmsh version : ",version, " module version ",gmsh.__version__)
771796

772797
# creates a simple 3D mesh

EXAMPLES/applications/Gmsh_simple_lddrk/mesh_example_with_Gmsh_simple.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import gmsh
3737

3838
# from python file import
39-
sys.path.append('../../utils/Cubit_or_Gmsh/')
39+
sys.path.append('../../../utils/Cubit_or_Gmsh/')
4040
from Gmsh2specfem import export2SPECFEM3D
4141

4242

@@ -634,6 +634,24 @@ def mesh_3D():
634634
meshio.write(filename, mesh)
635635
print("VTK file written to : ",filename)
636636

637+
# cleans out unnecessary cell data
638+
# to avoid issues when storing/reading mesh in older Gmsh format (legacy) 2.2
639+
if pygmsh_major_version >= 7:
640+
print("")
641+
print("mesh items:")
642+
keys_to_clean = []
643+
for key, d in mesh.cell_data.items():
644+
print(" key: ",key)
645+
if key in ["gmsh:physical", "gmsh:geometrical", "cell_tags"]:
646+
continue
647+
else:
648+
# delete key
649+
print(" will be cleaned out...")
650+
keys_to_clean.append(key)
651+
# clean out element data
652+
for key in keys_to_clean: del mesh.cell_data[key]
653+
print("")
654+
637655
# saves as Gmsh-file (msh mesh format)
638656
filename = "MESH/box.msh"
639657
if pygmsh_major_version >= 7:
@@ -678,12 +696,19 @@ def create_mesh():
678696
print("pygmsh version: ",version)
679697

680698
# Gmsh version
699+
# try to get Gmsh version also through pygmsh and compare against loaded gmsh module
681700
if pygmsh_major_version >= 7:
682701
# pygmsh version >= 7.x
683-
version = pygmsh.__gmsh_version__
702+
try:
703+
version = pygmsh.__gmsh_version__
704+
except:
705+
version = gmsh.__version__
684706
else:
685707
# pygmsh version 6.x
686-
version = pygmsh.get_gmsh_major_version()
708+
try:
709+
version = pygmsh.get_gmsh_major_version()
710+
except:
711+
version = gmsh.__version__
687712
print("Gmsh version : ",version, " module version ",gmsh.__version__)
688713

689714
# creates a simple 3D mesh

src/generate_databases/read_parameters.f90

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,16 +196,16 @@ subroutine read_parameters()
196196
! else
197197
! write(IMAIN,*) 'using a CMTSOLUTION source'
198198
! endif
199-
if(.not. USE_CMT_AND_FORCE_SOURCE) then
199+
if (.not. USE_CMT_AND_FORCE_SOURCE) then
200200
if (USE_FORCE_POINT_SOURCE) then
201201
write(IMAIN,*) 'using a FORCESOLUTION source instead of a CMTSOLUTION source'
202202
else
203203
write(IMAIN,*) 'using a CMTSOLUTION source'
204204
endif
205-
else
205+
else
206206
write(IMAIN,*) 'using both a FORCESOLUTION and a CMTSOLUTION source'
207207
endif
208-
208+
209209
if (USE_RICKER_TIME_FUNCTION) then
210210
write(IMAIN,*) ' with a Ricker source time function'
211211
else
@@ -215,13 +215,13 @@ subroutine read_parameters()
215215
! else
216216
! write(IMAIN,*) ' with a Gaussian source time function'
217217
! endif
218-
if(USE_CMT_AND_FORCE_SOURCE) then
218+
if (USE_CMT_AND_FORCE_SOURCE) then
219219
write(IMAIN,*) ' CMTSOLUTION with a quasi-Heaviside source time function'
220220
write(IMAIN,*) ' FORCESOLUTION with a Gaussian source time function'
221-
else
221+
else
222222
if (USE_FORCE_POINT_SOURCE) then
223223
write(IMAIN,*) ' with a quasi-Heaviside source time function'
224-
else
224+
else
225225
write(IMAIN,*) ' with a Gaussian source time function'
226226
endif
227227
endif

src/gpu/initialize_gpu.cu

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,16 @@ void initialize_cuda_device(int* myrank_f,int* ncuda_devices) {
241241
}else{
242242
fprintf(fp," canMapHostMemory: FALSE\n");
243243
}
244+
#if CUDA_VERSION < 13000 || (defined (__CUDACC_VER_MAJOR__) && (__CUDACC_VER_MAJOR__ < 13))
245+
if (deviceProp.deviceOverlap){
246+
fprintf(fp," deviceOverlap: TRUE\n");
247+
}else{
248+
fprintf(fp," deviceOverlap: FALSE\n");
249+
}
250+
#else
251+
// CUDA version >= 13, deviceOverlap deprecated, replaced by asyncEngineCount
244252
fprintf(fp," asyncEngineCount: %d\n", deviceProp.asyncEngineCount);
253+
#endif
245254
if (deviceProp.concurrentKernels){
246255
fprintf(fp," concurrentKernels: TRUE\n");
247256
}else{

src/gpu/smooth_pde_cuda.cu

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void FC_FUNC_(prepare_smooth_pde_gpu,
1717
Mesh* mp = (Mesh*)(*Mesh_pointer);
1818
Smooth_pde_data* sp = (Smooth_pde_data*) malloc(sizeof(Smooth_pde_data));
1919
*Container_smooth_pde = (long)sp;
20-
20+
2121
gpuCreateCopy_todevice_realw((void**)&sp->d_dat_smooth_glob, dat_smooth_glob, mp->NGLOB_AB);
2222
gpuMalloc_field((void**)&sp->d_ddat_smooth_glob, mp->NGLOB_AB);
2323
// initializes values to zero
@@ -70,8 +70,8 @@ void FC_FUNC_(compute_update_element_smooth_pde_gpu,
7070
mp->xix_regular,mp->jacobian_regular,
7171
mp->d_hprime_xx,
7272
mp->d_hprimewgll_xx,
73-
mp->d_wgllwgll_xy,
74-
mp->d_wgllwgll_xz,
73+
mp->d_wgllwgll_xy,
74+
mp->d_wgllwgll_xz,
7575
mp->d_wgllwgll_yz,
7676
sp->cv, sp->ch
7777
);
@@ -94,8 +94,8 @@ void FC_FUNC_(compute_update_element_smooth_pde_gpu,
9494
mp->xix_regular,mp->jacobian_regular,
9595
mp->d_hprime_xx,
9696
mp->d_hprimewgll_xx,
97-
mp->d_wgllwgll_xy,
98-
mp->d_wgllwgll_xz,
97+
mp->d_wgllwgll_xy,
98+
mp->d_wgllwgll_xz,
9999
mp->d_wgllwgll_yz,
100100
sp->cv, sp->ch
101101
);
@@ -114,7 +114,7 @@ void FC_FUNC_(transfer_boun_dat_smooth_pde_from_device,
114114
TRACE("transfer_boun_dat_smooth_pde_from_device");
115115
Mesh* mp = (Mesh*)(*Mesh_pointer);
116116
Smooth_pde_data* sp = (Smooth_pde_data*)(*Container_smooth_pde);
117-
117+
118118
if (sp->size_mpi_buffer_smooth > 0) {
119119
int blocksize = BLOCKSIZE_TRANSFER;
120120
int size_padded = ((int)ceil(((double)(mp->max_nibool_interfaces_ext_mesh))/((double)blocksize)))*blocksize;
@@ -152,7 +152,7 @@ void FC_FUNC_(transfer_boun_dat_smooth_pde_from_device,
152152
// copies buffer to CPU
153153
gpuMemcpy_tohost_field(send_buffer_smooth,sp->d_send_buffer,sp->size_mpi_buffer_smooth);
154154
}
155-
155+
156156
GPU_ERROR_CHECKING("transfer_boun_dat_smooth_pde_from_device");
157157
}
158158

@@ -162,7 +162,7 @@ void FC_FUNC_(transfer_asmbl_dat_smooth_pde_from_device,
162162
long * Container_smooth_pde,
163163
field * recv_buffer_smooth){
164164
TRACE("transfer_asmbl_dat_smooth_pde_from_device");
165-
165+
166166
Mesh* mp = (Mesh*)(*Mesh_pointer);
167167
Smooth_pde_data* sp = (Smooth_pde_data*)(*Container_smooth_pde);
168168

@@ -244,7 +244,7 @@ void FC_FUNC_(kernel_3_smooth_pde_cuda,
244244
sp->d_rvol,
245245
size);
246246
}
247-
#endif
247+
#endif
248248

249249
GPU_ERROR_CHECKING("kernel_3_smooth_pde_cuda");
250250
}
@@ -295,7 +295,7 @@ void FC_FUNC_(zero_pml_smooth_pde_cuda,
295295
ZERO_PML_SMOOTH_PDE_CUDA)(long * Mesh_pointer,
296296
long * Container_smooth_pde) {
297297
TRACE("zero_pml_smooth_pde_cuda");
298-
298+
299299
Mesh* mp = (Mesh*)(*Mesh_pointer);
300300
Smooth_pde_data* sp = (Smooth_pde_data*)(*Container_smooth_pde);
301301

@@ -325,7 +325,7 @@ void FC_FUNC_(zero_pml_smooth_pde_cuda,
325325
mp->d_ibool,
326326
sp->d_CPML_to_spec);
327327
}
328-
#endif
328+
#endif
329329

330330
GPU_ERROR_CHECKING("zero_pml_smooth_pde_cuda");
331331
}
@@ -429,5 +429,5 @@ void FC_FUNC_(transfer_dat_smooth_pde_from_device,
429429
gpuMemcpy_tohost_realw(dat_smooth_glob, sp->d_dat_smooth_glob, mp->NGLOB_AB);
430430

431431
GPU_ERROR_CHECKING("transfer_dat_smooth_pde_from_device");
432-
432+
433433
}

src/shared/check_mesh_resolution.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ subroutine check_mesh_resolution(NSPEC_AB,NGLOB_AB,ibool,xstore,ystore,zstore, &
440440
write(IMAIN,*) '*** Min element size = ',elemsize_min_glob
441441
write(IMAIN,*) '*** Max/min ratio = ',elemsize_max_glob/elemsize_min_glob
442442
write(IMAIN,*)
443-
write(IMAIN,*) '*** Minimum period resolved = ',pmax_glob
443+
write(IMAIN,*) '*** Minimum period resolved = ',pmax_glob,'(s)'
444+
if (abs(pmax_glob) > TINYVAL) then
445+
write(IMAIN,*) '*** (as frequency) = ',1.0_CUSTOM_REAL / pmax_glob,'(Hz)'
446+
endif
444447
write(IMAIN,*) '*** Maximum suggested time step = ',dt_suggested_glob
445448
write(IMAIN,*)
446449
if (DT_PRESENT) then

src/shared/count_number_of_sources.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ subroutine count_number_of_sources_by_type(NSOURCES,sources_filename,source_is_f
197197

198198
! get the number of lines describing the sources
199199
!if (USE_FORCE_POINT_SOURCE) then
200-
if(source_is_force) then
200+
if (source_is_force) then
201201
! FORCESOLUTION
202202
nlines_per_source = NLINES_PER_FORCESOLUTION_SOURCE
203203
else
@@ -233,7 +233,7 @@ subroutine count_number_of_sources_by_type(NSOURCES,sources_filename,source_is_f
233233
! checks lines are a multiple
234234
if (mod(icounter,nlines_per_source) /= 0) then
235235
!if (USE_FORCE_POINT_SOURCE) then
236-
if(source_is_force) then
236+
if (source_is_force) then
237237
print *,'Error: total number of lines in FORCESOLUTION file should be a multiple of ',nlines_per_source
238238
stop 'Error total number of lines in FORCESOLUTION file should be a multiple of NLINES_PER_FORCESOLUTION_SOURCE'
239239
else
@@ -261,15 +261,15 @@ end subroutine count_number_of_sources_by_type
261261

262262
! NQDU for binary source file
263263
subroutine count_number_of_sources_binary(ns_cmt,ns_force,sources_filename)
264-
use constants, only : MAX_STRING_LEN
264+
use constants, only: MAX_STRING_LEN
265265
implicit none
266266
integer,intent(inout) :: ns_cmt,ns_force
267-
character(len=MAX_STRING_LEN),intent(in) :: sources_filename
267+
character(len=MAX_STRING_LEN),intent(in) :: sources_filename
268268

269269
! local
270270
integer,parameter :: IO_SOURCE = 12341
271271

272-
open(IO_SOURCE,file=trim(sources_filename),form='unformatted',&
272+
open(IO_SOURCE,file=trim(sources_filename),form='unformatted', &
273273
action='read',access='stream')
274274
read(IO_SOURCE) ns_cmt
275275
read(IO_SOURCE) ns_force

src/shared/read_parameter_file.F90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,14 +426,14 @@ subroutine read_parameter_file(BROADCAST_AFTER_READ)
426426
! read two flags in CMT + FORCE simulation
427427
call read_value_logical(USE_CMT_AND_FORCE_SOURCE, 'USE_CMT_AND_FORCE_SOURCE', ier)
428428
ier = 0
429-
if (USE_CMT_AND_FORCE_SOURCE) then
429+
if (USE_CMT_AND_FORCE_SOURCE) then
430430
! write(*,'(a)') 'cmt + force simulation is enabled'
431431
USE_FORCE_POINT_SOURCE = .true.
432432
endif
433433

434434
call read_value_logical(USE_BINARY_SOURCE_FILE, 'USE_BINARY_SOURCE_FILE', ier)
435435
ier = 0
436-
if(.not. USE_CMT_AND_FORCE_SOURCE) USE_BINARY_SOURCE_FILE = .false. ! binary file is disabled
436+
if (.not. USE_CMT_AND_FORCE_SOURCE) USE_BINARY_SOURCE_FILE = .false. ! binary file is disabled
437437

438438
call read_value_logical(USE_RICKER_TIME_FUNCTION, 'USE_RICKER_TIME_FUNCTION', ier)
439439
if (ier /= 0) then
@@ -850,8 +850,8 @@ subroutine read_parameter_file(BROADCAST_AFTER_READ)
850850
endif
851851

852852
! inverse problem is enabled, disable USE_CMT_AND_FORCE/USE_BINARY_SOURCE_FILE
853-
if(INVERSE_FWI_FULL_PROBLEM .and. (USE_CMT_AND_FORCE_SOURCE)) then
854-
if(myrank == 0) then
853+
if (INVERSE_FWI_FULL_PROBLEM .and. (USE_CMT_AND_FORCE_SOURCE)) then
854+
if (myrank == 0) then
855855
write(*,'(a)') 'INVERSE_FWI_FULL_PROBLEM is enabled, disabling USE_CMT_AND_FORCE_SOURCE'
856856
write(*,*)
857857
endif
@@ -1258,8 +1258,8 @@ subroutine read_compute_parameters()
12581258
else
12591259
! gets number of sources
12601260
!NQDU call count_number_of_sources(NSOURCES,sources_filename)
1261-
if(USE_CMT_AND_FORCE_SOURCE) then
1262-
if(.not. USE_BINARY_SOURCE_FILE) then
1261+
if (USE_CMT_AND_FORCE_SOURCE) then
1262+
if (.not. USE_BINARY_SOURCE_FILE) then
12631263
! Force
12641264
sources_filename = path_to_add(1:len_trim(path_to_add)) // &
12651265
IN_DATA_FILES(1:len_trim(IN_DATA_FILES))//'FORCESOLUTION'
@@ -1269,17 +1269,17 @@ subroutine read_compute_parameters()
12691269
sources_filename = path_to_add(1:len_trim(path_to_add)) // &
12701270
IN_DATA_FILES(1:len_trim(IN_DATA_FILES))//'CMTSOLUTION'
12711271
call count_number_of_sources_by_type(NSOURCES_CMT,sources_filename,.false.)
1272-
else
1272+
else
12731273
sources_filename = path_to_add(1:len_trim(path_to_add)) // &
12741274
IN_DATA_FILES(1:len_trim(IN_DATA_FILES))//'SOLUTION.bin'
12751275
call count_number_of_sources_binary(NSOURCES_CMT,NSOURCES_FORCE,sources_filename)
12761276
endif
12771277
NSOURCES = NSOURCES_CMT + NSOURCES_FORCE
1278-
else
1278+
else
12791279
NSOURCES_CMT = 0
12801280
NSOURCES_FORCE = 0
12811281
call count_number_of_sources_by_type(NSOURCES,sources_filename,USE_FORCE_POINT_SOURCE)
1282-
if(USE_FORCE_POINT_SOURCE) then
1282+
if (USE_FORCE_POINT_SOURCE) then
12831283
NSOURCES_FORCE = NSOURCES
12841284
else
12851285
NSOURCES_CMT = NSOURCES

src/shared/shared_par.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module shared_input_parameters
169169
logical :: HAS_FINITE_FAULT_SOURCE
170170

171171
! cmt + point force simulation
172-
logical :: USE_CMT_AND_FORCE_SOURCE = .false.
172+
logical :: USE_CMT_AND_FORCE_SOURCE = .false.
173173
logical :: USE_BINARY_SOURCE_FILE = .false.
174174

175175
! external source time function
@@ -234,7 +234,7 @@ module shared_compute_parameters
234234
integer :: NSOURCES
235235

236236
!number of sources in CMTSOLUTION/FORCESOLUTION
237-
integer :: NSOURCES_CMT, NSOURCES_FORCE
237+
integer :: NSOURCES_CMT, NSOURCES_FORCE
238238

239239
! anchor points
240240
integer :: NGNOD2D

0 commit comments

Comments
 (0)