Example #1
0
    def _FV_utils(self, lGIDs, verbose=False):
        """
        This function constructs the Finite Volume discretisation for each local
        triangularised grid.

        Parameters
        ----------
        lGIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (including those on the edges).

        inIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (not those on the edges).
        """

        # Build the voronoi diagram (dual of the delaunay)
        walltime = time.clock()
        Vor_pts, Vor_edges = triangle.voronoi(self.node_coords)
        if verbose:
            print(" - build the voronoi diagram ", time.clock() - walltime)

        # Call the finite volume frame construction function from libUtils
        walltime = time.clock()
        self.control_volumes, self.neighbours, self.vor_edges, \
        self.edge_length, maxNgbhs = FVframe.discretisation.build( \
             lGIDs+1, self.localIDs+1, self.node_coords[:,0], self.node_coords[:,1],
            self.edges[:,:2]+1, self.cells[:,:3]+1, Vor_pts[:,0], Vor_pts[:,1], \
            Vor_edges[:,:2]+1)
        if verbose:
            print(" - construct Finite Volume representation ",
                  time.clock() - walltime)

        # Maximum number of neighbours for each partition
        self.maxNgbh = numpy.array(maxNgbhs)
Example #2
0
def test_voronoi():
    pts = [[0, 0], [0, 1], [0.5, 0.5], [1, 1], [1, 0]]
    points, edges, ray_origin, ray_direct = voronoi(pts)
    assert np.allclose(
        points,
        [[0.0, 0.5], [1.0, 0.5], [0.5, 0.0], [0.5, 1.0]],
    )
    assert np.allclose(edges, [[0, 2], [0, 3], [1, 2], [1, 3]])

    assert np.allclose(ray_origin, [0, 1, 2, 3])
    assert np.allclose(
        ray_direct,
        [[-1.0, 0.0], [1.0, 0.0], [0.0, -1.0], [0.0, 1.0]],
    )
Example #3
0
    def _FV_utils(self, lGIDs, verbose=False):
        """
        This function constructs the Finite Volume discretisation for each local
        triangularised grid.

        Parameters
        ----------
        variable : lGIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (including those on the edges).

        variable: inIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (not those on the edges).
        """

        comm = mpi.COMM_WORLD
        rank = comm.Get_rank()

        # Build the voronoi diagram (dual of the delaunay)
        walltime = time.clock()
        Vor_pts, Vor_edges = triangle.voronoi(self.node_coords)
        if rank == 0 and verbose:
            print " - build the voronoi diagram ", time.clock() - walltime

        # Call the finite volume frame construction function from libUtils
        walltime = time.clock()
        self.control_volumes, self.neighbours, self.vor_edges, self.edge_length, maxNgbhs = FVframe.discretisation.build(
            lGIDs + 1,
            self.localIDs + 1,
            self.node_coords[:, 0],
            self.node_coords[:, 1],
            self.edges[:, :2] + 1,
            self.cells[:, :3] + 1,
            Vor_pts[:, 0],
            Vor_pts[:, 1],
            Vor_edges[:, :2] + 1,
        )
        if rank == 0 and verbose:
            print " - construct Finite Volume representation ", time.clock() - walltime

        # Maximum number of neighbours for each partition
        maxNgbh = numpy.array(maxNgbhs)
        comm.Allreduce(mpi.IN_PLACE, maxNgbh, op=mpi.MAX)
        self.maxNgbh = maxNgbh
Example #4
0
def crust(points: list, filename = None)-> list:
    points = np.array(points)

    ax = plt.axes()
    drawing.plot_and_save(os.path.join(images_folder, filename+"_original.png"), False, ax, vertices=points, vertices_color="g")
    lim = ax.axis()

    vertices, edges, ray_origins, ray_directions = triangle.voronoi(points)
    try:
        drawing.plot_and_save(os.path.join(images_folder, os.path.join("voronoi", filename+"_voronoi.png")),
         False, ax, vertices=vertices, edges=edges, ray_origins=ray_origins, ray_directions=ray_directions)
        ax.axis(lim)
    except Exception as e:
        print("Could not draw voronoi diagram. Please, check if you have the correct directory")

    extended_points = np.concatenate((points, vertices))

    triangles = triangle.delaunay(extended_points)
    delaunay_edges = []
    for t in triangles:
        delaunay_edges.extend(edges_from_triangle(t))

    rec_edges = [e for e in delaunay_edges if ((e[0] < len(points)) and (e[1] < len(points)))]
    try:
        drawing.plot(ax, vertices=extended_points, edges=delaunay_edges, segments=rec_edges)
        drawing.plot_and_save(os.path.join(images_folder, os.path.join("delaunay",filename+"delaunay.png")),
            True, ax, vertices=points, vertices_color="b")
        ax.axis(lim)
    except Exception as e:
        print("Could not draw delaunay diagram. Please, check if you have the correct directory")


    #final reconstruction
    ax = plt.axes()
    drawing.plot_and_save(os.path.join(images_folder, filename+"_reconstruction.png"),
                            True, ax, vertices=points, segments=rec_edges, draw_vertices=False)
    # print(points)
    # print(rec_edges)
    ordered_points = []

    return ordered_points
