def test_addmultiply():
    x= Variable('x',2)
    y= Variable('y',3)
    z= Variable('z',4)
    expr = x+y*z
    assert pytest.approx(expr.eval()) == 14
    assert expr.print() == "x + y * z"
def test_multiply_subtract():
    x= Variable('x',2)
    y= Variable('y',7)
    z= Variable('z',4)
    expr = x*Par(y-z)
    assert pytest.approx(expr.eval()) == 6
    assert expr.print() == "x * (y - z)"
Ejemplo n.º 3
0
def test_multiply():
    x = Variable('x', 2)
    y = Variable('y', 3)
    expr = x * y
    assert pytest.approx(expr.eval()) == 6
    assert expr.print() == "x * y"
    assert pytest.approx(expr.diff(x)) == 3
    assert pytest.approx(expr.diff(y)) == 2
Ejemplo n.º 4
0
def test_subtract():
    x = Variable('x', 2)
    y = Variable('y', 3)
    expr = x - y
    assert pytest.approx(expr.eval()) == -1
    assert expr.print() == "x - y"
    assert pytest.approx(expr.diff(x)) == 1
    assert pytest.approx(expr.diff(y)) == -1
Ejemplo n.º 5
0
def test_add():
    x = Variable('x', 2)
    y = Variable('y', 3)
    expr = x + y
    assert pytest.approx(expr.eval()) == 5
    assert expr.print() == "x + y"
    assert pytest.approx(expr.diff(x)) == 1
    assert pytest.approx(expr.diff(y)) == 1
Ejemplo n.º 6
0
def test_divide():
    x = Variable('x', 1.0)
    y = Variable('y', 2.0)
    expr = x / y
    assert pytest.approx(expr.eval()) == 1.0 / 2.0
    assert expr.print() == "x / y"
    assert pytest.approx(expr.diff(x)) == 0.5
    assert pytest.approx(expr.diff(y)) == -0.25
Ejemplo n.º 7
0
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"
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def test_add_literal_left():

    y = Variable('y', 3)
    expr = 2.0 + y
    assert pytest.approx(expr.eval()) == 5
    assert expr.print() == "2.0 + y"
Ejemplo n.º 10
0
def test_divide_literal_right():
    x = Variable('x', 2.0)
    expr = x / 3.0
    assert pytest.approx(expr.eval()) == 2.0 / 3.0
    assert expr.print() == "x / 3.0"
Ejemplo n.º 11
0
def test_multiply_literal_right():
    x = Variable('x', 2)
    expr = x * 3.0
    assert pytest.approx(expr.eval()) == 6
    assert expr.print() == "x * 3.0"
Ejemplo n.º 12
0
def test_subtract_literal_right():
    x = Variable('x', 2)
    expr = x - 3.0
    assert pytest.approx(expr.eval()) == -1
    assert expr.print() == "x - 3.0"
Ejemplo n.º 13
0
def test_add_literal_right():
    x = Variable('x', 2)
    expr = x + 3.0
    assert pytest.approx(expr.eval()) == 5
    assert expr.print() == "x + 3.0"
Ejemplo n.º 14
0
def test_divide():
    x = Variable('x', 2.0)
    y = Variable('y', 3.0)
    expr = x / y
    assert pytest.approx(expr.eval()) == 2.0 / 3.0
    assert expr.print() == "x / y"
Ejemplo n.º 15
0
def test_subtract():
    x= Variable('x',2)
    y= Variable('y',3)
    expr = Subtraction(x,y)
    assert pytest.approx(expr.eval()) == -1
    assert expr.print() == "x - y"    
Ejemplo n.º 16
0
def test_cosh():
    x = Variable('x', math.pi / 2.0)
    expr = Cosh(x)
    assert pytest.approx(expr.eval()) == math.cosh(math.pi / 2.0)
    assert expr.print() == "cosh(x)"
Ejemplo n.º 17
0
def test_divide_literal_left():

    y = Variable('y', 3.0)
    expr = 2.0 / y
    assert pytest.approx(expr.eval()) == 2.0 / 3.0
    assert expr.print() == "2.0 / y"
