Exemplo n.º 1
0
class test_fillament_current_source(unittest.TestCase):
    test_data_file = 'fillament_source_test_data.pickle'
    rtol=1e-10
    atol=1e-12
    
    def setUp(self):
        desired_file = Paths.get_module_path_file(self.test_data_file, __file__)
        env = self.environment = FillamentEnvironment(desired_file)
        self.DUT = FillamentCurrentSource()
        self.DUT.set_function_space(env.discretisation_space)
        self.DUT.set_no_integration_points(env.no_integration_points)
        self.DUT.set_source_endpoints(env.source_endpoints)
        self.DUT.set_value(env.I)

    def test_source(self):
        actual_dofnos, actual_rhs = self.DUT.get_contribution()
        sortind = np.argsort(actual_dofnos)
        actual_dofnos = actual_dofnos[sortind].copy()
        actual_rhs = actual_rhs[sortind].copy()
        self.assertTrue(np.all(actual_dofnos == self.environment.desired_dofnos))
        self.assertTrue(np.allclose(actual_rhs, self.environment.desired_rhs_contribs,
                                    rtol=self.rtol, atol=self.atol))

    def test_negative_direction(self):
        dofnos, rhs = self.DUT.get_contribution()
        sortind = np.argsort(dofnos)
        dofnos = dofnos[sortind]
        rhs = rhs[sortind]
        self.DUT.set_source_endpoints(-self.DUT.source_endpoints)
        dofnos_neg, rhs_neg = self.DUT.get_contribution()
        sortind = np.argsort(dofnos_neg)
        dofnos_neg = dofnos_neg[sortind]
        rhs_neg = rhs_neg[sortind]
        self.assertTrue(np.all(dofnos == dofnos_neg))
        self.assertTrue(np.allclose(rhs, -rhs_neg))
Exemplo n.º 2
0
    def get_current_source(self):
        """get FillamentCurrentSource instance

        Each call results in a new instance being instantiated.
        """
        cs = FillamentCurrentSource()
        cs.set_function_space(self.function_space)
        cs.set_source_endpoints(self.source_parameters['endpoints'])
        cs.set_value(self.source_parameters['I'])
        return cs
l = lam/4                               # Dipole length
# l = 2.3*lam                               # Dipole length
I = 1.0                                 # Dipole current
source_direction = np.array([0,0,1.])    # Source orientation
source_centre = np.array([0,0,0.])        # Position of the source
source_endpoints =  np.array(
    [-source_direction*l/2, source_direction*l/2]) + source_centre

## Discretisation settings
order = 2
domain_size = np.array([lam]*3)/2
max_edge_len = lam/3
mesh = get_centred_cube(domain_size, max_edge_len)
## Implementation
V = dolfin.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", order)
dipole_source = FillamentCurrentSource()
dipole_source.no_integration_points = 20
dipole_source.set_function_space(V)
dipole_source.set_source_endpoints(source_endpoints)
dipole_source.set_value(I)
dofnos, rhs_contribs = dipole_source.get_contribution()
sortind = np.argsort(dofnos)
dofnos = dofnos[sortind].copy()
rhs_contribs = rhs_contribs[sortind].copy()

pickle.dump(dict(order=order,I=I, source_endpoints=source_endpoints,
                 domain_size=domain_size, max_edge_len=max_edge_len,
                 no_integration_points=dipole_source.no_integration_points,
                 dofnos=dofnos, rhs_contribs=rhs_contribs),
            open('fillament_source_test_data.pickle', 'w'))
Exemplo n.º 4
0
I = 1.0  # Dipole current
source_direction = np.array([0, 0, 1.])  # Source orientation
source_centre = np.array([0, 0, 0.])  # Position of the source
source_endpoints = np.array(
    [-source_direction * l / 2, source_direction * l / 2]) + source_centre

## Discretisation settings
order = 2
domain_size = np.array([lam] * 3) / 2
max_edge_len = lam / 3
mesh = get_centred_cube(domain_size, max_edge_len)
## Implementation
V = dolfin.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", order)
dipole_source = FillamentCurrentSource()
dipole_source.no_integration_points = 20
dipole_source.set_function_space(V)
dipole_source.set_source_endpoints(source_endpoints)
dipole_source.set_value(I)
dofnos, rhs_contribs = dipole_source.get_contribution()
sortind = np.argsort(dofnos)
dofnos = dofnos[sortind].copy()
rhs_contribs = rhs_contribs[sortind].copy()

pickle.dump(
    dict(order=order,
         I=I,
         source_endpoints=source_endpoints,
         domain_size=domain_size,
         max_edge_len=max_edge_len,
         no_integration_points=dipole_source.no_integration_points,
         dofnos=dofnos,