Beispiel #1
0
    def test_simple(self):
        rm = rand(100, 1000, 0.05).tocsc()
        fd, filename = tempfile.mkstemp(suffix="rb")
        try:
            hb_write(filename, rm, HBInfo.from_data(rm))
            m = hb_read(filename)
        finally:
            os.close(fd)
            os.remove(filename)

        assert_csc_almost_equal(m, rm)
    def test_simple(self):
        rm = rand(100, 1000, 0.05).tocsc()
        fd, filename = tempfile.mkstemp(suffix="rb")
        try:
            hb_write(filename, rm, HBInfo.from_data(rm))
            m = hb_read(filename)
        finally:
            os.close(fd)
            os.remove(filename)

        assert_csc_almost_equal(m, rm)
ftop = m.faces_from_pid(pidtop)
fbot = m.faces_from_pid(pidbot)
print "create boundary region"
NEUMANN_BOUNDARY = 1
DIRICHLET_BOUNDARY = 2
m.set_region(NEUMANN_BOUNDARY,ftop)
m.set_region(DIRICHLET_BOUNDARY,fbot)

print "create a MeshFem object"

mfd = gf.MeshFem(m, 1) # data

print "assign the FEM"
mfd.set_fem(gf.Fem('FEM_QK(3,3)'))

print "assembly"
nbd = mfd.nbdof()
K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd))
M = gf.asm_mass_matrix(mim, mfu)*rho

K.save('hb', 'K.hb')
M.save('hb', 'M.hb')

print "solve"

A = io.hb_read('M.hb')
B = io.hb_read('K.hb')

K = B.todense()
np.savetxt("K.txt", K, fmt=' (%+.18e) ')
fbot = m.faces_from_pid(pidbot)
print "create boundary region"
NEUMANN_BOUNDARY = 1
DIRICHLET_BOUNDARY = 2
m.set_region(NEUMANN_BOUNDARY, ftop)
m.set_region(DIRICHLET_BOUNDARY, fbot)

print "create a MeshFem object"

mfd = gf.MeshFem(m, 1)  # data

print "assign the FEM"
mfd.set_fem(gf.Fem('FEM_QK(3,3)'))

print "assembly"
nbd = mfd.nbdof()
K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd),
                             np.repeat([Mu], nbd))
M = gf.asm_mass_matrix(mim, mfu) * rho

K.save('hb', 'K.hb')
M.save('hb', 'M.hb')

print "solve"

A = io.hb_read('M.hb')
B = io.hb_read('K.hb')

K = B.todense()
np.savetxt("K.txt", K, fmt=' (%+.18e) ')
nbd = mfd.nbdof()
K = gf.asm_linear_elasticity(mim, mfu, mfd, np.repeat([Lambda], nbd), np.repeat([Mu], nbd))
M = gf.asm_mass_matrix(mim, mfu)*rho

(H,R) = gf.asm_dirichlet(DIRICHLET_BOUNDARY, mim, mfu, mfd, mfd.eval('[[1,0,0],[0,1,0],[0,0,1]]',globals(),locals()), mfd.eval('[0,0,0]'))
(N,U0) = H.dirichlet_nullspace(R)

Nt = gf.Spmat('copy',N)
Nt.transpose()
KK = Nt*K*N
MM = Nt*M*N

KK.save('hb', 'KK.hb')
MM.save('hb', 'MM.hb')

print "solve"

A = io.hb_read('MM.hb')
B = io.hb_read('KK.hb')

w, v = linalg.eigs(A,M=B)
omega = np.sqrt(1.000e+00/w)/2.000e+00/np.pi

print "post-processing"
np.savetxt("omega.txt", np.real(omega))
np.savetxt("v.txt", np.real(v))

sl = gf.Slice(('boundary',), mfu, 3)
sl.export_to_vtk('m.vtk', mfu, N*np.real(v[:,0]), 'Mode1', mfu, N*np.real(v[:,1]), 'Mode2', mfu, N*np.real(v[:,2]), 'Mode3', mfu, N*np.real(v[:,3]), 'Mode4', mfu, N*np.real(v[:,4]), 'Mode5', mfu, N*np.real(v[:,5]), 'Mode6')

Beispiel #6
0
 def check_save_load(self, value):
     with tempfile.NamedTemporaryFile(mode='w+t') as file:
         hb_write(file, value)
         file.file.seek(0)
         value_loaded = hb_read(file)
     assert_csc_almost_equal(value, value_loaded)
Beispiel #7
0
 def test_simple(self):
     m = hb_read(StringIO(SIMPLE))
     assert_csc_almost_equal(m, SIMPLE_MATRIX)
Beispiel #8
0
 def check_save_load(self, value):
     with tempfile.NamedTemporaryFile(mode='w+t') as file:
         hb_write(file, value)
         file.file.seek(0)
         value_loaded = hb_read(file)
     assert_csc_almost_equal(value, value_loaded)
Beispiel #9
0
 def test_simple(self):
     m = hb_read(StringIO(SIMPLE))
     assert_csc_almost_equal(m, SIMPLE_MATRIX)
    DIRICHLET_BOUNDARY, mim, mfu, mfd,
    mfd.eval('[[1,0,0],[0,1,0],[0,0,1]]', globals(), locals()),
    mfd.eval('[0,0,0]'))
(N, U0) = H.dirichlet_nullspace(R)

Nt = gf.Spmat('copy', N)
Nt.transpose()
KK = Nt * K * N
MM = Nt * M * N

KK.save('hb', 'KK.hb')
MM.save('hb', 'MM.hb')

print "solve"

A = io.hb_read('MM.hb')
B = io.hb_read('KK.hb')

w, v = linalg.eigs(A, M=B)
omega = np.sqrt(1.000e+00 / w) / 2.000e+00 / np.pi

print "post-processing"
np.savetxt("omega.txt", np.real(omega))
np.savetxt("v.txt", np.real(v))

sl = gf.Slice(('boundary', ), mfu, 3)
sl.export_to_vtk('m.vtk', mfu, N * np.real(v[:, 0]), 'Mode1', mfu,
                 N * np.real(v[:, 1]), 'Mode2', mfu, N * np.real(v[:, 2]),
                 'Mode3', mfu, N * np.real(v[:, 3]), 'Mode4', mfu,
                 N * np.real(v[:, 4]), 'Mode5', mfu, N * np.real(v[:, 5]),
                 'Mode6')
Beispiel #11
0
###############################################################################
# Solve the eigenproblem.
#
# Compute the residual error for SciPy.
#
# :math:`Err=\frac{||(K-\lambda.M).\phi||_2}{||K.\phi||_2}`
#
# Convert Lambda values to Frequency values:
# :math:`freq = \frac{\sqrt(\lambda)}{2.\pi}`
#

for i, (mass_matrix, linear_elasticity,
        mfu) in enumerate(zip(mass_matrixs, linear_elasticitys, mfus)):

    M = io.hb_read("M" + "{:02}".format(i) + ".hb")
    K = io.hb_read("K" + "{:02}".format(i) + ".hb")
    vals, vecs = linalg.eigsh(A=K, k=6, M=M, sigma=400.0, which="LA")

    omegas = np.sqrt(np.abs(vals))
    freqs = omegas / (2.0 * np.pi)

    nev = 6

    scipy_acc = np.zeros(nev)

    print(f"case{i}")

    for j in range(nev):
        lam = vals[j]  # j-th eigenvalue
        phi = vecs.T[j]  # j-th eigenshape