Ejemplo n.º 1
0
 def __init__(self, function_space, testing_space=None):
     self.function_space = function_space
     if testing_space is None:
         testing_space = function_space
     self.testing_space = testing_space
     self.functional = CalcEMFunctional(function_space, testing_space)
     self.testing_interpolator = SurfaceInterpolant(testing_space)
     self.cell_domains = dolfin.CellFunction('uint',
                                             self.function_space.mesh())
     self.cell_domains.set_all(0)
     self.cell_region = 1
     boundary_cells = Geometry.BoundaryEdgeCells(self.function_space.mesh())
     boundary_cells.mark(self.cell_domains, self.cell_region)
     self.surface_forms = SurfaceNTFFForms(self.function_space)
     self.testing_expression_gen = TransformTestingExpression()
     self.functional.set_cell_domains(self.cell_domains, self.cell_region)
Ejemplo n.º 2
0
 def __init__(self, function_space, testing_space=None):
     self.function_space = function_space
     if testing_space is None: 
         testing_space = function_space 
     self.testing_space = testing_space 
     self.functional = CalcEMFunctional(function_space, testing_space)
     self.testing_interpolator = SurfaceInterpolant(testing_space)
     self.cell_domains = dolfin.CellFunction('uint', self.function_space.mesh())
     self.cell_domains.set_all(0)
     self.cell_region = 1
     boundary_cells = Geometry.BoundaryEdgeCells(self.function_space.mesh())
     boundary_cells.mark(self.cell_domains, self.cell_region)
     self.surface_forms = SurfaceNTFFForms(self.function_space)
     self.testing_expression_gen = TransformTestingExpression()
     self.functional.set_cell_domains(self.cell_domains, self.cell_region)
Ejemplo n.º 3
0
class NTFF(object):
    def __init__(self, function_space, testing_space=None):
        self.function_space = function_space
        if testing_space is None:
            testing_space = function_space
        self.testing_space = testing_space
        self.functional = CalcEMFunctional(function_space, testing_space)
        self.testing_interpolator = SurfaceInterpolant(testing_space)
        self.cell_domains = dolfin.CellFunction('uint',
                                                self.function_space.mesh())
        self.cell_domains.set_all(0)
        self.cell_region = 1
        boundary_cells = Geometry.BoundaryEdgeCells(self.function_space.mesh())
        boundary_cells.mark(self.cell_domains, self.cell_region)
        self.surface_forms = SurfaceNTFFForms(self.function_space)
        self.testing_expression_gen = TransformTestingExpression()
        self.functional.set_cell_domains(self.cell_domains, self.cell_region)

    def set_k0(self, k0):
        self.k0 = k0
        self.functional.set_k0(k0)

    def set_frequency(self, frequency):
        self.frequency = frequency
        self.set_k0(self.frequency * 2 * np.pi / c0)

    def set_dofs(self, dofs):
        self.functional.set_E_dofs(dofs)
        self.surface_forms.set_dofs(dofs)

    def calc_pt(self, theta_deg, phi_deg):
        # H-field contribution using variational calculation
        E_H_theta, E_H_phi = self.calc_pt_E_H(theta_deg, phi_deg)
        theta = np.deg2rad(theta_deg)
        phi = np.deg2rad(phi_deg)
        self.surface_forms.set_parms(theta, phi, self.k0)
        L_theta, L_phi = self.surface_forms.assemble_L()
        #------------------------------
        # Calculate the far fields normalised to radius 1.
        r_fac = 1j * self.k0 * np.exp(-1j * self.k0) / (4 * np.pi)
        E_theta = r_fac * (-L_phi + E_H_theta)
        E_phi = r_fac * (L_theta + E_H_phi)
        return (E_theta, E_phi)

    def calc_pt_E_H(self, theta_deg, phi_deg):
        theta = np.deg2rad(theta_deg)
        phi = np.deg2rad(phi_deg)
        rhat = np.array([
            np.sin(theta) * np.cos(phi),
            np.sin(theta) * np.sin(phi),
            np.cos(theta)
        ],
                        dtype=np.float64)
        theta_hat = np.array([
            np.cos(theta) * np.cos(phi),
            np.cos(theta) * np.sin(phi), -np.sin(theta)
        ],
                             dtype=np.float64)
        phi_hat = np.array([-np.sin(phi), np.cos(phi), 0.], dtype=np.float64)
        E_H_theta = self.calc_ff_func(rhat, theta_hat)
        E_H_phi = self.calc_ff_func(rhat, phi_hat)
        return E_H_theta, E_H_phi

    def calc_ff_func(self, rhat, ahat):
        self.testing_expression_gen.set_parms(rhat, ahat, self.k0)
        fit_expr_r, fit_expr_i = self.testing_expression_gen.get_expression()
        self.testing_interpolator.set_interpolant_expression(
            fit_expr_r, fit_expr_i)
        g_dofs = self.testing_interpolator.calculate_interpolation()
        self.functional.set_g_dofs(g_dofs)
        return self.functional.calc_functional()
Ejemplo n.º 4
0
class NTFF(object):
    def __init__(self, function_space, testing_space=None):
        self.function_space = function_space
        if testing_space is None: 
            testing_space = function_space 
        self.testing_space = testing_space 
        self.functional = CalcEMFunctional(function_space, testing_space)
        self.testing_interpolator = SurfaceInterpolant(testing_space)
        self.cell_domains = dolfin.CellFunction('uint', self.function_space.mesh())
        self.cell_domains.set_all(0)
        self.cell_region = 1
        boundary_cells = Geometry.BoundaryEdgeCells(self.function_space.mesh())
        boundary_cells.mark(self.cell_domains, self.cell_region)
        self.surface_forms = SurfaceNTFFForms(self.function_space)
        self.testing_expression_gen = TransformTestingExpression()
        self.functional.set_cell_domains(self.cell_domains, self.cell_region)

    def set_k0(self, k0):
        self.k0 = k0
        self.functional.set_k0(k0)

    def set_frequency(self, frequency):
        self.frequency = frequency
        self.set_k0(self.frequency*2*np.pi/c0)

    def set_dofs(self, dofs):
        self.functional.set_E_dofs(dofs)
        self.surface_forms.set_dofs(dofs)

    def calc_pt(self, theta_deg, phi_deg):
        # H-field contribution using variational calculation
        E_H_theta, E_H_phi = self.calc_pt_E_H(theta_deg, phi_deg)
        theta = np.deg2rad(theta_deg)
        phi = np.deg2rad(phi_deg)
        self.surface_forms.set_parms(theta, phi, self.k0)
        L_theta, L_phi = self.surface_forms.assemble_L()
        #------------------------------
        # Calculate the far fields normalised to radius 1.
        r_fac = 1j*self.k0*np.exp(-1j*self.k0)/(4*np.pi)
        E_theta = r_fac*(-L_phi + E_H_theta)
        E_phi = r_fac*(L_theta + E_H_phi)
        return (E_theta, E_phi)
    
    def calc_pt_E_H(self, theta_deg, phi_deg):
        theta = np.deg2rad(theta_deg)
        phi = np.deg2rad(phi_deg)
        rhat = np.array([np.sin(theta)*np.cos(phi),
                        np.sin(theta)*np.sin(phi),
                        np.cos(theta)], dtype=np.float64)
        theta_hat = np.array([np.cos(theta)*np.cos(phi),
                             np.cos(theta)*np.sin(phi),
                             -np.sin(theta)], dtype=np.float64)
        phi_hat = np.array([-np.sin(phi), np.cos(phi), 0.], dtype=np.float64)
        E_H_theta = self.calc_ff_func(rhat, theta_hat)
        E_H_phi = self.calc_ff_func(rhat, phi_hat)
        return E_H_theta, E_H_phi
    
    def calc_ff_func(self, rhat, ahat):
        self.testing_expression_gen.set_parms(rhat, ahat, self.k0)
        fit_expr_r, fit_expr_i = self.testing_expression_gen.get_expression()
        self.testing_interpolator.set_interpolant_expression(fit_expr_r, fit_expr_i)
        g_dofs = self.testing_interpolator.calculate_interpolation()
        self.functional.set_g_dofs(g_dofs)
        return self.functional.calc_functional()