Пример #1
0
    def init_mesh(self, n=4, meshtype='tri', h=0.1):
        """ generate the initial mesh
        """
        node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float)

        if meshtype is 'quadtree':
            cell = np.array([(0, 1, 2, 3)], dtype=np.int)
            mesh = Quadtree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        if meshtype is 'quad':
            node = np.array([(0, 0), (1, 0), (1, 1), (0, 1), (0.5, 0),
                             (1, 0.4), (0.3, 1), (0, 0.6), (0.5, 0.45)],
                            dtype=np.float)
            cell = np.array([(0, 4, 8, 7), (4, 1, 5, 8), (7, 8, 6, 3),
                             (8, 5, 2, 6)],
                            dtype=np.int)
            mesh = QuadrangleMesh(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif 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 'stri':
            mesh = StructureQuadMesh([0, 1, 0, 1], h)
            return mesh
        else:
            raise ValueError("".format)
Пример #2
0
def quadmesh(n=10, L=12):
    box = [0, L, 0, L]
    qmesh = StructureQuadMesh(box, n, n)
    node = qmesh.node
    cell = qmesh.ds.cell
    quadtree = Quadtree(node, cell)
    return quadtree
Пример #3
0
 def init_mesh(self, n=4, meshtype='quadtree', h=0.1, nx=10, ny=10):
     point = np.array([(-1, -1), (1, -1), (1, 1), (-1, 1)],
                      dtype=np.float64)
     if meshtype == 'quadtree':
         cell = np.array([(0, 1, 2, 3)], dtype=np.int_)
         mesh = Quadtree(point, cell)
         mesh.uniform_refine(n)
         return mesh
     elif meshtype == 'tri':
         cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_)
         mesh = TriangleMesh(point, cell)
         mesh.uniform_refine(n)
         return mesh
     elif meshtype == 'stri':
         mesh = StructureQuadMesh([0, 1, 0, 1], nx, ny)
         return mesh
     else:
         raise ValueError("".format)
Пример #4
0
    def init_mesh(self, n=4, meshtype='tri', h=0.1):
        """ generate the initial mesh
        """
        node = np.array([(0, 0), (1, 0), (1, 1), (0, 1)], dtype=np.float64)

        if meshtype == 'quadtree':
            cell = np.array([(0, 1, 2, 3)], dtype=np.int_)
            mesh = Quadtree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype == '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 == 'stri':
            mesh = StructureQuadMesh([0, 1, 0, 1], h)
            return mesh
        else:
            raise ValueError("".format)
Пример #5
0
    def init_mesh(self, n=4, meshtype='tri', h=0.1):
        """ generate the initial mesh
        """
        node = np.array([(0, -1), (1, -1), (1, 1), (0, 1)], dtype=np.float64)

        if meshtype == 'quadtree':
            cell = np.array([(0, 1, 2, 3)], dtype=np.int_)
            mesh = Quadtree(node, cell)
            mesh.uniform_refine(n)
            return mesh
        if meshtype == 'quad':
            node = np.array([(0, 0), (1, 0), (1, 1), (0, 1), (0.5, 0),
                             (1, 0.4), (0.3, 1), (0, 0.6), (0.5, 0.45)],
                            dtype=np.float64)
            cell = np.array([(0, 4, 8, 7), (4, 1, 5, 8), (7, 8, 6, 3),
                             (8, 5, 2, 6)],
                            dtype=np.int_)
            mesh = QuadrangleMesh(node, cell)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype == 'tri':
            cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_)
            mesh = TriangleMesh(node, cell)
            mesh.uniform_refine(n)

            # |--- to test
            box = [0, 1, -1, 1]
            mesh = MF.boxmesh2d(box, nx=10, ny=20, meshtype='tri')
            # |---
            return mesh
        elif meshtype == 'halfedge':
            cell = np.array([(1, 2, 0), (3, 0, 2)], dtype=np.int_)
            mesh = TriangleMesh(node, cell)
            mesh = HalfEdgeMesh2d.from_mesh(mesh)
            mesh.uniform_refine(n)
            return mesh
        elif meshtype == 'squad':
            mesh = StructureQuadMesh([0, 1, 0, 1], h)
            return mesh
        else:
            raise ValueError("".format)
Пример #6
0
import numpy as np
import matplotlib.pyplot as plt
import sys

from fealpy.mesh.StructureQuadMesh import StructureQuadMesh
box = [0, 1, 0, 1]
n = 8
qmesh = StructureQuadMesh(box, n, n)
cell2cell = qmesh.ds.cell_to_cell()
print('cell2cell',cell2cell)

NN = qmesh.number_of_nodes()
NE = qmesh.number_of_edges()
NC = qmesh.number_of_cells()

#a = cell2cell[:NC:n,0]
#print('a',a)

X = np.zeros(NE + NC, dtype=np.float)

I = np.arange(NC, dtype=np.int)
J = I

fig = plt.figure()
axes = fig.gca()
qmesh.add_plot(axes)
qmesh.find_node(axes, showindex=True)
qmesh.find_edge(axes, showindex=False)
qmesh.find_cell(axes, showindex=False)
plt.show()
Пример #7
0
    return hg


n = int(sys.argv[1])
nx = n
ny = n

box = [-2, 2, -2, 2]
cxy = (0.0, 0.0)
r = 1 
interface0 = lambda p: dcircle(p, cxy, r)

interface = lambda p: circle(p, cxy, r)


mesh = StructureQuadMesh(box, nx, ny)

dx = mesh.dx
dy = mesh.dy

point = mesh.point
N = point.shape[0]
phi = interface(point)

phiSign = sign(phi)

edge = mesh.ds.edge
NE = edge.shape[0]
isCutEdge = phiSign[edge[:, 0]]*phiSign[edge[:, 1]] < 0
A = point[edge[isCutEdge, 0]].copy()
B = point[edge[isCutEdge, 1]].copy()
Пример #8
0
import numpy as np
import matplotlib.pyplot as plt
import sys

from fealpy.mesh.StructureQuadMesh import StructureQuadMesh
box = [0, 1, 0, 1]
n = 2
qmesh = StructureQuadMesh(box, n, n)
qmesh.print()

fig = plt.figure()
axes = fig.gca()
qmesh.add_plot(axes)
qmesh.find_point(axes, showindex=True)
qmesh.find_edge(axes, showindex=True)
qmesh.find_cell(axes, showindex=True)
plt.show()
Пример #9
0
import numpy as np
import matplotlib.pyplot as plt

from fealpy.mesh.StructureQuadMesh import StructureQuadMesh

L=20
box = [0, L, 0, L]
qmesh = StructureQuadMesh(box, nx=2, ny=2)
C = qmesh.ds.peoriod_matrix()
print(C.toarray())

fig = plt.figure()
axes = fig.gca()
qmesh.add_plot(axes)
qmesh.find_node(axes, showindex=True)
plt.show()