Skip to content

Commit 783ec2f

Browse files
author
Lachlan Grose
committed
test: adding test for points outisde of model support
1 parent 7ea9beb commit 783ec2f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/unit_tests/interpolator/test_discrete_supports.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ def test_evaluate_gradient():
4545
vector = grid.evaluate_gradient(grid.barycentre, grid.nodes[:, 1])
4646
assert np.sum(vector - np.array([0, 1, 0])) == 0
4747

48+
def test_outside_box():
49+
grid = StructuredGrid()
50+
# test by setting the scalar field to the y coordinate
51+
inside = grid.inside(grid.barycentre+5)
52+
assert np.all(~inside == np.any((grid.barycentre+5) > grid.maximum,axis=1))
53+
inside = grid.inside(grid.barycentre-5)
54+
assert np.all(~inside == np.any((grid.barycentre-5) < grid.origin,axis=1))
55+
56+
cix, ciy, ciz = grid.position_to_cell_index(grid.barycentre-5)
57+
assert np.all(cix[inside] < grid.nsteps_cells[0])
58+
assert np.all(ciy[inside] < grid.nsteps_cells[1])
59+
assert np.all(ciz[inside] < grid.nsteps_cells[2])
60+
cornersx, cornersy, cornersz = grid.cell_corner_indexes(cix, ciy, ciz)
61+
assert np.all(cornersx[inside] < grid.nsteps[0])
62+
assert np.all(cornersy[inside] < grid.nsteps[1])
63+
assert np.all(cornersz[inside] < grid.nsteps[2])
64+
globalidx = grid.global_indicies(np.dstack([cornersx, cornersy, cornersz]).T)
65+
# print(globalidx[inside],grid.n_nodes,inside)
66+
assert np.all(globalidx[inside] < grid.n_nodes)
67+
inside = grid.inside(grid.barycentre-5)
68+
inside, grid.position_to_cell_corners(grid.barycentre-5)
69+
vector = grid.evaluate_gradient(grid.barycentre-5, grid.nodes[:, 1])
70+
assert np.sum(np.mean(vector[inside,:],axis=0) - np.array([0, 1, 0])) == 0
71+
vector = grid.evaluate_gradient( grid.nodes, grid.nodes[:, 1])
4872

4973
def test_evaluate_gradient2():
5074
# this test is the same as above but we will use a random vector
@@ -211,3 +235,17 @@ def test_change_maximum_and_origin():
211235
assert np.all(grid.nsteps == np.array([8, 8, 8]))
212236
assert np.all(grid.maximum == np.array([7.0, 7.0, 7.0]))
213237
assert np.all(grid.step_vector == np.ones(3))
238+
239+
if __name__ == "__main__":
240+
test_create_structured_grid()
241+
test_create_structured_grid2d()
242+
test_create_structured_grid2d_origin_nsteps()
243+
test_change_maximum()
244+
test_change_maximum_and_origin()
245+
test_change_origin()
246+
test_create_structured_grid_origin_nsteps()
247+
test_create_testmesh()
248+
test_evaluate_gradient()
249+
test_evaluate_gradient2()
250+
test_outside_box()
251+

0 commit comments

Comments
 (0)