11import os
22import sys
3- import numpy as np
43import pyvista as pv
5- import matplotlib .pyplot as plt
64
75sys .path .append ('../wakis' )
86
1210from wakis import SolverFIT3D
1311from wakis import GridFIT3D
1412from wakis .sources import Beam
13+ from wakis import WakeSolver
1514
1615import 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
2322class 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 ' )
0 commit comments