Beispiel #1
0
    def get_current_linear_system(self):
        V = self.V
        model = self.model

        t = self.currentTime

        S = self.stiffMatrix
        M = self.massMatrix
        k = model.diffusion_coefficient()
        bc = DirichletBC(self.V, lambda p: model.dirichlet(p, t), model.is_dirichlet_boundary)
        F = SourceForm(V, lambda p: model.source(p, t), 3).get_vector() 
        dt = self.dt
        if self.method is 'FM':
            b = dt*(F - k*[email protected][-1]) + [email protected][-1]
            A, b = bc.apply(M, b) 
            return A, b
        if self.method is 'BM':
            b = dt*F + [email protected][-1]
            A = M + dt*k*S
            A, b = bc.apply(A, b)
            return A, b
        if self.method is 'CN':
            b = dt*F + (M - 0.5*dt*k*S)@self.solution[-1]
            A = M + 0.5*dt*k*S
            A, b = bc.apply(A, b)
            return A, b
Beispiel #2
0
n = int(sys.argv[3])

box = [0, 1, 0, 1]

model = CosCosData()
mesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='tri') 
maxit = 4 
Ndof = np.zeros(maxit, dtype=np.int)
error = np.zeros(maxit, dtype=np.float)
ratio = np.zeros(maxit, dtype=np.float)
for i in range(maxit):
    V = function_space(mesh, 'Lagrange', degree)
    uh = FiniteElementFunction(V)
    Ndof[i] = V.number_of_global_dofs() 
    a  = LaplaceSymetricForm(V, qt)
    L = SourceForm(V, model.source, qt)
    bc = DirichletBC(V, model.dirichlet, model.is_boundary)
    point = V.interpolation_points()
    solve(a, L, uh, dirichlet=bc, solver='direct')
    error[i] = L2_error(model.solution, uh, order=qt) 
    # error[i] = np.sqrt(np.sum((uh - model.solution(point))**2)/Ndof[i])
    if i < maxit-1:
        mesh.uniform_refine()

# 输出结果
ratio[1:] = error[0:-1]/error[1:]
print('Ndof:', Ndof)
print('error:', error)
print('ratio:', ratio)

#fig = plt.figure()
Beispiel #3
0
        P[:, i-1] = sinsin(i, point)

    return bmat([[I, P]])


box = [0, 1, 0, 1]
n = 6 
model = CosCosData()
mesh = rectangledomainmesh(box, nx=2**n, ny=2**n, meshtype='tri') 
N = mesh.number_of_points()
V = function_space(mesh, 'Lagrange', 1)
point = V.interpolation_points()

uh = FiniteElementFunction(V)
a  = LaplaceSymetricForm(V, 3)
L = SourceForm(V, model.source, 3)
bc = DirichletBC(V, model.dirichlet, model.is_boundary)

A = a.get_matrix()
b = L.get_vector()
A, b = bc.apply(A, b)

PI = prolongate_matrix(mesh, n)
AA = PI.transpose()@A@PI
bb = PI.transpose()@b

DL = tril(AA).tocsc()
DLInv = inv(DL)
U = triu(AA, 1)

x0 = np.zeros(N+n-1, dtype=np.float)
Beispiel #4
0
from fealpy.mesh.simple_mesh_generator import rectangledomainmesh
from fealpy.functionspace.tools import function_space
from fealpy.form.Form import LaplaceSymetricForm, MassForm, SourceForm
from fealpy.boundarycondition import DirichletBC
from fealpy.erroranalysis import L2_error
from fealpy.functionspace.function import FiniteElementFunction

model = SinCosExpData()
box = [0, 1, 0, 1]
n = 10
mesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='tri')
V = function_space(mesh, 'Lagrange', 1)
Ndof = V.number_of_global_dofs()
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