|
| 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