Exemple #1
0
    def test_complex(self):

        class ComplexOpts(properties.HasProperties):
            mycomplex = properties.Complex('My complex')

        comp = ComplexOpts()

        with self.assertRaises(ValueError):
            comp.mycomplex = 'hi'

        comp.mycomplex = 1
        assert comp.mycomplex == (1+0j)
        comp.mycomplex = 2.5j
        assert comp.mycomplex == (0+2.5j)
        comp.mycomplex = (5+2j)

        assert properties.Complex.to_json(5+2j) == '(5+2j)'
        assert properties.Complex.to_json(5) == '5'
        assert properties.Complex.to_json(2j) == '2j'

        assert properties.Complex.from_json('(5+2j)') == (5+2j)

        self.assertEqual(comp.serialize(include_class=False),
                         {'mycomplex': '(5+2j)'})
        assert ComplexOpts.deserialize({'mycomplex': '(0+1j)'}).mycomplex == 1j

        assert properties.Complex('').equal((1+1j), (1+1j))
        assert not properties.Complex('').equal((1+1j), 1)
        assert not properties.Complex('').equal('hi', 'hi')
Exemple #2
0
class BaseFDEM(BaseEM):
    """
    Base frequency domain electromagnetic class
    """
    sigma = properties.Complex(
        "Electrical conductivity (S/m)",
        default=1.0,
        cast=True
    )

    frequency = properties.Float(
        "Source frequency (Hz)",
        default=1.,
        min=0.0
    )

    quasistatic = properties.Bool(
        "Use the quasi-static approximation and ignore displacement current?",
        default=False
    )

    @properties.validator('sigma')
    def _validate_real_part(self, change):
        if not np.real(change['value']) > 0:
            raise properties.ValidationError("The real part of sigma must be positive")

    @property
    def omega(self):
        """
        Angular frequency

        .. math::

            \\omega = 2\\pi f

        """
        return omega(self.frequency)

    @property
    def sigma_hat(self):
        """
        conductivity with displacement current contribution

        .. math::

            \\hat{\\sigma} = \\sigma + i \\omega \\varepsilon

        """
        sigma = sigma_hat(
            self.frequency, self.sigma, epsilon=self.epsilon,
            quasistatic=self.quasistatic
        )
        if np.all(np.imag(sigma) == 0):
            sigma = np.real(sigma)
        return sigma

    @property
    def wavenumber(self):
        """
        Wavenumber of an electromagnetic wave in a medium with constant
        physical properties

        .. math::

            k = \\sqrt{\\omega**2 \\mu \\varepsilon - i \\omega \\mu \\sigma}

        """
        return wavenumber(
            self.frequency, self.sigma, mu=self.mu, epsilon=self.epsilon,
            quasistatic=self.quasistatic
        )

    @property
    def skin_depth(self):
        """
        Distance at which an em wave has decayed by a factor of :math:`1/e` in
        a medium with constant physical properties

        .. math::

            \\sqrt{\\frac{2}{\\omega \\sigma \\mu}}

        """
        return skin_depth(self.frequency, self.sigma, mu=self.mu)
Exemple #3
0
 class ComplexOpts(properties.HasProperties):
     mycomplex = properties.Complex('My complex')