def uncross_mesh(self, box, n=10, r="1"):
        qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad')
        node = qmesh.entity('node')
        cell = qmesh.entity('cell')
        NN = qmesh.number_of_nodes()
        NC = qmesh.number_of_cells()
        bc = qmesh.barycenter('cell')

        if r == "1":
            bc1 = np.sqrt(np.sum((bc - node[cell[:, 0], :])**2, axis=1))[0]
            newNode = np.r_['0', node, bc - bc1 * 0.3]
        elif r == "2":
            ll = node[cell[:, 0]] - node[cell[:, 2]]
            bc = qmesh.barycenter('cell') + ll / 4
            newNode = np.r_['0', node, bc]

        newCell = np.zeros((4 * NC, 3), dtype=np.int)
        newCell[0:NC, 0] = range(NN, NN + NC)
        newCell[0:NC, 1:3] = cell[:, 0:2]

        newCell[NC:2 * NC, 0] = range(NN, NN + NC)
        newCell[NC:2 * NC, 1:3] = cell[:, 1:3]

        newCell[2 * NC:3 * NC, 0] = range(NN, NN + NC)
        newCell[2 * NC:3 * NC, 1:3] = cell[:, 2:4]

        newCell[3 * NC:4 * NC, 0] = range(NN, NN + NC)
        newCell[3 * NC:4 * NC, 1:3] = cell[:, [3, 0]]
        return TriangleMesh(newNode, newCell)
 def fishbone(self, box, n=10):
     qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad')
     node = qmesh.entity('node')
     cell = qmesh.entity('cell')
     NC = qmesh.number_of_cells()
     isLeftCell = np.zeros((n, n), dtype=np.bool)
     isLeftCell[0::2, :] = True
     isLeftCell = isLeftCell.reshape(-1)
     lcell = cell[isLeftCell]
     rcell = cell[~isLeftCell]
     newCell = np.r_['0', lcell[:, [1, 2, 0]], lcell[:, [3, 0, 2]],
                     rcell[:, [0, 1, 3]], rcell[:, [2, 3, 1]]]
     return TriangleMesh(node, newCell)
    def cross_mesh(self, box, n=10):
        qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad')
        node = qmesh.entity('node')
        cell = qmesh.entity('cell')
        NN = qmesh.number_of_nodes()
        NC = qmesh.number_of_cells()
        bc = qmesh.barycenter('cell')
        newNode = np.r_['0', node, bc]

        newCell = np.zeros((4 * NC, 3), dtype=np.int)
        newCell[0:NC, 0] = range(NN, NN + NC)
        newCell[0:NC, 1:3] = cell[:, 0:2]

        newCell[NC:2 * NC, 0] = range(NN, NN + NC)
        newCell[NC:2 * NC, 1:3] = cell[:, 1:3]

        newCell[2 * NC:3 * NC, 0] = range(NN, NN + NC)
        newCell[2 * NC:3 * NC, 1:3] = cell[:, 2:4]

        newCell[3 * NC:4 * NC, 0] = range(NN, NN + NC)
        newCell[3 * NC:4 * NC, 1:3] = cell[:, [3, 0]]
        return TriangleMesh(newNode, newCell)
pfix = np.array([[-2, -2], [2, -2], [2, 2], [-2, 2]], dtype=np.float)

m = int(sys.argv[1])
maxit = int(sys.argv[2])
p = int(sys.argv[3])

if m == 1:
    model = ObstacleData1()
    quadtree = model.init_mesh(n=3, meshtype='quadtree')
elif m == 2:
    model = ObstacleData2()
    #mesh = load_mesh('nonconvexpmesh1.mat')
    #h0 = 0.2
    #mesh = distmesh2d(fd, h0, bbox, pfix, meshtype='polygon')
    n = 20
    mesh = rectangledomainmesh([-2, 2, -2, 2], nx=n, ny=n, meshtype='polygon')

errorType = [
    '$\| u - \Pi^\\nabla u_h\|_0$', '$\|\\nabla u - \\nabla \Pi^\\nabla u_h\|$'
]

integrator = TriangleQuadrature(3)
vem = ObstacleVEMModel2d(model, mesh, p=p, integrator=integrator)

Ndof = np.zeros((maxit, ), dtype=np.int)
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

data = {}
for i in range(maxit):
    print('step:', i)
    vem.solve(solver='direct')
 def regular(self, box, n=10):
     return rectangledomainmesh(box, nx=n, ny=n, meshtype='tri')
Пример #6
0
import numpy as np
import matplotlib.pyplot as plt
from fealpy.mesh.level_set_function import dcircle
from fealpy.mesh import QuadrangleMesh
from fealpy.mesh.simple_mesh_generator import rectangledomainmesh

box = [-2, 2, -2, 2]
n = 3
qmesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='quad')
qmesh.print()
Пример #7
0
from fealpy.functionspace.tools import function_space
from fealpy.form.Form import LaplaceSymetricForm, SourceForm
from fealpy.boundarycondition import DirichletBC
from fealpy.solver import solve
from fealpy.functionspace.function import FiniteElementFunction
from fealpy.erroranalysis import L2_error
from fealpy.model.poisson_model_2d import CosCosData

