Skip to content

Commit

Permalink
Re-introduce Numba to face area computations (UXARRAY#794)
Browse files Browse the repository at this point in the history
* re-introduce numba to face area calculation

* update coordinate conversion
  • Loading branch information
philipc2 authored May 18, 2024
1 parent 2a4bcee commit 93cf4d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions uxarray/grid/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

from uxarray.grid.coordinates import _lonlat_rad_to_xyz

from numba import njit, config
from uxarray.constants import ENABLE_JIT_CACHE, ENABLE_JIT

config.DISABLE_JIT = not ENABLE_JIT


@njit(cache=ENABLE_JIT_CACHE)
def calculate_face_area(
x, y, z, quadrature_rule="gaussian", order=4, coords_type="spherical"
):
Expand Down Expand Up @@ -92,6 +98,7 @@ def calculate_face_area(
return area, jacobian


@njit(cache=ENABLE_JIT_CACHE)
def get_all_face_area_from_coords(
x,
y,
Expand Down Expand Up @@ -166,6 +173,7 @@ def get_all_face_area_from_coords(
return area, jacobian


@njit(cache=ENABLE_JIT_CACHE)
def calculate_spherical_triangle_jacobian(node1, node2, node3, dA, dB):
"""Calculate Jacobian of a spherical triangle. This is a helper function
for calculating face area.
Expand Down Expand Up @@ -255,6 +263,7 @@ def calculate_spherical_triangle_jacobian(node1, node2, node3, dA, dB):
return dJacobian


@njit(cache=ENABLE_JIT_CACHE)
def calculate_spherical_triangle_jacobian_barycentric(node1, node2, node3, dA, dB):
"""Calculate Jacobian of a spherical triangle. This is a helper function
for calculating face area.
Expand Down Expand Up @@ -333,6 +342,7 @@ def calculate_spherical_triangle_jacobian_barycentric(node1, node2, node3, dA, d
return 0.5 * dJacobian


@njit(cache=ENABLE_JIT_CACHE)
def get_gauss_quadratureDG(nCount):
"""Gauss Quadrature Points for integration.
Expand Down Expand Up @@ -577,6 +587,7 @@ def get_gauss_quadratureDG(nCount):
return dG, dW


@njit(cache=ENABLE_JIT_CACHE)
def get_tri_quadratureDG(nOrder):
"""Triangular Quadrature Points for integration.
Expand Down
3 changes: 3 additions & 0 deletions uxarray/grid/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

from typing import Union

from numba import njit


@njit(cache=True)
def _lonlat_rad_to_xyz(
lon: Union[np.ndarray, float],
lat: Union[np.ndarray, float],
Expand Down

0 comments on commit 93cf4d9

Please sign in to comment.