1- import os , sys
2- import numpy as np
1+ import os
2+ import sys
33import pyvista as pv
44import matplotlib .pyplot as plt
55from scipy .constants import c
66
77sys .path .append ('../wakis' )
8-
8+
99from wakis import SolverFIT3D
10- from wakis import GridFIT3D
10+ from wakis import GridFIT3D
1111from 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
1718class 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' )
0 commit comments