Пример #1
0
def test_ported_cr():
    model = bgt.new()
    Sf = bgt.new('Sf', name="Sf")
    R = bgt.new("R", value=2)
    zero = bgt.new("0")
    ss = bgt.new("SS")

    model.add(Sf, R, zero, ss)
    connect(Sf, zero)
    connect(R, zero)
    connect(ss, zero)

    bgt.expose(ss, 'A')
    assert len(model.control_vars) == 1

    ts, ps, cs = model._build_internal_basis_vectors()
    assert len(cs) == 1
    assert len(ps) == 7
    assert len(ts) == 0

    mapping, coords = inverse_coord_maps(ts, ps, cs)
    assert len(coords) == 15

    coords, mappings, lin_op, nl_op, conttr = model.system_model()
    assert nl_op.is_zero_matrix
    assert not conttr

    assert model.constitutive_relations == [
        sympy.sympify('e_0 - 2*f_0 - 2*u_0')
    ]
Пример #2
0
def test_re_con_rel():
    Re = bgt.new("Re", library="BioChem", value={"R": 1, "T": 1})

    coords = list(sympy.sympify("e_0,f_0,e_1,f_1,r"))

    mappings, coords = inverse_coord_maps(*Re.basis_vectors)
    assert mappings
    assert coords

    for r in get_relations_iterator(Re, mappings, coords):
        assert r in [
            ({1: 1, 3: 1}, 0), ({1: 1}, sympy.sympify("-r*exp(e_0) + r*exp(e_1)"))
        ]
Пример #3
0
def test_cv_subs_state_func():
    c = bgt.new("C", value=1)
    se = bgt.new("Se")
    r = bgt.new("R", value=1)
    kcl = bgt.new("1")
    bg = bgt.new()
    bg.add([c, se, kcl, r])

    connect(c, (kcl, kcl.non_inverting))
    connect(r, (kcl, kcl.non_inverting))
    connect(se, (kcl, kcl.non_inverting))

    cv_s = {'u_0': ' -exp(-x_0)'}

    subs = [(sympy.Symbol('u_0'), sympy.sympify('-exp(-x_0)'))]

    mappings, coords = inverse_coord_maps(*bg.basis_vectors)
    assert _generate_cv_substitutions(cv_s, mappings, coords) == subs