Skip to content

Commit

Permalink
added parallel load and save test
Browse files Browse the repository at this point in the history
  • Loading branch information
Olender committed Jul 26, 2024
1 parent f843412 commit 497d642
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spyro/examples/immersed_polygon.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _polygon_velocity_model(self):
cond = fire.conditional(z <= -0.5 - 0.2*x, vl, cond)

cond = fire.conditional(300*((x-0.5)*(-z-0.5))**2 + ((x-0.5)+(-z-0.5))**2 <= 0.300**2, v2+dv, cond)

if self.abc_pad_length > 0.0:
middle_of_pad = -self.length_z - self.abc_pad_length*0.5
cond = fire.conditional(z <= middle_of_pad, v0, cond)
Expand Down
60 changes: 60 additions & 0 deletions test_polygon_fwi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# from mpi4py.MPI import COMM_WORLD
# import debugpy
# debugpy.listen(3000 + COMM_WORLD.rank)
# debugpy.wait_for_client()
import spyro
import numpy as np


def test_real_shot_record_generation_parallel():
dictionary = {}
dictionary["absorving_boundary_conditions"] = {
"pad_length": 2.0, # True or false
}
dictionary["mesh"] = {
"h": 0.05, # mesh size in km
}
dictionary["polygon_options"] = {
"water_layer_is_present": True,
"upper_layer": 2.0,
"middle_layer": 2.5,
"lower_layer": 3.0,
"polygon_layer_perturbation": 0.3,
}
dictionary["acquisition"] = {
"source_locations": spyro.create_transect((-0.1, 0.1), (-0.1, 0.9), 4),
"frequency": 5.0,
"receiver_locations": spyro.create_transect((-0.16, 0.1), (-0.16, 0.9), 100),
}
dictionary["visualization"] = {
"debug_output": True,
}
dictionary["time_axis"] = {
"final_time": 1.0, # Final time for event
"dt": 0.0005, # timestep size
"amplitude": 1, # the Ricker has an amplitude of 1.
"output_frequency": 500, # how frequently to output solution to pvds
# how frequently to save solution to RAM
"gradient_sampling_frequency": 1,
}
fwi = spyro.examples.Polygon_acoustic_FWI(dictionary=dictionary, periodic=True)
fwi.generate_real_shot_record(plot_model=True, save_shot_record=True)

dictionary["inversion"] = {
"real_shot_record_files": "shots/shot_record_",
}
fwi2 = spyro.examples.Polygon_acoustic_FWI(dictionary=dictionary, periodic=True)

max_value = np.max(fwi2.real_shot_record[:, fwi2.comm.ensemble_comm.rank*33])
test_core = np.isclose(max_value, 0.184, atol=1e-2)

test_core_all = fwi2.comm.ensemble_comm.allgather(test_core)
test = all(test_core_all)

print(f"Correctly loaded shots: {test}", flush=True)

assert test


if __name__ == "__main__":
test_real_shot_record_generation_parallel()

0 comments on commit 497d642

Please sign in to comment.