Skip to main content

No project description provided

Project description

Rust Poly

Fast polynomial and rational evaluation for Python written in Rust.

Quick example of computing a stiffness matrix:

from rust_poly import FloatExpression as Polynomial, from_terms
import numpy as np

terms = {"x1": 0, "x2": 1, "x1a": 2, "x2a": 3,
         "x1b": 4, "x2b": 5, "x1c": 6, "x2c": 7,
         "nu": 8, "none": None}

def get_term(term):
    t = [0] * (len(terms) - 1)
    if terms[term] is not None:
        t[terms[term]] = 1
    return tuple(t)

def get_term_array(term):
    return np.array(get_term(term))

def get_poly(**kwargs):
    return from_terms(
        {get_term(key): val for key, val in kwargs.items()}
    )

# Stiffness matrix interpolation functions
Na = (get_poly(x2=1, x2b=-1) *get_poly(x1c=1, x1b=-1)
    -get_poly(x1=1, x1b=-1) *get_poly(x2c=1, x2b=-1)
) / (get_poly(x2a=1, x2b=-1) *get_poly(x1c=1, x1b=-1)
    -get_poly(x1a=1, x1b=-1) *get_poly(x2c=1, x2b=-1))
Nb = (get_poly(x2=1, x2c=-1) *get_poly(x1a=1, x1c=-1)
    -get_poly(x1=1, x1c=-1) *get_poly(x2a=1, x2c=-1)
) / (get_poly(x2b=1, x2c=-1) *get_poly(x1a=1, x1c=-1)
    -get_poly(x1b=1, x1c=-1) *get_poly(x2a=1, x2c=-1))
Nc = (get_poly(x2=1, x2a=-1) *get_poly(x1b=1, x1a=-1)
    -get_poly(x1=1, x1a=-1) *get_poly(x2b=1, x2a=-1)
) / (get_poly(x2c=1, x2a=-1) *get_poly(x1b=1, x1a=-1)
    -get_poly(x1c=1, x1a=-1) *get_poly(x2b=1, x2a=-1))

# Strain-displacement matrix
B = np.full((3, 6), Polynomial.zero(len(terms) - 1) / Polynomial.one(len(terms) - 1))
B[0, 0] = Na.deriv(get_term_array('x1'))
B[0, 2] = Nb.deriv(get_term_array('x1'))
B[0, 4] = Nc.deriv(get_term_array('x1'))
B[1, 1] = Na.deriv(get_term_array('x2'))
B[1, 3] = Nb.deriv(get_term_array('x2'))
B[1, 5] = Nc.deriv(get_term_array('x2'))
B[2, 0] = Na.deriv(get_term_array('x2'))
B[2, 1] = Na.deriv(get_term_array('x1'))
B[2, 2] = Nb.deriv(get_term_array('x2'))
B[2, 3] = Nb.deriv(get_term_array('x1'))
B[2, 4] = Nc.deriv(get_term_array('x2'))
B[2, 5] = Nc.deriv(get_term_array('x1'))

# Material constitutive matrix (plane stress)
D = np.full(
    (3, 3),
    Polynomial.zero(len(terms) - 1) / Polynomial.one(len(terms) - 1)
)
D[0, 0] = D[1, 1] = get_poly(nu=0, none=1)
D[1, 0] = D[0, 1] = get_poly(nu=1)
D[2, 2] = get_poly(nu=-0.5, none=0.5)
D = D / (get_poly(none=1, nu=1) * get_poly(none=1, nu=-1))

# Coordinate Determinant
Det = (
    get_poly(x1a=1) * get_poly(x2b=1, x2c=-1)
    + get_poly(x1b=1) * get_poly(x2c=1, x2a=-1)
    + get_poly(x1c=1) * get_poly(x2a=1, x2b=-1)
)


# Compute an abstract representation for the stiffness matrix of a constant
# strain triangular element
K = (B.T @ D @ B) / Det


# Specialize the stiffness matrix for a particular element
coords = np.array([0, -1, 2, 0, 0, 1, 0.25])
indices = np.array([2, 3, 4, 5, 6, 7, 8])
vfunc = np.vectorize(lambda a: a.partial(indices, coords).expand().to_constant())
K_special = vfunc(K)

