Exemplo n.º 1
0
def vector(dx, dt, tau, I0, r02, k_sc, k_abs, rho, Cv, T0):
    nx = 2 ** dx # number of points in space
    nt = 2 ** dt # number of points in time
    
    bx = 1 # [0, b] - interval
    hx = bx / (nx - 1) # step 
    bt = 1 # [0, b] - interval
    ht = bt / (nt - 1) # step 
    
    
    x = hx * tt.xfun(2, dx) # coordinates generation
    ex = tt.ones(2, dx)
    t = ht * tt.xfun(2, dt) # coordinates generation
    et = tt.ones(2, dt)

    t0 = (T0 - 1)*tt.delta(2, dx, center = 0) # initial conditions for spatial
    t0 = tt.mkron(ex, ex, ex, et) + tt.mkron(t0, t0, t0, et)
    
    X = tt.mkron(x, ex, ex, et)
    Y = tt.mkron(ex, x, ex, et)
    Z = tt.mkron(ex, ex, x, et)
    T = tt.mkron(ex, ex, ex, t)
    
    Qs = tt.multifuncrs([X, Y, Z, T], lambda arg: I0 * (arg[:, 3]/tau *np.exp(-arg[:, 3]/tau)) * 
                        (np.exp( -(arg[:,1]**2 - arg[:,2]**2) / r02*np.exp(k_sc*arg[:,0]) ) * 
                         np.exp(-(k_sc + k_abs) * arg[:, 0]))  , 1e-14, verb = True)
    Qs = Qs + t0
    Qs = Qs.round(1e-14)
    
    return 1/(rho*Cv) * Qs
Exemplo n.º 2
0
def plot_patch(mesh_container, x, d, vmin=0, vmax=1, contours=True):
    px = zkronv(tt.xfun(2, d), tt.ones(2, d))
    py = zkronv(tt.ones(2, d), tt.xfun(2, d))
    px = px.full().flatten('F').astype(np.int)
    py = py.full().flatten('F').astype(np.int)

    pts = np.array([mesh_container._pts(ex, ey) for ex, ey in zip(px, py)])
    tri = Delaunay(pts)
    plt.tripcolor(pts[:, 0],
                  pts[:, 1],
                  tri.simplices.copy(),
                  x,
                  shading='gouraud',
                  vmin=vmin,
                  vmax=vmax)
    if contours:
        plt.tricontour(pts[:, 0],
                       pts[:, 1],
                       tri.simplices.copy(),
                       x,
                       np.linspace(vmin, vmax, 11),
                       colors='k')
    d = mesh_container.d
    p1 = mesh_container._pts(0, 0)
    p2 = mesh_container._pts(2**d - 1, 0)
    p3 = mesh_container._pts(2**d - 1, 2**d - 1)
    p4 = mesh_container._pts(0, 2**d - 1)
    plt.plot([p1[0], p2[0], p3[0], p4[0]], [p1[1], p2[1], p3[1], p4[1]], 'm')
Exemplo n.º 3
0
def vector(dx, dt, tau, I0, r02, k_sc, k_abs):
    nx = 2 ** dx # number of points in space
    nt = 2 ** dt # number of points in time
    
    bx = 1 # [0, b] - interval
    hx = bx / (nx - 1) # step 
    bt = 1 # [0, b] - interval
    ht = bt / (nt - 1) # step 
    
    x = hx * tt.xfun(2, dx) # coordinates generation
    ex = tt.ones(2, dx)
    t = ht * tt.xfun(2, dt) # coordinates generation
    et = tt.ones(2, dt)

    X = tt.mkron(x, ex, ex, et)
    Y = tt.mkron(ex, x, ex, et)
    Z = tt.mkron(ex, ex, x, et)
    T = tt.mkron(ex, ex, ex, t)
    
    Qs = tt.multifuncrs([X, Y, Z, T], lambda arg: I0 * (arg[:, 3]/tau *np.exp(-arg[:, 3]/tau)) * 
                        (np.exp( -(arg[:,1]**2 - arg[:,2]**2) / r02*np.exp(k_sc*arg[:,0]) ) * 
                         np.exp(-(k_sc + k_abs) * arg[:, 0]))  , 1e-6, verb = True)
    
    Qs = Qs.round(1e-6)
    
    return Qs
Exemplo n.º 4
0
 def arange(d, mode=MODE_NP, tau=None, name=DEF_VECTOR_NAME):
     res = Vector(None, d, mode, tau, False, name=name)
     if mode == MODE_NP or mode == MODE_SP:
         res.x = np.arange(res.n)
     if mode == MODE_TT:
         res.x = tt.xfun(2, d)
     return res
