Example #1
0
def calc_mesh(r, R, Theta):
    # Функция расчета сетки
    # с учетом границ областей в системе скважина-пласт.
    #
    # Аргументы:
    #     r -- радиусы границы области
    #     R -- радиусы концентрических окружностей в пространстве (r, z)
    # Theta -- углы лучей, исходящих из начала координат

    import triangle as tr
    from others import (cartprod, cylinder_verts, tri2mesh, concat_graphs)

    # точка в начале координат

    verts0 = [[0, 0]]
    graph0 = dict(vertices=verts0)

    # граф с точками, регулярно (структуировано) расположенными в пространстве

    RT_verts1 = cartprod(R, Theta, order='F')  # декартово произведение
    verts1 = cylinder_verts(
        RT_verts1)  # перевод из полярных координат в декартовые
    graph1 = dict(vertices=verts1, segments=np.array([]).reshape(0, 2))

    if r is None or len(r) == 0:
        # в случае если не заданы границы областей
        graph1 = dict(vertices=np.array([]).reshape(0, 2),
                      segments=np.array([]).reshape(0, 2))
    else:
        # добавление учета границ областей в графе
        for r_ in r:
            graph1 = build_line_2(r_, R, Theta, graph1)

    # объединение графов
    graph = concat_graphs(graph0, graph1)

    # добавление в граф границы выпуклой оболочки множества точек триангуляции,
    # служит границей расчетной сетки
    hull_segments = tr.convex_hull(graph['vertices'])
    graph['segments'] = np.append(graph['segments'], hull_segments, axis=0)

    # триангуляция Делоне по заданному графу
    tri = tr.triangulate(graph, 'p')

    # перевод расчетной сетки в читаемый FEniCS формат
    mesh = tri2mesh(tri)

    return graph, tri, mesh
Example #2
0
	def boundary_mask(self, tri):
		""" Create boundary mask from hull """

		bmask = np.zeros(len(self.x), dtype=bool)
		vertices = zip(self.x, self.y) # Convert back to tuples

		if self.is_concave:
			# Haven't worked this out yet!
			pass
		else:
			# triangle has a convex hull routine
			hull = triangle.convex_hull(tri['vertices'])
			convex_hull = zip( hull[:,0], hull[:,1] )
			for i, vert in enumerate(vertices):
				if vert in convex_hull:
					bmask[i] = True

		return bmask
Example #3
0
    def boundary_mask(self, tri):
        """ Create boundary mask from hull """

        bmask = np.zeros(len(self.x), dtype=bool)
        vertices = zip(self.x, self.y)  # Convert back to tuples

        if self.is_concave:
            # Haven't worked this out yet!
            pass
        else:
            # triangle has a convex hull routine
            hull = triangle.convex_hull(tri['vertices'])
            convex_hull = zip(hull[:, 0], hull[:, 1])
            for i, vert in enumerate(vertices):
                if vert in convex_hull:
                    bmask[i] = True

        return bmask
Example #4
0
import triangle
import triangle.plot as plot
import matplotlib.pyplot as plt

dots = triangle.get_data('dots')
pts = dots['vertices']
segs = triangle.convex_hull(pts)

plot.plot(plt.axes(), vertices=pts, segments=segs)

plt.show()
Example #5
0
import matplotlib.pyplot as plt

import triangle as tr

dots = tr.get_data('dots')
pts = dots['vertices']
segs = tr.convex_hull(pts)

tr.plot(plt.axes(), vertices=pts, segments=segs)

plt.show()
Example #6
0
import matplotlib.pyplot as plt
import numpy as np

import triangle as tr

pts = np.array([[0, 0], [0, 1], [1, 1], [1, 0]])
segments = tr.convex_hull(pts)

A = dict(vertices=pts)
B = dict(vertices=pts, segments=segments)
tr.compare(plt, A, B)
plt.show()
Example #7
0
def test_hull():
    pts = [[0, 0], [0, 1], [1, 1], [1, 0]]
    segments = convex_hull(pts)
    assert np.allclose(segments, [[3, 0], [2, 3], [1, 2], [0, 1]])