Skip to content

Commit

Permalink
Improve coverage of some isotropic elastic propagator code
Browse files Browse the repository at this point in the history
  • Loading branch information
SouzaEM committed Oct 8, 2024
1 parent 477e2b1 commit 74c6572
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 21 deletions.
4 changes: 0 additions & 4 deletions spyro/examples/camembert.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,3 @@ def _camembert_velocity_model(self):
)
self.set_initial_velocity_model(conditional=cond, dg_velocity_model=False)
return None

if __name__ == "__main__":
wave = Camembert_acoustic()
wave.forward_solve()
4 changes: 0 additions & 4 deletions spyro/examples/camembert_elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,3 @@

wave = spyro.IsotropicWave(d)
wave.set_mesh(user_mesh=mesh, mesh_parameters={})

print(f'Number of degrees of freedom: {wave.function_space.dim()}')

wave.forward_solve()
4 changes: 0 additions & 4 deletions spyro/examples/elastic_cube_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,3 @@

wave = spyro.IsotropicWave(d)
wave.set_mesh(mesh_parameters={'dx': h})

print(f'Number of degrees of freedom: {wave.function_space.dim()}')

wave.forward_solve()
4 changes: 0 additions & 4 deletions spyro/examples/rectangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,3 @@ def multiple_layer_velocity_model(self, z_switch, layers):
)
# cond = fire.conditional(self.mesh_z > z_switch, layer1, layer2)
self.set_initial_velocity_model(conditional=cond)

if __name__ == "__main__":
wave = Rectangle_acoustic()
wave.forward_solve()
7 changes: 7 additions & 0 deletions test/test_forward_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ def test_rectangle_forward():

assert all([test1, test2, test3])

def test_camembert_elastic():
from spyro.examples.camembert_elastic import wave
wave.forward_solve()

def test_elastic_cube_3D():
from spyro.examples.elastic_cube_3D import wave
wave.forward_solve()

if __name__ == "__main__":
test_camembert_forward()
Expand Down
63 changes: 58 additions & 5 deletions test/test_isotropic_wave.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import firedrake as fire
import numpy as np
import pytest

from spyro.solvers.elastic_wave.isotropic_wave import IsotropicWave

# TO REVIEW: it is extra work to have to define this dictionary everytime
# Here I listed only the required parameters for running to get a view of
# what is currently necessary. Note that the dictionary is not even complete
dummy_dict = {
"options": {
"cell_type": "T",
"variant": "lumped",
"degree": 3,
"dimension": 3,
},
"time_axis": {
"final_time": 1,
Expand All @@ -20,7 +21,7 @@
"acquisition": {
"receiver_locations": [],
"source_type": "ricker",
"source_locations": [(0, 0)],
"source_locations": [(0, 0, 0)],
"frequency": 5.0,
},
}
Expand Down Expand Up @@ -64,4 +65,56 @@ def test_initialize_model_parameters_from_object_redundant():
}
wave = IsotropicWave(dummy_dict)
with pytest.raises(Exception) as e:
wave.initialize_model_parameters_from_object(synthetic_dict)
wave.initialize_model_parameters_from_object(synthetic_dict)

def test_parse_boundary_conditions():
d = dummy_dict.copy()
d["mesh"] = {
"Lz": 1.0,
"Lx": 1.0,
"Ly": 1.0,
"mesh_file": None,
"mesh_type": "firedrake_mesh",
}
d["boundary_conditions"] = [
("u", 1, fire.Constant((1, 1, 1))), # x == 0: 1 (z in spyro)
("uz", 2, fire.Constant(2)), # x == Lx: 2 (z in spyro)
("ux", 3, fire.Constant(3)), # y == 0: 3 (x in spyro)
("uy", 4, fire.Constant(4)), # y == Ly: 4 (x in spyro)
]
wave = IsotropicWave(d)
wave.set_mesh(mesh_parameters={"dx": 0.2, "periodic": True})
wave.parse_boundary_conditions()
u = fire.Function(wave.function_space)
for bc in wave.bcs:
bc.apply(u)

assert np.allclose([1, 1, 1], u.at( 0.0, 0.5, 0.5))
assert np.allclose([2, 0, 0], u.at(-1.0, 0.5, 0.5))
assert np.allclose([0, 3, 0], u.at(-0.5, 0.0, 0.5))
assert np.allclose([0, 0, 4], u.at(-0.5, 1.0, 0.5))

def test_parse_boundary_conditions_exception():
d = dummy_dict.copy()
d["mesh"] = {
"Lz": 1.0,
"Lx": 1.0,
"Ly": 1.0,
"mesh_file": None,
"mesh_type": "firedrake_mesh",
}
d["boundary_conditions"] = [
("?", 2, fire.Constant(2)),
]
wave = IsotropicWave(d)
wave.set_mesh(mesh_parameters={"dx": 0.2, "periodic": True})
with pytest.raises(Exception) as e:
wave.parse_boundary_conditions()

def test_initialize_model_parameters_from_file_notimplemented():
synthetic_dict = {
"type": "file",
}
wave = IsotropicWave(dummy_dict)
with pytest.raises(NotImplementedError) as e:
wave.initialize_model_parameters_from_file(synthetic_dict)

0 comments on commit 74c6572

Please sign in to comment.