Exemplo n.º 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
Exemplo n.º 2
0
def test_element_equality():
    e1 = Element(0, 0, 1, 1)
    e2 = Element(0, 0, 1, 1)
    e3 = Element(0, 0, 1, 1.1)

    assert e1 == e2
    assert e1 != e3
Exemplo n.º 3
0
def test_element_intersects():
    e1 = Element(0, 0, 1, 1)
    e2 = Element(0.25, 0.25, 0.75, 0.75)
    e3 = Element(0.5, 0.5, 1.5, 1.5)
    e4 = Element(1, 0, 2, 1)

    assert e1.intersects(e2) and e2.intersects(e1)
    assert e1.intersects(e3) and e3.intersects(e1)
    assert not e1.intersects(e4)

    e5 = e1.split(axis=0, split_value=.5)
    assert not e1.intersects(e5)
Exemplo n.º 4
0
def test_lr_spline_minimal_span_line_superficial():
    """
    Constructed example, won't occur in practice.
    """

    element = Element(0.5, 0, 1, 2)
    ku1 = [-1, 0, 1]
    kv1 = [0, 1, 2]
    ku2 = [0, 0.5, 1]
    kv2 = [0, 1, 3]

    b1 = BSpline(1, 1, ku1, kv1)
    b2 = BSpline(1, 1, ku2, kv2)

    element.add_supported_b_spline(b1)
    element.add_supported_b_spline(b2)

    small_span_meshline_vertical = LRSpline.get_minimal_span_meshline(element,
                                                                      axis=0)
    small_span_meshline_horizontal = LRSpline.get_minimal_span_meshline(
        element, axis=1)

    assert small_span_meshline_vertical.start == 0
    assert small_span_meshline_vertical.stop == 2
    assert small_span_meshline_vertical.constant_value == 0.75

    assert small_span_meshline_horizontal.start == 0
    assert small_span_meshline_horizontal.stop == 1
    assert small_span_meshline_horizontal.constant_value == 1
Exemplo n.º 5
0
def test_element_containment():
    e = Element(0, 0, 1, 1)

    assert e.contains(0.5, 0.5)
    assert e.contains(0.5, 0)

    assert not e.contains(-1, 0.5)
    assert not e.contains(0, -1.0e-14)
Exemplo n.º 6
0
def test_element_support():
    e = Element(0, 0, 1, 1)
    e.add_supported_b_spline(max)

    assert e.has_supported_b_spline(max)
    assert e.get_supported_b_spline(0) == max

    e.remove_supported_b_spline(max)
    assert len(e.supported_b_splines) == 0
Exemplo n.º 7
0
def test_meshline_splits_element():
    start = 0
    stop = 1
    constant_value = 0.5

    m1 = Meshline(start, stop, constant_value, 0)
    m2 = Meshline(start, stop, constant_value, 1)
    e1 = Element(0, 0, 1, 1)
    e2 = Element(0, 0, 0.4, 1)
    e3 = Element(0, 0, 0.5, 1)

    assert m1.splits_element(e1)
    assert not m1.splits_element(e2)
    assert not m1.splits_element(e3)

    assert m2.splits_element(e1)
    assert m2.splits_element(e2)
    assert m2.splits_element(e3)
Exemplo n.º 8
0
def test_element_area():
    e1 = Element(0, 0, 1, 1)

    assert e1.area == 1
Exemplo n.º 9
0
def test_element_midpoint():
    e1 = Element(0, 0, 1, 1)
    mp = e1.midpoint

    assert mp == (0.5, 0.5)
Exemplo n.º 10
0
def test_element_init():
    e = Element(0, 0, 1, 1)

    assert e.u_min == 0 and e.u_max == 1 and e.v_min == 0 and e.v_max == 1 and e.supported_b_splines == []
Exemplo n.º 11
0
def test_element_invalid():
    e1 = Element(0, 0, 1, 1)
    e2 = e1.split(0, 1)

    assert e2 is None
    assert e1.u_min == 0 and e1.u_max == 1 and e1.v_min == 0 and e1.v_max == 1
Exemplo n.º 12
0
def test_element_split():
    e1 = Element(0, 0, 1, 1)
    e2 = e1.split(0, 0.5)

    assert e1.u_min == 0 and e1.v_min == 0 and e1.u_max == 0.5 and e1.v_max == 1
    assert e2.u_min == 0.5 and e2.v_min == 0 and e2.u_max == 1 and e2.v_max == 1
Exemplo n.º 13
0
def init_tensor_product_LR_spline(d1: int, d2: int, ku: Vector,
                                  kv: Vector) -> 'LRSpline':
    """
    Initializes an LR spline at the tensor product level of bidegree (d1, d2).

    :param d1: first component degree
    :param d2: second component degree
    :param ku: knots in u_direction
    :param kv: knots in v_direction
    :return: corresponding LR_spline
    """

    elements = []
    basis = []
    meshlines = []

    unique_ku = np.unique(ku)
    unique_kv = np.unique(kv)

    for i in range(len(unique_ku) - 1):
        for j in range(len(unique_kv) - 1):
            elements.append(
                Element(unique_ku[i], unique_kv[j], unique_ku[i + 1],
                        unique_kv[j + 1]))

    for i in range(len(ku) - d1 - 1):
        for j in range(len(kv) - d2 - 1):
            end_u = _at_end(ku, i + d1 + 1)
            end_v = _at_end(kv, j + d2 + 1)

            # TODO: This only works if the knot vectors are p+1-extended.

            north = j == len(kv) - d2 - 2
            south = j == 0
            east = i == len(ku) - d1 - 2
            west = i == 0

            basis.append(
                BSpline(d1,
                        d2,
                        ku[i:i + d1 + 2],
                        kv[j:j + d2 + 2],
                        end_u=end_u,
                        end_v=end_v,
                        north=north,
                        south=south,
                        east=east,
                        west=west))

    for b in basis:
        for e in elements:
            if b.add_to_support_if_intersects(e):
                e.add_supported_b_spline(b)

    for i in range(len(unique_ku)):
        for j in range(len(unique_kv) - 1):
            new_m = Meshline(start=unique_kv[j],
                             stop=unique_kv[j + 1],
                             constant_value=unique_ku[i],
                             axis=0)
            new_m.set_multiplicity(ku)
            meshlines.append(new_m)
    for i in range(len(unique_kv)):
        for j in range(len(unique_ku) - 1):
            new_m = Meshline(start=unique_ku[j],
                             stop=unique_ku[j + 1],
                             constant_value=unique_kv[i],
                             axis=1)
            new_m.set_multiplicity(kv)
            meshlines.append(new_m)

    u_range = [ku[0], ku[-1]]
    v_range = [kv[0], kv[-1]]

    return LRSpline(elements, basis, meshlines, u_range, v_range, unique_ku,
                    unique_kv)