Example #5
0
    def _FV_utils(self, allIDs, verbose=False):
        """
        This function constructs the Finite Volume discretisation for each local
        triangularised grid.

        Parameters
        ----------
        variable : allIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (including those on the edges).

        variable: inIDs
            Numpy integer-type array filled with the global vertex IDs for each local grid located
            within the partition (not those on the edges).
        """

        comm = mpi.COMM_WORLD
        rank = comm.Get_rank()

        # Build the voronoi diagram (dual of the delaunay)
        walltime = time.clock()
        Vor_pts, Vor_edges = triangle.voronoi(self.node_coords)
        if rank == 0 and verbose:
            print " - build the voronoi diagram ", time.clock() - walltime

        # Call the finite volume frame construction function from libUtils
        walltime = time.clock()
        self.control_volumes, self.neighbours, self.vor_edges, \
        self.edge_length, maxNgbhs = FVframe.discretisation.build( \
             allIDs+1, self.localIDs+1, self.node_coords[:,0], self.node_coords[:,1],
            self.edges[:,:2]+1, self.cells[:,:3]+1, Vor_pts[:,0], Vor_pts[:,1], \
            Vor_edges[:,:2]+1)
        if rank == 0 and verbose:
            print " - construct Finite Volume representation ", time.clock(
            ) - walltime

        # Maximum number of neighbours for each partition
        maxNgbh = numpy.array(maxNgbhs)
        comm.Allreduce(mpi.IN_PLACE, maxNgbh, op=mpi.MAX)
        self.maxNgbh = maxNgbh
Example #6
0
import matplotlib.pyplot as plt

import triangle as tr

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

A = dict(vertices=pts)

points, edges, ray_origin, ray_direct = tr.voronoi(pts)
B = dict(vertices=points,
         edges=edges,
         ray_origins=ray_origin,
         ray_directions=ray_direct)
tr.compare(plt, A, B)
plt.show()
Example #7
0
import triangle
import triangle.plot
import matplotlib.pyplot as plt

pts = [[0, 0], [0, 1], [0.5, 0.5], [1, 1], [1, 0]]
import numpy as np
pts = np.array(pts)

vertices, edges, ray_origins, ray_directions = triangle.voronoi(pts)
ax = plt.axes()
triangle.plot.plot(ax, vertices=pts)
lim = ax.axis()
triangle.plot.plot(ax,
                   vertices=vertices,
                   edges=edges,
                   ray_origins=ray_origins,
                   ray_directions=ray_directions)
ax.axis(lim)

plt.show()
Example #8
0
import triangle
import triangle.plot
import matplotlib.pyplot as plt

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

ax1 = plt.subplot(121, aspect='equal')
triangle.plot.plot(ax1, vertices=pts)
lim = ax1.axis()

points, edges, ray_origin, ray_direct = triangle.voronoi(pts)
d = dict(vertices=points, edges=edges, ray_origins=ray_origin, ray_directions=ray_direct)
ax2 = plt.subplot(122, sharex=ax1, sharey=ax1)
triangle.plot.plot(ax2, **d)
ax2.axis(lim)

plt.show()
Example #9
0
import triangle
import triangle.plot
import matplotlib.pyplot as plt

pts = [[0, 0], [0, 1], [0.5, 0.5], [1, 1], [1, 0]]
import numpy as np
pts = np.array(pts)

vertices, edges, ray_origins, ray_directions = triangle.voronoi(pts)
ax = plt.axes()
triangle.plot.plot(ax, vertices=pts)
lim = ax.axis()
triangle.plot.plot(ax, vertices=vertices, edges=edges, 
                   ray_origins=ray_origins, ray_directions=ray_directions)
ax.axis(lim)

plt.show()