Skip to content

Commit 40aba8d

Browse files
committed
tests: update interactive plots, now not skipped thanks to vtk-osmesa + ignore HTML outputs
1 parent f75be71 commit 40aba8d

File tree

4 files changed

+51
-67
lines changed

4 files changed

+51
-67
lines changed

.github/workflows/nightly_tests_CPU.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ jobs:
2828
- name: pip install
2929
run: |
3030
pip install wakis['notebook']
31-
31+
pip uninstall vtk -y
32+
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
3233
- name: Print versions
3334
run: conda list
3435
- name: Checkout wakis

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FDTD_*
77
ECT_*
88
*/img*
99
*.png
10+
*.html
1011
*.gif
1112
*.old*
1213
*.svg

tests/test_003_planewave_sphere.py

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
import os, sys
2-
import numpy as np
1+
import os
2+
import sys
33
import pyvista as pv
44
import matplotlib.pyplot as plt
55
from scipy.constants import c
66

77
sys.path.append('../wakis')
8-
8+
99
from wakis import SolverFIT3D
10-
from wakis import GridFIT3D
10+
from wakis import GridFIT3D
1111
from wakis.sources import PlaneWave
1212

13-
import pytest
13+
import pytest
1414

15-
flag_interactive = False # Set to true to run PyVista tests
15+
# Turn False when running local
16+
flag_offscreen = True
1617

1718
class TestPlanewave:
19+
20+
img_folder = 'tests/003_img/'
21+
1822
def test_simulation(self):
1923
print("\n---------- Initializing simulation ------------------")
2024
# Number of mesh cells
@@ -23,7 +27,7 @@ def test_simulation(self):
2327
Nz = 120
2428

2529
# Embedded boundaries
26-
stl_file = 'tests/stl/003_sphere.stl'
30+
stl_file = 'tests/stl/003_sphere.stl'
2731
surf = pv.read(stl_file)
2832

2933
stl_solids = {'Sphere': stl_file}
@@ -44,90 +48,75 @@ def test_simulation(self):
4448
xmax, ymax, zmax = (xmax+padx), (ymax+pady), (zmax+padz)
4549

4650
global grid
47-
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
48-
stl_solids=stl_solids,
51+
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
52+
stl_solids=stl_solids,
4953
stl_rotate=stl_rotate,
5054
stl_scale=stl_scale,
5155
stl_materials=stl_materials)
5256

