Beispiel #1
0
errorType = [
    '$|| u - u_h||_{\Omega,0}$', '$||\\nabla u - \\nabla u_h||_{\Omega, 0}$'
]
errorMatrix = np.zeros((2, maxit), dtype=np.float)
NDof = np.zeros(maxit, dtype=np.float)

for i in range(maxit):
    space = LagrangeFiniteElementSpace(mesh, p=p)
    NDof[i] = space.number_of_global_dofs()

    uh = space.function()
    A = space.stiff_matrix()
    F = space.source_vector(pde.source)

    bc = NeumannBC(space, pde.neumann)
    A, F = bc.apply(
        F, A=A)  # Here is the case for pure Neumann bc, we also need modify A
    # bc.apply(F) # Not pure Neumann bc case
    uh[:] = spsolve(A, F)[:-1]  # we add a addtional dof

    # Here can not work
    #ml = pyamg.ruge_stuben_solver(A)
    #x = ml.solve(F, tol=1e-12, accel='cg').reshape(-1)
    #uh[:] = x[-1]

    errorMatrix[0, i] = space.integralalg.L2_error(pde.solution, uh)
    errorMatrix[1, i] = space.integralalg.L2_error(pde.gradient, uh.grad_value)

    if i < maxit - 1:
        mesh.uniform_refine()

if d == 2:
Beispiel #2
0
mu = pde.mu
lam = pde.lam
mesh = pde.init_mesh(n=n)
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
plt.show()

space = LagrangeFiniteElementSpace(mesh, p=p)
bc0 = DirichletBC(space, pde.dirichlet, threshold=pde.is_dirichlet_boundary)
bc1 = NeumannBC(space, pde.neumann, threshold=pde.is_neumann_boundary)

uh = space.function(dim=2)
A = space.linear_elasticity_matrix(mu, lam)
F = space.source_vector(pde.source, dim=2)
bc1.apply(F)
A, F = bc0.apply(A, F, uh)
uh.T.flat[:] = spsolve(A, F)

scale = np.arange(1.0, scale, 0.1)
node = mesh.entity('node')
fname = 'test'
for val in scale:
    mesh.node = node + val * uh
    fig = plt.figure()
    axes = fig.gca()
    mesh.add_plot(axes)
    plt.savefig(fname + str(val) + '.png')

plt.close()
Beispiel #3
0
pde = BoxDomain2DData()

mesh = pde.init_mesh(n=n)

area = mesh.entity_measure('cell')

space = LagrangeFiniteElementSpace(mesh, p=p)

bc0 = DirichletBC(space, pde.dirichlet, threshold=pde.is_dirichlet_boundary)
bc1 = NeumannBC(space, pde.neumann, threshold=pde.is_neumann_boundary)

uh = space.function(dim=2)  # (gdof, 2) and vector fem function uh[i, j]
P = space.stiff_matrix(c=2 * pde.mu)
A = space.linear_elasticity_matrix(pde.mu, pde.lam)  # (2*gdof, 2*gdof)
F = space.source_vector(pde.source, dim=2)
F = bc1.apply(F)
A, F = bc0.apply(A, F, uh)

print(A.shape)

if False:
    uh.T.flat[:] = spsolve(A, F)  # (2, gdof ).flat
elif False:
    N = len(F)
    print(N)
    ilu = spilu(A.tocsc(), drop_tol=1e-6, fill_factor=40)
    M = LinearOperator((N, N), lambda x: ilu.solve(x))
    start = timer()
    uh.T.flat[:], info = cg(A, F, tol=1e-8, M=M)  # solve with CG
    print(info)
    end = timer()
Beispiel #4
0
p = int(sys.argv[2])

pde = BeamData2d(E=2 * 10**6, nu=0.3)
mu = pde.mu
lam = pde.lam
mesh = pde.init_mesh(n=n)

space = LagrangeFiniteElementSpace(mesh, p=p, q=4)
uh = space.function(dim=2)

A = space.linear_elasticity_matrix(lam, mu)
#A = space.recovery_linear_elasticity_matrix(lam, mu)
F = space.source_vector(pde.source, dim=2)

bc = NeumannBC(space, pde.neumann, threshold=pde.is_neumann_boundary)
F = bc.apply(F)

bc = DirichletBC(space, pde.dirichlet, threshold=pde.is_dirichlet_boundary)
A, F = bc.apply(A, F, uh)

ctx = DMumpsContext()
ctx.set_silent()
if ctx.myid == 0:
    ctx.set_centralized_sparse(A)
    x = F.copy()
    ctx.set_rhs(x)  # Modified in place
    ctx.run(job=6)  # Analysis + Factorization + Solve
    ctx.destroy()  # Cleanup

uh.T.flat[:] = x
# uh.T.flat[:] = spsolve(A, F) # (2, gdof ).flat