def test_reevaluate(): x = Variable('x', 2) y = Variable('y', 3) expr = x + y assert pytest.approx(expr.eval()) == 5 assert expr.print() == "x + y" y.value = 40 expr.reset() assert pytest.approx(expr.eval()) == 42 assert expr.print() == "x + y"
def test(): for c in sys.components: for p in [e for e in Properties]: fdesc = c.functions[p] T = Variable("T", 273.15, SI.K) T.displayUnit = METRIC.C TC = c.constants[PhysicalConstants.CriticalTemperature] PC = c.constants[PhysicalConstants.CriticalPressure] f = sys.correlationFactory.createFunction(fdesc, T, TC, PC) for i in range(2000): T.value = random.uniform(100.0, 550.0) f.reset() y = f.eval()
print(f"{SI.N} Dims: {SI.N.printDimensions()} Units: {SI.N.printBaseUnits()}") print(Unit.convert(SI.K, METRIC.C, 298.15)) units = UnitSetDefault() printUnit(units[PhysicalDimension.Temperature]) printUnit(units[PhysicalDimension.Pressure]) x = Variable('x', 1) f = x * x * x - 5 * x + 3 scalar.solveNewtonRaphson(f, x) x1 = x.value x.value = 1 scalar.solveBisection(f, x, 1, 2) x2 = x.value t = np.arange(0., 2., 0.001) #plt.plot(t, t*t*t-5*t+3, 'r') # plotting t, a separately #plt.plot(t, 0*t, 'b') # plotting t, b separately #plt.plot(x2, 0, 'kx') # plotting t, b separately #plt.plot(x1, 0, 'ko') # plotting t, b separately #plt.show() sys = AlgebraicSystem("test") x1 = sys.makevar('x1', 1) x2 = sys.makevar('x2', 1)