53-
# Boundary conditions and
57+
# Boundary conditions and
5458
bc_low=['periodic', 'periodic', 'pec']
5559
bc_high=['periodic', 'periodic', 'pml']
56-
60+
61+
# -------------- Output folder ---------------------
62+
if not os.path.exists(self.img_folder):
63+
os.mkdir(self.img_folder)
64+
5765
# simulation
5866
global solver
5967
solver = SolverFIT3D(grid, use_stl=True, bc_low=bc_low, bc_high=bc_high)
60-
68+
6169
# source
6270
f = 15/((solver.z.max()-solver.z.min())/c)
63-
source = PlaneWave(xs=slice(1, Nx-1), ys=slice(1,Ny-1), zs=1,
71+
source = PlaneWave(xs=slice(1, Nx-1), ys=slice(1,Ny-1), zs=1,
6472
f=f, beta=1.0)
65-
73+
6674
Nt = int(1.0*(solver.z.max()-solver.z.min())/c/solver.dt)
6775
solver.emsolve(Nt, source)
6876

69-
def test_plot2D(self):
77+
def test_plot1D(self):
7078
global solver
71-
solver.plot2D('Ex', plane='ZY', pos=0.5, cmap='rainbow',
72-
add_patch='Sphere', patch_alpha=0.3,
73-
off_screen=False)
74-
if not flag_interactive:
75-
plt.close()
76-
77-
def test_plot2D_offscreen(self):
79+
solver.plot1D('Ex', line='z', pos=[0.7, 0.6, 0.5, 0.4, 0.3, 0.2],
80+
xscale='linear', yscale='linear',
81+
off_screen=flag_offscreen, n=solver.Nt,
82+
colors=['#5ccfe6', '#fdb6d0', '#ffae57', '#bae67e', '#ffd580', '#a2aabc'],
83+
title=self.img_folder+'1Dplot_Ex')
84+
85+
def test_plot2D(self):
7886
global solver
79-
solver.plot2D('Hy', plane='ZY', pos=0.5, cmap='bwr',
87+
solver.plot2D('Hy', plane='ZY', pos=0.5, cmap='bwr',
8088
add_patch='Sphere', patch_alpha=0.1, interpolation='spline36',
81-
off_screen=True, n=solver.Nt, title='003_2Dplot_Hy')
82-
if not flag_interactive:
83-
os.remove(f'003_2Dplot_Hy_{str(solver.Nt).zfill(6)}.png')
84-
85-
@pytest.mark.skipif(not flag_interactive, reason="Requires interactive plotting")
89+
off_screen=flag_offscreen, n=solver.Nt,
90+
title=self.img_folder+'2Dplot_Hy')
91+
92+
@pytest.mark.skipif(flag_offscreen, reason="Requires interactive plotting")
8693
def test_plot3D_interactive(self):
8794
global solver
8895
solver.plot3D(field='E', component='x', cmap='jet',
8996
add_stl='Sphere', stl_opacity=0.1, stl_colors='white',
9097
clip_interactive=True, clip_normal='-y',
91-
off_screen=False)
92-
93-
@pytest.mark.skipif(not flag_interactive, reason="Requires Xserver connection for plotting")
98+
off_screen=False)
99+
94100
def test_plot3D_offscreen(self):
95101
global solver
96102
solver.plot3D(field='H', component='y', cmap='bwr',
97103
add_stl='Sphere', stl_opacity=0.1, stl_colors='white',
98-
clip_box=True, clip_bounds=None,
99-
off_screen=True, title='003_3Dplot_Hy')
100-
if not flag_interactive:
101-
os.remove('003_3Dplot_Hy.png')
102-
103-
@pytest.mark.skipif(not flag_interactive, reason="Requires interactive plotting")
104+
clip_box=True, clip_bounds=None,
105+
off_screen=flag_offscreen, title=self.img_folder+'3Dplot_Hy')
106+
107+
@pytest.mark.skipif(flag_offscreen, reason="Requires interactive plotting")
104108
def test_plot3DonSTL_interactive(self):
105109
global solver
106-
solver.plot3DonSTL('Ex', cmap='jet',
110+
solver.plot3DonSTL('Ex', cmap='jet',
107111
stl_with_field='Sphere', field_opacity=1.,
108112
stl_transparent='Sphere', stl_opacity=0.3, stl_colors='white',
109113
clip_interactive=True, clip_normal='-y',
110114
off_screen=False, zoom=1.0)
111-
112-
@pytest.mark.skipif(not flag_interactive, reason="Requires Xserver connection for plotting")
115+
113116
def test_plot3DonSTL_offscreen(self):
114117
global solver
115-
solver.plot3DonSTL('Ex', cmap='jet',
118+
solver.plot3DonSTL('Ex', cmap='jet',
116119
stl_with_field='Sphere', field_opacity=1.,
117120
stl_transparent=None, stl_opacity=0., stl_colors=None,
118-
off_screen=True, zoom=1.0, title='003_3DplotOnSTL_Hy')
119-
if not flag_interactive:
120-
os.remove('003_3DplotOnSTL_Hy.png')
121-
122-
123-
@pytest.mark.skipif(not flag_interactive, reason="Requires interactive plotting")
124-
def test_grid_inspect(self):
125-
global grid
126-
grid.inspect(add_stl=None, stl_opacity=0.5, stl_colors=None,
127-
anti_aliasing='ssa')
128-
129-
@pytest.mark.skipif(not flag_interactive, reason="Requires interactive plotting")
130-
def test_grid_plot_solids(self):
131-
global grid
132-
grid.plot_solids(bounding_box=False, opacity=1.0, specular=0.5,
133-
anti_aliasing=None)
121+
off_screen=flag_offscreen, zoom=1.0,
122+
title=self.img_folder+'3DplotOnSTL_Hy')

tests/test_008_3D_plotting.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
import pytest
1616

17-
# Turn true when running local
18-
flag_plot_3D = True
17+
# Turn False when running local
1918
flag_offscreen = True
2019

2120
@pytest.mark.slow
@@ -75,7 +74,7 @@ def test_simulation(self):
7574
xsource=xs, ysource=ys, ti=ti)
7675

7776
wake = WakeSolver(q=q, sigmaz=sigmaz, beta=beta,
78-
xsource=xs, ysource=ys, ti=ti)
77+
xsource=xs, ysource=ys, ti=ti)
7978

8079
# ----------- Solver & Simulation ----------
8180
# boundary conditions
@@ -102,7 +101,6 @@ def test_simulation(self):
102101
beam.update(solver, n*solver.dt)
103102
solver.one_step()
104103

105-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
106104
def test_grid_inspect(self):
107105
# Plot grid and imported solids
108106
global solver
@@ -113,7 +111,6 @@ def test_grid_inspect(self):
113111
#pl.screenshot(self.img_folder+'grid_inspect.png')
114112
pl.export_html(self.img_folder+'grid_inspect.html')
115113

116-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
117114
def test_grid_plot_solids(self):
118115
# Plot only imported solids
119116
global solver
@@ -124,7 +121,6 @@ def test_grid_plot_solids(self):
124121
smooth_shading=False,
125122
off_screen=flag_offscreen,)
126123

127-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
128124
def test_grid_stl_mask(self):
129125
# Plot STL solid masks in the grid
130126
global solver
@@ -137,7 +133,6 @@ def test_grid_stl_mask(self):
137133
ymax=0.0,
138134
off_screen=flag_offscreen,)
139135

140-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
141136
def test_solver_inspect(self):
142137
# Plot imported solids and beam source and integraiton path
143138
global solver
@@ -148,7 +143,6 @@ def test_solver_inspect(self):
148143
#pl.screenshot(self.img_folder+'solver_inspect.png')
149144
pl.export_html(self.img_folder+'solver_inspect.html')
150145

151-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
152146
def test_plot3D(self):
153147
# Plot Abs Electric field on domain
154148
global solver
@@ -159,7 +153,6 @@ def test_plot3D(self):
159153
title=self.img_folder+'Ez3d',
160154
off_screen=flag_offscreen)
161155

162-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
163156
def test_plot3DonSTL(self):
164157
# Plot Abs Electric field on STL solid `cavity`
165158
global solver

0 commit comments

Comments
 (0)