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)
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()
class test_DrivenProblemABC(unittest.TestCase): """Integration test for DrivenProblemABC class""" 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) def test_get_LHS_matrix(self): self.DUT.set_frequency(self.frequency) self.DUT.init_problem() # test data generated using a suspected-working version on 31 May 2011 actual_LHSmat = self.DUT.get_LHS_matrix().todense() desired_file = Paths.get_module_path_filename('LHS_matrix.npy', __file__) desired_LHSmat = N.load(desired_file) self.assertTrue( N.allclose(actual_LHSmat, desired_LHSmat, rtol=1e-10, atol=3e-15)) def test_get_RHS(self): self.DUT.set_frequency(self.frequency) self.DUT.init_problem() actual_RHS = self.DUT.get_RHS() # test data generated using a suspected-working version on 31 May 2011 desired_file = Paths.get_module_path_file('RHS_vector.pickle', __file__) desired_RHS = pickle.load(desired_file) self.assertTrue( N.allclose(actual_RHS, desired_RHS, rtol=1e-12, atol=1e-16))
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)
class test_DrivenProblemABC(unittest.TestCase): """Integration test for DrivenProblemABC class""" 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) def test_get_LHS_matrix(self): self.DUT.set_frequency(self.frequency) self.DUT.init_problem() # test data generated using a suspected-working version on 31 May 2011 actual_LHSmat = self.DUT.get_LHS_matrix().todense() desired_file = Paths.get_module_path_filename('LHS_matrix.npy', __file__) desired_LHSmat = N.load(desired_file) self.assertTrue(N.allclose( actual_LHSmat, desired_LHSmat, rtol=1e-10, atol=3e-15)) def test_get_RHS(self): self.DUT.set_frequency(self.frequency) self.DUT.init_problem() actual_RHS = self.DUT.get_RHS() # test data generated using a suspected-working version on 31 May 2011 desired_file = Paths.get_module_path_file('RHS_vector.pickle', __file__) desired_RHS = pickle.load(desired_file) self.assertTrue(N.allclose( actual_RHS, desired_RHS, rtol=1e-12, atol=1e-16))
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()
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)
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)
class EMProblem(object): """ A base class for solving electromagnetic problems """ 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() def get_global_dimension(self): """Return total number of system dofs, including Dirichlet constrained dofs """ return self.function_space.dofmap().global_dimension() def set_mesh(self, mesh): """Set the mesh associated with the problem. @param mesh: A dolfin mesh that defines the geometric discretisation of the problem. """ self.mesh = mesh def set_basis_order(self, order): """Set the order of the basis functions used in the discretisation of the problem. @param order: The polynomial order of the basis functions. """ self.basis_order = order if self.mesh is not None: self._init_function_space() def set_boundary_conditions(self, bcs): """ Set the boundary conditions for the problem based on the keyword arguments passed or with the boundary condition object provided @param bcs: A BoundaryConditions object containing a collection of boundary conditions, or a single BoundaryCondition. """ if type(bcs) == BoundaryConditions: self.boundary_conditions = bcs else: self.boundary_conditions.add_boundary_condition(bcs) def set_material_regions(self, material_regions): """Set material region properties See documentation of L{Materials.MaterialPropertiesFactory} for input format """ self.material_regions = material_regions def set_region_meshfunction(self, region_meshfunction): self.region_meshfunction = region_meshfunction def _init_boundary_conditions(self): """Initialise the boundary conditions associated with the problem. """ self.boundary_conditions.set_function_space(self.function_space) def _init_combined_forms(self): """Initialise the Dolfin forms for the problem. """ self.combined_forms = self.FormCombiner() self.combined_forms.set_interior_forms(self.interior_forms) self.combined_forms.set_boundary_conditions(self.boundary_conditions) def _init_function_space(self): """If required, initialise a dolfin function space from the stored mesh, element_type, and basis function order information. """ if self.function_space is None: self.function_space = dolfin.FunctionSpace(self.mesh, self.element_type, self.basis_order) def _init_interior_forms(self): """Initialise the Galerkin interior forms for the problem. """ self.interior_forms = Forms.EMGalerkinInteriorForms() self.interior_forms.set_material_functions(self.material_functions) self.interior_forms.set_function_space(self.function_space) def _init_material_properties(self): mat_props_fac = Materials.MaterialPropertiesFactory( self.material_regions) mat_func_fac = Materials.MaterialFunctionFactory( mat_props_fac.get_material_properties(), self.region_meshfunction, self.mesh) self.material_functions = mat_func_fac.get_material_functions( 'eps_r', 'mu_r') def _init_system_matrices(self, matrix_class=None): """Initialise the system matrices associated with the problem. @keyword matrix_class: An optional dolfin class to use for matrix storage. (default: None). """ bilin_forms = self.combined_forms.get_forms() sysmats = SystemMatrices.SystemMatrices() if matrix_class is not None: sysmats.set_matrix_class(matrix_class) sysmats.set_matrix_forms(bilin_forms) sysmats.set_boundary_conditions(self.boundary_conditions) self.system_matrices = sysmats.calc_system_matrices() def init_problem(self): """Perform the final initialisation of the problem components. """ self._init_function_space() self._init_material_properties() self._init_interior_forms() self._init_boundary_conditions() self._init_combined_forms() self._init_system_matrices()
### 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.set_source_endpoints(source_endpoints) fillament_source.set_value(I) current_sources.add_source(fillament_source) ## Set source in problem container
class EMProblem(object): """ A base class for solving electromagnetic problems """ 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() def get_global_dimension(self): """Return total number of system dofs, including Dirichlet constrained dofs """ return self.function_space.dofmap().global_dimension() def set_mesh(self, mesh): """Set the mesh associated with the problem. @param mesh: A dolfin mesh that defines the geometric discretisation of the problem. """ self.mesh = mesh; def set_basis_order(self, order): """Set the order of the basis functions used in the discretisation of the problem. @param order: The polynomial order of the basis functions. """ self.basis_order = order if self.mesh is not None: self._init_function_space() def set_boundary_conditions(self, bcs): """ Set the boundary conditions for the problem based on the keyword arguments passed or with the boundary condition object provided @param bcs: A BoundaryConditions object containing a collection of boundary conditions, or a single BoundaryCondition. """ if type(bcs) == BoundaryConditions: self.boundary_conditions = bcs else: self.boundary_conditions.add_boundary_condition ( bcs ) def set_material_regions(self, material_regions): """Set material region properties See documentation of L{Materials.MaterialPropertiesFactory} for input format """ self.material_regions = material_regions def set_region_meshfunction(self, region_meshfunction): self.region_meshfunction = region_meshfunction def _init_boundary_conditions(self): """Initialise the boundary conditions associated with the problem. """ self.boundary_conditions.set_function_space(self.function_space) def _init_combined_forms (self): """Initialise the Dolfin forms for the problem. """ self.combined_forms = self.FormCombiner() self.combined_forms.set_interior_forms(self.interior_forms) self.combined_forms.set_boundary_conditions(self.boundary_conditions) def _init_function_space (self): """If required, initialise a dolfin function space from the stored mesh, element_type, and basis function order information. """ if self.function_space is None: self.function_space = dolfin.FunctionSpace( self.mesh, self.element_type, self.basis_order) def _init_interior_forms(self): """Initialise the Galerkin interior forms for the problem. """ self.interior_forms = Forms.EMGalerkinInteriorForms() self.interior_forms.set_material_functions(self.material_functions) self.interior_forms.set_function_space(self.function_space) def _init_material_properties (self): mat_props_fac = Materials.MaterialPropertiesFactory ( self.material_regions ) mat_func_fac = Materials.MaterialFunctionFactory( mat_props_fac.get_material_properties(), self.region_meshfunction, self.mesh ) self.material_functions = mat_func_fac.get_material_functions ( 'eps_r', 'mu_r' ) def _init_system_matrices (self, matrix_class=None): """Initialise the system matrices associated with the problem. @keyword matrix_class: An optional dolfin class to use for matrix storage. (default: None). """ bilin_forms = self.combined_forms.get_forms() sysmats = SystemMatrices.SystemMatrices() if matrix_class is not None: sysmats.set_matrix_class ( matrix_class ) sysmats.set_matrix_forms(bilin_forms) sysmats.set_boundary_conditions(self.boundary_conditions) self.system_matrices = sysmats.calc_system_matrices() def init_problem(self): """Perform the final initialisation of the problem components. """ self._init_function_space() self._init_material_properties() self._init_interior_forms() self._init_boundary_conditions() self._init_combined_forms() self._init_system_matrices()
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()
## ## Solution settings 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()