def __init__(self, datafile): test_data = pickle.load(datafile) self.desired_dofnos = test_data['dofnos'] self.desired_rhs_contribs = test_data['rhs_contribs'] self.discretisation_order = test_data['order'] self.mesh = get_centred_cube( test_data['domain_size'], test_data['max_edge_len']) self.discretisation_space = dolfin.FunctionSpace( self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order) self.no_integration_points = test_data['no_integration_points'] self.I = test_data['I'] self.source_endpoints = test_data['source_endpoints']
def __init__(self, datafile): test_data = pickle.load(datafile) ff_result_data = test_data['ff_result_data'] nf_input_data = test_data['nf_input_data'] self.desired_E_ff = ff_result_data['E_ff'] self.desired_E_theta = self.desired_E_ff[:,0] self.desired_E_phi = self.desired_E_ff[:,1] self.theta_coords = ff_result_data['theta_deg'] self.phi_coords = ff_result_data['phi_deg'] self.discretisation_order = nf_input_data['order'] self.mesh = get_centred_cube( nf_input_data['domain_size'], nf_input_data['max_edge_len']) self.discretisation_space = dolfin.FunctionSpace( self.mesh, "Nedelec 1st kind H(curl)", self.discretisation_order) self.discretisation_dofs = nf_input_data['x'] self.frequency = nf_input_data['freq']
def __init__(self): ### Problem parameters self.freq = 1.0e+9 # Frequency self.lam = c0/self.freq self.l = self.lam/10 # Dipole length self.I = 1.0 # Dipole current self.source_direction = np.array([0,0,1.]) # Source orientation self.source_centre = np.array([0,0,0.]) # Position of the source self.source_endpoints = np.array( [-self.source_direction*self.l/2, self.source_direction*self.l/2]) \ + self.source_centre ### Discretisation settings self.order = 2 self.domain_size = np.array([self.lam]*3)*0.5 self.max_edge_len = self.lam/6 self.mesh = get_centred_cube(self.domain_size, self.max_edge_len) ## Set up materials function with all free-space material_mesh_func = dolfin.MeshFunction('uint', self.mesh, 3) material_mesh_func.set_all(0) materials = {0:dict(eps_r=1, mu_r=1),} ## Set up 1st-order analytical ABC abc = sucemfem.BoundaryConditions.ABC.ABCBoundaryCondition() abc.set_region_number(1) bcs = sucemfem.BoundaryConditions.container.BoundaryConditions() bcs.add_boundary_condition(abc) ## Set up high level problem class dp = sucemfem.ProblemConfigurations.EMDrivenProblem.DrivenProblemABC() dp.set_mesh(self.mesh) dp.set_basis_order(self.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 = sucemfem.Sources.fillament_current_source.FillamentCurrentSource() fillament_source.set_source_endpoints(self.source_endpoints) fillament_source.set_value(self.I) current_sources.add_source(fillament_source) ## Set source in problem container dp.set_sources(current_sources) self.problem = dp self.function_space = dp.function_space
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)
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)
from sucemfem.PostProcessing import surface_ntff, variational_ntff # Enable dolfin's form optimizations sucemfem.Utilities.Optimization.set_dolfin_optimisation() # Near-field of an infintesimal dipole fname = 'reference_dofs-2-0.149896229-0.0499654096667.pickle' theta_deg = N.linspace(0, 180, 181) no_ff_pts = len(theta_deg) phi_deg = N.zeros(no_ff_pts) data = pickle.load(open(fname)) print data lam = c0/data['freq'] k0 = data['freq']*2*N.pi/c0 mesh = get_centred_cube(data['domain_size'], data['max_edge_len']) #plot(mesh,interactive=True) V = dolfin.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", data['order']) #------------------------------ # Calculate using the standard surface integral NTFF surf_ntff = surface_ntff.NTFF(V) surf_ntff.set_dofs(data['x']) surf_ntff.set_frequency(data['freq']) surf_E_ff = N.array([surf_ntff.calc_pt(th_deg, ph_deg) for th_deg, ph_deg in zip(theta_deg, phi_deg)]) surf_E_theta = surf_E_ff[:,0] surf_E_phi = surf_E_ff[:,1] #------------------------------ # Calculate using the variational integral NTFF var_ntff = variational_ntff.NTFF(V)
import pickle sys.path.append('../../../') ## Problem parameters freq = 1e9 lam = c0/freq I = 1. # Dipole current l = lam/1000 # Dipole length source_value = N.array([0,0,1.])*I*l source_coord = N.array([0,0,0.]) ## Discretisation settings order = 2 domain_size = N.array([lam]*3)*0.5 max_edge_len = lam/6 mesh = get_centred_cube(domain_size, max_edge_len, source_coord) # Request information: field_pts = N.array( [N.max(domain_size)/2-max_edge_len/2,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 = sucemfem.BoundaryConditions.container.BoundaryConditions() bcs.add_boundary_condition(abc) dp = DrivenProblemABC() dp.set_mesh(mesh)
### Problem parameters freq = 1.0e+9 # Frequency lam = c0 / freq l = lam / 10 # Dipole length I = 1.0 # Dipole current source_direction = N.array([0, 0, 1.]) # Source orientation source_centre = N.array([0, 0, 0.]) # Position of the source source_endpoints = N.array( [-source_direction * l / 2, source_direction * l / 2]) + source_centre ### Discretisation settings order = 2 domain_size = N.array([lam] * 3) * 0.25 max_edge_len = lam / 6 mesh = get_centred_cube(domain_size, max_edge_len) fname = 'power_flux_reference_dofs_f-%f_o-%d_s-%f_l-%f_h-%f' % ( freq, order, domain_size[0], l / lam, max_edge_len / lam) meshfilename = fname + '_mesh.xml' materialsfilename = fname + '_materials.xml' print fname ### 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
from pylab import * from blog_example import analytical_pts, analytical_result ## Problem parameters I = problem_data['I'] # Dipole current l = problem_data['l'] # Dipole length source_value = N.array([0, 0, 1.]) * I * l freq = problem_data['f'] lam = c0 / freq source_coord = N.array([0, 0, 0.]) ## Discretisation settings 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)
### Problem parameters freq = 1.0e+9 # Frequency lam = c0/freq l = lam/4 # Dipole length I = 1.0 # Dipole current source_direction = N.array([0,0,1.]) # Source orientation source_centre = N.array([0,0,0.]) # Position of the source source_endpoints = N.array( [-source_direction*l/2, source_direction*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)