示例#1
0
mu = float(sys.argv[3])
stype = sys.argv[4]

pde = PolyModel3d(lam=lam, mu=mu) 

mesh = pde.init_mesh(n=n)

NN = mesh.number_of_nodes()
print("NN:", 3*NN)

space = LagrangeFiniteElementSpace(mesh, p=1)

bc = DirichletBC(space, pde.dirichlet)

uh = space.function(dim=3)
A = space.linear_elasticity_matrix(pde.lam, pde.mu, q=1)
F = space.source_vector(pde.source, dim=3)
A, F = bc.apply(A, F, uh)

I = space.rigid_motion_matrix()
S = space.stiff_matrix(2*pde.mu)
S = bc.apply_on_matrix(S)

solver = LinearElasticityLFEMFastSolver_1(A, S, I, stype=stype, drop_tol=1e-6,
        fill_factor=40) 

solver.solve(uh, F)
error = space.integralalg.error(pde.displacement, uh)
print(error)

示例#2
0
A = LaplaceSymetricForm(V, 3).get_matrix()
M = MassForm(V, 3).get_matrix()
b = SourceForm(V, model.source, 1).get_vector()
BC = DirichletBC(V, model.dirichlet, model.is_dirichlet_boundary)

T0 = 0.0
T1 = 1
N = 400
dt = (T1 - T0) / N
print(dt)

uh = FiniteElementFunction(V)
uh[:] = model.init_value(V.interpolation_points())

uht = [uh]
MD = BC.apply_on_matrix(M)
for i in range(1, N + 1):
    t = T0 + i * dt

    AD = M + dt / 16 * A
    F = M @ uht[i - 1] + dt * b
    AD, F = BC.apply(AD, F)
    uh = FiniteElementFunction(V)
    uh[:] = spsolve(AD, F)

    #    F = dt*(b - 1/16*A@uht[i-1]) + M@uht[i-1]
    #    F = BC.apply_on_source_vector(F, M)
    #    uh[:] = spsolve(MD, F)
    uht.append(uh)
    e = L2_error(lambda p: model.solution(p, t), uh)
    print(e)