Exemplo n.º 1
0
 def init_mesh(self, n=4, meshtype='tri'):
     node = np.array([(-1, -1), (0, -1), (-1, 0), (0, 0), (1, 0), (-1, 1),
                      (0, 1), (1, 1)],
                     dtype=np.float64)
     if meshtype == 'tri':
         cell = np.array([(1, 3, 0), (2, 0, 3), (3, 6, 2), (5, 2, 6),
                          (4, 7, 3), (6, 3, 7)],
                         dtype=np.int_)
         mesh = TriangleMesh(node, cell)
         mesh.uniform_refine(n)
         return mesh
     elif meshtype == 'quadtree':
         cell = np.array([(0, 1, 3, 2), (2, 3, 6, 5), (3, 4, 7, 6)],
                         dtype=np.int_)
         mesh = Quadtree(node, cell)
         mesh.uniform_refine(n)
         return mesh
     elif meshtype == 'tritree':
         cell = np.array([(1, 3, 0), (2, 0, 3), (3, 6, 2), (5, 2, 6),
                          (4, 7, 3), (6, 3, 7)],
                         dtype=np.int_)
         mesh = TriangleMesh(node, cell)
         mesh.uniform_refine(n)
         node = mesh.entity('node')
         cell = mesh.entity('cell')
         mesh = Tritree(node, cell)
         return mesh
     else:
         raise ValueError("I don't know the meshtype %s".format(meshtype))
Exemplo n.º 2
0
    def init_mesh(self, n=1, meshtype='tri'):
        node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float)

        if meshtype is 'tri':
            cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int)
            mesh = TriangleMesh(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype is 'quadtree':
            cell = np.array([(0, 1, 2, 3)], dtype=np.int)
            mesh = Quadtree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype is 'tritree':
            cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int)
            mesh = Tritree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        else:
            raise ValueError("I don't know the meshtype %s".format(meshtype))
Exemplo n.º 3
0
    def init_mesh(self, n=4, meshtype='tri'):
        if meshtype == 'tri':
            node = np.array([(0, -1), (-1, 0), (0, 0), (1, 0), (1, 0), (0, 1)],
                            dtype=np.float64)

            cell = np.array([(2, 1, 0), (2, 0, 3), (2, 5, 1), (2, 4, 5)],
                            dtype=np.int_)
            mesh = TriangleMesh(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype == 'quadtree':
            r = 1 - 2**(1 / 2) / 2
            a = 1 / 2 - 2**(1 / 2) / 2
            rr = 1 / 2
            node = np.array([(0, -1), (-rr, -rr), (rr, -rr), (-r, -r), (0, -r),
                             (r, -r), (-1, 0), (-r, 0), (0, 0), (r, 0), (1, 0),
                             (r, 0), (-r, r), (0, r), (r, r), (-rr, rr),
                             (rr, rr), (0, 1)],
                            dtype=np.float64)
            cell = np.array([(0, 4, 3, 1), (2, 5, 4, 0), (1, 3, 7, 6),
                             (3, 4, 8, 7), (4, 5, 9, 8), (5, 2, 10, 9),
                             (6, 7, 12, 15), (7, 8, 13, 12), (8, 11, 14, 13),
                             (11, 10, 16, 14), (12, 13, 17, 15),
                             (13, 14, 16, 17)],
                            dtype=np.int_)
            mesh = Quadtree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype == 'tritree':
            node = np.array([(0, -1), (-1, 0), (0, 0), (1, 0), (1, 0), (0, 1)],
                            dtype=np.float64)

            cell = np.array([(2, 1, 0), (2, 0, 3), (2, 5, 1), (2, 4, 5)],
                            dtype=np.int_)
            mesh = Tritree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        else:
            raise ValueError("I don't know the meshtype %s".format(meshtype))
Exemplo n.º 4
0
node = np.array([
    (0, 0),
    (1, 0),
    (1, 1),
    (0, 1)], dtype=np.float)

cell = np.array([
        [1, 2, 0],
        [3, 0, 2]], dtype=np.int)


mesh = TriangleMesh(node, cell)
mesh.uniform_refine(1)
node = mesh.entity('node')
cell = mesh.entity('cell')
tmesh = Tritree(node, cell)
isLeafCell = tmesh.is_leaf_cell()
flag = (np.sum(cell == 0, axis=1) == 5) & isLeafCell
idx, = np.where(flag)
for i in range(2):
    tmesh.refine(idx)
    tmesh.coarsen(idx)
fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes)
#tmesh.find_node(axes, showindex=True)
#tmesh.find_edge(axes, showindex=True)
#tmesh.find_cell(axes, showindex=True)
plt.show()
Exemplo n.º 5
0
node = np.array([
    (0, 0.5), 
    (0.865, 0), 
    (1.73, 0.5),
    (0.865, 1)], dtype=np.float)
cell = np.array([
    (1, 2, 3),
    (3, 0, 1)], dtype=np.int)

tmesh = TriangleMesh(node, cell)
tmesh.uniform_refine(0)

node = tmesh.entity('node')
cell = tmesh.entity('cell')
tritree = Tritree(node, cell, irule=1)
marker = AdaptiveMarker()

for i in range(1):
    tritree.refine(marker)



a = np.array([2, 4], dtype=np.int)
fig = plt.figure()
axes = fig.gca()
tritree.add_plot(axes)
#tritree.find_node(axes, showindex=True)
tritree.find_cell(axes, index=a)
#tritree.find_edge(axes, showindex=True) 
plt.show()
    mesh = pde.init_mesh(n=4, meshtype='tri')

theta = 0.45
errorType = [
    '$|| u_I - u_h ||_{l_2}$',
    '$|| u- u_h ||_{0}$',
    '$|| \\nabla u - \\nabla u_h ||_{0}$',
    '$|| \\nabla u - G(\\nabla u_h) ||_{0}$',
]

