From b48280cf76327fdf9428d5cdd0ab058dd471b592 Mon Sep 17 00:00:00 2001 From: Olender Date: Mon, 3 Mar 2025 11:49:08 +0000 Subject: [PATCH 1/7] basic model from notebook --- simple_forward_overthrust.py | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 simple_forward_overthrust.py diff --git a/simple_forward_overthrust.py b/simple_forward_overthrust.py new file mode 100644 index 00000000..0ecc94e7 --- /dev/null +++ b/simple_forward_overthrust.py @@ -0,0 +1,60 @@ +import spyro +import numpy as np + +dictionary = {} +dictionary["options"] = { + "cell_type": "T", # simplexes such as triangles or tetrahedra (T) or quadrilaterals (Q) + "variant": "lumped", # lumped, equispaced or DG, default is lumped + "degree": 4, # p order + "dimension": 2, # dimension +} +dictionary["parallelism"] = { + "type": "automatic", # options: automatic (same number of cores for evey processor) or spatial +} +dictionary["mesh"] = { + "Lz": 2.8, # depth in km - always positive # Como ver isso sem ler a malha? + "Lx": 6.0, # width in km - always positive + "Ly": 0.0, # thickness in km - always positive + "mesh_file": "meshes/cut_overthrust.msh", +} +dictionary["acquisition"] = { + "source_type": "ricker", + "source_locations": [(-0.01, 3.0)], + "frequency": 5.0, + "receiver_locations": spyro.create_transect((-0.37, 0.2), (-0.37, 5.8), 300), +} +dictionary["absorving_boundary_conditions"] = { + "status": True, + "damping_type": "PML", + "exponent": 2, + "cmax": 4.5, + "R": 1e-6, + "pad_length": 0.75, +} +dictionary["synthetic_data"] = { + "real_velocity_file": "velocity_models/cut_overthrust.hdf5", +} +dictionary["time_axis"] = { + "initial_time": 0.0, # Initial time for event + "final_time": 5.00, # Final time for event + "dt": 0.0005, # timestep size + "output_frequency": 200, # how frequently to output solution to pvds - Perguntar Daiane ''post_processing_frequnecy' + "gradient_sampling_frequency": 1, # how frequently to save solution to RAM - Perguntar Daiane 'gradient_sampling_frequency' +} +dictionary["visualization"] = { + "forward_output": True, + "forward_output_filename": "results/forward_output.pvd", + "fwi_velocity_model_output": False, + "velocity_model_filename": None, + "gradient_output": False, + "gradient_filename": "results/Gradient.pvd", + "adjoint_output": False, + "adjoint_filename": None, + "debug_output": False, +} +Wave_obj = spyro.AcousticWave(dictionary=dictionary) +Wave_obj.forward_solve() +spyro.plots.plot_model(Wave_obj, filename="model_overthrust.png", show=True) +shot_record = Wave_obj.receivers_output +vmax = 0.1*np.max(shot_record) +spyro.plots.plot_shots(Wave_obj, contour_lines=100, vmin=-vmax, vmax=vmax, show=True) \ No newline at end of file From a92896a4a7a374e8f35ab440e815e616dca8eec3 Mon Sep 17 00:00:00 2001 From: Olender Date: Mon, 3 Mar 2025 18:34:39 +0000 Subject: [PATCH 2/7] fixed None source error --- spyro/solvers/wave.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyro/solvers/wave.py b/spyro/solvers/wave.py index e0c1effc..30941eb2 100644 --- a/spyro/solvers/wave.py +++ b/spyro/solvers/wave.py @@ -76,6 +76,7 @@ def __init__(self, dictionary=None, comm=None): self.mesh = self.get_mesh() self.c = None + self.sources = None if self.mesh is not None: self._build_function_space() self._map_sources_and_receivers() @@ -88,7 +89,6 @@ def __init__(self, dictionary=None, comm=None): # Expression to define sources through UFL (less efficient) self.source_expression = None # Object for efficient application of sources - self.sources = None self.field_logger = FieldLogger(self.comm, self.input_dictionary["visualization"]) self.field_logger.add_field("forward", self.get_function_name(), From d87b5c394b920af603baa66c267c63dc5708cba7 Mon Sep 17 00:00:00 2001 From: Olender Date: Tue, 4 Mar 2025 11:29:14 +0000 Subject: [PATCH 3/7] fixed cpw based quad auto mesh --- spyro/meshing/meshing_functions.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spyro/meshing/meshing_functions.py b/spyro/meshing/meshing_functions.py index e82edb79..f7e736d0 100644 --- a/spyro/meshing/meshing_functions.py +++ b/spyro/meshing/meshing_functions.py @@ -274,9 +274,7 @@ def create_firedrake_mesh(self): """ Creates a mesh based on Firedrake meshing utilities. """ - if self.dx is None: - raise ValueError("dx is not set") - elif self.dimension == 2: + if self.dimension == 2: return self.create_firedrake_2D_mesh() elif self.dimension == 3: return self.create_firedrake_3D_mesh() @@ -287,6 +285,8 @@ def create_firedrake_2D_mesh(self): """ Creates a 2D mesh based on Firedrake meshing utilities. """ + if self.dx is None and self.cpw is not None: + self.dx = calculate_edge_length(self.cpw, self.minimum_velocity, self.source_frequency) if self.abc_pad: nx = int((self.length_x + 2*self.abc_pad) / self.dx) nz = int((self.length_z + self.abc_pad) / self.dx) @@ -481,6 +481,13 @@ def create_seismicmesh_2D_mesh_homogeneous(self): return fire.Mesh(self.output_file_name) # raise NotImplementedError("Not implemented yet") +def calculate_edge_length(cpw, minimum_velocity, frequency): + v_min = minimum_velocity + + lbda_min = v_min/frequency + + edge_length = lbda_min/cpw + return edge_length # def create_firedrake_3D_mesh_based_on_parameters(dx, cell_type): # nx = int(self.length_x / dx) From 0a70be03db31f3613e0f935b6e23858153be566a Mon Sep 17 00:00:00 2001 From: Olender Date: Tue, 4 Mar 2025 15:34:49 +0000 Subject: [PATCH 4/7] relaxing codecov changes --- codecov.yml | 8 ++++++++ setup.cfg | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..7e3b360b --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +coverage: + status: + project: + default: + target: auto + # adjust accordingly based on how flaky your tests are + # this allows a 1% drop from the previous base commit coverage + threshold: 1% diff --git a/setup.cfg b/setup.cfg index 56f3b668..3938897f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,14 +7,6 @@ exclude = .git,__pycache__ [coverage:run] omit=*/site-packages/*,*/test/*,*/.eggs/*,/home/alexandre/firedrake/* -[codecov] -precision = 2 -range = 70...100 -comment_layout = diff, files -comment_behavior = default -require_changes = false -threshold = 1 - [pep8] ignore = E501,E226,E731,E741,W503 exclude = .git,__pycache__ \ No newline at end of file From ee721e06b6fa13bf20e219e6099bc7eb1eb43895 Mon Sep 17 00:00:00 2001 From: Olender Date: Wed, 5 Mar 2025 10:02:10 +0000 Subject: [PATCH 5/7] taking sudo out --- .github/workflows/build_firedrake_main.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.github/workflows/build_firedrake_main.yml b/.github/workflows/build_firedrake_main.yml index c7698666..cbca49f8 100644 --- a/.github/workflows/build_firedrake_main.yml +++ b/.github/workflows/build_firedrake_main.yml @@ -18,13 +18,6 @@ jobs: - uses: actions/checkout@v4 - - name: Install system dependencies - run: | - git clone https://github.com/firedrakeproject/firedrake.git - sudo apt-get update - sudo apt-get -y install \ - $(python3 ./firedrake/scripts/firedrake-configure --show-system-packages) - - name: Install PETSc run: | git clone https://github.com/firedrakeproject/petsc.git From f2df445600515a97a9fa928965df6b358551a2b3 Mon Sep 17 00:00:00 2001 From: Olender Date: Wed, 5 Mar 2025 10:04:00 +0000 Subject: [PATCH 6/7] cleanup --- simple_forward_overthrust.py | 60 ------------------------------------ 1 file changed, 60 deletions(-) delete mode 100644 simple_forward_overthrust.py diff --git a/simple_forward_overthrust.py b/simple_forward_overthrust.py deleted file mode 100644 index 0ecc94e7..00000000 --- a/simple_forward_overthrust.py +++ /dev/null @@ -1,60 +0,0 @@ -import spyro -import numpy as np - -dictionary = {} -dictionary["options"] = { - "cell_type": "T", # simplexes such as triangles or tetrahedra (T) or quadrilaterals (Q) - "variant": "lumped", # lumped, equispaced or DG, default is lumped - "degree": 4, # p order - "dimension": 2, # dimension -} -dictionary["parallelism"] = { - "type": "automatic", # options: automatic (same number of cores for evey processor) or spatial -} -dictionary["mesh"] = { - "Lz": 2.8, # depth in km - always positive # Como ver isso sem ler a malha? - "Lx": 6.0, # width in km - always positive - "Ly": 0.0, # thickness in km - always positive - "mesh_file": "meshes/cut_overthrust.msh", -} -dictionary["acquisition"] = { - "source_type": "ricker", - "source_locations": [(-0.01, 3.0)], - "frequency": 5.0, - "receiver_locations": spyro.create_transect((-0.37, 0.2), (-0.37, 5.8), 300), -} -dictionary["absorving_boundary_conditions"] = { - "status": True, - "damping_type": "PML", - "exponent": 2, - "cmax": 4.5, - "R": 1e-6, - "pad_length": 0.75, -} -dictionary["synthetic_data"] = { - "real_velocity_file": "velocity_models/cut_overthrust.hdf5", -} -dictionary["time_axis"] = { - "initial_time": 0.0, # Initial time for event - "final_time": 5.00, # Final time for event - "dt": 0.0005, # timestep size - "output_frequency": 200, # how frequently to output solution to pvds - Perguntar Daiane ''post_processing_frequnecy' - "gradient_sampling_frequency": 1, # how frequently to save solution to RAM - Perguntar Daiane 'gradient_sampling_frequency' -} -dictionary["visualization"] = { - "forward_output": True, - "forward_output_filename": "results/forward_output.pvd", - "fwi_velocity_model_output": False, - "velocity_model_filename": None, - "gradient_output": False, - "gradient_filename": "results/Gradient.pvd", - "adjoint_output": False, - "adjoint_filename": None, - "debug_output": False, -} -Wave_obj = spyro.AcousticWave(dictionary=dictionary) -Wave_obj.forward_solve() -spyro.plots.plot_model(Wave_obj, filename="model_overthrust.png", show=True) -shot_record = Wave_obj.receivers_output -vmax = 0.1*np.max(shot_record) -spyro.plots.plot_shots(Wave_obj, contour_lines=100, vmin=-vmax, vmax=vmax, show=True) \ No newline at end of file From f5ceafb77ded06a6ff874479025a519e41f251e1 Mon Sep 17 00:00:00 2001 From: Olender Date: Wed, 5 Mar 2025 10:13:15 +0000 Subject: [PATCH 7/7] linting --- spyro/meshing/meshing_functions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyro/meshing/meshing_functions.py b/spyro/meshing/meshing_functions.py index f7e736d0..7c947660 100644 --- a/spyro/meshing/meshing_functions.py +++ b/spyro/meshing/meshing_functions.py @@ -481,6 +481,7 @@ def create_seismicmesh_2D_mesh_homogeneous(self): return fire.Mesh(self.output_file_name) # raise NotImplementedError("Not implemented yet") + def calculate_edge_length(cpw, minimum_velocity, frequency): v_min = minimum_velocity