コード例 #1
0
ファイル: test_numbers.py プロジェクト: 101man/sympy
def test_issue1512():
    assert abs(pi._evalf(50) - 3.14159265358979) < 1e-10
    assert abs(E._evalf(50) - 2.71828182845905) < 1e-10
    assert abs(Catalan._evalf(50) - 0.915965594177219) < 1e-10
    assert abs(EulerGamma._evalf(50) - 0.577215664901533) < 1e-10
    assert abs(GoldenRatio._evalf(50) - 1.61803398874989) < 1e-10
    x = Symbol("x")
    assert (pi+x).evalf() == pi.evalf()+x
    assert (E+x).evalf() == E.evalf()+x
    assert (Catalan+x).evalf() == Catalan.evalf()+x
    assert (EulerGamma+x).evalf() == EulerGamma.evalf()+x
    assert (GoldenRatio+x).evalf() == GoldenRatio.evalf()+x
コード例 #2
0
def test_issue_4611():
    assert abs(pi._evalf(50) - 3.14159265358979) < 1e-10
    assert abs(E._evalf(50) - 2.71828182845905) < 1e-10
    assert abs(Catalan._evalf(50) - 0.915965594177219) < 1e-10
    assert abs(EulerGamma._evalf(50) - 0.577215664901533) < 1e-10
    assert abs(GoldenRatio._evalf(50) - 1.61803398874989) < 1e-10
    x = Symbol("x")
    assert (pi + x).evalf() == pi.evalf() + x
    assert (E + x).evalf() == E.evalf() + x
    assert (Catalan + x).evalf() == Catalan.evalf() + x
    assert (EulerGamma + x).evalf() == EulerGamma.evalf() + x
    assert (GoldenRatio + x).evalf() == GoldenRatio.evalf() + x
コード例 #3
0
def test_fcode_NumberSymbol():
    prec = 17
    p = FCodePrinter()
    assert fcode(
        Catalan
    ) == "      parameter (Catalan = %sd0)\n      Catalan" % Catalan.evalf(
        prec)
    assert fcode(
        EulerGamma
    ) == "      parameter (EulerGamma = %sd0)\n      EulerGamma" % EulerGamma.evalf(
        prec)
    assert fcode(E) == "      parameter (E = %sd0)\n      E" % E.evalf(prec)
    assert fcode(
        GoldenRatio
    ) == "      parameter (GoldenRatio = %sd0)\n      GoldenRatio" % GoldenRatio.evalf(
        prec)
    assert fcode(
        pi) == "      parameter (pi = %sd0)\n      pi" % pi.evalf(prec)
    assert fcode(
        pi,
        precision=5) == "      parameter (pi = %sd0)\n      pi" % pi.evalf(5)
    assert fcode(Catalan, human=False) == (
        set([(Catalan, p._print(Catalan.evalf(prec)))]),
        set([]),
        "      Catalan",
    )
    assert fcode(EulerGamma, human=False) == (
        set([(EulerGamma, p._print(EulerGamma.evalf(prec)))]),
        set([]),
        "      EulerGamma",
    )
    assert fcode(E, human=False) == (
        set([(E, p._print(E.evalf(prec)))]),
        set([]),
        "      E",
    )
    assert fcode(GoldenRatio, human=False) == (
        set([(GoldenRatio, p._print(GoldenRatio.evalf(prec)))]),
        set([]),
        "      GoldenRatio",
    )
    assert fcode(pi, human=False) == (
        set([(pi, p._print(pi.evalf(prec)))]),
        set([]),
        "      pi",
    )
    assert fcode(pi, precision=5, human=False) == (
        set([(pi, p._print(pi.evalf(5)))]),
        set([]),
        "      pi",
    )
コード例 #4
0
ファイル: test_fcode.py プロジェクト: tuhina/sympy
def test_fcode_NumberSymbol():
    p = FCodePrinter()
    assert fcode(
        Catalan
    ) == '      parameter (Catalan = 0.915965594177219d0)\n      Catalan'
    assert fcode(
        EulerGamma
    ) == '      parameter (EulerGamma = 0.577215664901533d0)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905d0)\n      E'
    assert fcode(
        GoldenRatio
    ) == '      parameter (GoldenRatio = 1.61803398874989d0)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979d0)\n      pi'
    assert fcode(pi,
                 precision=5) == '      parameter (pi = 3.1416d0)\n      pi'
    assert fcode(Catalan, human=False) == (set([
        (Catalan, p._print(Catalan.evalf(15)))
    ]), set([]), '      Catalan')
    assert fcode(EulerGamma, human=False) == (set([
        (EulerGamma, p._print(EulerGamma.evalf(15)))
    ]), set([]), '      EulerGamma')
    assert fcode(E, human=False) == (set([(E, p._print(E.evalf(15)))]),
                                     set([]), '      E')
    assert fcode(GoldenRatio, human=False) == (set([
        (GoldenRatio, p._print(GoldenRatio.evalf(15)))
    ]), set([]), '      GoldenRatio')
    assert fcode(pi, human=False) == (set([(pi, p._print(pi.evalf(15)))]),
                                      set([]), '      pi')
    assert fcode(pi, precision=5, human=False) == (set([
        (pi, p._print(pi.evalf(5)))
    ]), set([]), '      pi')
