Skip to content

Commit ae3492a

Browse files
Fix damping and examples (#70)
* damping * damping * computing eta * alternative calculationa * fixing forward * fix model * clean up model * clean up model * fix examples * fix acoustic2d
1 parent 91d9595 commit ae3492a

File tree

12 files changed

+171
-1914
lines changed

12 files changed

+171
-1914
lines changed

examples/acoustic_2D.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,11 @@
4545
)
4646

4747
# Velocity model
48+
#vel = np.zeros(shape=(512, 512), dtype=np.float32)
4849
vel = np.zeros(shape=(512, 512), dtype=np.float32)
4950
vel[:] = 1500.0
50-
vel[100:] = 2000.0
51-
51+
#vel[100:] = 2000.0
52+
#vel[1,1]=4500
5253
# create the space model
5354
space_model = SpaceModel(
5455
bounding_box=(0, 5120, 0, 5120),
@@ -61,14 +62,13 @@
6162
# config boundary conditions
6263
# (none, null_dirichlet or null_neumann)
6364
space_model.config_boundary(
64-
damping_length=(0, 510, 510, 510),
65+
damping_length=(510, 510, 510, 510),
6566
boundary_condition=(
66-
"null_neumann", "null_dirichlet",
67+
"null_dirichlet", "null_dirichlet",
6768
"null_dirichlet", "null_dirichlet"
6869
)
6970
)
7071

71-
print(' damping_alpha=',space_model.damping_alpha)
7272

7373
# create the time model
7474
time_model = TimeModel(

examples/acoustic_2D_density.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,11 @@
6666
# config boundary conditions
6767
# (none, null_dirichlet or null_neumann)
6868
space_model.config_boundary(
69-
damping_length=0,
69+
damping_length=(510, 510, 510, 510),
7070
boundary_condition=(
7171
"null_neumann", "null_dirichlet",
7272
"none", "null_dirichlet"
73-
),
74-
damping_polynomial_degree=3,
75-
damping_alpha=0.001
73+
)
7674
)
7775

7876
# create the time model

examples/acoustic_3D.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@
5959
# config boundary conditions
6060
# (none, null_dirichlet or null_neumann)
6161
space_model.config_boundary(
62-
damping_length=0,
62+
damping_length=(0, 100, 100, 100, 100, 100),
6363
boundary_condition=(
6464
"null_neumann", "null_dirichlet",
6565
"null_dirichlet", "null_dirichlet",
6666
"null_dirichlet", "null_dirichlet"
67-
),
68-
damping_polynomial_degree=3,
69-
damping_alpha=0.001
67+
)
7068
)
71-
7269
# create the time model
7370
time_model = TimeModel(
7471
space_model=space_model,

examples/acoustic_3D_density.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@
6565
# config boundary conditions
6666
# (none, null_dirichlet or null_neumann)
6767
space_model.config_boundary(
68-
damping_length=0,
68+
damping_length=(0, 100, 100, 100, 100, 100),
6969
boundary_condition=(
7070
"null_neumann", "null_dirichlet",
7171
"null_dirichlet", "null_dirichlet",
7272
"null_dirichlet", "null_dirichlet"
73-
),
74-
damping_polynomial_degree=3,
75-
damping_alpha=0.001
73+
)
7674
)
7775

7876
# create the time model

examples/micro.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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)

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import versioneer
21
from setuptools import setup, find_packages
32

43
with open("requirements.txt") as f:
@@ -9,8 +8,6 @@
98

