Skip to content

Commit

Permalink
Moved function location
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronzedwick committed Jan 9, 2025
1 parent c28772a commit e055327
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
27 changes: 2 additions & 25 deletions uxarray/grid/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from html import escape

from numba import njit
from xarray.core.options import OPTIONS

from typing import (
Expand All @@ -14,7 +13,7 @@
Set,
)

from uxarray.grid.utils import _get_cartesian_face_edge_nodes
from uxarray.grid.utils import _get_cartesian_face_edge_nodes, _find_faces

# reader and writer imports
from uxarray.io._exodus import _read_exodus, _encode_exodus
Expand Down Expand Up @@ -71,7 +70,6 @@
_construct_boundary_edge_indices,
compute_temp_latlon_array,
calculate_max_face_radius,
point_in_face,
)

from uxarray.grid.neighbors import (
Expand Down Expand Up @@ -2442,6 +2440,7 @@ def get_faces_containing_point(self, point_xyz):
subset.node_y.values,
subset.node_z.values,
)

inverse_indices = subset.inverse_indices.face.values

# Check if any of the faces in the subset contain the point
Expand All @@ -2467,25 +2466,3 @@ def get_max_face_radius(self):
)

return max_distance


@njit(cache=True)
def _find_faces(face_edge_cartesian, point_xyz, inverse_indices):
"""Finds the faces that contain a given point, inside a subset "face_edge_cartesian"""

index = []

# Loop through the whole subset
for i, face in enumerate(face_edge_cartesian):
# Check if the point is inside the face
contains_point = point_in_face(
face,
point_xyz,
inclusive=True,
)

# If the point is, add it to the list of faces
if contains_point:
index.append(inverse_indices[i])

return index
24 changes: 24 additions & 0 deletions uxarray/grid/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from numba import njit

from uxarray.grid.geometry import point_in_face


@njit(cache=True)
def _small_angle_of_2_vectors(u, v):
Expand Down Expand Up @@ -458,3 +460,25 @@ def _get_lonlat_rad_face_edge_nodes(
face_edges_lonlat_rad[valid_mask, 1] = node_lat_rad[valid_edges]

return face_edges_lonlat_rad.reshape(n_face, n_max_face_edges, 2, 2)


@njit(cache=True)
def _find_faces(face_edge_cartesian, point_xyz, inverse_indices):
"""Finds the faces that contain a given point, inside a subset "face_edge_cartesian"""

index = []

# Loop through the whole subset
for i, face in enumerate(face_edge_cartesian):
# Check if the point is inside the face
contains_point = point_in_face(
face,
point_xyz,
inclusive=True,
)

# If the point is, add it to the list of faces
if contains_point:
index.append(inverse_indices[i])

return index

0 comments on commit e055327

Please sign in to comment.