Beispiel #1
0
    def apply_boundary_condition(self, A, b, uh, timeline):
        from fealpy.boundarycondition import RobinBC
        from fealpy.boundarycondition import NeumannBC
        from fealpy.boundarycondition import DirichletBC
        t0 = timeline.current_time_level()
        t1 = timeline.next_time_level()
        i = timeline.current

        # 对 robin 边界条件进行处理
        bc = RobinBC(self.space,
                     lambda x, n: self.pde.robin(x, n, t0),
                     threshold=self.pde.is_robin_boundary)
        A0, b = bc.apply(A, b)

        # 对 neumann 边界条件进行处理
        bc = NeumannBC(self.space,
                       lambda x, n: self.pde.neumann(x, n, t0),
                       threshold=self.pde.is_neumann_boundary)
        b = bc.apply(b)  # 混合边界条件不需要输入矩阵A
        return b
Beispiel #2
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()
Beispiel #3
0

n = int(sys.argv[1])
p = int(sys.argv[2])
scale = float(sys.argv[3])

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)
Beispiel #4
0
n = int(sys.argv[1])
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