Skip to content

Commit c169393

Browse files
authored
Merge branch 'main' into Mesh-refinement
2 parents 3b0d7dc + ec75ae5 commit c169393

14 files changed

+829
-317
lines changed

.github/workflows/manual_tests_CPU.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
- name: pip install
2929
run: |
3030
pip install wakis['notebook']
31+
pip uninstall vtk -y
32+
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
3133
3234
- name: Print versions
3335
run: conda list

.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

.github/workflows/pull_request_CPU.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ jobs:
3232
run: |
3333
cd wakis
3434
pip install .['notebook']
35+
pip uninstall vtk -y
36+
pip install --extra-index-url https://wheels.vtk.org vtk-osmesa
3537
3638
- name: Print installed packages
3739
run: conda list

.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

notebooks/002_Wakefield_simulation.ipynb

Lines changed: 233 additions & 37 deletions
Large diffs are not rendered by default.

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_007_mpi_lossy_cavity.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ class TestMPILossyCavity:
8686
-6.04105997e+01 ,-3.06532160e+01 ,-1.17749936e+01 ,-3.12574866e+00,
8787
-7.35339521e-01 ,-1.13085658e-01 , 7.18247535e-01 , 8.73829036e-02])
8888

89-
9089
gridLogs = {'use_mesh_refinement': False, 'Nx': 60, 'Ny': 60, 'Nz': 140, 'dx': 0.00866666634877522,
9190
'dy': 0.00866666634877522, 'dz': 0.005714285799435207,
9291
'xmin': -0.25999999046325684, 'xmax': 0.25999999046325684,
@@ -95,11 +94,11 @@ class TestMPILossyCavity:
9594
'stl_solids': {'cavity': 'tests/stl/007_vacuum_cavity.stl', 'shell': 'tests/stl/007_lossymetal_shell.stl'},
9695
'stl_materials': {'cavity': 'vacuum', 'shell': [30, 1.0, 30]},
9796
'gridInitializationTime': 0}
98-
99-
solverLogs = {'use_gpu': False, 'use_mpi': False, 'background': 'pec','bc_low': ['pec', 'pec', 'pec'],
100-
'bc_high': ['pec', 'pec', 'pec'], 'dt': 6.970326728398968e-12,
101-
'solverInitializationTime': 0}
102-
97+
98+
solverLogs = {'use_gpu': False, 'use_mpi': False, 'background': 'pec',
99+
'bc_low': ['pec', 'pec', 'pec'], 'bc_high': ['pec', 'pec', 'pec'],
100+
'dt': 6.970326728398966e-12, 'solverInitializationTime': 0}
101+
103102
wakeSolverLogs = {'ti': 2.8516132094735135e-09, 'q': 1e-09, 'sigmaz': 0.1, 'beta': 1.0,
104103
'xsource': 0.0, 'ysource': 0.0, 'xtest': 0.0, 'ytest': 0.0, 'chargedist': None,
105104
'skip_cells': 10, 'results_folder': 'tests/007_results/', 'wakelength': 10.0, 'simulationTime': 0}
@@ -253,29 +252,6 @@ def test_mpi_plot1D(self):
253252
xscale='linear', yscale='linear',
254253
off_screen=True, title=self.img_folder+'Ez1d', n=3000)
255254

256-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
257-
def test_mpi_plot3D(self):
258-
# Plot Abs Electric field on domain
259-
# disabled when mpi = True
260-
global solver
261-
solver.plot3D('E', component='Abs',
262-
cmap='rainbow', clim=[0, 500],
263-
add_stl=['cavity', 'shell'], stl_opacity=0.1,
264-
clip_interactive=True, clip_normal='-y')
265-
266-
@pytest.mark.skipif(not flag_plot_3D, reason="Requires interactive plotting")
267-
def test_mpi_plot3DonSTL(self):
268-
# Plot Abs Electric field on STL solid `cavity`
269-
# disabled when mpi = True
270-
global solver
271-
solver.plot3DonSTL('E', component='Abs',
272-
cmap='rainbow', clim=[0, 500],
273-
stl_with_field='cavity', field_opacity=1.0,
274-
stl_transparent='shell', stl_opacity=0.1, stl_colors='white',
275-
clip_plane=True, clip_normal='-y', clip_origin=[0,0,0],
276-
off_screen=False, zoom=1.2, title=self.img_folder+'Ez3d')
277-
278-
279255
def test_mpi_wakefield(self):
280256
# Reset fields
281257
global solver
@@ -394,7 +370,7 @@ def assert_dict_allclose(d1, d2, rtol=1e-6, atol=1e-12, path=""):
394370

395371
global solver
396372
# Exclude timing info from comparison as they can vary between runs
397-
solver.logger.grid["gridInitializationTime"] = 0
373+
solver.logger.grid["gridInitializationTime"] = 0
398374
solver.logger.solver["solverInitializationTime"] = 0
399375
solver.logger.wakeSolver["simulationTime"] = 0
400376
self.solverLogs['use_mpi'] = use_mpi

0 commit comments

Comments
 (0)