コード例 #5
0
def test_fcode_NumberSymbol():
    assert fcode(
        Catalan
    ) == '      parameter (Catalan = 0.915965594177219)\n      Catalan'
    assert fcode(
        EulerGamma
    ) == '      parameter (EulerGamma = 0.577215664901533)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905)\n      E'
    assert fcode(
        GoldenRatio
    ) == '      parameter (GoldenRatio = 1.61803398874989)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979)\n      pi'
    assert fcode(pi, precision=5) == '      parameter (pi = 3.1416)\n      pi'
    assert fcode(Catalan, human=False) == ([('Catalan', Catalan.evalf(15))],
                                           set([]), '      Catalan')
    assert fcode(EulerGamma,
                 human=False) == ([('EulerGamma', EulerGamma.evalf(15))],
                                  set([]), '      EulerGamma')
    assert fcode(E, human=False) == ([('E', E.evalf(15))], set([]), '      E')
    assert fcode(GoldenRatio,
                 human=False) == ([('GoldenRatio', GoldenRatio.evalf(15))],
                                  set([]), '      GoldenRatio')
    assert fcode(pi,
                 human=False) == ([('pi', pi.evalf(15))], set([]), '      pi')
    assert fcode(pi, precision=5,
                 human=False) == ([('pi', pi.evalf(5))], set([]), '      pi')
コード例 #6
0
ファイル: test_fcode.py プロジェクト: tovrstra/sympy
def test_fcode_NumberSymbol():
    assert fcode(Catalan) == '      parameter (Catalan = 0.915965594177219)\n      Catalan'
    assert fcode(EulerGamma) == '      parameter (EulerGamma = 0.577215664901533)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905)\n      E'
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = 1.61803398874989)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979)\n      pi'
    assert fcode(pi,precision=5) == '      parameter (pi = 3.1416)\n      pi'
    assert fcode(Catalan,human=False) == ([('Catalan', Catalan.evalf(15))], set([]), '      Catalan')
    assert fcode(EulerGamma,human=False) == ([('EulerGamma', EulerGamma.evalf(15))], set([]), '      EulerGamma')
    assert fcode(E,human=False) == ([('E', E.evalf(15))], set([]), '      E')
    assert fcode(GoldenRatio,human=False) == ([('GoldenRatio', GoldenRatio.evalf(15))], set([]), '      GoldenRatio')
    assert fcode(pi,human=False) == ([('pi', pi.evalf(15))], set([]), '      pi')
    assert fcode(pi,precision=5,human=False) == ([('pi', pi.evalf(5))], set([]), '      pi')
コード例 #7
0
ファイル: test_fcode.py プロジェクト: Jerryy/sympy
def test_fcode_NumberSymbol():
    p = FCodePrinter()
    assert fcode(Catalan) == '      parameter (Catalan = 0.915965594177219d0)\n      Catalan'
    assert fcode(EulerGamma) == '      parameter (EulerGamma = 0.577215664901533d0)\n      EulerGamma'
    assert fcode(E) == '      parameter (E = 2.71828182845905d0)\n      E'
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = 1.61803398874989d0)\n      GoldenRatio'
    assert fcode(pi) == '      parameter (pi = 3.14159265358979d0)\n      pi'
    assert fcode(pi,precision=5) == '      parameter (pi = 3.1416d0)\n      pi'
    assert fcode(Catalan,human=False) == (set([(Catalan, p._print(Catalan.evalf(15)))]), set([]), '      Catalan')
    assert fcode(EulerGamma,human=False) == (set([(EulerGamma, p._print(EulerGamma.evalf(15)))]), set([]), '      EulerGamma')
    assert fcode(E,human=False) == (set([(E, p._print(E.evalf(15)))]), set([]), '      E')
    assert fcode(GoldenRatio,human=False) == (set([(GoldenRatio, p._print(GoldenRatio.evalf(15)))]), set([]), '      GoldenRatio')
    assert fcode(pi,human=False) == (set([(pi, p._print(pi.evalf(15)))]), set([]), '      pi')
    assert fcode(pi,precision=5,human=False) == (set([(pi, p._print(pi.evalf(5)))]), set([]), '      pi')
