def test_horseshoe_modes(plot=False, skip_asserts=False, write_reference=False): "Modes of horseshoe" sim = openmodes.Simulation(name='horseshoe_modes', basis_class=openmodes.basis.LoopStarBasis) shoe = sim.load_mesh(osp.join(mesh_dir, 'horseshoe_rect.msh')) sim.place_part(shoe) s_start = 2j * np.pi * 10e9 estimates = sim.estimate_poles(s_start, modes=3, cauchy_integral=False) modes = sim.refine_poles(estimates) mode_s = modes.s mode_j = modes.vr print("Singularities found at", mode_s) if write_reference: write_1d_complex(osp.join(reference_dir, 'eigenvector_0.txt'), mode_j["J", :, 'modes', 0]) write_1d_complex(osp.join(reference_dir, 'eigenvector_1.txt'), mode_j["J", :, 'modes', 1]) write_1d_complex(osp.join(reference_dir, 'eigenvector_2.txt'), mode_j["J", :, 'modes', 2]) j_0_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_0.txt')) j_1_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_1.txt')) j_2_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_2.txt')) if not skip_asserts: assert_allclose(mode_s[0], [ -2.585729e+09 + 3.156438e+10j, -1.887518e+10 + 4.500579e+10j, -1.991163e+10 + 6.846221e+10j ], rtol=1e-3) assert_allclose_sign(mode_j["J", :, 'modes', 0], j_0_ref, rtol=1e-2) assert_allclose_sign(mode_j["J", :, 'modes', 1], j_1_ref, rtol=1e-2) assert_allclose_sign(mode_j["J", :, 'modes', 2], j_2_ref, rtol=1e-2) if plot: sim.plot_3d(solution=mode_j["J", :, 'modes', 0], output_format='mayavi', compress_scalars=3) sim.plot_3d(solution=mode_j["J", :, 'modes', 1], output_format='mayavi', compress_scalars=3) sim.plot_3d(solution=mode_j["J", :, 'modes', 2], output_format='mayavi', compress_scalars=3)
def test_horseshoe_modes(plot=False, skip_asserts=False, write_reference=False): "Modes of horseshoe" sim = openmodes.Simulation(name='horseshoe_modes', basis_class=openmodes.basis.LoopStarBasis) shoe = sim.load_mesh(osp.join(mesh_dir, 'horseshoe_rect.msh')) sim.place_part(shoe) s_start = 2j*np.pi*10e9 estimates = sim.estimate_poles(s_start, modes=3, cauchy_integral=False) modes = sim.refine_poles(estimates) mode_s = modes.s mode_j = modes.vr print("Singularities found at", mode_s) if write_reference: write_1d_complex(osp.join(reference_dir, 'eigenvector_0.txt'), mode_j["J", :, 'modes', 0]) write_1d_complex(osp.join(reference_dir, 'eigenvector_1.txt'), mode_j["J", :, 'modes', 1]) write_1d_complex(osp.join(reference_dir, 'eigenvector_2.txt'), mode_j["J", :, 'modes', 2]) j_0_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_0.txt')) j_1_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_1.txt')) j_2_ref = read_1d_complex(osp.join(reference_dir, 'eigenvector_2.txt')) if not skip_asserts: assert_allclose(mode_s[0], [-2.585729e+09 + 3.156438e+10j, -1.887518e+10 + 4.500579e+10j, -1.991163e+10 + 6.846221e+10j], rtol=1e-3) assert_allclose_sign(mode_j["J", :, 'modes', 0], j_0_ref, rtol=1e-2) assert_allclose_sign(mode_j["J", :, 'modes', 1], j_1_ref, rtol=1e-2) assert_allclose_sign(mode_j["J", :, 'modes', 2], j_2_ref, rtol=1e-2) if plot: sim.plot_3d(solution=mode_j["J", :, 'modes', 0], output_format='mayavi', compress_scalars=3) sim.plot_3d(solution=mode_j["J", :, 'modes', 1], output_format='mayavi', compress_scalars=3) sim.plot_3d(solution=mode_j["J", :, 'modes', 2], output_format='mayavi', compress_scalars=3)
def test_extinction(plot_extinction=False, skip_asserts=False, write_reference=False): "Test extinction of a horseshoe" sim = openmodes.Simulation(name='horseshoe_extinction', basis_class=openmodes.basis.LoopStarBasis) shoe = sim.load_mesh(osp.join(mesh_dir, 'horseshoe_rect.msh')) sim.place_part(shoe) num_freqs = 101 freqs = np.linspace(1e8, 20e9, num_freqs) extinction = np.empty(num_freqs, np.complex128) e_inc = np.array([1, 0, 0], dtype=np.complex128) k_hat = np.array([0, 0, 1], dtype=np.complex128) pw = PlaneWaveSource(e_inc, k_hat) for freq_count, s in sim.iter_freqs(freqs): Z = sim.impedance(s) V = sim.source_vector(pw, s) extinction[freq_count] = np.vdot(V, Z.solve(V)) if write_reference: # generate the reference extinction solution write_1d_complex(osp.join(reference_dir, 'extinction.txt'), extinction) extinction_ref = read_1d_complex(osp.join(reference_dir, 'extinction.txt')) if not skip_asserts: assert_allclose(extinction, extinction_ref, rtol=1e-3) if plot_extinction: # to plot the generated and reference solutions plt.figure() plt.plot(freqs * 1e-9, extinction.real) plt.plot(freqs * 1e-9, extinction_ref.real, '--') plt.plot(freqs * 1e-9, extinction.imag) plt.plot(freqs * 1e-9, extinction_ref.imag, '--') plt.xlabel('f (GHz)') plt.show()
def test_extinction(plot_extinction=False, skip_asserts=False, write_reference=False): "Test extinction of a horseshoe" sim = openmodes.Simulation(name='horseshoe_extinction', basis_class=openmodes.basis.LoopStarBasis) shoe = sim.load_mesh(osp.join(mesh_dir, 'horseshoe_rect.msh')) sim.place_part(shoe) num_freqs = 101 freqs = np.linspace(1e8, 20e9, num_freqs) extinction = np.empty(num_freqs, np.complex128) e_inc = np.array([1, 0, 0], dtype=np.complex128) k_hat = np.array([0, 0, 1], dtype=np.complex128) pw = PlaneWaveSource(e_inc, k_hat) for freq_count, s in sim.iter_freqs(freqs): Z = sim.impedance(s) V = sim.source_vector(pw, s) extinction[freq_count] = np.vdot(V, Z.solve(V)) if write_reference: # generate the reference extinction solution write_1d_complex(osp.join(reference_dir, 'extinction.txt'), extinction) extinction_ref = read_1d_complex(osp.join(reference_dir, 'extinction.txt')) if not skip_asserts: assert_allclose(extinction, extinction_ref, rtol=1e-3) if plot_extinction: # to plot the generated and reference solutions plt.figure() plt.plot(freqs*1e-9, extinction.real) plt.plot(freqs*1e-9, extinction_ref.real, '--') plt.plot(freqs*1e-9, extinction.imag) plt.plot(freqs*1e-9, extinction_ref.imag, '--') plt.xlabel('f (GHz)') plt.show()
def test_extinction_all(plot_extinction=False, skip_asserts=False, write_reference=False): "Extinction of a PEC sphere with EFIE, MFIE, CFIE" tests = (("EFIE", EfieOperator, 'extinction_efie.npy'), ("MFIE", MfieOperator, 'extinction_mfie.npy'), ("CFIE", CfieOperator, 'extinction_cfie.npy')) for operator_name, operator_class, reference_filename in tests: sim = openmodes.Simulation(name='horseshoe_extinction', basis_class=DivRwgBasis, operator_class=operator_class) radius = 5e-3 sphere = sim.load_mesh(osp.join(mesh_dir, 'sphere.msh')) sim.place_part(sphere) num_freqs = 101 freqs = np.linspace(1e8, 20e9, num_freqs) extinction = np.empty(num_freqs, np.complex128) e_inc = np.array([1, 0, 0], dtype=np.complex128) k_hat = np.array([0, 0, 1], dtype=np.complex128) pw = PlaneWaveSource(e_inc, k_hat) for freq_count, s in sim.iter_freqs(freqs): Z = sim.impedance(s) V = sim.source_vector(pw, s) V_E = sim.source_vector(pw, s, extinction_field=True) extinction[freq_count] = np.vdot(V_E, Z.solve(V)) extinction_filename = osp.join(reference_dir, reference_filename) if write_reference: # generate the reference extinction solution write_1d_complex(extinction_filename, extinction) extinction_ref = read_1d_complex(extinction_filename) if not skip_asserts: assert_allclose(extinction, extinction_ref, rtol=1e-3) if plot_extinction: # to plot the generated and reference solutions # calculate analytically extinction_analytical = sphere_extinction_analytical(freqs, radius) plt.figure(figsize=(8, 6)) plt.plot(freqs*1e-9, extinction.real) plt.plot(freqs*1e-9, extinction_ref.real, '--') plt.plot(freqs*1e-9, extinction_analytical, 'x') plt.plot(freqs*1e-9, extinction.imag) plt.plot(freqs*1e-9, extinction_ref.imag, '--') plt.xlabel('f (GHz)') plt.legend(('Calculated (Re)', 'Reference (Re)', 'Analytical (Re)', 'Calculated (Im)', 'Reference (Im)'), loc='right') plt.title('Extinction with operator %s' % operator_name) plt.ylim(ymin=0) plt.show()