Exemplo n.º 5
0
def zmeshgrid(d):
    """

    :param d:
    :return:
    """
    # assert d > 2

    lin = tt.xfun(2, d)
    one = tt.ones(2, d)

    xx = zkronv(lin, one)
    yy = zkronv(one, lin)

    return xx, yy
Exemplo n.º 6
0
#!/usr/bin/env python2
#   test_common.py
#   See LICENSE for details
"""Test common matrix operation with QTT-toolbox like matmat-operation and matvec-operation.
"""

from __future__ import print_function, absolute_import, division
import numpy as np
import sys

sys.path.append('../')

import tt

x = tt.xfun(2, 3)
e = tt.ones(2, 2)
X = tt.matrix(x, n=[2] * 3, m=[1] * 3)  # [0, 1, 2, 3, 4, 5, 6, 7]^T
E = tt.matrix(e, n=[1] * 2, m=[2] * 2)  # [1, 1, 1, 1]
#[[ 0.  0.  0.  0.]
# [ 1.  1.  1.  1.]
# [ 2.  2.  2.  2.]
# [ 3.  3.  3.  3.]
# [ 4.  4.  4.  4.]
# [ 5.  5.  5.  5.]
# [ 6.  6.  6.  6.]
# [ 7.  7.  7.  7.]]
print((X * E).full())
assert np.all((X * E) * np.arange(4) == np.arange(8) * 6.)

A = tt.matrix(tt.xfun(2, 3), n=[1] * 3, m=[2] * 3)
u = np.arange(8)
Exemplo n.º 7
0
from __future__ import print_function, absolute_import, division
import sys
sys.path.append('../')
import numpy as np
import tt

d = 30
n = 2 ** d
b = 1E3
h = b / (n + 1)
#x = np.arange(n)
#x = np.reshape(x, [2] * d, order = 'F')
#x = tt.tensor(x, 1e-12)
x = tt.xfun(2, d)
e = tt.ones(2, d)
x = x + e
x = x * h


sf = lambda x : np.sin(x) / x #Should be rank 2

y = tt.multifuncrs([x], sf, 1e-6, y0=tt.ones(2, d))
#y1 = tt.tensor(sf(x.full()), 1e-8)

print("pi / 2 ~ ", tt.dot(y, tt.ones(2, d)) * h)
#print (y - y1).norm() / y.norm()
Exemplo n.º 8
0
#!/usr/bin/env python2
#   test_common.py
#   See LICENSE for details
"""Test common matrix operation with QTT-toolbox like matmat-operation and matvec-operation.
"""

from __future__ import print_function, absolute_import, division
import numpy as np
import sys

sys.path.append('../')

import tt


x = tt.xfun(2, 3)
e = tt.ones(2, 2)
X = tt.matrix(x, n=[2] * 3, m=[1] * 3) # [0, 1, 2, 3, 4, 5, 6, 7]^T
E = tt.matrix(e, n=[1] * 2, m=[2] * 2) # [1, 1, 1, 1]
#[[ 0.  0.  0.  0.]
# [ 1.  1.  1.  1.]
# [ 2.  2.  2.  2.]
# [ 3.  3.  3.  3.]
# [ 4.  4.  4.  4.]
# [ 5.  5.  5.  5.]
# [ 6.  6.  6.  6.]
# [ 7.  7.  7.  7.]]
print((X * E).full())
assert np.all((X * E) * np.arange(4) == np.arange(8) * 6.)

A = tt.matrix(tt.xfun(2, 3), n=[1] * 3, m=[2] * 3)
Exemplo n.º 9
0
from __future__ import print_function, absolute_import, division
import sys
sys.path.append('../')
import numpy as np
import tt

d = 30
n = 2**d
b = 1E3
h = b / (n + 1)
#x = np.arange(n)
#x = np.reshape(x, [2] * d, order = 'F')
#x = tt.tensor(x, 1e-12)
x = tt.xfun(2, d)
e = tt.ones(2, d)
x = x + e
x = x * h

sf = lambda x: np.sin(x) / x  #Should be rank 2

y = tt.multifuncrs([x], sf, 1e-6, y0=tt.ones(2, d))
#y1 = tt.tensor(sf(x.full()), 1e-8)

print("pi / 2 ~ ", tt.dot(y, tt.ones(2, d)) * h)
#print (y - y1).norm() / y.norm()