forked from NDF-Poli-USP/spyro
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 0041 - Add elastic wave propagation #53
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
44345b3
Add empty files to test access to GitHub repository
SouzaEM 8b6d064
Merge branch 'main' into issue_0041
SouzaEM bb6f3b0
Add parsing of input parameters of elastic model. Remove some extra s…
SouzaEM 9f3edbd
Refactor time integration code to merge 'central_difference' and 'mix…
SouzaEM baa852d
Refactor time integration code to merge 'central_difference' and 'cen…
SouzaEM db5b048
Remove correction of time integration configuration for ABC
SouzaEM 85b5f31
Merge branch 'main' into issue_0041
Olender File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
from .backward_time_integration import ( | ||
backward_wave_propagator, | ||
) | ||
|
||
from ..utils.typing import override | ||
|
||
class AcousticWave(Wave): | ||
def save_current_velocity_model(self, file_name=None): | ||
|
@@ -40,7 +40,7 @@ def forward_solve(self): | |
if self.function_space is None: | ||
self.force_rebuild_function_space() | ||
|
||
self._get_initial_velocity_model() | ||
self._initialize_model_parameters() | ||
self.c = self.initial_velocity_model | ||
self.matrix_building() | ||
self.wave_propagator() | ||
|
@@ -68,6 +68,7 @@ def matrix_building(self): | |
self.trial_function = None | ||
self.u_nm1 = None | ||
self.u_n = None | ||
self.u_np1 = fire.Function(self.function_space) | ||
self.lhs = None | ||
self.solver = None | ||
self.rhs = None | ||
|
@@ -81,6 +82,7 @@ def matrix_building(self): | |
self.X = None | ||
self.X_n = None | ||
self.X_nm1 = None | ||
self.X_np1 = fire.Function(V * Z) | ||
construct_solver_or_matrix_with_pml(self) | ||
|
||
@ensemble_propagator | ||
|
@@ -144,3 +146,94 @@ def reset_pressure(self): | |
self.u_n.assign(0.0) | ||
except: | ||
warnings.warn("No pressure to reset") | ||
|
||
@override | ||
def _initialize_model_parameters(self): | ||
if self.initial_velocity_model is not None: | ||
return None | ||
|
||
if self.initial_velocity_model_file is None: | ||
raise ValueError("No velocity model or velocity file to load.") | ||
|
||
if self.initial_velocity_model_file.endswith(".segy"): | ||
vp_filename, vp_filetype = os.path.splitext( | ||
self.initial_velocity_model_file | ||
) | ||
warnings.warn("Converting segy file to hdf5") | ||
write_velocity_model( | ||
self.initial_velocity_model_file, ofname=vp_filename | ||
) | ||
self.initial_velocity_model_file = vp_filename + ".hdf5" | ||
|
||
if self.initial_velocity_model_file.endswith((".hdf5", ".h5")): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added |
||
self.initial_velocity_model = interpolate( | ||
self, | ||
self.initial_velocity_model_file, | ||
self.function_space.sub(0), | ||
) | ||
|
||
if self.debug_output: | ||
fire.File("initial_velocity_model.pvd").write( | ||
self.initial_velocity_model, name="velocity" | ||
) | ||
|
||
@override | ||
def _set_vstate(self, vstate): | ||
if self.abc_boundary_layer_type == "PML": | ||
self.X_n.assign(vstate) | ||
else: | ||
self.u_n.assign(vstate) | ||
|
||
@override | ||
def _get_vstate(self): | ||
if self.abc_boundary_layer_type == "PML": | ||
return self.X_n | ||
else: | ||
return self.u_n | ||
|
||
@override | ||
def _set_prev_vstate(self, vstate): | ||
if self.abc_boundary_layer_type == "PML": | ||
self.X_nm1.assign(vstate) | ||
else: | ||
self.u_nm1.assign(vstate) | ||
|
||
@override | ||
def _get_prev_vstate(self): | ||
if self.abc_boundary_layer_type == "PML": | ||
return self.X_nm1 | ||
else: | ||
return self.u_nm1 | ||
|
||
@override | ||
def _set_next_vstate(self, vstate): | ||
if self.abc_boundary_layer_type == "PML": | ||
self.X_np1.assign(vstate) | ||
else: | ||
self.u_np1.assign(vstate) | ||
|
||
@override | ||
def _get_next_vstate(self): | ||
if self.abc_boundary_layer_type == "PML": | ||
return self.X_np1 | ||
else: | ||
return self.u_np1 | ||
|
||
@override | ||
def get_receivers_output(self): | ||
if self.abc_boundary_layer_type == "PML": | ||
data_with_halos = self.X_n.dat.data_ro_with_halos[0][:] | ||
else: | ||
data_with_halos = self.u_n.dat.data_ro_with_halos[:] | ||
return self.receivers.interpolate(data_with_halos) | ||
|
||
@override | ||
def get_function(self): | ||
if self.abc_boundary_layer_type == "PML": | ||
return self.X_n.sub(0) | ||
else: | ||
return self.u_n | ||
|
||
@override | ||
def get_function_name(self): | ||
return "Pressure" |
This file was deleted.
Oops, something went wrong.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from abc import abstractmethod | ||
|
||
from ..wave import Wave | ||
|
||
class ElasticWave(Wave): | ||
'''Base class for elastic wave propagators''' | ||
def __init__(self, dictionary, comm=None): | ||
super().__init__(dictionary, comm=comm) | ||
|
||
#@override | ||
def _initialize_model_parameters(self): | ||
d = self.input_dictionary.get("synthetic_data", False) | ||
if bool(d) and "type" in d: | ||
if d["type"] == "object": | ||
self.initialize_model_parameters_from_object(d) | ||
elif d["type"] == "file": | ||
self.initialize_model_parameters_from_file(d) | ||
else: | ||
raise Exception(f"Invalid synthetic data type: {d['type']}") | ||
else: | ||
raise Exception("Input dictionary must contain ['synthetic_data']['type']") | ||
|
||
@abstractmethod | ||
def initialize_model_parameters_from_object(self, synthetic_data_dict): | ||
pass | ||
|
||
@abstractmethod | ||
def initialize_model_parameters_from_file(self, synthetic_data_dict): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from .elastic_wave import ElasticWave | ||
|
||
class IsotropicWave(ElasticWave): | ||
'''Isotropic elastic wave propagator''' | ||
def __init__(self, dictionary, comm=None): | ||
super().__init__(dictionary, comm=comm) | ||
|
||
self.rho = None # Density | ||
self.lmbda = None # First Lame parameter | ||
self.mu = None # Second Lame parameter | ||
self.c_s = None # Secondary wave velocity | ||
|
||
#@override | ||
def initialize_model_parameters_from_object(self, synthetic_data_dict: dict): | ||
self.rho = synthetic_data_dict.get("density", None) | ||
self.lmbda = synthetic_data_dict.get("lambda", | ||
synthetic_data_dict.get("lame_first", None)) | ||
self.mu = synthetic_data_dict.get("mu", | ||
synthetic_data_dict.get("lame_second", None)) | ||
self.c = synthetic_data_dict.get("p_wave_velocity", None) | ||
self.c_s = synthetic_data_dict.get("s_wave_velocity", None) | ||
|
||
# Check if {rho, lambda, mu} is set and {c, c_s} are not | ||
option_1 = bool(self.rho) and \ | ||
bool(self.lmbda) and \ | ||
bool(self.mu) and \ | ||
not bool(self.c) and \ | ||
not bool(self.c_s) | ||
# Check if {rho, c, c_s} is set and {lambda, mu} are not | ||
option_2 = bool(self.rho) and \ | ||
bool(self.c) and \ | ||
bool(self.c_s) and \ | ||
not bool(self.lmbda) and \ | ||
not bool(self.mu) | ||
|
||
if not option_1 and not option_2: | ||
raise Exception(f"Inconsistent selection of isotropic elastic wave parameters:\n" \ | ||
f" Density : {bool(self.rho)}\n"\ | ||
f" Lame first : {bool(self.lmbda)}\n"\ | ||
f" Lame second : {bool(self.mu)}\n"\ | ||
f" P-wave velocity: {bool(self.c)}\n"\ | ||
f" S-wave velocity: {bool(self.c_s)}\n"\ | ||
"The valid options are \{Density, Lame first, Lame second\} "\ | ||
"or \{Density, P-wave velocity, S-wave velocity\}") | ||
|
||
#@override | ||
def initialize_model_parameters_from_file(self, synthetic_data_dict): | ||
raise NotImplementedError |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed some extra empty spaces from some warning messages. This is not related to the actual development of elastic waves.