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)
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)
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)