artorg-unibe-ch / spline_mesher

Meshing tool for homogenised finite elements based on HR-pQCT images
https://artorg-unibe-ch.github.io/spline_mesher/
MIT License
0 stars 0 forks source link

maybe reactivate it? #24

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

return array, idx_list

adding here all the functions related to the mesh building

def gmsh_add_points(self, x, y, z):

https://github.com/simoneponcioni/spline-mesher/blob/3c9d558608e9e291a52501b64106c622945bd7a1/src/spline_mesher/gmsh_mesh_builder.py#L187


        3. calculate nearest neighbor of the intersection point
        4. insert the intersection point into the contours
        """
        radius = 50
        intersection_1 = self.shapely_line_polygon_intersection(
            array, self.partition_lines(radius, centroid)[0]
        )
        intersection_2 = self.shapely_line_polygon_intersection(
            array, self.partition_lines(radius, centroid)[1]
        )
        intersections = np.array([intersection_1, intersection_2])

        # TODO: rm after debug
        fig, ax = plt.subplots()
        ax.set_title("Calculating nearest neighbor of the intersection point")
        ax.scatter(array[:, 0], array[:, 1])
        ax.scatter(intersections[0][:, 0], intersections[0][:, 1], color="red")
        ax.scatter(intersections[1][:, 0], intersections[1][:, 1], color="red")
        for i, txt in enumerate(array[:, 0]):
            ax.annotate(i, (array[:, 0][i], array[:, 1][i]))
        plt.show()

        idx_list = []
        for i, intersection in enumerate(intersections):
            for j, inters in enumerate(intersection):
                closest_idx = self.intersection_point(array, inters)
                # array = self.insert_closest_point(array, closest_idx, inters)

                # # TODO: rm after debug
                # fig, ax = plt.subplots()
                # ax.set_title("BEFORE")
                # ax.plot(array[:, 0], array[:, 1])
                # ax.scatter(intersections[0][:, 0], intersections[0][:, 1], color="red")
                # ax.scatter(intersections[1][:, 0], intersections[1][:, 1], color="red")
                # for i, txt in enumerate(array[:, 0]):
                #     ax.annotate(i, (array[:, 0][i], array[:, 1][i]))
                # plt.show()
                if closest_idx == len(array) - 1:
                    array = np.vstack((array, array[-1]))
                else:
                    array = np.insert(array, closest_idx + 1, inters, axis=0)

                # # TODO: rm after debug
                # fig, ax = plt.subplots()
                # ax.set_title("AFTER")
                # ax.plot(array[:, 0], array[:, 1])
                # ax.scatter(intersections[0][:, 0], intersections[0][:, 1], color="red")
                # ax.scatter(intersections[1][:, 0], intersections[1][:, 1], color="red")
                # for i, txt in enumerate(array[:, 0]):
                #     ax.annotate(i, (array[:, 0][i], array[:, 1][i]))
                # plt.show()

                idx_list.append(closest_idx)
        # TODO: rm after debug
        fig, ax = plt.subplots()
        ax.set_title("Inserting intersection points into the contours")
        ax.plot(array[:, 0], array[:, 1])
        ax.scatter(intersections[0][:, 0], intersections[0][:, 1], color="red")
        ax.scatter(intersections[1][:, 0], intersections[1][:, 1], color="red")
        for i, txt in enumerate(array[:, 0]):
            ax.annotate(i, (array[:, 0][i], array[:, 1][i]))
        plt.show()
        array = self.close_loop_if_open(array)  # TODO: maybe reactivate it?
        return array, idx_list

    # adding here all the functions related to the mesh building

    def gmsh_add_points(self, x, y, z):
        """
        https://gitlab.onelab.info/gmsh/gmsh/-/issues/456
        https://bbanerjee.github.io/ParSim/fem/meshing/gmsh/quadrlateral-meshing-with-gmsh/
        """
        gmsh.option.setNumber("General.Terminal", 1)
        point_tag = self.factory.addPoint(x, y, z, tag=-1)
        return point_tag

    def gmsh_insert_bspline(self, points):
        line = self.factory.addBSpline(points)
        return line

    def gmsh_geometry_formulation(self, array: np.ndarray):
        # points
        array_pts_tags = []
        for i, _ in enumerate(array):
            array_tag = self.gmsh_add_points(
                array[i][0],
                array[i][1],
                array[i][2],
            )
            array_pts_tags = np.append(array_pts_tags, array_tag)
        array_pts_tags = np.asarray(array_pts_tags, dtype=int)

        # bsplines
        array_pts_tags = np.array_split(array_pts_tags, len(np.unique(array[:, 2])))
        array_bspline = np.empty([len(array_pts_tags)])
        for i, _ in enumerate(array_pts_tags):
            array_bspline[i] = self.gmsh_insert_bspline(array_pts_tags[i])
        return array_pts_tags, array_bspline

if __name__ == "__main__":
simoneponcioni commented 1 year ago

Function removed in latest commit