def __init__(self, mesh, options=None): if options == None: options = scftmodel_options() self.options = options self.vemspace = ConformingVirtualElementSpace2d(mesh, p=options['order']) self.mesh = self.vemspace.mesh self.totalArea = np.sum(self.vemspace.smspace.cellmeasure) self.count = 0 fA = options['fA'] T0 = options['T0'] T1 = options['T1'] self.timeline0 = ChebyshevTimeLine(0, fA, T0) self.timeline1 = ChebyshevTimeLine(fA, 1, T1) N = T0 + T1 + 1 gdof = self.vemspace.number_of_global_dofs() self.gof = gdof self.q0 = np.zeros((gdof, N), dtype=self.mesh.ftype) self.q1 = np.zeros((gdof, N), dtype=self.mesh.ftype) self.rho = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.grad = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.w = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.sQ1 = np.zeros((N, 1), dtype=self.mesh.ftype) self.sQ = 0.0 nupdate = options['nupdate'] self.A = self.vemspace.stiff_matrix() self.M = self.vemspace.mass_matrix() self.solver = PDESolver(self.A, self.M, nupdate) self.eta_ref = 0
def reinit(self, mesh): options = self.options self.vemspace = ConformingVirtualElementSpace2d(mesh, p=options['order']) self.mesh = self.vemspace.mesh self.totalArea = np.sum(self.vemspace.smspace.cellmeasure) fA = options['fA'] T0 = options['T0'] T1 = options['T1'] self.timeline0 = ChebyshevTimeLine(0, fA, T0) self.timeline1 = ChebyshevTimeLine(fA, 1, T1) N = T0 + T1 + 1 gdof = self.vemspace.number_of_global_dofs() self.gdof = gdof self.q0 = np.ones((gdof, N), dtype=self.mesh.ftype) self.q1 = np.ones((gdof, N), dtype=self.mesh.ftype) self.rho = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.grad = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.w = np.zeros((gdof, 2), dtype=self.mesh.ftype) self.sQ = np.zeros((N, 1), dtype=self.mesh.ftype) self.nupdate = options['nupdate'] self.A = self.vemspace.stiff_matrix() self.M = self.vemspace.mass_matrix() self.F = np.zeros(self.A.shape, dtype=np.float) self.smodel = ParabolicVEMSolver2d(self.A, self.M, self.F) self.eta_ref = 0
def interpolation(self, n=2, plot=True): from fealpy.pde.poisson_2d import CosCosData from fealpy.functionspace import ConformingVirtualElementSpace2d pde = CosCosData() node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float64) cell = np.array([(0, 1, 2, 3)], dtype=np.int_) mesh = QuadrangleMesh(node, cell) #mesh = PolygonMesh.from_mesh(mesh) mesh = HalfEdgeMesh2d.from_mesh(mesh) mesh.uniform_refine(n=n) #mesh.print() space = ConformingVirtualElementSpace2d(mesh, p=1) uI = space.interpolation(pde.solution) up = space.project_to_smspace(uI) error = space.integralalg.L2_error(pde.solution, up) print(error) if plot: fig = plt.figure() axes = fig.gca() #mesh.add_halfedge_plot(axes, showindex=True) mesh.add_plot(axes) mesh.find_node(axes, showindex=True) mesh.find_edge(axes, showindex=True) mesh.find_cell(axes, showindex=True) plt.show()
(1.0, 1.0), (1.0, 2.0), (2.0, 0.0), (2.0, 1.0), (2.0, 2.0)], dtype=np.float) cell = np.array([0, 3, 4, 4, 1, 0, 1, 4, 5, 2, 3, 6, 7, 4, 4, 7, 8, 5], dtype=np.int) cellLocation = np.array([0, 3, 6, 10, 14, 18], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) if False: node = np.array([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)], dtype=np.float) cell = np.array([0, 1, 2, 3], dtype=np.int) cellLocation = np.array([0, 4], dtype=np.int) mesh = PolygonMesh(node, cell, cellLocation) space = ConformingVirtualElementSpace2d(mesh, p=1) A0, S0 = space.chen_stability_term() A = space.stiff_matrix() print("A:", A.toarray()) print("A0:", A0.toarray()) print("S0:", S0.toarray()) np.savetxt('A.txt', A.toarray(), fmt='%.2e') np.savetxt('A0.txt', A0.toarray(), fmt='%.2e') np.savetxt('S0.txt', S0.toarray(), fmt='%.2e') if False: h = 0.1 maxit = 1 pde = CosCosData()
import numpy as np import matplotlib.pyplot as plt from fealpy.pde.poisson_2d import CosCosData from fealpy.functionspace import ConformingVirtualElementSpace2d, ScaledMonomialSpace2d p = 1 pde = CosCosData() quadtree = pde.init_mesh(n=5, meshtype='quadtree') options = quadtree.adaptive_options(method='numrefine', maxsize=1, HB=True) pmesh = quadtree.to_pmesh() space0 = ConformingVirtualElementSpace2d(pmesh, p=p) uh0 = space0.interpolation(pde.solution) sh0 = space0.project_to_smspace(uh0) error = space0.integralalg.L2_error(pde.solution, sh0.value) print(error) axes0 = plt.subplot(1, 2, 1) pmesh.add_plot(axes0) pmesh.find_cell(axes0, showindex=True) NC = pmesh.number_of_cells() eta = -1 * np.ones(NC, dtype=np.int) quadtree.adaptive(eta, options) pmesh = quadtree.to_pmesh() space1 = ConformingVirtualElementSpace2d(pmesh, p=p) uI = space1.interpolation(sh0, options['HB'])