Пример #1
0
    def test_TE_modes(self):
        mesh = dolfin.UnitSquare ( 5, 5 )
        a = 1.0
        b = 1.0
        mesh.coordinates()[:,0] = a*mesh.coordinates()[:,0]
        mesh.coordinates()[:,1] = b*mesh.coordinates()[:,1]
        
        pec_walls = PECWallsBoundaryCondition ()
        pec_walls.init_with_mesh ( mesh )
        
        # Use 3rd order basis functions 
        order = 3
        # Set up the eigen problem
        ep = EigenProblem()
        ep.set_mesh(mesh)
        ep.set_basis_order(order)
        ep.set_boundary_conditions(pec_walls)
        ep.init_problem()
        
        # Set up eigen problem solver where sigma is the shift to use
        # in the shift-invert process
        sigma = 1.5
        es = DefaultEigenSolver()
        es.set_eigenproblem(ep)
        es.set_sigma(sigma)

        # Solve the eigenproblem
        eigs_w, eigs_v = es.solve_problem(10)

        # Output the results
        res = np.array(sorted(eigs_w)[0:])
        res = np.sqrt(res)/np.pi
        
        steps = 5
        abd = (a, b)
        ids = []
        values = []
        for m in range(steps):
            for n in range(steps):
                l = 0
                i = (m,n)
                if i.count(0) < 2:
                    ids.append((m,n,l))
                    values.append(k_mnl ( abd, m, n, l, True ))

        r = 0;
        errors = np.zeros_like(res)
        for i in np.argsort(values).tolist():
            if r < len(res):
                errors[r] = np.linalg.norm( res[r] - values[i])/np.linalg.norm( values[i] )
                
                r += 1
            else:
                break;

        np.testing.assert_array_almost_equal( errors, np.zeros_like(res), 4 )
Пример #2
0
from sucemfem.BoundaryConditions import PECWallsBoundaryCondition
from sucemfem.Consts import c0
del sys.path[0]

script_path = os.path.dirname(__file__)
# Load the mesh and the material region markers
mesh = dol.UnitCube(4, 4, 4)
a = 1.0
b = 1.0
d = 1.0
mesh.coordinates()[:, 0] = a * mesh.coordinates()[:, 0]
mesh.coordinates()[:, 1] = b * mesh.coordinates()[:, 1]
mesh.coordinates()[:, 2] = d * mesh.coordinates()[:, 2]

# init the PEC walls boundary condition
pec_walls = PECWallsBoundaryCondition()
pec_walls.init_with_mesh(mesh)

# Use 3rd order basis functions
order = 3
# Set up the eigen problem
ep = EigenProblem()
ep.set_mesh(mesh)
ep.set_basis_order(order)
ep.set_boundary_conditions(pec_walls)
ep.init_problem()

# Set up eigen problem solver where sigma is the shift to use in the shift-invert process
sigma = 1.1
es = DefaultEigenSolver()
es.set_eigenproblem(ep)
Пример #3
0
from sucemfem.BoundaryConditions import PECWallsBoundaryCondition
from sucemfem.Consts import c0
del sys.path[0]

script_path = os.path.dirname(__file__)
# Load the mesh and the material region markers
mesh = dol.UnitCube ( 4, 4, 4 )
a = 1.0
b = 1.0
d = 1.0
mesh.coordinates()[:,0] = a*mesh.coordinates()[:,0]
mesh.coordinates()[:,1] = b*mesh.coordinates()[:,1]
mesh.coordinates()[:,2] = d*mesh.coordinates()[:,2]

# init the PEC walls boundary condition
pec_walls = PECWallsBoundaryCondition ()
pec_walls.init_with_mesh ( mesh ) 

# Use 3rd order basis functions 
order = 3
# Set up the eigen problem
ep = EigenProblem()
ep.set_mesh(mesh)
ep.set_basis_order(order)
ep.set_boundary_conditions ( pec_walls )
ep.init_problem()

# Set up eigen problem solver where sigma is the shift to use in the shift-invert process
sigma = 1.1
es = DefaultEigenSolver()
es.set_eigenproblem(ep)
Пример #4
0
solver_type = solver_types[1]
##
## Calculations
mesh = dolfin.Mesh(meshname + '.xml')
materials_mesh_function = dolfin.MeshFunction(
    'uint', mesh, meshname + '_physical_region.xml')