109
setup(
1110
name="simwave",
12-
version=versioneer.get_version(),
13-
cmdclass=versioneer.get_cmdclass(),
1411
description="Finite difference 2D/3D acoustic wave propagator.",
1512
long_description=readme,
1613
long_description_content_type="text/markdown",

simwave/kernel/backend/c_code/forward/constant_density/2d/wave.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ double forward(f_type *u, f_type *velocity, f_type *damp,
3434
size_t saving_stride, f_type dt,
3535
size_t begin_timestep, size_t end_timestep,
3636
size_t space_order, size_t num_snapshots){
37-
37+
3838
size_t stencil_radius = space_order / 2;
3939

40+
//size_t stencil_radius = space_order / 2;
41+
4042
size_t domain_size = nz * nx;
4143

4244
f_type dzSquared = dz * dz;
@@ -167,13 +169,16 @@ double forward(f_type *u, f_type *velocity, f_type *damp,
167169
value += sum_x/dxSquared + sum_z/dzSquared;
168170

169171
// parameter to be used
170-
f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
172+
//f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
173+
f_type c2 = velocity[domain_offset] * velocity[domain_offset];
171174

172175
// denominator with damp coefficient
173-
f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
174-
f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
176+
// f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
177+
f_type denominator = 1.0 + damp[domain_offset] * dt;
178+
f_type numerator = 1.0 - damp[domain_offset] * dt;
175179

176-
value *= (dtSquared / slowness) / denominator;
180+
//value *= (dtSquared / slowness) / denominator;
181+
value *= (dtSquared * c2) / denominator;
177182

178183
u[next_snapshot] = 2.0 / denominator * u[current_snapshot] - (numerator / denominator) * u[prev_snapshot] + value;
179184
}

simwave/kernel/backend/c_code/forward/constant_density/3d/wave.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,17 @@ double forward(f_type *u, f_type *velocity, f_type *damp,
174174
value += sum_y/dySquared + sum_x/dxSquared + sum_z/dzSquared;
175175

176176
// parameter to be used
177-
f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
177+
//f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
178+
f_type c2 = velocity[domain_offset] * velocity[domain_offset];
178179

179180
// denominator with damp coefficient
180-
f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
181-
f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
181+
//f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
182+
f_type denominator = 1.0 + damp[domain_offset] * dt;
183+
//f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
184+
f_type numerator = 1.0 - damp[domain_offset] * dt;
182185

183-
value *= (dtSquared / slowness) / denominator;
186+
//value *= (dtSquared /slowness) / denominator;
187+
value *= (dtSquared * c2) / denominator;
184188

185189
u[next_snapshot] = 2.0 / denominator * u[current_snapshot] - (numerator / denominator) * u[prev_snapshot] + value;
186190
}

simwave/kernel/backend/c_code/forward/variable_density/2d/wave.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ double forward(f_type *u, f_type *velocity, f_type *density, f_type *damp,
189189
value -= (term_x + term_z) / density[domain_offset];
190190

191191
// parameter to be used
192-
f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
192+
//f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
193+
f_type c2 = velocity[domain_offset] * velocity[domain_offset];
193194

194195
// denominator with damp coefficient
195-
f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
196-
f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
196+
//f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
197+
f_type denominator = 1.0 + damp[domain_offset] * dt;
198+
//f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
199+
f_type numerator = 1.0 - damp[domain_offset] * dt;
197200

198-
value *= (dtSquared / slowness) / denominator;
201+
//value *= (dtSquared / slowness) / denominator;
202+
value *= (dtSquared * c2) / denominator;
199203

200204
u[next_snapshot] = 2.0 / denominator * u[current_snapshot] - (numerator / denominator) * u[prev_snapshot] + value;
201205
}

simwave/kernel/backend/c_code/forward/variable_density/3d/wave.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,17 @@ double forward(f_type *u, f_type *velocity, f_type *density, f_type *damp,
200200
value -= (term_y + term_x + term_z) / density[domain_offset];
201201

202202
// parameter to be used
203-
f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
203+
//f_type slowness = 1.0 / (velocity[domain_offset] * velocity[domain_offset]);
204+
f_type c2 = velocity[domain_offset] * velocity[domain_offset];
204205

205206
// denominator with damp coefficient
206-
f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
207-
f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
207+
// f_type denominator = (1.0 + damp[domain_offset] * dt / (2 * slowness));
208+
f_type denominator = 1.0 + damp[domain_offset] * dt;
209+
// f_type numerator = (1.0 - damp[domain_offset] * dt / (2 * slowness));
210+
f_type numerator = 1.0 - damp[domain_offset] * dt;
208211

209-
value *= (dtSquared / slowness) / denominator;
212+
//value *= (dtSquared / slowness) / denominator;
213+
value *= (dtSquared * c2) / denominator;
210214

211215
u[next_snapshot] = 2.0 / denominator * u[current_snapshot] - (numerator / denominator) * u[prev_snapshot] + value;
212216
}

0 commit comments

Comments
 (0)