degree = int(sys.argv[1]) 
qt = int(sys.argv[2])  
n = int(sys.argv[3])

box = [0, 1, 0, 1]

model = CosCosData()
mesh = rectangledomainmesh(box, nx=n, ny=n, meshtype='tri') 
maxit = 4 
Ndof = np.zeros(maxit, dtype=np.int)
error = np.zeros(maxit, dtype=np.float)
ratio = np.zeros(maxit, dtype=np.float)
for i in range(maxit):
    V = function_space(mesh, 'Lagrange', degree)
    uh = FiniteElementFunction(V)
    Ndof[i] = V.number_of_global_dofs() 
    a  = LaplaceSymetricForm(V, qt)
    L = SourceForm(V, model.source, qt)
    bc = DirichletBC(V, model.dirichlet, model.is_boundary)
    point = V.interpolation_points()
    solve(a, L, uh, dirichlet=bc, solver='direct')
    error[i] = L2_error(model.solution, uh, order=qt) 
    # error[i] = np.sqrt(np.sum((uh - model.solution(point))**2)/Ndof[i])
Пример #8
0
import numpy as np
import sys
from fealpy.mesh.implicit_curve import Circle, Curve1
from fealpy.mesh.simple_mesh_generator import rectangledomainmesh
from fealpy.mesh.adaptive_interface_mesh_generator import AdaptiveMarker2d, QuadtreeInterfaceMesh2d

import matplotlib.pyplot as plt

phi = Curve1(a=12)
#phi = Curve3()
mesh = rectangledomainmesh(phi.box, nx=10, ny=10, meshtype='quad')
marker = AdaptiveMarker2d(phi, maxh=0.1, maxa=2)
alg = QuadtreeInterfaceMesh2d(mesh, marker)
pmesh = alg.get_interface_mesh()
fig = plt.figure()
axes = fig.gca()
pmesh.add_plot(axes)
#pmesh.find_point(axes, point=cutPoint, markersize=10)
plt.show()
Пример #9
0
 def init_mesh(self, n=1):
     from fealpy.mesh.simple_mesh_generator import rectangledomainmesh
     box = self.domain()
     mesh = rectangledomainmesh(box, nx=8, ny=2)
     mesh.uniform_refine(n)
     return mesh
Пример #10
0
import numpy as np

import matplotlib.pyplot as plt
from fealpy.mesh.simple_mesh_generator import rectangledomainmesh
from fealpy.mesh.TriangleMesh import TriangleMeshWithInfinityPoint
from fealpy.mesh.PolygonMesh import PolygonMesh

# Generate mesh
box = [-1, 1, -1, 1]
mesh = rectangledomainmesh(box, nx=10, ny=10, meshtype='tri')
mesht = TriangleMeshWithInfinityPoint(mesh)
ppoint, pcell, pcellLocation = mesht.to_polygonmesh()
pmesh = PolygonMesh(ppoint, pcell, pcellLocation)

# Virtual  element space

fig = plt.figure()
axes = fig.gca()
pmesh.add_plot(axes)
plt.show()
Пример #11
0
 def init_mesh(self, n=1):
     from fealpy.mesh.simple_mesh_generator import rectangledomainmesh
     domain = self.domain()
     mesh = rectangledomainmesh(domain, nx=4 * n, ny=1 * n, meshtype='tri')
     return mesh
Пример #12
0
    '$\| u - u_h\|$', '$\|\\nabla u - \\nabla u_h\|$',
    '$\|\\nabla u_h - G(\\nabla u_h) \|$', '$\|\\nabla u - G(\\nabla u_h)\|$',
    '$\|\Delta u - \\nabla\cdot G(\\nabla u_h)\|$',
    '$\|\Delta u -  G(\\nabla\cdot G(\\nabla u_h))\|$',
    '$\|G(\\nabla\cdot G(\\nabla u_h)) - \\nabla\cdot G(\\nabla u_h)\|$'
]
errorMatrix = np.zeros((len(errorType), maxit), dtype=np.float)

h0 = 0.025
if (meshtype == 3):
    mesh = load_mat_mesh('../data/square' + str(1) + '.mat')

for i in range(maxit):
    if meshtype == 1:  # uniform mesh
        n = 20 * 2**i
        mesh = rectangledomainmesh(box, nx=n, ny=n)
    elif meshtype == 2:  # CVT mesh
        mesh = load_mat_mesh('../data/square' + str(i + 2) + '.mat')
    elif meshtype == 3:  # Delaunay uniform refine mesh
        mesh.uniform_refine()
    elif meshtype == 4:  # Delaunay mesh
        mesh = triangle(box, h0 / 2**i)
    elif meshtype == 5:
        mesh = load_mat_mesh('../data/sqaureperturb' + str(i + 2) + '.' +
                             str(0.5) + '.mat')

    V = function_space(mesh, 'Lagrange', degree)
    V2 = function_space(mesh, 'Lagrange_2', degree)
    uh = FiniteElementFunction(V)
    rgh = FiniteElementFunction(V2)
    rlh = FiniteElementFunction(V)