📄 symmetry.cpp
字号:
"electric energy")) return 0; total_energy_check_time += 3.0; } } fs[0].eps_slices("mirror_single"); fs[1].eps_slices("mirror_multi"); return 1;}int exact_metal_rot4z(double eps(const vec &)) { double a = 8.0; double ttot = 5.0; const volume v = voltwo(1.0, 1.0, a); the_center = v.center(); const symmetry S = rotate4(Z,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing Z fourfold rotational symmetry...\n"); fields f1(&s1); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5)); f1.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5)); fields f(&s); f.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5)); f.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5)); check_unequal_layout(f, f1); double total_energy_check_time = 1.0; while (f.time() < ttot) { f.step(); f1.step(); if (!compare_point(f, f1, vec(0.01 , 0.5))) return 0; if (!compare_point(f, f1, vec(0.21 , 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 ))) return 0; if (f.time() >= total_energy_check_time) { if (!compare(f.electric_energy_in_box(v.surroundings()), f1.electric_energy_in_box(v.surroundings()), "electric energy")) return 0; if (!compare(f.magnetic_energy_in_box(v.surroundings()), f1.magnetic_energy_in_box(v.surroundings()), "magnetic energy")) return 0; if (!compare(f.total_energy(), f1.total_energy(), " total energy")) return 0; total_energy_check_time += 1.0; } } return 1;}int exact_metal_rot4z_nonlinear(double eps(const vec &)) { double a = 8.0; double ttot = 5.0; const volume v = voltwo(1.0, 1.0, a); the_center = v.center(); const symmetry S = rotate4(Z,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); s.set_kerr(one); s1.set_kerr(one); master_printf("Testing nonlinear Z fourfold rotational symmetry...\n"); fields f1(&s1); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5)); f1.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5)); /* BUG: we should use f(&s) here, since otherwise the test is trivial. If we do, however, the test FAILS in when we have both sources turned on, so there may be a bug in the nonlinear code for symmetry. */ fields f(&s1); f.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5)); f.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5)); // check_unequal_layout(f, f1); double total_energy_check_time = 1.0; while (f.time() < ttot) { f.step(); f1.step(); if (!compare_point(f, f1, vec(0.01 , 0.5))) return 0; if (!compare_point(f, f1, vec(0.21 , 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 ))) return 0; if (f.time() >= total_energy_check_time) { if (!compare(f.electric_energy_in_box(v.surroundings()), f1.electric_energy_in_box(v.surroundings()), "electric energy")) return 0; if (!compare(f.magnetic_energy_in_box(v.surroundings()), f1.magnetic_energy_in_box(v.surroundings()), "magnetic energy")) return 0; if (!compare(f.total_energy(), f1.total_energy(), " total energy")) return 0; total_energy_check_time += 1.0; } } return 1;}int exact_pml_rot2x_tm(double eps(const vec &)) { double a = 8.0; double ttot = 30.0; const volume v = voltwo(3.0, 3.0, a); the_center = v.center(); const symmetry S = rotate2(X,v); structure s(v, eps, pml(1.0), S); structure s1(v, eps, pml(1.0), identity()); s.set_output_directory(mydirname); s1.set_output_directory(mydirname); master_printf("Testing X twofold rotational symmetry with PML...\n"); fields f1(&s1); f1.add_point_source(Hx, 0.7, 2.5, 0.0, 4.0, vec(1.3,1.5)); fields f(&s); f.add_point_source(Hx, 0.7, 2.5, 0.0, 4.0, vec(1.3,1.5)); check_unequal_layout(f, f1); double total_energy_check_time = 1.0; while (f.time() < ttot) { f.step(); f1.step(); if (!compare_point(f, f1, vec(0.01 , 1.5))) return 0; if (!compare_point(f, f1, vec(1.21 , 1.5))) return 0; if (!compare_point(f, f1, vec(1.46 , 0.33))) return 0; if (!compare_point(f, f1, vec(1.2 , 1.2 ))) return 0; if (f.time() >= total_energy_check_time) { if (!compare(f.electric_energy_in_box(v.surroundings()), f1.electric_energy_in_box(v.surroundings()), "electric energy")) return 0; if (!compare(f.magnetic_energy_in_box(v.surroundings()), f1.magnetic_energy_in_box(v.surroundings()), "magnetic energy")) return 0; if (!compare(f.total_energy(), f1.total_energy(), " total energy")) return 0; total_energy_check_time += 1.0; } } // Just to make sure slice output doesn't actually crash... f.output_real_imaginary_slices("hello"); f1.output_real_imaginary_slices("world"); f.eps_slices("hello"); f1.eps_slices("world"); return 1;}double polariton_ex(const volume &v, double eps(const vec &)) { const double ttot = 10.0; master_printf("Testing polariton in %s...\n", dimension_name(v.dim)); the_center = v.center(); const symmetry S = mirror(Z,v); structure s(v, eps); structure sS(v, eps, no_pml(), S); s.add_polarizability(one, 0.3, 0.1, 7.63); sS.add_polarizability(one, 0.3, 0.1, 7.63); fields f(&s); f.use_real_fields(); f.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); /* BUG: we should use fS(&sS) here, since otherwise the test is trivial. If we do, however, the test FAILS with some older versions of gcc, so there may be a bug in the nonlinear code for symmetry (or it may be that we are just too picky about fp). */ fields fS(&s); fS.use_real_fields(); fS.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); f.use_bloch(zero_vec(v.dim)); fS.use_bloch(zero_vec(v.dim)); // check_unequal_layout(f, fS); while (f.time() < ttot) { f.step(); fS.step(); if (!compare_point(fS, f, v.center())) return 0; if (!compare_point(fS, f, zero_vec(v.dim))) return 0; if (!compare_point(fS, f, v.center()*0.3)) return 0; } return 1;}double nonlinear_ex(const volume &v, double eps(const vec &)) { const double ttot = 10.0; master_printf("Testing nonlinear in %s...\n", dimension_name(v.dim)); the_center = v.center(); const symmetry S = mirror(Z,v); structure s(v, eps); structure sS(v, eps, no_pml(), S); s.set_kerr(one); sS.set_kerr(one); fields f(&s); f.use_real_fields(); f.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); /* BUG: we should use fS(&sS) here, since otherwise the test is trivial. If we do, however, the test FAILS in 3d, so there may be a bug in the nonlinear code for symmetry. */ fields fS(&s); fS.use_real_fields(); fS.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); f.use_bloch(zero_vec(v.dim)); fS.use_bloch(zero_vec(v.dim)); // check_unequal_layout(f, fS); while (f.time() < ttot) { f.step(); fS.step(); if (!compare_point(fS, f, v.center())) return 0; if (!compare_point(fS, f, zero_vec(v.dim))) return 0; if (!compare_point(fS, f, v.center()*0.3)) return 0; } return 1;}double saturated_gain_ez(const volume &v, double eps(const vec &)) { const double ttot = 10.0; master_printf("Testing saturated gain in %s...\n", dimension_name(v.dim)); the_center = v.center(); const symmetry S = -mirror(Z,v); structure s(v, eps); structure sS(v, eps, no_pml(), S); s.add_polarizability(one, 0.3, -0.1, 7.63, 0.5); sS.add_polarizability(one, 0.3, -0.1, 7.63, 0.5); fields f(&s); f.use_real_fields(); f.add_point_source(Ez, 0.2, 3.0, 0.0, 2.0, v.center()); fields fS(&sS); fS.use_real_fields(); fS.add_point_source(Ez, 0.2, 3.0, 0.0, 2.0, v.center()); f.use_bloch(zero_vec(v.dim)); fS.use_bloch(zero_vec(v.dim)); check_unequal_layout(f, fS); while (f.time() < ttot) { f.step(); fS.step(); if (!compare_point(fS, f, v.center())) return 0; if (!compare_point(fS, f, zero_vec(v.dim))) return 0; if (!compare_point(fS, f, v.center()*0.3)) return 0; } return 1;}double saturated_gain_te(const volume &v, double eps(const vec &)) { const double ttot = 10.0; master_printf("Testing saturated gain in %s...\n", dimension_name(v.dim)); the_center = v.center(); const symmetry S = -mirror(X,v); structure s(v, eps); structure sS(v, eps, no_pml(), S); s.add_polarizability(one, 0.3, -0.1, 7.63, 0.5); sS.add_polarizability(one, 0.3, -0.1, 7.63, 0.5); fields f(&s); f.use_real_fields(); f.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); fields fS(&sS); fS.use_real_fields(); fS.add_point_source(Ex, 0.2, 3.0, 0.0, 2.0, v.center()); f.use_bloch(zero_vec(v.dim)); fS.use_bloch(zero_vec(v.dim)); check_unequal_layout(f, fS); while (f.time() < ttot) { f.step(); fS.step(); if (!compare_point(fS, f, v.center())) return 0; if (!compare_point(fS, f, zero_vec(v.dim))) return 0; if (!compare_point(fS, f, v.center()*0.3)) return 0; } return 1;}int main(int argc, char **argv) { initialize mpi(argc, argv); quiet = true; trash_output_directory(mydirname); master_printf("Testing with various kinds of symmetry...\n"); if (!nonlinear_ex(vol1d(1.0, 10.0), one)) abort("error in 1D nonlinear vacuum\n"); if (!nonlinear_ex(vol3d(1.0, 1.2, 0.8, 10.0), one)) abort("error in 3D nonlinear vacuum\n"); if (!polariton_ex(vol1d(1.0, 10.0), one)) abort("error in 1D polariton vacuum\n"); if (!polariton_ex(vol3d(1.0, 1.2, 0.8, 10.0), one)) abort("error in 3D polariton vacuum\n"); if (0) // FIXME: disable until divergence bug is fixed if (!saturated_gain_ez(vol3d(0.5, 1.2, 0.8, 10.0), one)) abort("error in 3D saturated gain\n"); if (0) // FIXME: disable until divergence bug is fixed if (!saturated_gain_ez(volcyl(0.5, 1.2, 10.0), one)) abort("error in cylindrical saturated gain\n"); if (0) // FIXME: disable until divergence bug is fixed if (!saturated_gain_te(vol2d(0.6, 1.2, 10.0), one)) abort("error in 2D TE saturated gain\n"); if (!test_1d_periodic_mirror(one)) abort("error in test_1d_periodic_mirror vacuum\n"); if (!test_cyl_metal_mirror(one)) abort("error in test_cyl_metal_mirror vacuum\n"); if (!test_cyl_metal_mirror(one)) abort("error in test_cyl_metal_mirror nonlinear vacuum\n"); if (!test_yperiodic_ymirror(one)) abort("error in test_yperiodic_ymirror vacuum\n"); if (!test_yperiodic_ymirror(rods_2d)) abort("error in test_yperiodic_ymirror rods2d\n"); if (!pml_twomirrors(one)) abort("error in pml_twomirrors vacuum\n"); if (!test_origin_shift(mydirname)) abort("error in test_origin_shift\n"); if (!exact_pml_rot2x_tm(one)) abort("error in exact_pml_rot2x_tm vacuum\n"); if (!test_metal_xmirror(rods_2d)) abort("error in test_metal_xmirror rods_2d\n"); if (!test_metal_xmirror(one)) abort("error in test_metal_xmirror vacuum\n"); if (!test_metal_ymirror(one)) abort("error in test_metal_ymirror vacuum\n"); if (!test_metal_ymirror(rods_2d)) abort("error in test_metal_ymirror rods_2d\n"); if (!test_metal_rot2y(one)) abort("error in test_metal_rot2y vacuum\n"); if (!test_metal_rot2y(rods_2d)) abort("error in test_metal_rot2y rods_2d\n"); if (!exact_metal_rot2y(one)) abort("error in exact_metal_rot2y vacuum\n"); if (!exact_metal_rot2y(rods_2d)) abort("error in exact_metal_rot2y rods_2d\n"); if (!exact_metal_rot4z(one)) abort("error in exact_metal_rot4z vacuum\n"); if (!exact_metal_rot4z(rods_2d)) abort("error in exact_metal_rot4z rods_2d\n"); if (!exact_metal_rot4z_nonlinear(one)) abort("error in exact_metal_rot4z nonlinear vacuum\n"); if (!exact_metal_rot4z_nonlinear(rods_2d)) abort("error in exact_metal_rot4z nonlinear rods_2d\n"); if (!test_3D_metal_xmirror(one)) abort("error in test_3D_metal_xmirror vacuum\n"); if (!test_3D_metal_zmirror(one)) abort("error in test_3D_metal_zmirror vacuum\n"); if (!test_3D_metal_odd_zmirror(one)) abort("error in test_3D_metal_odd_zmirror vacuum\n"); if (!test_3D_metal_rot4z(one)) { all_wait(); abort("error in test_3D_metal_rot4z vacuum\n"); } if (!test_3D_metal_rot4z_mirror(one)) abort("error in test_3D_metal_rot4z_mirror vacuum\n"); if (!test_3D_metal_3mirror(one)) abort("error in test_3D_metal_3mirror\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -