def __init__(self, pde, mesh, p, dt): self.pde = pde self.p = p self.mesh = mesh self.timemesh, self.dt = self.pde.time_mesh(dt) self.itype = self.mesh.itype self.ftype = self.mesh.ftype self.pde = pde self.space = LagrangeFiniteElementSpace(mesh, p) self.dof = self.space.dof self.cellmeasure = mesh.entity_measure('cell') self.integralalg = FEMeshIntegralAlg(self.mesh, p + 4, cellmeasure=self.cellmeasure) self.uh = self.space.function() self.wh = self.space.function() self.StiffMatrix = self.space.stiff_matrix() self.MassMatrix = self.space.mass_matrix()
def __init__(self, pde, mesh, p, dt, T): self.p = p self.mesh = mesh self.dt = dt self.T = T self.itype = self.mesh.itype self.ftype = self.mesh.ftype self.pde = pde self.vspace = LagrangeFiniteElementSpace(mesh, p+1) self.pspace = LagrangeFiniteElementSpace(mesh, p) self.vdof = self.vspace.dof self.pdof = self.pspace.dof self.cellmeasure = mesh.entity_measure('cell') self.integralalg = FEMeshIntegralAlg(self.mesh, p+4, cellmeasure=self.cellmeasure) self.uh0 = self.vspace.function() self.uh1 = self.vspace.function() self.ph = self.pspace.function()
p = 1 n = 3 #pde = SpaceMeasureDiracSourceData() pde = TimeMeasureDiracSourceData() mesh = pde.init_mesh(n) node = mesh.entity('node') cell = mesh.entity('cell') print('cell', cell.shape) bc = mesh.entity_barycenter('cell') integrator = mesh.integrator(p + 2) cellmeasure = mesh.entity_measure('cell') space = LagrangeFiniteElementSpace(mesh, p, spacetype='C') integralalg = FEMeshIntegralAlg(integrator, mesh) uI = space.interpolation(lambda x: pde.solution(x, t)) #uI = pde.solution(node,p=node, t=t) gu = pde.gradient #uI = space.function() guI = uI.grad_value eta = integralalg.L2_error(gu, guI, celltype=True) # size = (cell.shape[0], 2) eta = np.sum(eta, axis=-1) print('eta', eta.shape) tmesh = TriangleMesh(node, cell) mark = mark(eta, 0.75) options = tmesh.adaptive_options(method='mean', maxrefine=10, maxcoarsen=0, theta=0.5)
grad = self.gradient(p) # (NQ, NE, 2) val = np.sum(grad * n, axis=-1) shape = len(val.shape) * (1, ) kappa = np.array([1.0], dtype=np.float64).reshape(shape) val += self.solution(p) return val, kappa p = 1 q = 3 pde = CosCosData() print(pde.a) domain = pde.domain() mesh = MF.boxmesh2d(domain, nx=10, ny=10, meshtype='tri') intalg = FEMeshIntegralAlg(mesh, q) c = intalg.mesh_integral(pde.solution, q=q, power=2) print(c) space = LagrangeFiniteElementSpace(mesh, p=p) node = mesh.entity('node') # (NN, 2) uI = pde.solution(node) # ndarray (NN, ) uI = space.function(array=uI) # 返回一个有限元函数对象 fig0 = plt.figure() axes = fig0.gca() mesh.add_plot(axes)