Skip to content

Commit e713135

Browse files
committed
test: solve deprecation warnings and off_screen/on_screen test passing in test_008
1 parent 6e53f24 commit e713135

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

tests/test_008_3D_plotting.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import os
22
import sys
3-
import numpy as np
43
import pyvista as pv
5-
import matplotlib.pyplot as plt
64

75
sys.path.append('../wakis')
86

@@ -12,12 +10,13 @@
1210
from wakis import SolverFIT3D
1311
from wakis import GridFIT3D
1412
from wakis.sources import Beam
13+
from wakis import WakeSolver
1514

1615
import pytest
1716

1817
# Turn true when running local
19-
flag_plot_3D = False
20-
flag_offscreen = False
18+
flag_plot_3D = True
19+
flag_offscreen = True
2120

2221
@pytest.mark.slow
2322
class Test3Dplotting:
@@ -40,8 +39,8 @@ def test_simulation(self):
4039
'shell': [30, 1.0, 30] #[eps_r, mu_r, sigma[S/m]]
4140
}
4241

43-
stl_colors = {'cavity': 'vacuum',
44-
'shell': [1, 1, 1]}
42+
stl_colors = {'cavity': 'tab:blue',
43+
'shell': 'silver'}
4544

4645
# Extract domain bounds from geometry
4746
solids = pv.read(solid_1) + pv.read(solid_2)
@@ -69,20 +68,23 @@ def test_simulation(self):
6968
q = 1e-9 #[C]
7069
beta = 1.0 # beam beta
7170
xs = 0. # x source position [m]
72-
ys = 0. # y source position [m]
71+
ys = 1e-2 # y source position [m]
7372
ti = 3*sigmaz/c # injection time [s]
7473

7574
beam = Beam(q=q, sigmaz=sigmaz, beta=beta,
7675
xsource=xs, ysource=ys, ti=ti)
7776

77+
wake = WakeSolver(q=q, sigmaz=sigmaz, beta=beta,
78+
xsource=xs, ysource=ys, ti=ti)
79+
7880
# ----------- Solver & Simulation ----------
7981
# boundary conditions
8082
bc_low=['pec', 'pec', 'pec']
8183
bc_high=['pec', 'pec', 'pec']
8284

8385
# Solver setup
8486
global solver
85-
solver = SolverFIT3D(grid,
87+
solver = SolverFIT3D(grid, wake,
8688
bc_low=bc_low,
8789
bc_high=bc_high,
8890
use_stl=True,
@@ -95,7 +97,7 @@ def test_simulation(self):
9597
os.mkdir(self.img_folder)
9698

9799
# -------------- Custom time loop -----------------
98-
Nt = 3000
100+
Nt = 1000
99101
for n in tqdm(range(Nt)):
100102
beam.update(solver, n*solver.dt)
101103
solver.one_step()
@@ -104,16 +106,19 @@ def test_simulation(self):
104106
def test_grid_inspect(self):
105107
# Plot grid and imported solids
106108
global solver
107-
solver.grid.inspect(add_stl=['cavity', 'shell'],
109+
pl = solver.grid.inspect(add_stl=['cavity', 'shell'],
108110
stl_opacity=0.1, off_screen=flag_offscreen,
109111
anti_aliasing='ssaa')
112+
if flag_offscreen:
113+
#pl.screenshot(self.img_folder+'grid_inspect.png')
114+
pl.export_html(self.img_folder+'grid_inspect.html')
110115

111116
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
112117
def test_grid_plot_solids(self):
113118
# Plot only imported solids
114119
global solver
115120
solver.grid.plot_solids(bounding_box=True,
116-
show_grid=True,
121+
show_grid=False,
117122
opacity=1,
118123
specular=0.5,
119124
smooth_shading=False,
@@ -137,20 +142,21 @@ def test_solver_inspect(self):
137142
# Plot imported solids and beam source and integraiton path
138143
global solver
139144
pl = solver.inspect(window_size=(1200,800), off_screen=flag_offscreen,
140-
specular=0.,opacity=1, inactive_opacity=0.1,
145+
specular=0., opacity=1, inactive_opacity=0.1,
141146
add_silhouette=True,)
142147
if flag_offscreen:
148+
#pl.screenshot(self.img_folder+'solver_inspect.png')
143149
pl.export_html(self.img_folder+'solver_inspect.html')
144-
pl.screenshot(self.img_folder+'solver_inspect.png')
145150

146151
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
147152
def test_plot3D(self):
148153
# Plot Abs Electric field on domain
149154
global solver
150-
solver.plot3D('E', component='Abs',
155+
solver.plot3D('E', component='z',
151156
cmap='rainbow', clim=[0, 500],
152157
add_stl=['cavity', 'shell'], stl_opacity=0.1,
153158
clip_interactive=True, clip_normal='-y',
159+
title=self.img_folder+'Ez3d',
154160
off_screen=flag_offscreen)
155161

156162
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
@@ -162,4 +168,4 @@ def test_plot3DonSTL(self):
162168
stl_with_field='cavity', field_opacity=1.0,
163169
stl_transparent='shell', stl_opacity=0.1, stl_colors='white',
164170
clip_plane=True, clip_normal='-y', clip_origin=[0,0,0],
165-
off_screen=flag_offscreen, zoom=1.2, title=self.img_folder+'Ez3d')
171+
off_screen=flag_offscreen, zoom=1.2, title=self.img_folder+'EAbs3donSTL')

wakis/gridFIT3D.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,12 @@ def clip(widget):
929929
pl.enable_anti_aliasing(anti_aliasing)
930930

931931
if off_screen:
932-
pl.export_html('grid_inspect.html')
932+
pl.off_screen = True
933+
return pl
934+
#pl.export_html('grid_inspect.html')
933935
else:
934936
pl.show()
937+
return None
935938

936939
def save_to_h5(self, filename='grid.h5'):
937940
'''Save generated grid to HDF5 file

wakis/plotting.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def plot3DonSTL(self, field='E', component='z', clim=None, cmap='jet', log_scale
324324
except Exception:
325325
print("[!] Surface non-manifold, clip with plane skipped")
326326

327-
fieldonsurf = surf.sample(points, tolerance)
327+
fieldonsurf = surf.sample(points, tolerance=tolerance)
328328

329329
if clip_interactive: # interactive plotting with a plane
330330
ac1 = pl.add_mesh_clip_plane(fieldonsurf, normal=clip_normal, normal_rotation=False,
@@ -359,7 +359,7 @@ def plot3DonSTL(self, field='E', component='z', clim=None, cmap='jet', log_scale
359359
except Exception:
360360
print("Surface non-manifold, clip with plane skipped")
361361

362-
fieldonsurf = surf.sample(points)
362+
fieldonsurf = surf.sample(points, tolerance=tolerance)
363363

364364
if clip_interactive: # interactive plotting with a plane
365365
ac1 = pl.add_mesh_clip_plane(fieldonsurf, normal=clip_normal, normal_rotation=False,
@@ -954,6 +954,7 @@ def path_cb(v):
954954

955955
# Save
956956
if off_screen:
957+
pl.off_screen = True
957958
return pl
958959
else:
959960
pl.show()

0 commit comments

Comments
 (0)