コード例 #8
0
ファイル: test_fcode.py プロジェクト: Eric-Muthemba/eabl
def test_fcode_NumberSymbol():
    prec = 17
    p = FCodePrinter()
    assert fcode(
        Catalan
    ) == '      parameter (Catalan = %sd0)\n      Catalan' % Catalan.evalf(
        prec)
    assert fcode(
        EulerGamma
    ) == '      parameter (EulerGamma = %sd0)\n      EulerGamma' % EulerGamma.evalf(
        prec)
    assert fcode(E) == '      parameter (E = %sd0)\n      E' % E.evalf(prec)
    assert fcode(
        GoldenRatio
    ) == '      parameter (GoldenRatio = %sd0)\n      GoldenRatio' % GoldenRatio.evalf(
        prec)
    assert fcode(
        pi) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(prec)
    assert fcode(
        pi,
        precision=5) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(5)
    assert fcode(Catalan, human=False) == (set([
        (Catalan, p._print(Catalan.evalf(prec)))
    ]), set([]), '      Catalan')
    assert fcode(EulerGamma, human=False) == (set([
        (EulerGamma, p._print(EulerGamma.evalf(prec)))
    ]), set([]), '      EulerGamma')
    assert fcode(E, human=False) == (set([(E, p._print(E.evalf(prec)))]),
                                     set([]), '      E')
    assert fcode(GoldenRatio, human=False) == (set([
        (GoldenRatio, p._print(GoldenRatio.evalf(prec)))
    ]), set([]), '      GoldenRatio')
    assert fcode(pi, human=False) == (set([(pi, p._print(pi.evalf(prec)))]),
                                      set([]), '      pi')
    assert fcode(pi, precision=5, human=False) == (set([
        (pi, p._print(pi.evalf(5)))
    ]), set([]), '      pi')
コード例 #9
0
ファイル: test_fcode.py プロジェクト: normalhuman/sympy
def test_fcode_NumberSymbol():
    prec = 17
    p = FCodePrinter()
    assert fcode(Catalan) == '      parameter (Catalan = %sd0)\n      Catalan' % Catalan.evalf(prec)
    assert fcode(EulerGamma) == '      parameter (EulerGamma = %sd0)\n      EulerGamma' % EulerGamma.evalf(prec)
    assert fcode(E) == '      parameter (E = %sd0)\n      E' % E.evalf(prec)
    assert fcode(GoldenRatio) == '      parameter (GoldenRatio = %sd0)\n      GoldenRatio' % GoldenRatio.evalf(prec)
    assert fcode(pi) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(prec)
    assert fcode(
        pi, precision=5) == '      parameter (pi = %sd0)\n      pi' % pi.evalf(5)
    assert fcode(Catalan, human=False) == (set(
        [(Catalan, p._print(Catalan.evalf(prec)))]), set([]), '      Catalan')
    assert fcode(EulerGamma, human=False) == (set([(EulerGamma, p._print(
        EulerGamma.evalf(prec)))]), set([]), '      EulerGamma')
    assert fcode(E, human=False) == (
        set([(E, p._print(E.evalf(prec)))]), set([]), '      E')
    assert fcode(GoldenRatio, human=False) == (set([(GoldenRatio, p._print(
        GoldenRatio.evalf(prec)))]), set([]), '      GoldenRatio')
    assert fcode(pi, human=False) == (
        set([(pi, p._print(pi.evalf(prec)))]), set([]), '      pi')
    assert fcode(pi, precision=5, human=False) == (
        set([(pi, p._print(pi.evalf(5)))]), set([]), '      pi')
コード例 #10
0
import copy
from math import ceil
import numpy as np
import numexpr as ne
from sympy import EulerGamma

g = 9.81
eg = np.float64(EulerGamma.evalf(16))


def hydrodynamic_model(Input, l2, phij):
    """ Iterates the friction coefficient and yields flow velocities.
    Computes the flow solution in the inlets and basin, and iterates the velocity scale
    until it matches that found in the hydrodynamic solution (given a certain tolerance).
    Solves the system :math:`\mathbf{A} \mathbf{\hat{u}} = \mathbf{f}`
    for the flow velocity amplitude :math:`\mathbf{\hat{u}}`. The forcing therm :math:`\mathbf{f}`
    consists of a tidal forcing, and matrix :math:`\mathbf{A} = \mathbf{A}_1 + \mathbf{A}_2 - \mathbf{A}_3`.
    The first term is associated with friction in the channel.
    The second with the sea impedance.
    The third term is associated with basin impedance.

    Args:
        Input (Class): Class containing all data for the various geograpical elements.
            Consists of the Basin, OpenInlets, Ocean, and Pars classes.
        l2 (np.ndarray): 3d-array containing the L2-norm for the eigenfunctinos :math:`\phi_{m, n}(x, y)`.
        phij (np.ndarray): 3d-array containing the integrated eigenfunctions over all j inlets.

    Returns:
        returnObject (dict):
            uj (np.ndarray): flow velocity in the inlets.
            ub (float): flow velocity in the basin.