def __init__(self, size=(5.0, 5.0), resolution=(5, 5), center=(0, 0, 0), normal=(1, 0, 0), translational_symmetry=False, reflection_symmetry=False, name=None): assert len(size) == 2, "Size of a rectangle should be given as a couple of values." assert all([h > 0 for h in size]), "Size of the rectangle mesh should be given as positive values." assert len(resolution) == 2, "Resolution of a rectangle should be given as a couple a values." assert all([h > 0 for h in resolution]), "Resolution of the rectangle mesh should be given as positive values." assert all([i == int(i) for i in resolution]), "Resolution of a rectangle should be given as integer values." assert len(center) == 3, "Position of the center of a rectangle should be given a 3-ple of values." self.size = np.asarray(size, dtype=np.float) width, height = self.size self.geometric_center = np.asarray(center, dtype=np.float) nw, nh = resolution if translational_symmetry and reflection_symmetry: raise NotImplementedError("Rectangle generation with both reflection and translational symmetries " "has not been implemented yet.") if translational_symmetry and nw == 1: LOG.warning("To use the translation symmetry of the mesh, " "it should have more than one panel in this direction. " "Will return a standard mesh instead.") if reflection_symmetry and nw % 2 == 1: raise ValueError("To use the reflection symmetry of the mesh, " "it should have an even number of panels in this direction.") if (reflection_symmetry or translational_symmetry) and normal[2] != 0: raise ValueError("To use the symmetry of the mesh, it should be vertical.") if name is None: name = f"rectangle_{next(Mesh._ids)}" LOG.debug(f"New rectangle body of size ({width}, {height}) and resolution ({nw}, {nh}), named {name}.") if reflection_symmetry: half_mesh = Rectangle.generate_rectangle_mesh( width=width/2, height=height, nw=nw//2, nh=nh, center=(0, -width/4, 0), name=f"half_of_{name}_mesh" ) mesh = ReflectionSymmetricMesh(half_mesh, plane=xOz_Plane, name=f"{name}_mesh") elif translational_symmetry and nw > 1: strip = Rectangle.generate_rectangle_mesh( width=width/nw, height=height, nw=1, nh=nh, center=(0, -width/2 + width/(2*nw), 0), name=f"strip_of_{name}_mesh" ) mesh = TranslationalSymmetricMesh(strip, translation=np.asarray([0, width/nw, 0]), nb_repetitions=int(nw)-1, name=name) else: mesh = Rectangle.generate_rectangle_mesh(width=width, height=height, nw=nw, nh=nh, name=name) mesh.rotate_around_center_to_align_vectors((0, 0, 0), mesh.faces_normals[0], normal) mesh.translate(center) FloatingBody.__init__(self, mesh=mesh, name=name)
def __init__(self, radius=1.0, resolution=(3, 5), center=(0, 0, 0), normal=(1, 0, 0), reflection_symmetry=False, axial_symmetry=False, name=None): assert radius > 0, "Radius of the disk mesh should be given as a positive value." assert len( resolution ) == 2, "Resolution of a disk should be given as a couple a values." assert all([ h > 0 for h in resolution ]), "Resolution of the disk mesh should be given as positive values." assert all([ i == int(i) for i in resolution ]), "Resolution of a disk should be given as integer values." assert len( center ) == 3, "Position of the center of a disk should be given a 3-ple of values." self.radius = float(radius) self.geometric_center = np.asarray(center, dtype=float) nr, ntheta = resolution if reflection_symmetry and ntheta % 2 == 1: raise ValueError( "To use the reflection symmetry of the mesh, " "it should have an even number of panels in this direction.") if reflection_symmetry and axial_symmetry: raise NotImplementedError( "Disk generators with both symmetries have not been implemented." ) if name is None: name = f"disk_{next(Mesh._ids)}" LOG.debug( f"New disk body of radius {radius} and resolution ({nr}, {ntheta}), named {name}." ) if reflection_symmetry: half_mesh = Disk.generate_disk_mesh(radius=self.radius, theta_max=np.pi / 2, nr=nr, ntheta=ntheta // 2, name=f"half_of_{name}_mesh") mesh = ReflectionSymmetricMesh(half_mesh, plane=xOz_Plane, name=f"{name}_mesh") elif axial_symmetry: mesh_slice = Disk.generate_disk_mesh(radius=self.radius, theta_max=np.pi / ntheta, nr=nr, ntheta=1, name=f"slice_of_{name}_mesh") mesh_slice.rotate_around_center_to_align_vectors( (0, 0, 0), e_x, e_z ) # Convoluted way to avoid a warning message in AxialSymmetry... mesh = AxialSymmetricMesh(mesh_slice, axis=Oz_axis, nb_repetitions=ntheta - 1, name=f"{name}_mesh") mesh.rotate_around_center_to_align_vectors((0, 0, 0), e_z, e_x) else: mesh = Disk.generate_disk_mesh(radius=self.radius, nr=nr, ntheta=ntheta, name=f"{name}_mesh") mesh.rotate_around_center_to_align_vectors( (0, 0, 0), mesh.faces_normals[0], normal) mesh.translate(center) FloatingBody.__init__(self, mesh=mesh, name=name)