Ejemplo n.º 1
0
    def __init__(self, model, mesh, interval, N):
        super(HeatEquationSolver, self).__init__(interval)
        self.model = model
        self.dt = (interval[1] - interval[0])/N

        V = function_space(mesh, 'Lagrange', 1)
        uh = FiniteElementFunction(V)
        uh[:] = model.init_value(V.interpolation_points())

        self.solution = [uh]

        self.BC = DirichletBC(V, model.dirichlet, model.is_dirichlet_boundary)
        self.stiff_matrix = LaplaceSymetricForm(V, 3).get_matrix()
        self.mass_matrix = MassForm(V, 3).get_matrix()
Ejemplo n.º 2
0
    def __init__(self, model, mesh, initTime, stopTime, N, method='FM'):
        super(HeatEquationSolver, self).__init__(initTime, stopTime)
        self.model = model
        self.N = N
        self.dt = (stopTime - initTime)/N
        self.method = method
        self.V = function_space(mesh, 'Lagrange', 1)
        uh = FiniteElementFunction(self.V)
        uh[:] = model.init_value(self.V.interpolation_points())

        self.solution = [uh]
        self.maxError = 0.0 
        self.stiffMatrix = LaplaceSymetricForm(self.V, 3).get_matrix()
        self.massMatrix = MassForm(self.V, 3).get_matrix()
Ejemplo n.º 3
0
from fealpy.model.poisson_model_2d import CosCosData

degree = int(sys.argv[1]) 
qt = int(sys.argv[2])  
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)
Ejemplo n.º 4
0
degree = int(sys.argv[1])

point = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 0, 1],
                  [1, 0, 1], [1, 1, 1], [0, 1, 1]],
                 dtype=np.float)

cell = np.array([[0, 1, 2, 3, 4, 5, 6, 7]], dtype=np.int)

tree = Octree(point, cell)
tree.uniform_refine()
isLeafCell = tree.is_leaf_cell()
print('child', tree.child)
print('isLeafCell', isLeafCell)

mesh = HexahedronMesh(tree.point, tree.ds.cell[isLeafCell])

V = function_space(mesh, 'Q', degree)
cell2dof = V.cell_to_dof()
ipoints = V.interpolation_points()

ax0 = a3.Axes3D(pl.figure())
ax1 = a3.Axes3D(pl.figure())
mesh.add_plot(ax0)
mesh.find_point(ax0, showindex=True)

mesh.add_plot(ax1)
mesh.find_point(ax1, point=ipoints, showindex=True)
mesh.print()
print('cell2dof:\n', cell2dof)
pl.show()
Ejemplo n.º 5
0
    N = mesh.number_of_points()
    I = spdiags(np.ones(N, dtype=np.float), 0, N, N)
    P = np.zeros((N, n-1), dtype=np.float)

    for i in range(1, n):
        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