def __init__(self, model, p, NS=0, NT=100):

        self.model = model  # 物理模型
        self.mesh0 = model.space_mesh(NS=NS, p=p)  # 初始网格
        self.mesh1 = model.space_mesh(NS=NS, p=p)  # 计算网格

        self.timeline = model.time_mesh(NT=NT)  # 时间离散网格

        # 运动学空间
        self.cspace = ParametricLagrangeFiniteElementSpace(self.mesh1,
                                                           p=p,
                                                           spacetype='C')
        # 热力学空间
        self.dspace = ParametricLagrangeFiniteElementSpace(self.mesh1,
                                                           p=p - 1,
                                                           spacetype='D')

        self.integrator = self.cspace.integralalg.integrator

        bc = self.mesh0.entity_barycenter('cell')
        # 物质密度
        self.rho = model.init_rho(bc)  # (NC, )
        # 绝热指数
        self.gamma = model.adiabatic_index(bc)  #(NC, )

        self.MV = self.cspace.mass_matrix(c=self.rho)  # 运动空间的质量矩阵
        self.ME = self.dspace.mass_matrix(c=self.rho)  # 热力学空间的质量矩阵

        GD = self.mesh1.geo_dimension()
        self.x = self.cspace.function(dim=GD)  # 位置
        self.v = self.cspace.function(dim=GD)  # 速度
        self.e = self.dspace.function()  # 能量

        self.x[:] = self.mesh1.entity('node')  # 初始化自由度位置
        model.init_velocity(self.v)  # 初始化速度
        model.init_energe(self.e)  # 初始化能量

        self.cx = self.cspace.function(dim=GD)  # 保存临时的解
        self.cv = self.cspace.function(dim=GD)
        self.ce = self.dspace.function()

        self.cx[:] = self.mesh1.entity('node')
        model.init_velocity(self.cv)
        model.init_energe(self.ce)

        self.mesh1.celldata['rho'] = self.rho
        self.mesh1.celldata['gamma'] = self.gamma
        self.mesh1.nodedata['velocity'] = self.cv
    def plane_quad_interpolation(self, p=2, fname='plane.vtu'):
        from fealpy.pde.poisson_2d import CosCosData
        from fealpy.mesh import LagrangeQuadrangleMesh
        pde = CosCosData()
        node = np.array([(0, 0), (0, 1), (1, 0), (1, 1)], dtype=np.float64)
        cell = np.array([(0, 1, 2, 3)], dtype=np.int_)

        mesh = LagrangeQuadrangleMesh(node, cell, p=p)

        for i in range(4):
            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)
            if i < 3:
                mesh.uniform_refine()

        mesh.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)
Ejemplo n.º 4
0
mesh.uniform_refine(n=nrefine)

errorType = [
    '$|| u - u_h||_{\Omega,0}$', '$||\\nabla u - \\nabla u_h||_{\Omega, 0}$',
    '$|| u - u_I||_{\Omega,0}$', '$||\\nabla u - \\nabla u_I||_{\Omega, 0}$',
    '$|| u_I - u_h ||_{\Omega, \infty}$'
]
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float64)
NDof = np.zeros(maxit, dtype=np.int_)

m = 4

for i in range(maxit):
    print("The {}-th computation:".format(i))

    space = ParametricLagrangeFiniteElementSpace(mesh, p=sdegree)
    NDof[i] = space.number_of_global_dofs()

    uI = space.interpolation(pde.solution)

    A = space.stiff_matrix()
    C = space.integral_basis()
    F = space.source_vector(pde.source)

    NN = mesh.number_of_corner_nodes()
    NC = mesh.number_of_cells()
    delta = (A @ uI - F)

    A = bmat([[A, C.reshape(-1, 1)], [C, None]], format='csr')
    F = np.r_[F, 0]
Ejemplo n.º 5
0
    def __init__(self, mesh):
        self.space = ParametricLagrangeFiniteElementSpace(mesh, p=1)
        self.mesh = self.space.mesh

        self.M = self.space.mass_matrix()
        self.A = self.space.stiff_matrix()
Ejemplo n.º 6
0
parser.print_help()
args = parser.parse_args()
print(args)

# 开始主程序

pde = PDE()

mf = MeshFactory()

# 创建一个双 p 次的四边形网格
mesh = mf.boxmesh2d(args.b, nx=args.n, ny=args.n, meshtype='quad', p=args.p)

# 在 mesh 上创建一个双 p 次的有限元函数空间
space = ParametricLagrangeFiniteElementSpace(mesh, p=args.p, spacetype='C')

# 数值解函数
uh = space.function()

# 组装刚度矩阵
A = space.stiff_matrix()

# 右端载荷
F = space.source_vector(pde.source)

# 定义边界条件
bc = DirichletBC(space, pde.dirichlet)

# 处理边界条件
A, F = bc.apply(A, F, uh)