コード例 #1
0
ファイル: rectangles.py プロジェクト: pp1565156/capytaine
    def _generate_mesh_with_translational_symmetry(self, resolution, top,
                                                   bottom, name):
        width, thickness, height = self.size
        nw, nth, nh = resolution

        front_panel = Rectangle.generate_rectangle_mesh(
            width=width / nw,
            height=height,
            nw=1,
            nh=nh,
            center=(-width / 2 + width / (2 * nw), thickness / 2, 0),
            normal=(0, 1, 0),
            name=f"front_panel_of_{name}_mesh")

        back_panel = front_panel.mirror(plane=xOz_Plane,
                                        inplace=False,
                                        name=f"back_panel_of_{name}_mesh")

        top_panel = Rectangle.generate_rectangle_mesh(
            width=thickness,
            height=width / nw,
            nw=nth,
            nh=1,
            center=(-width / 2 + width / (2 * nw), 0, height / 2),
            normal=(0, 0, 1),
            name=f"top_panel_of_{name}_mesh")

        bottom_panel = top_panel.mirror(plane=xOy_Plane,
                                        inplace=False,
                                        name=f"bottom_panel_of_{name}_mesh")

        panels = [front_panel, back_panel]
        if top:
            panels.append(top_panel)
        if bottom:
            panels.append(bottom_panel)
        ring = CollectionOfMeshes(panels, name=f"ring_of_{name}_mesh").merged()
        ring.merge_duplicates()
        ring.heal_triangles()

        open_parallelepiped = TranslationalSymmetricMesh(
            ring,
            translation=(width / nw, 0, 0),
            nb_repetitions=int(nw) - 1,
            name=f"body_of_{name}_mesh")

        side = Rectangle.generate_rectangle_mesh(width=thickness,
                                                 height=height,
                                                 nw=nth,
                                                 nh=nh,
                                                 center=(width / 2, 0, 0),
                                                 normal=(1, 0, 0),
                                                 name=f"side_of_{name}_mesh")

        other_side = side.mirror(plane=yOz_Plane,
                                 inplace=False,
                                 name=f"other_side_of_{name}_mesh")

        return CollectionOfMeshes([open_parallelepiped, side, other_side],
                                  name=f"{name}_mesh")
コード例 #2
0
ファイル: cylinders.py プロジェクト: MRE-Code-Hub/Capytaine
    def __init__(self,
                 length=10.0,
                 radius=1.0,
                 center=(0, 0, 0),
                 nx=10,
                 ntheta=10,
                 nr=2,
                 clever=True,
                 name=None):
        self.length = length
        self.radius = radius
        self.geometric_center = np.asarray(center, dtype=float)

        if name is None:
            name = f"cylinder_{next(Mesh._ids)}"

        ntheta = 2 * (ntheta // 2)  # Temporary fix to avoid mismatch in mesh
        # When symmetries are used, one needs an even number of panels.
        # TODO: When symmetries are not used, implement the odd case.

        open_cylinder = self._generate_open_cylinder_mesh(
            nx, ntheta, f"body_of_{name}")

        if nr > 0:
            side = Disk(radius=radius,
                        center=(-np.array([length / 2, 0, 0])),
                        normal=(-1, 0, 0),
                        resolution=(nr, ntheta),
                        name=f"side_of_{name}").mesh

            other_side = side.copy(name=f"other_side_of_{name}_mesh")
            other_side.mirror(yOz_Plane)

            mesh = CollectionOfMeshes((open_cylinder, side, other_side))

        else:
            mesh = open_cylinder

        if not clever:
            mesh = mesh.merged()
            mesh.merge_duplicates()
            mesh.heal_triangles()

        mesh.translate(self.geometric_center)
        mesh.name = f"{name}_mesh"

        FloatingBody.__init__(self, mesh=mesh, name=name)
コード例 #3
0
ファイル: cylinders.py プロジェクト: mrsonandrade/capytaine
    def __init__(self,
                 length=10.0,
                 radius=1.0,
                 center=(0, 0, 0),
                 nx=10,
                 ntheta=10,
                 nr=2,
                 clever=True,
                 name=None):
        self.length = length
        self.radius = radius
        self.geometric_center = np.asarray(center, dtype=np.float)

        if name is None:
            name = f"cylinder_{next(Mesh._ids)}"

        open_cylinder = self._generate_open_cylinder_mesh(
            nx, ntheta, f"body_of_{name}")

        if nr > 0:
            side = Disk(radius=radius,
                        center=(-np.array([length / 2, 0, 0])),
                        normal=(-1, 0, 0),
                        resolution=(nr, ntheta),
                        name=f"side_of_{name}").mesh

            other_side = side.copy(name=f"other_side_of_{name}_mesh")
            other_side.mirror(yOz_Plane)

            mesh = CollectionOfMeshes((open_cylinder, side, other_side))

        else:
            mesh = open_cylinder

        if not clever:
            mesh = mesh.merged()
            mesh.merge_duplicates()
            mesh.heal_triangles()

        mesh.translate(self.geometric_center)
        mesh.name = f"{name}_mesh"

        FloatingBody.__init__(self, mesh=mesh, name=name)
コード例 #4
0
ファイル: cylinders.py プロジェクト: pp1565156/capytaine
    def __init__(self,
                 length=10.0,
                 radius=1.0,
                 center=(0, 0, 0),
                 nx=10,
                 ntheta=10,
                 nr=2,
                 clever=True,
                 name=None):
        """Generate the mesh of an horizontal cylinder.

        Parameters
        ----------
        length : float, optional
            length of the cylinder
        radius : float, optional
            radius of the cylinder
        center : 3-ple or array of shape (3,), optional
            position of the geometric center of the cylinder
        nx : int, optional
            number of circular slices
        ntheta : int, optional
            number of panels along a circular slice of the cylinder
        nr : int, optional
            number of panels along a radius on the extremities of the cylinder
        clever : bool, optional
            if True, uses the mesh symmetries
        name : str, optional
            a string naming the floating body
        """
        self.length = length
        self.radius = radius
        self.geometric_center = np.asarray(center, dtype=np.float)

        if name is None:
            name = f"cylinder_{next(Mesh._ids)}"

        open_cylinder = self._generate_open_cylinder_mesh(
            nx, ntheta, f"body_of_{name}")

        if nr > 0:
            side = Disk(radius=radius,
                        center=(-np.array([length / 2, 0, 0])),
                        normal=(-1, 0, 0),
                        resolution=(nr, ntheta),
                        name=f"side_of_{name}").mesh

            other_side = side.copy(name=f"other_side_of_{name}_mesh")
            other_side.mirror(yOz_Plane)

            mesh = CollectionOfMeshes((open_cylinder, side, other_side))

        else:
            mesh = open_cylinder

        if not clever:
            mesh = mesh.merged()
            mesh.merge_duplicates()
            mesh.heal_triangles()

        mesh.translate(self.geometric_center)
        mesh.name = f"{name}_mesh"

        FloatingBody.__init__(self, mesh=mesh, name=name)