Skip to content

Commit 61601ac

Browse files
committed
Test for charge accumulation
1 parent 71a64ca commit 61601ac

File tree

1 file changed

+67
-29
lines changed

1 file changed

+67
-29
lines changed

tests/test_011_smart_mesh.py

Lines changed: 67 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,76 @@ class TestSmartMesh:
1717
xedges = [-0.025,-0.005, 0.005, 0.025]
1818
yedges = [-0.025,-0.005, 0.005, 0.025]
1919

20+
print("\n---------- Initializing simulation ------------------")
21+
# Number of mesh cells
22+
Nx = 50
23+
Ny = 50
24+
Nz = 80
25+
26+
# Embedded boundaries
27+
stl_file = 'tests/stl/001_cubic_cavity.stl'
28+
surf = pv.read(stl_file)
29+
30+
stl_solids = {'cavity': stl_file}
31+
stl_materials = {'cavity': 'vacuum'}
32+
33+
# Domain bounds
34+
xmin, xmax, ymin, ymax, zmin, zmax = surf.bounds
35+
36+
refinement_tol=1e-8
37+
snap_tol=1e-2
38+
# set grid and geometry
39+
global grid
40+
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
41+
stl_solids=stl_solids,
42+
stl_materials=stl_materials,
43+
use_mesh_refinement=True,
44+
snap_tol=snap_tol,
45+
refinement_tol=refinement_tol)
46+
47+
# Beam parameters
48+
beta = 1. # beam beta
49+
sigmaz = 18.5e-3*beta #[m]
50+
q = 1e-9 #[C]
51+
xs = 0. # x source position [m]
52+
ys = 0. # y source position [m]
53+
xt = 0. # x test position [m]
54+
yt = 0. # y test position [m]
55+
56+
global wake
57+
skip_cells = 12 # no. cells to skip in WP integration
58+
wake = WakeSolver(q=q, sigmaz=sigmaz, beta=beta,
59+
xsource=xs, ysource=ys, xtest=xt, ytest=yt,
60+
save=False, Ez_file='tests/011_Ez.h5',
61+
skip_cells=skip_cells,
62+
)
63+
64+
# boundary conditions
65+
bc_low=['pec', 'pec', 'pec']
66+
bc_high=['pec', 'pec', 'pec']
67+
68+
# set Solver object
69+
solver = SolverFIT3D(grid, wake,
70+
bc_low=bc_low, bc_high=bc_high,
71+
use_stl=True, bg='pec')
72+
73+
wakelength = 1. #[m]
74+
solver.wakesolve(wakelength=wakelength, save_J=False)
75+
os.remove('tests/011_Ez.h5')
76+
2077
def test_grid_generation(self):
21-
print("\n---------- Initializing simulation ------------------")
22-
# Number of mesh cells
23-
Nx = 50
24-
Ny = 50
25-
Nz = 150
26-
27-
# Embedded boundaries
28-
stl_file = 'tests/stl/001_cubic_cavity.stl'
29-
surf = pv.read(stl_file)
30-
31-
stl_solids = {'cavity': stl_file}
32-
stl_materials = {'cavity': 'vacuum'}
33-
34-
# Domain bounds
35-
xmin, xmax, ymin, ymax, zmin, zmax = surf.bounds
36-
37-
refinement_tol=1e-8
38-
snap_tol=1e-2
39-
# set grid and geometry
40-
grid = GridFIT3D(xmin, xmax, ymin, ymax, zmin, zmax, Nx, Ny, Nz,
41-
stl_solids=stl_solids,
42-
stl_materials=stl_materials,
43-
use_mesh_refinement=True,
44-
snap_tol=snap_tol,
45-
refinement_tol=refinement_tol)
78+
global grid
4679
for edg in self.zedges:
4780
diff = np.min(np.abs(grid.z-edg))
48-
assert diff <= refinement_tol + snap_tol, "Mesh not inside the tolerance at the z edges"
81+
assert diff <= 1e-8 + 1e-2, "Mesh not inside the tolerance at the z edges"
4982

5083
for edg in self.yedges:
5184
diff = np.min(np.abs(grid.y-edg))
52-
assert diff <= refinement_tol + snap_tol, "Mesh not inside the tolerance at the y edges"
85+
assert diff <= 1e-8 + 1e-2, "Mesh not inside the tolerance at the y edges"
5386

5487
for edg in self.xedges:
5588
diff = np.min(np.abs(grid.x-edg))
56-
assert diff <= refinement_tol + snap_tol, "Mesh not inside the tolerance at the x edges"
89+
assert diff <= 1e-8 + 1e-2, "Mesh not inside the tolerance at the x edges"
5790

5891
zdiff=np.abs(np.diff(grid.dz))
5992
for cell in range(len(grid.dz)-1):
@@ -69,4 +102,9 @@ def test_grid_generation(self):
69102

70103
assert np.min(grid.dz) > 0.25 * (grid.zmax-grid.zmin)/grid.Nz, "Smallest z difference is too small"
71104
assert np.min(grid.dy) > 0.25 * (grid.ymax-grid.ymin)/grid.Ny, "Smallest y difference is too small"
72-
assert np.min(grid.dx) > 0.25 * (grid.xmax-grid.xmin)/grid.Nx, "Smallest x difference is too small"
105+
assert np.min(grid.dx) > 0.25 * (grid.xmax-grid.xmin)/grid.Nx, "Smallest x difference is too small"
106+
107+
def test_nonuniform_simulation(self):
108+
global wake
109+
assert np.abs(wake.Z[0]) < 0.01 * np.abs(np.max(wake.Z)), "Charge Accumulation - DC component"
110+
# TODO: Test that checks the continuity equation

0 commit comments

Comments
 (0)