expected = np.array([
    [ 2.5  ,  1.25 , -2.   , -1.5  , -0.5  ,  0.25 ],
    [ 1.25 ,  4.375, -1.   , -0.75 , -0.25 , -3.625],
    [-2.   , -1.   ,  4.   ,  0.   , -2.   ,  1.   ],
    [-1.5  , -0.75 ,  0.   ,  1.5  ,  1.5  , -0.75 ],
    [-0.5  , -0.25 , -2.   ,  1.5  ,  2.5  , -1.25 ],
    [ 0.25 , -3.625,  1.   , -0.75 , -1.25 ,  4.375]
]) / (0.9375 * 64)
assert np.allclose(expected, K_special)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rust_poly-0.1.2.tar.gz (8.2 MB view details)

Uploaded Source

Built Distributions

rust_poly-0.1.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl (401.4 kB view details)

Uploaded PyPy manylinux: glibc 2.5+ x86-64

rust_poly-0.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl (401.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.5+ x86-64

rust_poly-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl (398.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

rust_poly-0.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl (401.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.5+ x86-64

rust_poly-0.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl (402.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.5+ x86-64

rust_poly-0.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (401.9 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.5+ x86-64

rust_poly-0.1.2-cp36-cp36m-manylinux_2_24_x86_64.whl (398.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.24+ x86-64

rust_poly-0.1.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl (398.5 kB view details)

Uploaded CPython 3.6m manylinux: glibc 2.5+ x86-64

File details

Details for the file rust_poly-0.1.2.tar.gz.

File metadata

  • Download URL: rust_poly-0.1.2.tar.gz
  • Upload date:
  • Size: 8.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.12.7-beta.8

File hashes

Hashes for rust_poly-0.1.2.tar.gz
Algorithm Hash digest
SHA256 68b0770cfc411c051c66cadf3eef80453e96eed55d9a35e88edd0efceeade67b
MD5 fb08bafe03a3dcd8f758542e22b5abb0
BLAKE2b-256 437f312a19e6c8d1c5ae51cc6bf87183f341bb09f6d92cc90b2db6bd8b797265

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-pp37-pypy37_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0b3619c7174c1dc2bf99b5f04ce0e535a47ec639c2f6e21e84489a2d751da9ab
MD5 7bb1da42c68a607d4f476acf037e47aa
BLAKE2b-256 01d750403a937d0b686009c42407cebe8972e22c016c13eae156f43390d8ade1

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 98ae816fce3ceb9dc5151a9ef320cc083ed2364474ac7f3cfd90db8c406e447e
MD5 25ad571f46682618a74d0775edc89ff6
BLAKE2b-256 ca571dcc0cd8e569d4073341e8dde9417785e2d97f6b0d703b1bc232d4820b61

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 09f3d55841df0f903d153dcc9f7a5591d312658d27dfd36bcbc4170223608c1c
MD5 3e5b04af661f439b564abefce4b7d54d
BLAKE2b-256 66cc4d23149cd81590950b6e6b1c7ab3b9a66bc1e78469b162a44e9c8a116bab

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5f5fd83ded54cf4b61c9706ea95bd798b01ebc0d809329027419ce3bfca925d4
MD5 fca733237df6588f240f35a2c24008a7
BLAKE2b-256 dcd624597b5d1e9aa862895c1f643f68077d41323ec6a4d18fed3b7cc87ab83d

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 df8953107de2098037e18eef0ae16535d89912237e2760ae25db7b4eb76b742e
MD5 96fa85c8442d196117dd4cc091cf8e34
BLAKE2b-256 b2e705f3b297a1cc0d46319aa1f68280f10c900b5820ba2c36a28fac43e9228d

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d697eaaf9fa1407740f4f14674e7a945e9d5fdc8ef968922cb56af7dafba4a01
MD5 d8b21f4740fe8ffb7de81df647d6f090
BLAKE2b-256 f14020124a3e72804d48671cd1d85df4e1ea2bf39b5e7f9ef43f87cebbe185a4

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp36-cp36m-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp36-cp36m-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 7d55568d659fe1ea598df6bdc17d10b606ce6d069303378a19511343d79cb831
MD5 7e0829565dd34bf8c6af79af7f444dd1
BLAKE2b-256 f724d2f42a2e0471dce5e8fcbbc459636f4760138f5ceff4fcad752de5a9b25d

See more details on using hashes here.

File details

Details for the file rust_poly-0.1.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for rust_poly-0.1.2-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5668f60ae201e9ac704fdee3ede6d6c3d47f0f17731ff95229e4a2605991aafe
MD5 d0ec0f78062186f956f893ce893124b4
BLAKE2b-256 6e6db06355778e38924d4ee94247dbd9c3d3d94669f54a5246d9144a97f85338

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page