Beispiel #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
Beispiel #2
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
Beispiel #3
0
def get_space_transorm_jacobians(mesh_container, eps, verbose=False):
    detJ = get_jacobian_determinants(mesh_container)

    # 1/detJ
    idetJ = tt.multifuncrs([detJ], lambda x: 1. / x, eps=eps, verb=False)

    if verbose: print 'idetJ.erank =', idetJ.erank

    # J = [[j11, j12], [j21, j22]]
    j11, j12, j21, j22 = get_jacobian_components(mesh_container)

    # J^A J^AT/detJ в векторизованом виде (для каждого элемента)
    TJ11 = (j22 * j22 + j12 * j12) * idetJ
    TJ11 = TJ11.round(eps)

    TJ22 = (j11 * j11 + j21 * j21) * idetJ
    TJ22 = TJ22.round(eps)

    TJ12 = -(j22 * j21 + j12 * j11) * idetJ
    TJ12 = TJ12.round(eps)

    return TJ11, TJ12, TJ22, detJ
Beispiel #4
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()
Beispiel #5
0
import sys
sys.path.append("../")
import tt
#import ctypes as ct
#ct.CDLL("libblas.so.3", ct.RTLD_GLOBAL)
#ct.CDLL("libcblas.so.1", ct.RTLD_GLOBAL)
#ct.CDLL("liblapacke.so", ct.RTLD_GLOBAL)
import numpy as np

a = tt.rand([3, 5, 7, 11], 4, [1, 4, 6, 5, 1])
b = tt.rand([3, 5, 7, 11], 4, [1, 2, 4, 3, 1])

c = tt.multifuncrs([a, b], lambda x: np.sum(x, axis=1), eps=1E-6)

print "Relative error norm:", (c - (a + b)).norm() / (a + b).norm()









Beispiel #6
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()
Beispiel #7
0
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()