Example #1
0
    def solve_poisson_3d(self, n=2):
        from fealpy.pde.poisson_3d import CosCosCosData as PDE
        from fealpy.mesh import MeshFactory
        from fealpy.functionspace import LagrangeFiniteElementSpace
        from fealpy.boundarycondition import DirichletBC

        pde = PDE()
        mf = MeshFactory()
        m = 2**n
        box = [0, 1, 0, 1, 0, 1]
        mesh = mf.boxmesh3d(box, nx=m, ny=m, nz=m, meshtype='tet')
        space = LagrangeFiniteElementSpace(mesh, p=1)
        gdof = space.number_of_global_dofs()
        NC = mesh.number_of_cells()
        print('gdof:', gdof, 'NC:', NC)
        bc = DirichletBC(space, pde.dirichlet)
        uh = space.function()
        A = space.stiff_matrix()
        A = space.parallel_stiff_matrix(q=1)

        M = space.parallel_mass_matrix(q=2)
        M = space.mass_matrix()

        F = space.source_vector(pde.source)

        A, F = bc.apply(A, F, uh)

        solver = PETScSolver()
        solver.solve(A, F, uh)
        error = space.integralalg.L2_error(pde.solution, uh)
        print(error)
Example #2
0
mesh = mf.special_boxmesh2d(box, n=10, meshtype='fishbone')

mesh = mf.special_boxmesh2d(box, n=10, meshtype='rice')

mesh = mf.special_boxmesh2d(box, n=10, meshtype='cross')

mesh = mf.special_boxmesh2d(box, n=10, meshtype='nonuniform')

mesh = mf.unitcirclemesh(0.1, meshtype='tri')

mesh = mf.unitcirclemesh(0.1, meshtype='poly')

# 3d mesh
if False:
    box = [0, 1, 0, 1, 0, 1]
    mesh = mf.boxmesh3d(box, nx=1, ny=1, nz=1, meshtype='hex')

    mesh = mf.boxmesh3d(box, nx=1, ny=1, nz=1, meshtype='tet')

# plot
GD = mesh.geo_dimension()
fig = plt.figure()
if GD == 2:
    axes = fig.gca()
    mesh.add_plot(axes)
#    mesh.find_node(axes, showindex=True)
#    mesh.find_cell(axes, showindex=True)
elif GD == 3:
    axes = fig.gca(projection='3d')
    mesh.add_plot(axes)
Example #3
0
 def space_mesh(self, n=32):
     from fealpy.mesh import MeshFactory
     mf = MeshFactory()
     mesh = mf.boxmesh3d(self.domain, nx=n, ny=n, meshtype='tet')
     return mesh
Example #4
0
        writer.SetFileName(fname)
        writer.SetInputData(vmesh)
        writer.Write()


if __name__ == '__main__':
    """
    python3 ConcentrationDG3d.py 0 20 20000 500 /home/why/result/c/3d
    """

    mf = MeshFactory()

    m = int(sys.argv[1])
    if m == 0:
        mesh = mf.boxmesh3d([0, 1, 0, 1, 0, 1],
                            nx=10,
                            ny=10,
                            nz=10,
                            meshtype='tet')
        vdata = VelocityData_0()
        cdata = ConcentrationData_0()

    T = float(sys.argv[2])
    NT = int(sys.argv[3])
    step = int(sys.argv[4])
    timeline = UniformTimeLine(0, T, NT)
    options = {'rdir': sys.argv[5], 'step': step, 'porosity': 0.2}

    model = ConcentrationDG3d(vdata, cdata, mesh, timeline, options=options)
    model.solve()