Ejemplo n.º 18
0
def test_sin():
    x = Variable('x', math.pi / 2.0)
    expr = Sin(x)
    assert pytest.approx(expr.eval()) == math.sin(math.pi / 2.0)
    assert expr.print() == "sin(x)"
Ejemplo n.º 19
0
import math
import numpy as np
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

sys = ThermodynamicSystem("Test", "NRTL")
sys.addComponent(pcdb.Water())
sys.addComponent(pcdb.Ethanol())
sys.addComponent(pcdb.Methanol())
sys.addComponent(pcdb.Acetone())
sys.addComponent(pcdb.Isopropanol())
sys.fill()

T = Variable("T", 273.15, SI.K)
T.displayUnit = METRIC.C

P = Variable("P", 1e5, SI.Pa)
P.displayUnit = METRIC.mbar

c1 = st.sidebar.selectbox('Substance 1',
                          sys.components,
                          format_func=str,
                          index=0)
c2 = st.sidebar.selectbox('Substance 2',
                          sys.components,
                          format_func=str,
                          index=1)

tiso = st.sidebar.slider('Isothermal Temperature [°C]', -100, 300, 25)
Ejemplo n.º 20
0
def test_add():
    x= Variable('x',2)
    y= Variable('y',3)
    expr = Addition(x,y)
    assert pytest.approx(expr.eval()) == 5
    assert expr.print() == "x + y"
Ejemplo n.º 21
0
def test_multiply():
    x= Variable('x',2)
    y= Variable('y',3)
    expr = Multiplication(x,y)
    assert pytest.approx(expr.eval()) == 6
    assert expr.print() == "x * y"    
Ejemplo n.º 22
0
def test_subtract_literal_left():
    y = Variable('y', 3)
    expr = 2.0 - y
    assert pytest.approx(expr.eval()) == -1
    assert expr.print() == "2.0 - y"
Ejemplo n.º 23
0
def test_multiply_literal_left():
    y = Variable('y', 3)
    expr = 2.0 * y
    assert pytest.approx(expr.eval()) == 6
    assert expr.print() == "2.0 * y"
Ejemplo n.º 24
0
def test_tanh():
    x = Variable('x', math.pi / 2.0)
    expr = Tanh(x)
    assert pytest.approx(expr.eval()) == math.tanh(math.pi / 2.0)
    assert expr.print() == "tanh(x)"
Ejemplo n.º 25
0
from pypedream import AlgebraicSystem, Equation, Variable, Addition, Subtraction, Multiplication, Division, Unit, SI, METRIC, PhysicalDimension, UnitSet, UnitSetDefault, UnitSetSI
from pypedream.thermodynamics import PureComponentFunctionFactory, Substance, ThermodynamicSystem, Properties, PhysicalConstants
from pypedream.database import purecomponents as pcdb

import math
import numpy as np
import streamlit as st
import pandas as pd
import plotly.express as px

sys = ThermodynamicSystem("Test")
sys.addComponent(pcdb.Water())
sys.addComponent(pcdb.Isopropanol())
sys.addComponent(pcdb.Methanol())

T = Variable("T", 273.15, SI.K)
T.displayUnit = METRIC.C

c = st.sidebar.selectbox('Substance', sys.components, format_func=str)
p = st.sidebar.selectbox('Property', [e for e in Properties])
fdesc = c.functions[p]
tmin = st.sidebar.slider('Minimum Temperature', -100, 500, 25)
tmax = st.sidebar.slider('Maximum Temperature', -100, 500, 200)
samples = st.sidebar.number_input('samples', 10, 150)

TC = c.constants[PhysicalConstants.CriticalTemperature]
PC = c.constants[PhysicalConstants.CriticalPressure]
f = sys.correlationFactory.createFunction(fdesc, T, TC, PC)


def calculate():
Ejemplo n.º 26
0
    return


print(SI.K)
print(SI.mol)

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()