Esempio n. 1
0
def test_volume_conversion():
    """tests conversion of volume and radius of droplet"""
    for dim in [1, 2, 3]:
        radius = 1 + random.random()
        volume = spherical.volume_from_radius(radius, dim=dim)
        radius2 = spherical.radius_from_volume(volume, dim=dim)
        assert radius2 == pytest.approx(radius)
Esempio n. 2
0
def test_surface():
    """test whether the surface is calculated correctly"""
    for dim in [1, 2, 3]:
        radius = 1 + random.random()
        eps = 1e-10
        vol1 = spherical.volume_from_radius(radius + eps, dim=dim)
        vol0 = spherical.volume_from_radius(radius, dim=dim)
        surface_approx = (vol1 - vol0) / eps
        surface = spherical.surface_from_radius(radius, dim=dim)
        assert surface == pytest.approx(surface_approx, rel=1e-3)

        r2s = spherical.make_surface_from_radius_compiled(dim)
        assert surface == pytest.approx(r2s(radius))

        if dim == 1:
            with pytest.raises(RuntimeError):
                spherical.radius_from_surface(surface, dim=dim)
        else:
            assert spherical.radius_from_surface(
                surface, dim=dim) == pytest.approx(radius)
Esempio n. 3
0
 def volume(self) -> float:
     """float: volume of the droplet"""
     return spherical.volume_from_radius(self.radius, self.dim)
Esempio n. 4
0
 def volume_approx(self) -> float:
     """float: approximate volume to linear order in the perturbation"""
     volume = spherical.volume_from_radius(self.radius, 3)
     if len(self.amplitudes) > 0:
         volume += self.amplitudes[0] * 2 * np.sqrt(np.pi) * self.radius**2
     return volume