Beispiel #1
0
def test_emulsion_two():
    """test an emulsions with two droplets"""
    grid = UnitGrid([30])
    e = Emulsion([DiffuseDroplet([10], 3, 1)], grid=grid)
    e1 = Emulsion([DiffuseDroplet([20], 5, 1)], grid=grid)
    e.extend(e1)
    assert e
    assert len(e) == 2
    assert e == e.copy()
    assert e is not e.copy()
    assert e.interface_width == pytest.approx(1)
    assert e.total_droplet_volume == pytest.approx(16)

    dists = e.get_pairwise_distances()
    np.testing.assert_array_equal(dists, np.array([[0, 10], [10, 0]]))
    expect = {
        "count": 2,
        "radius_mean": 4,
        "radius_std": 1,
        "volume_mean": 8,
        "volume_std": 2,
    }
    assert e.get_size_statistics() == expect

    np.testing.assert_array_equal(e.get_neighbor_distances(False), np.array([10, 10]))
    np.testing.assert_array_equal(e.get_neighbor_distances(True), np.array([2, 2]))
Beispiel #2
0
def test_emulsion_plotting():
    """test plotting emulsions"""
    # 1d emulsion
    e1 = Emulsion([DiffuseDroplet([1], 10, 0.5)] * 2)
    with pytest.raises(NotImplementedError):
        e1.plot()

    # 2d emulsion
    field = ScalarField(UnitGrid([10, 10], periodic=True))
    es = [
        Emulsion([DiffuseDroplet([0, 1], 10, 0.5)] * 2),
        Emulsion([droplets.PerturbedDroplet2D([0, 1], 3, 1, [1, 2, 3, 4])]),
    ]
    for e2 in es:
        e2.plot()
        e2.plot(field=field)

    # 3d emulsion
    field = ScalarField(UnitGrid([5, 5, 5], periodic=True))
    e3 = Emulsion([DiffuseDroplet([0, 1, 2], 10, 0.5)] * 2)
    e3.plot()
    e3.plot(field=field)

    e3 = Emulsion([droplets.PerturbedDroplet3D([0, 1, 2], 3, 1, [1, 2, 3, 4, 5, 6])])
    with pytest.raises(NotImplementedError):
        e3.plot()

    with pytest.raises(NotImplementedError):
        Emulsion().plot()
Beispiel #3
0
def test_timecourse_io(tmp_path):
    """test writing and reading emulsions time courses"""
    path = tmp_path / "test_timecourse_io.hdf5"

    e1 = Emulsion()
    e2 = Emulsion([DiffuseDroplet([0, 1], 10, 0.5)] * 2)
    tc1 = emulsions.EmulsionTimeCourse([e1, e2], times=[0, 10])

    tc1.to_file(path)
    tc2 = emulsions.EmulsionTimeCourse.from_file(path, progress=False)
    assert tc1.times == tc2.times
    assert tc1.emulsions == tc2.emulsions
    assert len(tc2) == 2
Beispiel #4
0
def test_emulsion_io(tmp_path):
    """test writing and reading emulsions"""
    path = tmp_path / "test_emulsion_io.hdf5"

    es = [
        Emulsion(),
        Emulsion([DiffuseDroplet([0, 1], 10, 0.5)] * 2),
        Emulsion([droplets.PerturbedDroplet2D([0, 1], 3, 1, [1, 2, 3])]),
    ]
    for e1 in es:
        e1.to_file(path)
        e2 = Emulsion.from_file(path)
        assert e1 == e2
Beispiel #5
0
def test_emulsion_incompatible():
    """test incompatible droplets in an emulsion"""
    # different type
    d1 = SphericalDroplet([1], 2)
    d2 = DiffuseDroplet([1], 2, 1)
    e = Emulsion([d1, d2])
    assert len(e) == 2
    with pytest.raises(TypeError):
        e.data

    # same type
    d1 = SphericalDroplet([1], 2)
    d2 = SphericalDroplet([1, 2], 2)
    with pytest.raises(ValueError):
        e = Emulsion([d1, d2])
Beispiel #6
0
def test_emulsion_single():
    """test an emulsions with a single droplet"""
    e = Emulsion([], grid=UnitGrid([2]))
    e.append(DiffuseDroplet([10], 3, 1))
    assert e
    assert len(e) == 1
    assert e == e.copy()
    assert e is not e.copy()
    assert e.interface_width == pytest.approx(1)
    assert e.total_droplet_volume == pytest.approx(6)
    dists = e.get_pairwise_distances()
    np.testing.assert_array_equal(dists, np.zeros((1, 1)))
    expect = {
        "count": 1,
        "radius_mean": 3,
        "radius_std": 0,
        "volume_mean": 6,
        "volume_std": 0,
    }
    assert e.get_size_statistics() == expect
    for b in [True, False]:
        np.testing.assert_array_equal(e.get_neighbor_distances(b), np.array([np.nan]))
Beispiel #7
0
#!/usr/bin/env python3

from droplets import DiffuseDroplet, Emulsion, SphericalDroplet

# construct two droplets
drop1 = SphericalDroplet(position=[0, 0], radius=2)
drop2 = DiffuseDroplet(position=[6, 8], radius=3, interface_width=1)

# check whether they overlap
print(drop1.overlaps(drop2))  # prints False

# construct an emulsion and query it
e = Emulsion([drop1, drop2])
e.get_size_statistics()
Beispiel #8
0
#!/usr/bin/env python3

import numpy as np

from droplets import DiffuseDroplet, Emulsion

# create 10 random droplets
droplets = [
    DiffuseDroplet(
        position=np.random.uniform(0, 100, 2),
        radius=np.random.uniform(5, 10),
        interface_width=1,
    ) for _ in range(10)
]

# remove overlapping droplets in emulsion and plot it
emulsion = Emulsion(droplets)
emulsion.remove_overlapping()
emulsion.plot()