Skip to content

Commit 17001d5

Browse files
committed
tests: include test functions for load and save grid
1 parent bfff446 commit 17001d5

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

tests/test_001_pec_cubic_cavity.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
sys.path.append('../wakis')
66

77
from wakis import SolverFIT3D
8-
from wakis import GridFIT3D
8+
from wakis import GridFIT3D
99
from wakis import WakeSolver
1010

11-
import pytest
11+
import pytest
1212

1313
@pytest.mark.slow
1414
class TestPecCubicCavity:
@@ -72,7 +72,7 @@ def test_simulation(self):
7272
Nz = 150
7373

7474
# Embedded boundaries
75-
stl_file = 'tests/stl/001_cubic_cavity.stl'
75+
stl_file = 'tests/stl/001_cubic_cavity.stl'
7676
surf = pv.read(stl_file)
7777

7878
stl_solids = {'cavity': stl_file}
@@ -82,10 +82,11 @@ def test_simulation(self):
8282
xmin, xmax, ymin, ymax, zmin, zmax = surf.bounds
8383

8484
# set grid and geometry
85-
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
86-
stl_solids=stl_solids,
85+
global grid
86+
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
87+
stl_solids=stl_solids,
8788
stl_materials=stl_materials)
88-
89+
8990
# Beam parameters
9091
beta = 1. # beam beta
9192
sigmaz = 18.5e-3*beta #[m]
@@ -95,9 +96,9 @@ def test_simulation(self):
9596
xt = 0. # x test position [m]
9697
yt = 0. # y test position [m]
9798

98-
global wake
99+
global wake
99100
skip_cells = 12 # no. cells to skip in WP integration
100-
wake = WakeSolver(q=q, sigmaz=sigmaz, beta=beta,
101+
wake = WakeSolver(q=q, sigmaz=sigmaz, beta=beta,
101102
xsource=xs, ysource=ys, xtest=xt, ytest=yt,
102103
save=False, logfile=False, Ez_file='tests/001_Ez.h5',
103104
skip_cells=skip_cells,
@@ -109,7 +110,7 @@ def test_simulation(self):
109110

110111
# set Solver object
111112
solver = SolverFIT3D(grid, wake,
112-
bc_low=bc_low, bc_high=bc_high,
113+
bc_low=bc_low, bc_high=bc_high,
113114
use_stl=True, bg='pec')
114115

115116
wakelength = 1. #[m]
@@ -127,3 +128,20 @@ def test_long_impedance(self):
127128
assert np.allclose(np.real(wake.Z)[::20], np.real(self.Z)), "Real Impedance samples failed"
128129
assert np.allclose(np.imag(wake.Z)[::20], np.imag(self.Z)), "Imag Impedance samples failed"
129130
assert np.cumsum(np.abs(wake.Z))[-1] == pytest.approx(372019.59123029554, 0.1), "Abs Impedance cumsum failed"
131+
132+
def test_grid_save_to_h5(self):
133+
global grid
134+
grid.save_to_h5('tests/001_grid.h5')
135+
assert os.path.exists('tests/001_grid.h5'), "Grid save_to_h5 failed"
136+
137+
def test_grid_load_from_h5(self):
138+
global grid
139+
grid2 = GridFIT3D(load_from_h5='tests/001_grid.h5',
140+
verbose=2)
141+
142+
assert np.array_equal(grid.x, grid2.x), "Grid load_from_h5 x-coords failed"
143+
assert np.array_equal(grid.y, grid2.y), "Grid load_from_h5 y-coords failed"
144+
assert np.array_equal(grid.z, grid2.z), "Grid load_from_h5 z-coords failed"
145+
assert np.array_equal(grid.grid['cavity'], grid2.grid['cavity']), "Grid load_from_h5 solid mask failed"
146+
os.remove('tests/001_grid.h5')
147+

0 commit comments

Comments
 (0)