Beispiel #1
0
 def setUp(self):
     self.source_coord = N.array([0, 0, 0.])
     self.source_value = N.array([2, -1, 3.])
     self.frequency = 1e8
     testmesh = Meshes.InscribedTet()
     self.mesh = testmesh.get_dolfin_mesh()
     self.material_mesh_func = dolfin.MeshFunction('uint', self.mesh, 3)
     self.material_mesh_func.set_all(0)
     self.materials = {
         0: dict(eps_r=1, mu_r=1),
     }
     self.abc = ABCBoundaryCondition()
     self.abc.set_region_number(1)
     self.bcs = BoundaryConditions()
     self.bcs.add_boundary_condition(self.abc)
     self.current_sources = current_source.CurrentSources()
     self.dipole_source = point_source.PointCurrentSource()
     self.dipole_source.set_position(self.source_coord)
     self.dipole_source.set_value(self.source_value)
     self.current_sources.add_source(self.dipole_source)
     self.DUT = EMDrivenProblem.DrivenProblemABC()
     self.DUT.set_mesh(self.mesh)
     self.DUT.set_basis_order(1)
     self.DUT.set_material_regions(self.materials)
     self.DUT.set_region_meshfunction(self.material_mesh_func)
     self.DUT.set_boundary_conditions(self.bcs)
     self.DUT.set_sources(self.current_sources)
Beispiel #2
0
 def __init__(self):
     self.element_type = "Nedelec 1st kind H(curl)"
     self.mesh = None
     self.order = None
     self.function_space = None
     self.material_regions = None
     self.region_meshfunction = None
     self.boundary_conditions = BoundaryConditions()
