Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@santisoler
Copy link
Member

@santisoler santisoler commented May 15, 2024

Summary

Replace usage of the deprecated refine_tree_xyz function from discretize for their latest equivalent methods of the TreeMesh: refine_surface and refine_points. Apply these replacements across simpeg tests.

PR Checklist

  • If this is a work in progress PR, set as a Draft PR
  • Linted my code according to the style guides.
  • Added tests to verify changes to the code.
  • Added necessary documentation to any new functions/classes following the
    expect style.
  • Marked as ready for review (if this is was a draft PR), and converted
    to a Pull Request
  • Tagged @simpeg/simpeg-developers when ready for review.

Reference issue

What does this implement/fix?

Part of #1467

Additional information

Replace usage of the deprecated `refine_tree_xyz` function from
discretize for their latest equivalent methods of the `TreeMesh`:
`refine_surface` and `refine_points`. Apply these replacements across
simpeg tests.
@codecov
Copy link

codecov bot commented May 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.58%. Comparing base (80e3b18) to head (cacebc0).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1466      +/-   ##
==========================================
+ Coverage   82.56%   82.58%   +0.01%     
==========================================
  Files         168      168              
  Lines       25728    25728              
==========================================
+ Hits        21243    21248       +5     
+ Misses       4485     4480       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

santisoler and others added 2 commits May 16, 2024 09:44
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Comment on lines -74 to -80
self.mesh = refine_tree_xyz(
self.mesh,
topo,
method="surface",
octree_levels=nCpad,
octree_levels_padding=nCpad,
finalize=True,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, my bad. The issue is not with radial methods, but with surface methods. When passing octree_levels_padding, the refined meshes are different between the old code and the new code.

Minimal example:

import numpy as np
from simpeg import utils
from discretize.utils import mesh_builder_xyz, refine_tree_xyz

# First we need to define the direction of the inducing field
# As a simple case, we pick a vertical inducing field of magnitude
# 50,000nT.
# From old convention, field orientation is given as an
# azimuth from North (positive clockwise)
# and dip from the horizontal (positive downward).
h0_amplitude, h0_inclination, h0_declination = (50000.0, 90.0, 0.0)

# Create a mesh
h = [5, 5, 5]
padDist = np.ones((3, 2)) * 100
nCpad = [2, 4, 2]

# Create grid of points for topography
# Lets create a simple Gaussian topo and set the active cells
[xx, yy] = np.meshgrid(np.linspace(-200.0, 200.0, 50), np.linspace(-200.0, 200.0, 50))

b = 100
A = 50
zz = A * np.exp(-0.5 * ((xx / b) ** 2.0 + (yy / b) ** 2.0))

# We would usually load a topofile
topo = np.c_[utils.mkvc(xx), utils.mkvc(yy), utils.mkvc(zz)]

# Create and array of observation points
xr = np.linspace(-100.0, 100.0, 20)
yr = np.linspace(-100.0, 100.0, 20)
X, Y = np.meshgrid(xr, yr)
Z = A * np.exp(-0.5 * ((X / b) ** 2.0 + (Y / b) ** 2.0)) + 5

xyzLoc = np.c_[utils.mkvc(X.T), utils.mkvc(Y.T), utils.mkvc(Z.T)]

# Build mesh with deprecated functions
old_mesh = mesh_builder_xyz(
    xyzLoc,
    h,
    padding_distance=padDist,
    mesh_type="TREE",
)
old_mesh = refine_tree_xyz(
    old_mesh,
    topo,
    method="surface",
    octree_levels=nCpad,
    octree_levels_padding=nCpad,
    finalize=True,
)

# Build mesh with new methods
new_mesh = mesh_builder_xyz(
    xyzLoc,
    h,
    padding_distance=padDist,
    mesh_type="TREE",
)

new_mesh.refine_surface(topo, padding_cells_by_level=nCpad, finalize=True)

print(f"old_mesh.n_cells: {old_mesh.n_cells}")
print(f"new_mesh.n_cells: {new_mesh.n_cells}")
old_mesh.n_cells: 39624
new_mesh.n_cells: 57516

@santisoler santisoler added this to the 0.25.0 milestone Apr 24, 2025
@santisoler santisoler modified the milestones: 0.25.0, 0.26.0 Oct 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants