Пример #1
0
def test_lr_spline_insert_line_multiple():
    LR = init_tensor_product_LR_spline(1, 1, [0, 1, 2, 3], [0, 1, 2])
    M1 = Meshline(0, 2, constant_value=0.5, axis=1)  # horizontal split
    M2 = Meshline(0, 1, constant_value=1.5, axis=0)  # vertical split
    LR.insert_line(M1)
    LR.insert_line(M2)

    # expected functions
    b1 = BSpline(1, 1, [0, 1, 1.5], [0, 0.5, 1])
    b2 = BSpline(1, 1, [1, 1.5, 2], [0, 0.5, 1])
    b3 = BSpline(1, 1, [0, 1, 2], [0.5, 1, 2])
    b4 = BSpline(1, 1, [1, 2, 3], [0, 1, 2])

    assert b1 in LR.S
    assert b2 in LR.S
    assert b3 in LR.S
    assert b3 in LR.S
    assert len(LR.S) == 4

    expected_elements = [
        Element(0, 0, 1, 0.5),
        Element(1, 0, 1.5, 0.5),
        Element(1.5, 0, 2, 0.5),
        Element(0, 0.5, 1, 1),
        Element(1, 0.5, 1.5, 1),
        Element(1.5, 0.5, 2, 1),
        Element(2, 0, 3, 1),
        Element(0, 1, 1, 2),
        Element(1, 1, 2, 2),
        Element(2, 1, 3, 2)
    ]

    assert all([LR.contains_element(e) for e in expected_elements])
    assert len(LR.M) == 10
Пример #2
0
def test_lr_spline_unique_basis_functions():
    LR = init_tensor_product_LR_spline(1, 1, [0, 0, 1, 1], [0, 1, 2])
    m = Meshline(0, 2, constant_value=0.5, axis=0)
    LR.insert_line(m, debug=False)
    m = Meshline(0, 1, constant_value=0.5, axis=1)
    LR.insert_line(m, debug=False)

    c = Counter(LR.S)
    assert all([count == 1 for count in c.values()])
Пример #3
0
def test_element_overloaded():
    LR = init_tensor_product_LR_spline(1, 1, [0, 0, 1, 2, 2], [0, 0, 1, 2, 2])

    e = LR.M[2]

    assert not e.is_overloaded()

    e.add_supported_b_spline(LR.S[2])

    assert e.is_overloaded()
Пример #4
0
def test_lr_spline_at_end_vs_knots_tensor_product():
    d1, d2 = 2, 2
    ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
    kv = [0, 0, 0, 1, 2, 3, 3, 3]
    LR = init_tensor_product_LR_spline(d1, d2, ku, kv)

    for b in LR.S:
        if b.end_u:
            assert ku[-1] in b.knots_u
        if b.end_v:
            assert kv[-1] in b.knots_v
Пример #5
0
def test_lr_spline_dimension_bilinear():
    ku = [0, 0, 1, 2, 2]
    kv = [0, 0, 1, 1]

    du = 1
    dv = 1

    LR = init_tensor_product_LR_spline(du, dv, ku, kv)
    m = Meshline(1, 2, constant_value=0.5, axis=1)
    LR.insert_line(m)
    assert len(LR.S) == 7
Пример #6
0
def test_lr_spline_partition_at_end_uv_point():
    d1, d2 = 2, 2
    ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
    kv = [0, 0, 0, 1, 2, 3, 3, 3]
    LR = init_tensor_product_LR_spline(d1, d2, ku, kv)

    e = LR.find_element_containing_point(1, 3)
    for b in e.supported_b_splines:
        assert b.end_v
        assert 3 in b.knots_v
        if b.end_u:
            assert 1 in b.knots_u
Пример #7
0
def test_lr_spline_minimal_span_line():
    d1, d2 = (2, 2)
    ku = [0, 1, 2, 3]
    kv = [0, 1, 2, 3]
    LR = init_tensor_product_LR_spline(d1, d2, ku, kv)

    element_to_refine = LR.M[1]
    minimal_span_meshline = LR.get_minimal_span_meshline(element_to_refine,
                                                         axis=0)

    assert minimal_span_meshline.start == 0
    assert minimal_span_meshline.stop == 3
    assert minimal_span_meshline.constant_value == 0.5
Пример #8
0
def test_lr_spline_partition_of_unity_tensor_product(N):
    d1, d2 = 2, 2
    ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
    LR = init_tensor_product_LR_spline(d1, d2, ku, ku)

    x = np.linspace(0, 1, N, endpoint=True)
    np.random.seed(42)

    z = np.zeros((N, N))
    for i in range(N):
        for j in range(N):
            z[i, j] = LR(x[i], x[j])
    expected = np.ones((N, N))
    np.testing.assert_array_almost_equal(z, expected)
Пример #9
0
def test_lr_spline_partition_of_unity_interior(N):
    LR = init_tensor_product_LR_spline(2, 2, [0, 0, 0, 1, 2, 4, 5, 6, 6, 6], [0, 0, 0, 1, 2, 4, 5, 6, 6, 6])

    x = np.linspace(0, 6, N, endpoint=False)
    y = np.linspace(0, 6, N, endpoint=False)
    for j in range(12):
        m = LR.get_minimal_span_meshline(np.random.choice(LR.M), axis=j % 2)
        LR.insert_line(m)
    z = np.zeros((N, N))
    for i in range(N):
        for j in range(N):
            z[i, j] = LR(x[i], y[j])
    expected = np.ones((N, N))
    np.testing.assert_array_almost_equal(z, expected)
