|
| 1 | +from simwave import ( |
| 2 | + SpaceModel, TimeModel, RickerWavelet, Solver, Compiler, |
| 3 | + Receiver, Source, plot_wavefield, plot_shotrecord, plot_velocity_model |
| 4 | +) |
| 5 | +import numpy as np |
| 6 | + |
| 7 | + |
| 8 | +# available language options: |
| 9 | +# c (sequential) |
| 10 | +# cpu_openmp (parallel CPU) |
| 11 | +# gpu_openmp (GPU) |
| 12 | +# gpu_openacc (GPU) |
| 13 | +compiler_options = { |
| 14 | + 'c': { |
| 15 | + 'cc': 'gcc', |
| 16 | + 'language': 'c', |
| 17 | + 'cflags': '-O3 -fPIC -ffast-math -Wall -std=c99 -shared' |
| 18 | + }, |
| 19 | + 'cpu_openmp': { |
| 20 | + 'cc': 'gcc', |
| 21 | + 'language': 'cpu_openmp', |
| 22 | + 'cflags': '-O3 -fPIC -ffast-math -Wall -std=c99 -shared -fopenmp' |
| 23 | + }, |
| 24 | + 'gpu_openmp': { |
| 25 | + 'cc': 'clang', |
| 26 | + 'language': 'gpu_openmp', |
| 27 | + 'cflags': '-O3 -fPIC -ffast-math -fopenmp \ |
| 28 | + -fopenmp-targets=nvptx64-nvidia-cuda \ |
| 29 | + -Xopenmp-target -march=sm_75' |
| 30 | + }, |
| 31 | + 'gpu_openacc': { |
| 32 | + 'cc': 'pgcc', |
| 33 | + 'language': 'gpu_openacc', |
| 34 | + 'cflags': '-O3 -fPIC -acc:gpu -gpu=pinned -mp' |
| 35 | + }, |
| 36 | +} |
| 37 | + |
| 38 | +selected_compiler = compiler_options['c'] |
| 39 | + |
| 40 | +# set compiler options |
| 41 | +compiler = Compiler( |
| 42 | + cc=selected_compiler['cc'], |
| 43 | + language=selected_compiler['language'], |
| 44 | + cflags=selected_compiler['cflags'] |
| 45 | +) |
| 46 | + |
| 47 | +# Velocity model |
| 48 | +#vel = np.zeros(shape=(512, 512), dtype=np.float32) |
| 49 | +vel = np.zeros(shape=(3, 3), dtype=np.float32) |
| 50 | +vel[:] = 1500.0 |
| 51 | +#vel[100:] = 2000.0 |
| 52 | + |
| 53 | +# create the space model |
| 54 | +space_model = SpaceModel( |
| 55 | + bounding_box=(0, 20, 0, 20), |
| 56 | + grid_spacing=(10, 10), |
| 57 | + velocity_model=vel, |
| 58 | + space_order=4, |
| 59 | + dtype=np.float32 |
| 60 | +) |
| 61 | + |
| 62 | +# config boundary conditions |
| 63 | +# (none, null_dirichlet or null_neumann) |
| 64 | +space_model.config_boundary( |
| 65 | + # damping_length=(0, 1010, 1010, 1010), |
| 66 | + damping_length=(20, 20, 20, 20), |
| 67 | +# damping_length=0, |
| 68 | + boundary_condition=( |
| 69 | + # "null_neumann", "null_dirichlet", |
| 70 | + "null_dirichlet", "null_dirichlet", |
| 71 | + "null_dirichlet", "null_dirichlet" |
| 72 | + ) |
| 73 | +) |
| 74 | + |
| 75 | +print(' damping_alpha=',space_model.damping_alpha) |
| 76 | + |
| 77 | +# create the time model |
| 78 | +time_model = TimeModel( |
| 79 | + space_model=space_model, |
| 80 | + tf=0.01, |
| 81 | + saving_stride=0 |
| 82 | +) |
| 83 | + |
| 84 | +# create the set of sources |
| 85 | +source = Source( |
| 86 | + space_model, |
| 87 | + coordinates=[(10, 10)], |
| 88 | + window_radius=4 |
| 89 | +) |
| 90 | + |
| 91 | +# crete the set of receivers |
| 92 | +receiver = Receiver( |
| 93 | + space_model=space_model, |
| 94 | + coordinates=[(10, i) for i in range(0, 10, 10)], |
| 95 | + window_radius=4 |
| 96 | +) |
| 97 | + |
| 98 | +# create a ricker wavelet with 10hz of peak frequency |
| 99 | +ricker = RickerWavelet(10.0, time_model) |
| 100 | + |
| 101 | +# create the solver |
| 102 | +solver = Solver( |
| 103 | + space_model=space_model, |
| 104 | + time_model=time_model, |
| 105 | + sources=source, |
| 106 | + receivers=receiver, |
| 107 | + wavelet=ricker, |
| 108 | + compiler=compiler |
| 109 | +) |
| 110 | + |
| 111 | +print("Timesteps:", time_model.timesteps) |
| 112 | + |
| 113 | +# run the forward |
| 114 | +u_full, recv = solver.forward() |
| 115 | + |
| 116 | +print("u_full shape:", u_full.shape) |
| 117 | +plot_velocity_model(space_model.velocity_model) |
| 118 | +plot_wavefield(u_full[-1]) |
| 119 | +plot_shotrecord(recv) |
0 commit comments