Skip to content

Commit b003f30

Browse files
authored
Merge pull request #33 from UXARRAY/integration
Integration. Thanks team!
2 parents da436a3 + ed61bbd commit b003f30

File tree

18 files changed

+1026
-57
lines changed

18 files changed

+1026
-57
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ test/dask-worker-space/
142142
.vscode/
143143
generated/
144144

145-
146145
# Test grid files.
147146
test/meshfiles/*.g
148147
test/meshfiles/*.ug

ci/environment.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ channels:
44
dependencies:
55
- dask
66
- netcdf4
7+
- numba
8+
# pinning the numpy version for numba compatibility
9+
- numpy>=1.2, <1.22
710
- pathlib
811
- pre_commit
912
- pytest
1013
- pytest-cov
1114
- python
15+
- scipy
1216
- xarray

docs/internal_api/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ Grid Helper Modules
3434
_ugrid._read_ugrid
3535
_scrip._read_scrip
3636
_scrip._to_ugrid
37+
helpers._spherical_to_cartesian_unit_
3738
helpers._is_ugrid

docs/user_api/index.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@ Grid Methods
2121
:toctree: _autosummary
2222

2323
grid.Grid.write
24+
grid.Grid.calculate_total_face_area
25+
grid.Grid.integrate
26+
grid.Grid.compute_face_areas
2427

2528
Helper Functions
2629
----------------
2730
.. autosummary::
2831
:toctree: _autosummary
2932

30-
parse_grid_type
33+
helpers.get_all_face_area_from_coords
34+
helpers.calculate_face_area
35+
helpers.calculate_spherical_triangle_jacobian
36+
helpers.calculate_spherical_triangle_jacobian_barycentric
37+
get_gauss_quadratureDG
38+
get_tri_quadratureDG
39+
helpers.parse_grid_type

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
xarray
2+
numpy>=1.2,<=1.22

test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import constants

test/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
NNODES_outCSne30 = 5402
55
NNODES_outRLL1deg = 64442
66
DATAVARS_outCSne30 = 2
7+
TRI_AREA = 1.047
8+
# 4*Pi is 12.56
9+
MESH30_AREA = 12.566
10+
PSI_INTG = 12.566
11+
VAR2_INTG = 12.566

test/test_dataset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
from pathlib import Path
44

55
import uxarray as ux
6-
from . import constants
6+
7+
try:
8+
import constants
9+
except ImportError:
10+
from . import constants
711

812
current_path = Path(os.path.dirname(os.path.realpath(__file__)))
913

test/test_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def test_read_shpfile(self):
7575
"""Reads a shape file and write ugrid file."""
7676
with self.assertRaises(RuntimeError):
7777
shp_filename = current_path / "meshfiles" / "grid_fire.shp"
78-
tgrid = ux.Grid(str(shp_filename))
78+
tgrid = ux.open_dataset(str(shp_filename))
7979

8080
def test_read_scrip(self):
8181
"""Reads a scrip file and write ugrid file."""

test/test_helpers.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
import numpy as np
3+
import numpy.testing as nt
4+
5+
from unittest import TestCase
6+
from pathlib import Path
7+
8+
import uxarray as ux
9+
10+
try:
11+
import constants
12+
except ImportError:
13+
from . import constants
14+
15+
# Data files
16+
current_path = Path(os.path.dirname(os.path.realpath(__file__)))
17+
18+
exodus = current_path / "meshfiles" / "outCSne8.g"
19+
20+
21+
class TestIntegrate(TestCase):
22+
23+
def test_face_area_coords(self):
24+
"""Test function for helper function get_all_face_area_from_coords."""
25+
# Note: currently only testing one face, but this can be used to get area of multiple faces
26+
x = np.array([0.57735027, 0.57735027, -0.57735027])
27+
y = np.array([-5.77350269e-01, 5.77350269e-01, 5.77350269e-01])
28+
z = np.array([-0.57735027, -0.57735027, -0.57735027])
29+
face_nodes = np.array([[0, 1, 2]])
30+
area = ux.get_all_face_area_from_coords(x,
31+
y,
32+
z,
33+
face_nodes,
34+
3,
35+
coords_type="cartesian")
36+
nt.assert_almost_equal(area, constants.TRI_AREA, decimal=1)
37+
38+
def test_calculate_face_area(self):
39+
"""Test function for helper function calculate_face_area - only one face."""
40+
# Note: currently only testing one face, but this can be used to get area of multiple faces
41+
# Also note, this does not need face_nodes, assumes nodes are in counterclockwise orientation
42+
x = np.array([0.57735027, 0.57735027, -0.57735027])
43+
y = np.array([-5.77350269e-01, 5.77350269e-01, 5.77350269e-01])
44+
z = np.array([-0.57735027, -0.57735027, -0.57735027])
45+
area = ux.calculate_face_area(x, y, z, "gaussian", 5, "cartesian")
46+
nt.assert_almost_equal(area, constants.TRI_AREA, decimal=3)
47+
48+
def test_quadrature(self):
49+
order = 1
50+
dG, dW = ux.get_tri_quadratureDG(order)
51+
G = np.array([[0.33333333, 0.33333333, 0.33333333]])
52+
W = np.array([1.0])
53+
54+
np.testing.assert_array_almost_equal(G, dG)
55+
np.testing.assert_array_almost_equal(W, dW)
56+
57+
dG, dW = ux.get_gauss_quadratureDG(order)
58+
G = np.array([[0.5]])
59+
W = np.array([1.0])
60+
61+
np.testing.assert_array_almost_equal(G, dG)
62+
np.testing.assert_array_almost_equal(W, dW)

0 commit comments

Comments
 (0)