Ndof = np.zeros((maxit, ), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)
integrator = mesh.integrator(3)
ralg = FEMFunctionRecoveryAlg()

tmesh = Tritree(mesh.node, mesh.ds.cell)
pmesh = tmesh.to_conformmesh()
for i in range(maxit):
    print('step:', i)
    fem = PoissonFEMModel(pde, pmesh, p, integrator)
    fem.solve()
    uh = fem.uh
    rguh = ralg.simple_average(uh)
    eta = fem.recover_estimate(rguh)
    Ndof[i] = len(fem.uh)
    errorMatrix[0, i] = fem.get_l2_error()
    errorMatrix[1, i] = fem.get_L2_error()
    errorMatrix[2, i] = fem.get_H1_error()
    errorMatrix[3, i] = fem.get_recover_error(rguh)
    #isMarkedCell = tmesh.refine_marker(eta, theta, method='L2')
    if i < maxit - 1:
Exemplo n.º 7
0
theta = 0.4

errorType = [
    '$|| u_I - u_h ||_{l_2}$', '$|| u - u_h ||_{S,0}$',
    '$||\\nabla_S u - \\nabla_S u_h||_{S,0}$'
]

Ndof = np.zeros((maxit, ), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)
integrator = TriangleQuadrature(3)
ralg = FEMFunctionRecoveryAlg()
pde = SphereSinSinSinData()
surface = Sphere()
mesh = surface.init_mesh()
mesh.uniform_refine(n=2, surface=surface)
tmesh = Tritree(mesh.node, mesh.ds.cell, irule=1)
pmesh = tmesh.to_conformmesh()

fig = pl.figure()
axes = a3.Axes3D(fig)
pmesh.add_plot(axes)

for i in range(maxit):
    print('step:', i)
    fem = SurfacePoissonFEMModel(pmesh, pde, p, integrator)
    fem.solve()
    uh = fem.uh
    rguh = ralg.harmonic_average(uh)
    eta = fem.recover_estimate(rguh)
    Ndof[i] = len(fem.uh)
    errorMatrix[0, i] = fem.get_l2_error()
Exemplo n.º 8
0
    def is_uniform(self):
        stde = np.std(self.eta) / self.maxeta
        print('The current relative std of eta is ', stde)
        if stde < 0.05:
            return True
        else:
            return False


pde = LShapeRSinData()
mesh = pde.init_mesh(n=4, meshtype='tri')
integrator = mesh.integrator(3)
node = mesh.entity('node')
cell = mesh.entity('cell')
tmesh = Tritree(node, cell)
pmesh = tmesh.to_conformmesh()

tol = 1.0e-4

for i in range(maxit):
    fem = PoissonFEMModel(pde, pmesh, p, integrator)
    fem.solve()
    res = fem.get_H1_error()
    #res = fem.get_L2_error()

    estimator = Estimator(fem.uh[:], mesh, 0.3, 0.5)

    fig = plt.figure()
    axes = fig.gca()
    mesh.add_plot(axes, cellcolor=estimator.eta, showcolorbar=True)
Exemplo n.º 9
0
node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float)

cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int)

mesh = TriangleMesh(node, cell)
mesh.uniform_refine(0)
node = mesh.entity('node')
cell = mesh.entity('cell')
fig = plt.figure()
axes = fig.gca()
mesh.add_plot(axes)
#mesh.find_node(axes, showindex=True)
#mesh.find_edge(axes, showindex=True)
#mesh.find_cell(axes, showindex=True)
tmesh = Tritree(node, cell)

ismarkedcell = np.array([True, False])
tmesh.refine(ismarkedcell)

fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes)

pmesh = tmesh.to_conformmesh()
fig = plt.figure()
axes = fig.gca()
pmesh.add_plot(axes)

plt.show()
Exemplo n.º 10
0
import sys
import numpy as np
import mpl_toolkits.mplot3d as a3
import pylab as pl
from fealpy.mesh.level_set_function import Sphere
from fealpy.mesh.TriangleMesh import TriangleMesh
from fealpy.mesh.Tritree import Tritree

surface = Sphere()
mesh = surface.init_mesh()
mesh.uniform_refine(n=0, surface = surface)
node = mesh.node
cell = mesh.ds.cell
tmesh = Tritree(node, cell, irule=1)
marker = AdaptiveMarkerdd()
for i in range(4):
    tmesh.refine(marker, surface=surface)
print(tmesh.node)
fig0 = pl.figure()
axes0 = a3.Axes3D(fig0)
tmesh.add_plot(axes0)

pmesh = tmesh.to_conformmesh()
fig1 = pl.figure()
axes1 = a3.Axes3D(fig1)
pmesh.add_plot(axes1)
plt.show()
Exemplo n.º 11
0
        return idx

    def coarsen_marker(self, qtmesh):
        pass


node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float)
cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int)

tmesh = TriangleMesh(node, cell)
tmesh.uniform_refine(0)

node = tmesh.entity('node')
cell = tmesh.entity('cell')
ismarkedcell = np.array([True, False])
tritree = Tritree(node, cell, irule=1)
tritree.refine(ismarkedcell)
pmesh = tritree.to_conformmesh()

fig = plt.figure()
axes = fig.gca()
tmesh.add_plot(axes, cellcolor='w', linewidths=1.5)
#tritree.find_node(axes, showindex=True)
#tmesh.find_cell(axes, showindex=True)
#tritree.find_edge(axes, showindex=True)
plt.show()

#fig = plt.figure()
#axes = fig.gca()
#tmesh.add_plot(axes)
#tmesh.find_node(axes, showindex=True)