Skip to content

Commit

Permalink
shorten tests (#1161)
Browse files Browse the repository at this point in the history
* speed up some tests

* faster, better, stronger

* fix

* shorter prism test
  • Loading branch information
stevengj authored Mar 27, 2020
1 parent 9aba9c0 commit e7e02a6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
12 changes: 11 additions & 1 deletion python/tests/prism.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def spiral_gds(self):

return prism_eps

def test_prism(self):
# lots of tests, turned off by default since they run too long;
# rename to test_something to run these tests.
def bigtest_prism(self):
print("Testing Non-Convex Prism #1 using marching squares algorithm...")
d1_a = self.nonconvex_marching_squares(1,208)
d1_b = self.nonconvex_marching_squares(1,448)
Expand Down Expand Up @@ -225,5 +227,13 @@ def test_prism(self):
d_ref = 455.01744881372224
self.assertAlmostEqual(d,d_ref,places=5)

def test_prism(self):
print("Testing Non-Convex Prism #3 using marching squares algorithm...")
d3_a = self.nonconvex_marching_squares(3,164)
d3_b = self.nonconvex_marching_squares(3,336)
d3_ref = 640.0738356076143 ## self.nonconvex_marching_squares(3,672)
self.assertLess(abs((d3_b-d3_ref)/d3_ref),abs((d3_a-d3_ref)/d3_ref))
self.assertLess(abs((d3_b-d3_ref)/d3_ref), 0.02)

if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion tests/2D_convergence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int main(int argc, char **argv) {
#ifdef HAVE_HARMINV
master_printf("Running holes square-lattice resolution convergence test.\n");
check_convergence(Ey, 0.179944, 0); // from MPB; correct to >= 4 dec. places
check_convergence(Ez, 0.166998, 0); // from MPB; correct to >= 4 dec. places
// check_convergence(Ez, 0.166998, 0); // from MPB; correct to >= 4 dec. places
check_convergence(Ez, 0.173605, .1); // from MPB; correct to >= 4 dec. places
#endif
return 0;
Expand Down
29 changes: 22 additions & 7 deletions tests/near2far.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,29 @@ int check_cyl(double sr, double sz, double a) {
return 1;
}

int check_2d_3d(ndim dim, const double xmax, double a, component c0) {
int check_2d_3d(ndim dim, const double xmax, double a, component c0, component c1 = NO_COMPONENT, bool evenz = true) {
const double dpml = 1;
if (dim != D2 && dim != D3) abort("2d or 3d required");
grid_volume gv = dim == D2 ? vol2d(xmax + 2 * dpml, xmax + 2 * dpml, a)
: vol3d(xmax + 2 * dpml, xmax + 2 * dpml, xmax + 2 * dpml, a);
gv.center_origin();

if (!gv.has_field(c0)) return 1;
if (c1 != NO_COMPONENT && !gv.has_field(c1)) return 1;
master_printf("TESTING %s AT RESOLUTION %g FOR %s SOURCE...\n", dim == D2 ? "2D" : "3D", a,
component_name(c0));
if (c1 != NO_COMPONENT) master_printf(" (and %s SOURCE)\n", component_name(c1));

structure s(gv, two, pml(dpml));
// HACK: to speed up tests, we assume c0 and c1 have these symmetries
symmetry S = dim == D3 ? (evenz ? mirror(Z, gv) - mirror(X, gv) : mirror(X, gv) - mirror(Z, gv)) :
(evenz ? -mirror(X, gv) : mirror(X, gv)); // 2d

structure s(gv, two, pml(dpml), S);
fields f(&s);
double w = 0.30;
continuous_src_time src(w);
f.add_point_source(c0, src, zero_vec(dim));
if (c1 != NO_COMPONENT) f.add_point_source(c1, src, zero_vec(dim), 0.7654321);
f.solve_cw(1e-6);

FOR_E_AND_H(c) {
Expand All @@ -145,6 +152,10 @@ int check_2d_3d(ndim dim, const double xmax, double a, component c0) {
F[i] = f.get_field(c, x) * phase;
(dim == D2 ? green2d : green3d)(EH, x, w, 2.0, 1.0, x0, c0, 1.0);
F0[i] = EH[EHcomp[c]];
if (c1 != NO_COMPONENT) {
(dim == D2 ? green2d : green3d)(EH, x, w, 2.0, 1.0, x0, c1, 0.7654321);
F0[i] += EH[EHcomp[c]];
}
double d = abs(F0[i] - F[i]);
double f = abs(F[i]);
double f0 = abs(F0[i]);
Expand Down Expand Up @@ -208,6 +219,10 @@ int check_2d_3d(ndim dim, const double xmax, double a, component c0) {
F[i] = EH[EHcomp[c]] * phase;
(dim == D2 ? green2d : green3d)(EH, x, w, 2.0, 1.0, x0, c0, 1.0);
F0[i] = EH[EHcomp[c]];
if (c1 != NO_COMPONENT) {
(dim == D2 ? green2d : green3d)(EH, x, w, 2.0, 1.0, x0, c1, 0.7654321);
F0[i] += EH[EHcomp[c]];
}
double d = abs(F0[i] - F[i]);
double f0 = abs(F0[i]);
diff += d * d;
Expand Down Expand Up @@ -237,12 +252,12 @@ int main(int argc, char **argv) {
const double a2d = argc > 1 ? atof(argv[1]) : 20, a3d = argc > 1 ? a2d : 10;

if (!check_cyl(5.0, 10.0, 20.0)) return 1;
if (!check_2d_3d(D3, 4, a3d, Ez)) return 1;
if (!check_2d_3d(D3, 4, a3d, Hz)) return 1;

// NOTE: see hack above -- we require sources to be odd in Z and even in X or vice-versa
if (!check_2d_3d(D3, 4, a3d, Ez, Hx, false)) return 1;
#ifdef HAVE_LIBGSL
FOR_E_AND_H(c0) {
if (!check_2d_3d(D2, 8, a2d, c0)) return 1;
}
if (!check_2d_3d(D2, 8, a2d, Ez, Hx, false)) return 1;
if (!check_2d_3d(D2, 8, a2d, Ex, Hz, true)) return 1;
#endif

return 0;
Expand Down
13 changes: 7 additions & 6 deletions tests/pml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,17 @@ int main(int argc, char **argv) {
initialize mpi(argc, argv);
verbosity = 0;
master_printf("Running PML tests...\n");
if (check_pml1d(one, 0)) abort("not a pml in 1d.");
// if (check_pml1d(one, 0)) abort("not a pml in 1d.");
if (check_pml1d(one, 10.0)) abort("not a pml in 1d + conductivity.");
if (check_pml2d(one, Ez, 0, false, 0)) abort("not a pml in 2d TM.");
if (check_pml2d(one, Hz, 1, true, 0.5)) abort("not a pml in 2d TE + conduct. + dispersion + offdiag");
// if (check_pml2d(one, Ez, 0, false, 0)) abort("not a pml in 2d TM.");
// if (check_pml2d(one,Ez,1,false,0)) abort("not a pml in 2d TM + conduct.");
// if (check_pml2d(one,Hz,0,false,0)) abort("not a pml in 2d TE.");
if (check_pml2d(one, Hz, 1, false, 0)) abort("not a pml in 2d TE + conduct.");
// if (check_pml2d(one, Hz, 1, false, 0)) abort("not a pml in 2d TE + conduct.");
// if (check_pml2d(one,Ez,0,true,0)) abort("not a pml in 2d TM + dispersion.");
if (check_pml2d(one, Hz, 0, true, 0)) abort("not a pml in 2d TE + dispersion.");
if (check_pml2d(one, Ez, 0, false, 0.5)) abort("not a pml in 2d TM + offdiag.");
if (check_pml2d(one, Hz, 0, false, 0.5)) abort("not a pml in 2d TE + offdiag.");
// if (check_pml2d(one, Hz, 0, true, 0)) abort("not a pml in 2d TE + dispersion.");
// if (check_pml2d(one, Ez, 0, false, 0.5)) abort("not a pml in 2d TM + offdiag.");
// if (check_pml2d(one, Hz, 0, false, 0.5)) abort("not a pml in 2d TE + offdiag.");
// if (check_pmlcyl(one)) abort("not a pml in cylincrical co-ordinates.");
if (pml1d_scaling(one)) abort("pml doesn't scale properly with length.");
if (pmlcyl_scaling(one, 0)) abort("m=0 cylindrical pml doesn't scale properly with length.");
Expand Down

0 comments on commit e7e02a6

Please sign in to comment.