def test_get_odesys__with_units(): a = Substance('A') b = Substance('B') molar = u.molar second = u.second r = Reaction({'A': 2}, {'B': 1}, param=1e-3 / molar / second) rsys = ReactionSystem([r], [a, b]) odesys = get_odesys(rsys, include_params=True, unit_registry=SI_base_registry)[0] c0 = {'A': 13 * u.mol / u.metre**3, 'B': .2 * u.molar} conc_unit = get_derived_unit(SI_base_registry, 'concentration') t = np.linspace(0, 10) * u.hour xout, yout, info = odesys.integrate(t, rsys.as_per_substance_array( c0, unit=conc_unit), atol=1e-10, rtol=1e-12) t_unitless = to_unitless(xout, u.second) Aref = dimerization_irrev(t_unitless, 1e-6, 13.0) # Aref = 1/(1/13 + 2*1e-6*t_unitless) yref = np.zeros((xout.size, 2)) yref[:, 0] = Aref yref[:, 1] = 200 + (13 - Aref) / 2 print((yout - yref * conc_unit) / yout) assert allclose(yout, yref * conc_unit)
def test_get_odesys_1(): k = .2 a = Substance('A') b = Substance('B') r = Reaction({'A': 1}, {'B': 1}, param=k) rsys = ReactionSystem([r], [a, b]) odesys = get_odesys(rsys, include_params=True)[0] c0 = { 'A': 1.0, 'B': 3.0, } t = np.linspace(0.0, 10.0) xout, yout, info = odesys.integrate(t, rsys.as_per_substance_array(c0)) yref = np.zeros((t.size, 2)) yref[:, 0] = np.exp(-k * t) yref[:, 1] = 4 - np.exp(-k * t) assert np.allclose(yout, yref)
def molarTable(subs): console.clear() x = Table(show_header=True, header_style="cyan") x.add_column("Af: Daniel Nettelfield") [x.add_column(i) for i in reactants] x.add_row( *(["Molarmasse \[g/mol]"] + [str(float(Substance.from_formula(x).molar_mass())) for x in subs])) console.print(x) consider(input("Tryk enter for at starte igen: "))
def test_get_odesys_2(): g = Radiolytic([3.14]) a = Substance('A') b = Substance('B') r = Reaction({'A': 1}, {'B': 1}, param=g) rsys = ReactionSystem([r], [a, b]) odesys = get_odesys(rsys, include_params=True)[0] c0 = { 'A': 1.0, 'B': 3.0, } t = np.linspace(0.0, .1) xout, yout, info = odesys.integrate(t, rsys.as_per_substance_array(c0), { 'doserate': 2.72, 'density': .998 }) yref = np.zeros((t.size, 2)) k = 3.14 * 2.72 * .998 yref[:, 0] = 1 - k * t yref[:, 1] = 3 + k * t assert np.allclose(yout, yref)
reactants = reactants.replace(' ', '').split("+") molarTable(reactants) continue reactants = reactants.replace(' ', '').split("+") products = products.replace(' ', '').split("+") productsSym = [ "+ " + i if reactants.index(i) != 0 else i for i in reactants ] + [ "+ " + x if products.index(x) != 0 else "-> " + x for x in products ] substances = reactants + products molMass = [ float(Substance.from_formula(x).molar_mass()) for x in substances ] coEffiList = balance(productsSym, molMass, substances) x = Table(show_header=True, header_style="cyan") x.add_column("Af: Daniel Nettelfield") for i in productsSym: x.add_column(i) x.add_row(*(["Koefficient"] + [str(i) for i in coEffiList])) x.add_row(*(["Molarmasse \[g/mol]"] + [str(round(i, decimals)) for i in molMass])) x.add_row(*(["Index Værdi"] + [str(i + 1) for i in range(len(substances))]))
#!/usr/bin/env python # -*- coding: utf-8 -*- from chempy.chemistry import Substance assert Substance.from_formula('H2O').composition == {1: 2, 8: 1}
def _get_rsys(): r1 = Reaction({'A': 2}, {'B': 1}, param=3.0) A = Substance('A', latex_name='\\boldsymbol{A}') B = Substance('B', latex_name='\\boldsymbol{B}') rsys = ReactionSystem([r1], [A, B]) return rsys