Beispiel #3
0
    def test_ff_error(self):
        sucemfem.Utilities.Optimization.set_dolfin_optimisation(True)
        ### Postprocessing requests
        theta_deg = N.linspace(10, 170, 161)
        no_ff_pts = len(theta_deg)
        phi_deg = N.zeros(no_ff_pts)
        ### Problem parameters
        freq = 1.0e+9  # Frequency
        lam = c0 / freq
        l = lam / 4  # Dipole length
        I = 1.0  # Dipole current
        source_direction_z = N.array([0, 0, 1.])  # Source orientation
        source_direction_x = N.array([1., 0, 0])  # Source orientation
        source_direction_y = N.array([0, 1, 0.])  # Source orientation
        source_centre = N.array([0, 0, 0.])  # Position of the source
        source_endpoints_z = N.array([
            -source_direction_z * l / 2, source_direction_z * l / 2
        ]) + source_centre
        source_endpoints_x = N.array([
            -source_direction_x * l / 2, source_direction_x * l / 2
        ]) + source_centre
        source_endpoints_y = N.array([
            -source_direction_y * l / 2, source_direction_y * l / 2
        ]) + source_centre

        ### Discretisation settings
        order = 2
        domain_size = N.array([lam] * 3) * 1
        max_edge_len = lam / 6
        mesh = get_centred_cube(domain_size, max_edge_len)

        ### Implementation
        #
        ## Set up materials function with all free-space
        material_mesh_func = dolfin.MeshFunction('uint', mesh, 3)
        material_mesh_func.set_all(0)
        materials = {
            0: dict(eps_r=1, mu_r=1),
        }
        ## Set up 1st-order analytical ABC
        abc = ABCBoundaryCondition()
        abc.set_region_number(1)
        bcs = BoundaryConditions()
        bcs.add_boundary_condition(abc)
        ## Set up high level problem class
        dp = DrivenProblemABC()
        dp.set_mesh(mesh)
        dp.set_basis_order(order)
        dp.set_material_regions(materials)
        dp.set_region_meshfunction(material_mesh_func)
        dp.set_boundary_conditions(bcs)
        ## Set up current fillament source
        current_sources = sucemfem.Sources.current_source.CurrentSources()
        fillament_source = FillamentCurrentSource()
        fillament_source.no_integration_points = 1000
        fillament_source.set_source_endpoints(source_endpoints_z)
        fillament_source.set_value(I)
        current_sources.add_source(fillament_source)
        ## Set source in problem container
        dp.set_sources(current_sources)
        dp.init_problem()
        dp.set_frequency(freq)

        ## Get sytem LHS matrix and RHS Vector
        A = dp.get_LHS_matrix()
        b_z = dp.get_RHS()
        fillament_source.set_source_endpoints(source_endpoints_x)
        b_x = dp.get_RHS()
        fillament_source.set_source_endpoints(source_endpoints_y)
        b_y = dp.get_RHS()

        #import pdb ; pdb.set_trace()
        A
        print 'solve using UMFPack'
        umf_solver = sucemfem.Utilities.LinalgSolvers.UMFPACKSolver(A)
        x_z = umf_solver.solve(b_z)
        x_x = umf_solver.solve(b_x)
        x_y = umf_solver.solve(b_y)

        ## Post-process solution to obtain far-field
        print 'calculating far field'
        surf_ntff = surface_ntff.NTFF(dp.function_space)
        surf_ntff.set_dofs(x_z)
        surf_ntff.set_frequency(freq)
        surf_E_ff_z = N.array([
            surf_ntff.calc_pt(th_deg, ph_deg)
            for th_deg, ph_deg in zip(theta_deg, phi_deg)
        ])
        surf_E_theta_z = surf_E_ff_z[:, 0]
        surf_E_phi_z = surf_E_ff_z[:, 1]
        surf_ntff.set_dofs(x_x)
        surf_E_ff_x = N.array([
            surf_ntff.calc_pt(th_deg + 90, ph_deg)
            for th_deg, ph_deg in zip(theta_deg, phi_deg)
        ])
        surf_E_theta_x = surf_E_ff_x[:, 0]
        surf_E_phi_x = surf_E_ff_x[:, 1]
        surf_ntff.set_dofs(x_y)
        surf_E_ff_y = N.array([
            surf_ntff.calc_pt(th_deg + 90, ph_deg)
            for th_deg, ph_deg in zip(theta_deg, phi_deg)
        ])
        surf_E_theta_y = surf_E_ff_y[:, 0]
        surf_E_phi_y = surf_E_ff_y[:, 1]

        ## Calculate some errors relative to the analytical solution
        an_E_theta = [
            current_fillament_farfield.eval_E_theta(freq, l, I, th)
            for th in N.deg2rad(theta_deg)
        ]
        err_z = normalised_RMS(surf_E_theta_z, an_E_theta, surf_E_phi_z)
        err_theta_z = normalised_RMS(surf_E_theta_z, an_E_theta)
        err_abs_theta_z = normalised_RMS(N.abs(surf_E_theta_z),
                                         N.abs(an_E_theta))
        err_x = normalised_RMS(surf_E_theta_x, an_E_theta, surf_E_phi_x)
        err_theta_x = normalised_RMS(surf_E_theta_x, an_E_theta)
        err_abs_theta_x = normalised_RMS(N.abs(surf_E_theta_x),
                                         N.abs(an_E_theta))
        err_y = normalised_RMS(surf_E_theta_y, an_E_theta, surf_E_phi_y)
        err_theta_y = normalised_RMS(surf_E_theta_y, an_E_theta)
        err_abs_theta_y = normalised_RMS(N.abs(surf_E_theta_y),
                                         N.abs(an_E_theta))
        print 'Far-field RMS error: ', err_z, err_x, err_y
        # Expected error for lam/6 mesh, 2nd order discretisation,
        # lam/4 current fillament source is ~4.685%
        self.assertTrue(err_z < 4.7)
        self.assertTrue(err_x < 4.7)
        self.assertTrue(err_z < 4.7)
Beispiel #4
0
order = 1
domain_size = N.array([2 * lam] * 3)
max_edge_len = lam / 6
mesh = get_centred_cube(domain_size, max_edge_len, source_coord)
# Request information:
field_pts = N.array([lam, 0, 0]) * (N.arange(88) / 100 + 1 / 10)[:, N.newaxis]

## Implementation
material_mesh_func = dolfin.MeshFunction('uint', mesh, 3)
material_mesh_func.set_all(0)
materials = {
    0: dict(eps_r=1, mu_r=1),
}
abc = ABCBoundaryCondition()
abc.set_region_number(1)
bcs = BoundaryConditions()
bcs.add_boundary_condition(abc)
dp = DrivenProblemABC()
dp.set_mesh(mesh)
dp.set_basis_order(order)
dp.set_material_regions(materials)
dp.set_region_meshfunction(material_mesh_func)
dp.set_boundary_conditions(bcs)
current_sources = sucemfem.Sources.current_source.CurrentSources()
dipole_source = point_source.PointCurrentSource()
dipole_source.set_position(source_coord)
dipole_source.set_value(source_value)
current_sources.add_source(dipole_source)
dp.set_sources(current_sources)
dp.init_problem()
dp.set_frequency(freq)