예제 #1
0
 def test_contains_points(self):
     #
     # Define 2D HalfEdge
     #
     v1 = Vertex((0,0))
     v2 = Vertex((1,1))
     h = HalfEdge(v1,v2)
     
     points = np.array([[0,0],[0.5,0.5],[3,2]])
     on_half_edge = h.contains_points(points)
     self.assertTrue(all(on_half_edge==[True, True, False]))
     
     v1 = Vertex(0)
     v2 = Vertex(1)
     h = HalfEdge(v1,v2)
     points = [Vertex(0), Vertex(0.5), Vertex(3)]
     on_half_edge = h.contains_points(points)
     self.assertTrue(all(on_half_edge==[True, True, False]))
예제 #2
0
from mesh import Mesh1D
from mesh import QuadMesh
from mesh import Vertex
from mesh import HalfEdge
from solver import LinearSystem as LS
from plot import Plot
import numpy as np

# =============================================================================
# Computational mesh
# =============================================================================
mesh = QuadMesh(box=[-0.5, 0.5, -0.5, 0.5], resolution=(20, 20))

# Mark slit region
slit = HalfEdge(Vertex((0, 0)), Vertex((0, -0.5)))
sf = lambda x, y: slit.contains_points(np.array([x, y]))[0]
mesh.mark_region('slit', sf, entity_type='half_edge')

# Mark perimeter
tol = 1e-9
pf = lambda x,y: np.abs(x+0.5)<tol or np.abs(x-0.5)<tol or \
                 np.abs(y+0.5)<tol or np.abs(y-0.5)<tol
mesh.mark_region('perimeter', pf, entity_type='half_edge')

# Get rid of neighbors of half-edges on slit
for he in mesh.half_edges.get_leaves('slit'):
    if he.unit_normal()[0] < 0:
        he.mark('B')
mesh.tear_region('B')

# =============================================================================