Exemple #1
0
    def save_mesh(self, p=2, fname='test.vtu'):
        mf = MeshFactory()

        mesh = mf.boxmesh2d([0, 1, 0, 1], nx=2, ny=2, meshtype='tri')
        node = mesh.entity('node')
        cell = mesh.entity('cell')

        mesh = LagrangeTriangleMesh(node, cell, p=p)
        mesh.to_vtk(fname=fname)
Exemple #2
0
    def surface_mesh(self, p=2, fname='surface.vtu'):
        from fealpy.geometry import SphereSurface, EllipsoidSurface, SphereSurfaceTest

        surface = SphereSurface()
        #surface = SphereSurfaceTest()
        #surface = EllipsoidSurface()
        #surface = ScaledSurface(surface,scale=[9,3,1])
        mesh = surface.init_mesh()

        node = mesh.entity('node')
        cell = mesh.entity('cell')

        lmesh = LagrangeTriangleMesh(node, cell, p=p, surface=surface)
        NC = lmesh.number_of_cells()
        a = lmesh.cell_area()
        lmesh.to_vtk(fname=fname)
    def interpolation(self, p=2, n=1, fname='surface.vtu'):
        from fealpy.geometry import SphereSurface
        from fealpy.pde.surface_poisson_model_3d import SphereSinSinSinData

        pde = SphereSinSinSinData()
        surface = pde.domain()
        mesh = pde.init_mesh(n=n)

        node = mesh.entity('node')
        cell = mesh.entity('cell')

        mesh = LagrangeTriangleMesh(node, cell, p=p, surface=surface)
        space = ParametricLagrangeFiniteElementSpace(mesh, p=p)

        uI = space.interpolation(pde.solution)
        mesh.nodedata['uI'] = uI[:]
        error0 = space.integralalg.error(pde.solution, uI.value)
        error1 = space.integralalg.error(pde.gradient, uI.grad_value)
        print(error0, error1)
        mesh.to_vtk(fname=fname)
Exemple #4
0
    # 封闭曲面,设置其第 0 个插值节点的值为真解值
    bc = DirichletBC(space, pde.solution)
    A, F = bc.apply(A, F, uh, threshold=np.array([0]))
    uh[:] = spsolve(A, F).reshape(-1)

    uI = space.interpolation(pde.solution)
    errorMatrix[0, i] = space.integralalg.error(pde.solution,
                                                uh.value,
                                                linear=False)
    errorMatrix[1, i] = space.integralalg.error(pde.gradient,
                                                uh.grad_value,
                                                linear=False)
    errorMatrix[2, i] = space.integralalg.error(pde.solution,
                                                uI.value,
                                                linear=False)
    errorMatrix[3, i] = space.integralalg.error(pde.gradient,
                                                uI.grad_value,
                                                linear=False)

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

lmesh.nodedata['uh'] = uh
lmesh.nodedata['uI'] = uI

lmesh.to_vtk(fname='surface_with_solution.vtu')
show_error_table(NDof, errorType, errorMatrix)
showmultirate(plt, 0, NDof, errorMatrix, errorType, propsize=20)
plt.show()
Exemple #5
0
from fealpy.mesh import LagrangeTriangleMesh, MeshFactory, LagrangeWedgeMesh
from fealpy.writer import MeshWriter

#p = int(sys.argv[1])
#n = int(sys.argv[2])
#h = sys.argv[3]
#nh = int(sys.argv[4])

fname = 'initial/file1.vtu'
data = meshio.read(fname)
node = data.points
cell = data.cells[0][1]

mesh = LagrangeTriangleMesh(node*500, cell, p=1)
mesh.uniform_refine(n=0)
mesh = LagrangeWedgeMesh(mesh, h=0.005, nh=1, p=1)

edge = mesh.entity('edge')
node = mesh.entity('node')
cell = mesh.entity('cell')
tface, qface = mesh.entity('face')

print(tface.shape)

mesh.celldata['a'] = np.arange(len(cell))
mesh.to_vtk(fname='write.vtu')