Пример #10
0
def test_lr_spline_global_knot_vector():
    ku = [0, 0, 1, 2, 3, 3]
    kv = [0, 0, 0.5, 1, 1]

    du = 1
    dv = 1

    LR = init_tensor_product_LR_spline(du, dv, ku, kv)

    np.testing.assert_array_almost_equal([0, 1, 2, 3], LR.global_knots_u)
    np.testing.assert_array_almost_equal([0, 0.5, 1], LR.global_knots_v)

    m = Meshline(start=0, stop=0.5, constant_value=1.5, axis=0)
    LR.insert_line(m)
    np.testing.assert_array_almost_equal([0, 1, 1.5, 2, 3], LR.global_knots_u)
Пример #11
0
def test_lr_spline_partition_of_unity_two_full(N):
    d1, d2 = 2, 2
    ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
    LR = init_tensor_product_LR_spline(d1, d2, ku, ku)

    x = np.linspace(0, 1, N, endpoint=True)
    np.random.seed(42)
    for k in range(12):
        m = LR.get_minimal_span_meshline(np.random.choice(LR.M), axis=k % 2)
        LR.insert_line(m)
    z = np.zeros((N, N))
    for i in range(N):
        for j in range(N):
            z[i, j] = LR(x[i], x[j])
    expected = np.ones((N, N))
    np.testing.assert_array_almost_equal(z, expected)
Пример #12
0
def test_lr_spline_at_end_vs_knots_refined():
    d1, d2 = 2, 2
    ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
    kv = [0, 0, 0, 1, 2, 3, 3, 3]
    LR = init_tensor_product_LR_spline(d1, d2, ku, kv)

    np.random.seed(42)
    for k in range(12):
        m = LR.get_minimal_span_meshline(np.random.choice(LR.M), axis=k % 2)
        LR.insert_line(m)

    for b in LR.S:
        if b.end_u:
            assert ku[-1] in b.knots_u
        if b.end_v:
            assert kv[-1] in b.knots_v
Пример #13
0
def test_lr_spline_overloading_count_bilinear():
    LR = init_tensor_product_LR_spline(1, 1, [0, 0, 1, 2, 3, 4, 5, 6, 6],
                                       [0, 0, 1, 2, 3, 4, 5, 6, 6])

    m1 = Meshline(2, 4, constant_value=3.5, axis=0)
    m2 = Meshline(2, 4, constant_value=2.5, axis=0)
    m3 = Meshline(2, 4, constant_value=2.5, axis=1)
    m4 = Meshline(2, 4, constant_value=3.5, axis=1)

    # culprit = 3, 3.5, 4 x 2 3 4
    LR.insert_line(m1, debug=True)
    LR.insert_line(m2, debug=True)
    LR.insert_line(m3, debug=True)
    LR.insert_line(m4, debug=True)

    for e in LR.M:
        c = Counter(e.supported_b_splines)
        assert all([count == 1 for count in c.values()])

    for e in LR.M:
        assert len(e.supported_b_splines) in [4, 5]
Пример #14
0
from LRSplines import Element, np
from LRSplines.lr_spline import init_tensor_product_LR_spline


def element_contribution(e: Element):
    mp_x, mp_y = e.midpoint

    return (mp_x - 3)**2 + (mp_y - 3)**2 < 3


def circle(t):
    return 2.5 * np.cos(t) + 3, 2.5 * np.sin(t) + 3


if __name__ == '__main__':
    LR = init_tensor_product_LR_spline(1, 1, [0, 0, 1, 2, 3, 4, 5, 6, 6],
                                       [0, 0, 1, 2, 3, 4, 5, 6, 6])

    LR.visualize_mesh(False, False)
    # LR.refine(beta=0.5, error_function=element_contribution, refinement_strategy='full')
    # LR.visualize_mesh(False, False)

    while len(LR.S) < 200:
        print(len(LR.S))
        circl_vals = [circle(t) for t in np.linspace(0, 2 * np.pi, 50)]
        for x, y in circl_vals:
            e = LR.find_element_containing_point(x, y)
            LR.refine_by_element_minimal(e)
    LR.visualize_mesh(False, False)
Пример #15
0
                              w,
                              h,
                              fill=True,
                              color='green',
                              alpha=0.2))

        axs.text(m.midpoint[0], m.midpoint[1],
                 '{}'.format(len(m.supported_b_splines)))
    plt.title('dim(S) = {}'.format(len(LR.S)))


if __name__ == '__main__':
    for N in [2, 4, 6, 8]:
        d1, d2 = 2, 2
        ku = [0, 0, 0, 0.5, 0.75, 1, 1, 1]
        LR = init_tensor_product_LR_spline(d1, d2, ku, ku)

        x = np.linspace(0, 1, N, endpoint=False)
        np.random.seed(42)
        for k in range(12):
            m = LR.get_minimal_span_meshline(np.random.choice(LR.M),
                                             axis=k % 2)
            LR.insert_line(m)
        visualize_mesh(LR)
        z = np.zeros((N, N))
        for i in range(N):
            for j in range(N):
                z[i, j] = LR(x[i], x[j])
        expected = np.ones((N, N))
        X, Y = np.meshgrid(x, x)
Пример #16
0
def test_lr_spline_previously_split_functions():
    LR = init_tensor_product_LR_spline(2, 2, [0, 0, 0, 1, 2, 4, 5, 6, 6, 6],
                                       [0, 0, 0, 1, 2, 4, 5, 6, 6, 6])
    m = Meshline(1, 5, constant_value=3, axis=0)
    LR.insert_line(m)