📄 symmetry.cpp
字号:
double a = 8.0; double ttot = 3.0; const volume v = vol3d(1.1, 0.6, 1.0, a); const symmetry S = -mirror(Z,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing odd Z mirror symmetry in 3D...\n"); fields f1(&s1); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.55,0.51,0.5)); fields f(&s); f.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.55,0.51,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.5 , 0.01 , 0.75))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.21 , 0.15))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.501, 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33 , 0.51))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 , 0.05))) 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 test_3D_metal_rot4z(double eps(const vec &)) { double a = 8.0; double ttot = 3.0; const volume v = vol3d(1.0, 1.0, 1.0, a); const symmetry S = rotate4(Z,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing Z fourfold rotational symmetry in 3D...\n"); fields f1(&s1); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5,0.52)); f1.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5,0.43)); fields f(&s); f.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5,0.52)); f.add_point_source(Hz, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.5,0.43)); 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.5 , 0.01 , 0.75))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.21 , 0.15))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.501, 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33 , 0.51))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 , 0.05))) 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 test_3D_metal_rot4z_mirror(double eps(const vec &)) { double a = 8.0; double ttot = 3.0; const volume v = vol3d(1.0, 1.0, 1.0, a); const symmetry S = rotate4(Z,v) + mirror(Z,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing Z fourfold rotational symmetry in 3D with horizontal mirror...\n"); fields f1(&s1); f1.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5,0.5)); fields f(&s); f.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.5,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.5 , 0.01 , 0.75))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.21 , 0.15))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.501, 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33 , 0.51))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 , 0.05))) 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 test_3D_metal_3mirror(double eps(const vec &)) { double a = 8.0; double ttot = 3.0; const volume v = vol3d(1.0, 1.0, 1.0, a); const symmetry S = mirror(Z,v) - mirror(Y,v) - mirror(X,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing three mirror planes in 3D...\n"); fields f1(&s1); f1.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.5,0.5,0.5)); fields f(&s); f.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.5,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.5 , 0.01 , 0.75))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.21 , 0.15))) return 0; if (!compare_point(f, f1, vec(0.5 , 0.501, 0.5))) return 0; if (!compare_point(f, f1, vec(0.46 , 0.33 , 0.51))) return 0; if (!compare_point(f, f1, vec(0.2 , 0.2 , 0.05))) 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 test_metal_ymirror(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 = mirror(Y,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing Y mirror symmetry...\n"); fields f1(&s1); f1.add_point_source(Ex, 0.7, 2.5, 0.0, 4.0, vec(0.85 ,0.5)); f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.401,0.5)); fields f(&s); f.add_point_source(Ex, 0.7, 2.5, 0.0, 4.0, vec(0.85 ,0.5)); f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.401,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 test_yperiodic_ymirror(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 = mirror(Y,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); s.set_output_directory(mydirname); s1.set_output_directory(mydirname); master_printf("Testing Y periodic with mirror symmetry...\n"); fields f1(&s1); f1.use_bloch(vec(0.1*pi/2,0.0)); //f1.add_point_source(Ex, 0.7, 2.5, 0.0, 4.0, vec(0.85 ,0.5)); f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.401,0.5)); fields f(&s); f.use_bloch(vec(0.1*pi/2,0.0)); //f.add_point_source(Ex, 0.7, 2.5, 0.0, 4.0, vec(0.85 ,0.5)); f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.401,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.951 , 0.5))) return 0; 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 test_metal_rot2y(double eps(const vec &)) { double a = 16.0; double ttot = 5.0; const volume v = voltwo(1.0, 1.0, a); the_center = v.center(); const symmetry S = rotate2(Y,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing Y twofold rotational symmetry...\n"); fields f1(&s1); f1.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.25, 0.875), 1.0); f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.25,0.375), 1.0); f1.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.75, 0.875),-1.0); f1.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.75,0.375),-1.0); fields f(&s); f.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.25,0.875 ), 1.0); f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.25,0.375), 1.0); f.add_point_source(Hz, 0.7, 2.5, 0.0, 4.0, vec(0.75,0.875 ),-1.0); f.add_point_source(Ez, 0.8, 0.6, 0.0, 4.0, vec(0.75,0.375),-1.0); 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_rot2y(double eps(const vec &)) { double a = 16.0; double ttot = 5.0; const volume v = voltwo(1.0, 1.5, a); the_center = v.center(); const symmetry S = rotate2(Y,v); structure s(v, eps, no_pml(), S); structure s1(v, eps); master_printf("Testing exact Y twofold rotational symmetry...\n"); fields f1(&s1); f1.add_point_source(Ey, 0.7, 2.5, 0.0, 4.0, vec(0.5, 0.875)); f1.add_point_source(Hy, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.375)); fields f(&s); f.add_point_source(Ey, 0.7, 2.5, 0.0, 4.0, vec(0.5, 0.875)); f.add_point_source(Hy, 0.8, 0.6, 0.0, 4.0, vec(0.5,0.375)); 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 pml_twomirrors(double eps(const vec &)) { double a = 16.0; double ttot = 10.0; const volume v = voltwo(2.0, 2.0, a); the_center = v.center(); const symmetry S = mirror(X,v) + mirror(Y,v); structure s_mm(v, eps, pml(0.5), S); structure s1(v, eps, pml(0.5), identity()); master_printf("Testing two mirrors with PML...\n"); fields f_mm(&s_mm); fields f1(&s1); f_mm.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.0,1.0),-1.5); f_mm.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.75,0.75)); f_mm.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.75,1.25)); f_mm.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.25,0.75)); f_mm.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.25,1.25)); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.0,1.0),-1.5); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.75,0.75)); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(0.75,1.25)); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.25,0.75)); f1.add_point_source(Ez, 0.7, 2.5, 0.0, 4.0, vec(1.25,1.25)); check_unequal_layout(f_mm, f1); double total_energy_check_time = 3.0; while (f_mm.time() < ttot) { f_mm.step(); f1.step(); if (!compare_point(f1, f_mm, vec(0.01 , 0.5))) return 0; if (!compare_point(f1, f_mm, vec(0.21 , 0.5))) return 0; if (!compare_point(f1, f_mm, vec(0.46 , 0.33))) return 0; if (!compare_point(f1, f_mm, vec(0.2 , 0.2 ))) return 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -