Exemplo n.º 1
0
 def set_dofs(self, dofs):
     self.dofs = dofs
     self.x_r = as_dolfin_vector(self.dofs.real)
     self.x_i = as_dolfin_vector(self.dofs.imag)
     self.E_r = dolfin.Function(self.function_space, self.x_r)
     self.E_i = dolfin.Function(self.function_space, self.x_i)
     self.real_voltage = VoltageAlongLine(self.E_r)
     self.imag_voltage = VoltageAlongLine(self.E_i)
Exemplo n.º 2
0
 def set_dofs(self, dofs):
     self.dofs = dofs
     self.x_r = as_dolfin_vector(self.dofs.real)
     self.x_i = as_dolfin_vector(self.dofs.imag)
     self.E_r = dolfin.Function(self.function_space, self.x_r)
     self.E_i = dolfin.Function(self.function_space, self.x_i)
     self.real_voltage = VoltageAlongLine(self.E_r)
     self.imag_voltage = VoltageAlongLine(self.E_i)
Exemplo n.º 3
0
    def set_dofs(self, dofs):
        x_r = np.real(dofs).copy()
        x_i = np.imag(dofs).copy()
        self.E_r.vector()[:] = x_r
        self.E_i.vector()[:] = x_i
        self.dofs = dofs

        boundary = dolfin.DomainBoundary()
        E_r_dirich = dolfin.DirichletBC(self.function_space, self.E_r,
                                        boundary)
        E_i_dirich = dolfin.DirichletBC(self.function_space, self.E_i,
                                        boundary)
        x_r_dirich = as_dolfin_vector(np.zeros(len(x_r)))
        x_i_dirich = as_dolfin_vector(np.zeros(len(x_r)))
        E_r_dirich.apply(x_r_dirich)
        E_i_dirich.apply(x_i_dirich)
        self.dirich_dofs = x_r_dirich.array() + 1j * x_i_dirich.array()
        self.functional.set_E_dofs(dofs)
Exemplo n.º 4
0
 def set_dofs(self, dofs):
     x_r = np.real(dofs).copy()
     x_i = np.imag(dofs).copy()
     self.E_r.vector()[:] = x_r
     self.E_i.vector()[:] = x_i
     self.dofs = dofs
     
     boundary = dolfin.DomainBoundary()
     E_r_dirich = dolfin.DirichletBC(
         self.function_space, self.E_r, boundary)
     E_i_dirich = dolfin.DirichletBC(
         self.function_space, self.E_i, boundary)
     x_r_dirich = as_dolfin_vector(np.zeros(len(x_r)))
     x_i_dirich = as_dolfin_vector(np.zeros(len(x_r)))
     E_r_dirich.apply(x_r_dirich)
     E_i_dirich.apply(x_i_dirich)
     self.dirich_dofs = x_r_dirich.array() + 1j*x_i_dirich.array()
     self.functional.set_E_dofs(dofs)
Exemplo n.º 5
0
def calcs(fname):
    data = pickle.load(open(fname+'.pickle'))
    mesh = dolfin.Mesh(data['meshfile'])
    elen = np.array([e.length() for e in dolfin.edges(mesh)])
    ave_elen = np.average(elen)
    material_meshfn = dolfin.MeshFunction('uint', mesh, data['materialsfile'])
    V = dolfin.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", data['order'])
    x = data['x']
    x_r = as_dolfin_vector(x.real)
    x_i = as_dolfin_vector(x.imag)
    E_r = dolfin.Function(V, x_r)
    E_i = dolfin.Function(V, x_i)
    k0 = 2*np.pi*data['freq']/c0

    n = V.cell().n

    ReS = (1/k0/Z0)*dolfin.dot(n, (dolfin.cross(E_r, -dolfin.curl(E_i)) +
                                   dolfin.cross(E_i, dolfin.curl(E_r))))*dolfin.ds
    energy_flux = dolfin.assemble(ReS)
    surface_flux = SurfaceFlux(V)
    surface_flux.set_dofs(x)
    surface_flux.set_k0(k0)
    energy_flux2 = surface_flux.calc_flux()
    assert(np.allclose(energy_flux, energy_flux2, rtol=1e-8, atol=1e-8))    

    def boundary(x, on_boundary):
        return on_boundary
    E_r_dirich = dolfin.DirichletBC(V, E_r, boundary)
    x_r_dirich = as_dolfin_vector(np.zeros(len(x)))
    E_r_dirich.apply(x_r_dirich)
    E_i_dirich = dolfin.DirichletBC(V, E_i, boundary)
    x_i_dirich = as_dolfin_vector(np.zeros(len(x)))
    E_i_dirich.apply(x_i_dirich)
    x_dirich = x_r_dirich.array() + 1j*x_i_dirich.array()

    emfunc = CalcEMFunctional(V)
    emfunc.set_k0(k0)
    cell_domains = dolfin.CellFunction('uint', mesh)
    cell_domains.set_all(0)
    cell_region = 1
    boundary_cells = Geometry.BoundaryEdgeCells(mesh)
    boundary_cells.mark(cell_domains, cell_region)
    emfunc.set_cell_domains(cell_domains, cell_region)

    emfunc.set_E_dofs(x)
    emfunc.set_g_dofs(1j*x_dirich.conjugate()/k0/Z0)
    var_energy_flux = emfunc.calc_functional().conjugate()
    var_surf_flux = VariationalSurfaceFlux(V)
    var_surf_flux.set_dofs(x)
    var_surf_flux.set_k0(k0)
    var_energy_flux2 = var_surf_flux.calc_flux()
    assert(np.allclose(var_energy_flux, var_energy_flux2, rtol=1e-8, atol=1e-8))

    complex_voltage = ComplexVoltageAlongLine(V)
    complex_voltage.set_dofs(x)

    volts = complex_voltage.calculate_voltage(*data['source_endpoints'])

    result = dict(h=ave_elen, order=order, volts=volts,
                  sflux=energy_flux, vflux=var_energy_flux)


    print 'source power: ', volts*data['I']
    print 'energy flux:      ', energy_flux
    print 'var energy flux: ', var_energy_flux

    # print '|'.join(str(s) for s in ('', volts*data['I'], energy_flux,
    #                                 var_energy_flux, ''))

    return result