pec_mesh_function = dolfin.MeshFunction('uint', mesh,
                                        meshname + '_facet_region.xml')
mesh.init(3, 1)
print '%d elements with %d edges' % (mesh.num_cells(), mesh.num_edges())

abc = ABCBoundaryCondition()
abc.set_region_number(1)
bcs = BoundaryConditions()
bcs.add_boundary_condition(abc)
pec_walls = PECWallsBoundaryCondition()
pec_walls.init_with_meshfunction(pec_mesh_function, PEC_label)
bcs.add_boundary_condition(pec_walls)

## 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(materials_mesh_function)
dp.set_boundary_conditions(bcs)
## Set up current fillament source
current_sources = sucemfem.Sources.current_source.CurrentSources()
fillament_source = FillamentCurrentSource()
fillament_source.set_source_endpoints(feed_pts)
fillament_source.set_value(I)
Пример #5
0
order = 1                               # Discretisation order
solver_types = ['umfpack', 'bicgstab', 'gmres']
solver_type = solver_types[1]
##
## Calculations
mesh = dolfin.Mesh(meshname+'.xml')
materials_mesh_function = dolfin.MeshFunction('uint', mesh, meshname + '_physical_region.xml')
pec_mesh_function = dolfin.MeshFunction('uint', mesh, meshname + '_facet_region.xml')
mesh.init(3,1)
print '%d elements with %d edges' % (mesh.num_cells(), mesh.num_edges())

abc = ABCBoundaryCondition()
abc.set_region_number(1)
bcs = BoundaryConditions()
bcs.add_boundary_condition(abc)
pec_walls = PECWallsBoundaryCondition()
pec_walls.init_with_meshfunction (pec_mesh_function, PEC_label)
bcs.add_boundary_condition(pec_walls)

## 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(materials_mesh_function)
dp.set_boundary_conditions(bcs)
## Set up current fillament source
current_sources = sucemfem.Sources.current_source.CurrentSources()
fillament_source = FillamentCurrentSource()
fillament_source.set_source_endpoints(feed_pts)
fillament_source.set_value(I)
Пример #6
0
 def test_gmsh_resonant_cavity(self):
     mesh_folder = os.path.join(get_module_path(__file__), "data/meshes")
     mesh_base_name = "rectangular_prism"
     mesh_extension = ".xml"
     mesh = dolfin.Mesh ( os.path.join (mesh_folder, mesh_base_name + mesh_extension))
     
     a = 1.0;
     b = 0.5;
     d = 0.25;
     # load the mesh function defining the boundaries
     pec_filename = os.path.join(mesh_folder, "%s_%s%s" % (
         mesh_base_name, "facet_region", mesh_extension))
     pec_mesh_function = dolfin.MeshFunction ( 'uint', mesh, pec_filename)
     
     pec_walls = PECWallsBoundaryCondition ()
     pec_walls.init_with_meshfunction ( pec_mesh_function, 1 )
     
     order = 4;
     ep = EigenProblem()
     ep.set_mesh(mesh)
     ep.set_basis_order(order)
     ep.set_boundary_conditions ( pec_walls )
     ep.init_problem()
     
     # Set up eigen problem solver where sigma is the shift to use
     # in the shift-invert process
     sigma = 1.1
     es = DefaultEigenSolver()
     es.set_eigenproblem(ep)
     es.set_sigma(sigma)
     
     # Solve the eigenproblem
     eigs_w, eigs_v = es.solve_problem(10)
     
     # Output the results
     res = np.array(sorted(eigs_w)[0:])
     res = np.sqrt(res)/np.pi
     
     steps = 5
     abd = (a, b, d)
     ids = []
     values = []
     for m in range(steps):
         for n in range(steps):
             for l in range(steps):
                 i = (m,n,l)
                 if i.count(0) < 2:
                     ids.append((m,n,l))
                     values.append(k_mnl ( abd, m, n, l, True ))
                 
                 # mode is both a TE and TM mode            
                 if i.count( 0 ) == 0:
                     ids.append((m,n,l))
                     values.append(k_mnl ( abd, m, n, l, True ))
     
     r = 0;
     errors = np.zeros_like(res)
     for i in np.argsort(values).tolist():
         if r < len(res):
             errors[r] = np.linalg.norm(
                 res[r] - values[i])/np.linalg.norm( values[i] )
             r += 1
         else:
             break;
     
     np.testing.assert_array_almost_equal( errors, np.zeros_like(res), 4 )