/
chukharev
/
geometry3d
Обзор
Документация
Войти
/
chukharev
/
geometry3d
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
FormPARAMS.py
244 строки
12 KB
chukharev
Minor: comments.
25 июл 2026, 09:25
25 июл 2026, 09:25
a3e1f4a
Код
Авторство
О чём код?
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Define parameters of a shape of a stamping matrix for a heat exchanger foil plate. Odd/even plate profiles with bumps, pits, and half-cylinders. For low Half: Bumps have a dint (recession) on top, Pits should be correspondingly deeper. That means that height/depth of Bumps and Pits are the same if dints are not counted, but a dint makes a Bump shorter by half of dint depth, and a Pit sinks into a dint on same depth. Half-pipes have dints and protrusions, but these do not change separation between the plates. F means Form (the whole stamp), N - Nose, L - Leap (in-out openings), B - Bump, P - Pit, S - Side, C - half-Cylinder, CE - half-Cylinder End part, P1 ... P8 - points, collar - the frame holding foil around the stamp stretched (not in use yet). Pit is formed by an approx. quarter sphere and an approx. quarter toroid, conjugating the base plane and the quarter sphere. Bump is like a Pit of opposite direction, plus a dint (spherical recession) on the top, with the only sharp edge. Side is an approx. quarter cylinder and a plane at small angle from vertical. Nose is a short Side. Leap is a double quarter-toroid conjugating the base plane and the plane of touching a Leap of a neighbor plate. Sizes are in mm, relative values are obtained by dividing by `Radius`. """ from __future__ import annotations from math import acos, asin, cos, degrees, pi, sin, sqrt, tan import numpy __version__ = "$Id$" __all__ = [ 'B_dint_radius', 'B_height', 'B_max_z', 'B_radius', 'B_rdint', 'B_rhalf_width', 'B_rwidth', 'B_width', 'CE_height', 'CE_rwidth', 'CE_type', 'CE_width', 'C_length', 'C_max_y', 'C_max_z', 'C_width', 'Eccentricity', 'F_max_x', 'F_max_y', 'F_plane', 'Fname', 'Grid', 'Half', 'Height', 'L1_a0', 'L1_a1', 'L1_cx', 'L1_cy', 'L1_max_x', 'L1_max_y', 'L1_min_x', 'L1_min_y', 'L1_r', 'L2_a0', 'L2_a1', 'L2_cx', 'L2_cy', 'L2_r', 'L3_a0', 'L3_a1', 'L3_cx', 'L3_cy', 'L3_r', 'L4_a0', 'L4_a1', 'L4_cx', 'L4_cy', 'L4_r', 'L_angular_width', 'L_length', 'Length', 'Mesh_accuracy', 'Mesh_max_x', 'Mesh_max_y', 'Mesh_rim', 'Mesh_start', 'Mesh_step', 'Mesh_step_x', 'Mesh_step_y', 'Mesh_type', 'N1_x0', 'N1_x1', 'N1_y0', 'N1_y1', 'N2_x0', 'N2_x1', 'N2_y0', 'N2_y1', 'N_length', 'N_width', 'P1_x', 'P1_y', 'P2_x', 'P2_y', 'P3_x', 'P3_y', 'P4_x', 'P4_y', 'P5_x', 'P5_y', 'P6_x', 'P6_y', 'P7_x', 'P7_y', 'P8_x', 'P8_y', 'P_height', 'P_radius', 'P_rhalf_width', 'P_rwidth', 'P_width', 'Parity', 'Partname', 'Radius', 'Rel_dint', 'S_length', 'S_steepness', 'Separation', 'Version', 'Width', 'Xm', 'Xx', 'Yn', 'Yy', 'collar_height', 'collar_length', 'collar_max_x', 'collar_max_y', 'collar_throat', 'collar_width', 'cos_alpha', 'cos_beta', 'cos_gamma', 'show_params', 'sin_alpha', 'sin_beta', 'sin_gamma', 'x_step', 'y_step', ] # Main parameters. Sizes in mm, relative values are obtained by dividing by `Radius`. Version: str = "12" Length: float = 108.0 # X size of foil Width: float = 38.0 # Y size of foil Height: float = 10.0 # Z size of the die punch or the die matrix for foil stamping Radius: float = 1.0 # radius of main cutting spherical tool, i.e. characteristic (smallest) radius of all curvatures Eccentricity: float = 0.05 # relative shortening of halfpipe height Rel_dint: float = Eccentricity # 0.05, relative depth of dints for fixing touching sites (bump/pit, halfpipe ridges) Angle: float = pi / 4.0 # . 90 degrees = 0.7853981633974483 rad, in/out horde angle from the long axis S_steepness: float = pi / 18.0 # 10 degrees = 0.17453292519943295 rad L_angular_width: float = pi / 3.0 # 60 degrees = 1.0471975511965976 rad Mesh_step: float = 0.1 # dx and dy in mm (for a square mesh, for a triangular mesh dy is recalculated for the angle) Mesh_rim: int = 1 # . points of mesh around the part body, at least 1, for NaN values, to detect the boundary Mesh_type: str = ("triangular", "square")[1] # regular points placing pattern in mesh for surface tesselation CE_type: int = 2 # . Ending type: 0 - Bump type, 1 - constant radius; 2- growing radius; 3 - with second curvature Grid: str = ("triangular", "square")[0] # mode of bumps/pits placing Half: str = ("Low", "Top")[0] # . for die matrix and die punch Parity: str = ("Odd", "Even")[1] # . two complimenting types of foil plates collar_throat: float = 10.0 # . size of collar at narrowest point collar_height: float = 12.0 Partname: str = "F" # . stands for Foil, is used in the output file name F_plane: str = "XY_Plane" # Distance from the center of a mesh segment with ends on the smallest sphere to the closest sphere point Mesh_accuracy: float = Radius * (1.0 - sqrt(1.0 - (Mesh_step / (2.0 * Radius)) ** 2)) # = 0.0012507822280910519 Separation: float = 2.0 * Radius * (1.0 - Eccentricity) # = 1.9 B_rdint: float = Rel_dint # . = 0.05 B_radius: float = Radius # . = 1.0, mm B_dint: float = B_radius * B_rdint # . = 0.05, mm # Bump height when a dint would not be made B_height: float = 0.5 * Separation * (1.0 + B_rdint) # . = 0.9974999999999999, mm # Bump actual height B_max_z: float = B_height - B_dint # . = 0.9474999999999999, mm # Pit height (or is it depth?) P_height: float = 0.5 * Separation * (1.0 + B_rdint) # . = 0.9974999999999999, mm # alpha - angle from vertical at steepest tangent for cylinder part # beta - angle from vertical at steepest tangent for bumps and pits # gamma - angle from vertical at steepest tangent for lips sin_alpha: float = Eccentricity # . = 0.05 cos_alpha: float = sqrt(1.0 - sin_alpha ** 2) # . = 0.998749217771909 sin_beta: float = 1.0 - B_height / (2.0 * Radius) # = 0.50125 cos_beta: float = sqrt(1.0 - sin_beta ** 2) # . = 0.8653025121308732 sin_gamma: float = (1.0 + Eccentricity) / 2.0 # . = 0.525 cos_gamma: float = sqrt(1.0 - sin_gamma ** 2) # . = 0.85110222652746 S_length: float = 1.3 * Radius # . = 1.3, mm L_length: float = 1.733 * Radius # leap radial size = 1.733, mm N_width: float = 2.75 * L_length # >= 2*L_length = 4.765750000000001, mm N_length: float = S_length # . = 1.3, mm C_width: float = 2.0 * Radius * cos_alpha # . = 1.997498435543818, mm C_length: float = Length - Width - 1.5 * N_width # = 62.851375, mm C_max_y: float = C_width / 2.0 # . = 0.998749217771909, mm C_max_z: float = Radius * (1.0 - Eccentricity) # . = 0.95, mm CE_height: float = Radius * (1.0 - Eccentricity) # = 0.95, mm CE_width: float = 2.0 * Radius * cos_gamma # . = 1.70220445305492, mm CE_rwidth: float = CE_width / Radius # . = 1.70220445305492 collar_width: float = Width + collar_throat # . = 48.0, mm collar_length: float = Length + collar_throat # . = 118.0, mm collar_max_x: float = collar_length / 2.0 # . = 59.0, mm collar_max_y: float = collar_width / 2.0 # . = 24.0, mm # if Mesh_type == "square": Mesh_step_x: float = Mesh_step # . = 0.1, mm Mesh_step_y: float = Mesh_step # . = 0.1, mm Mesh_start: float = 0.0 # . = 0.0, mm if Mesh_type == "triangular": # pyright: ignore[reportUnnecessaryComparison] # for equilateral triangles: Mesh_step_y = Mesh_step * sin(pi / 3.0) # . = 0.086602540..., mm Mesh_start = 0.5 * Mesh_step_x # . = 0.05, mm F_max_x: float = Length / 2.0 # . = 54.0, mm F_max_y: float = Width / 2.0 # . = 19.0, mm # ensure the last inner point stays inside by slightly decreasing the mesh size Mesh_max_x: float = 0.99999 * F_max_x + Mesh_rim * Mesh_step # = 54.09946, mm Mesh_max_y: float = 0.99999 * F_max_y + Mesh_rim * Mesh_step # = 19.09981, mm Xm: int = int(Length / Mesh_step_x) + 2 * Mesh_rim + 1 Yn: int = int(Width / Mesh_step_y) + 2 * Mesh_rim + 1 Xx: numpy.ndarray = numpy.linspace(-Mesh_max_x, Mesh_max_x, Xm) Yy: numpy.ndarray = numpy.linspace(-Mesh_max_y, Mesh_max_y, Yn) x_step: float = 2.0 * Radius * cos_beta # width of pits, bumps = 1.7306050242617463, mm y_step: float = x_step # if Grid == "square": if Grid == "triangular": y_step = x_step * sin(pi / 3.0) # for equilateral triangles = 1.498747914927657, mm B_width: float = 2.0 * Radius * cos_beta # bump width = 1.7306050242617463, mm B_rwidth: float = B_width / B_radius # . relative width = 1.7306050242617463 B_rhalf_width: float = B_rwidth / 2.0 # . transition sphere/thor = 0.8653025121308732 B_dint_radius: float = sqrt(B_dint * (2.0 * B_radius - B_dint)) # = 0.3122498999199199, mm P_radius: float = Radius P_width: float = x_step P_rwidth: float = P_width / P_radius # relative width P_rhalf_width: float = P_rwidth / 2.0 # transit convex to concave P1_x: float = F_max_x P1_y: float = N_width / 2.0 P2_x: float = P1_x - (F_max_y - P1_y) / tan(Angle) P2_y: float = F_max_y P3_x: float = -P2_x P3_y: float = P2_y P4_x: float = -P1_x P4_y: float = P1_y P5_x: float = -P1_x P5_y: float = -P1_y P6_x: float = -P2_x P6_y: float = -P2_y P7_x: float = P2_x P7_y: float = -P2_y P8_x: float = P1_x P8_y: float = -P1_y N1_x0: float = F_max_x - N_length N1_y0: float = -N_width / 2.0 - L_length N1_x1: float = F_max_x N1_y1: float = N_width / 2.0 + L_length N2_x0: float = -N1_x1 N2_y0: float = N1_y0 N2_x1: float = -N1_x0 N2_y1: float = N1_y1 L1_a0: float = pi * 13.0 / 12.0 # 195 degrees = 180 + 45 - 60/2 L1_a1: float = L1_a0 + pi / 3.0 # pi*17/12 # 255 degrees = L1_a0 + 60 L1_min_x: float = N1_x1 + (F_max_y - N1_x1) / tan(Angle) - L_length L1_max_x: float = F_max_x L1_min_y: float = N1_y1 - L_length L1_max_y: float = F_max_y L1_r: float = (L1_max_y - L1_min_y) / cos(Angle) / (2 * sin(L_angular_width / 2)) L1_cx: float = L1_max_x - L1_r * cos(L1_a1) L1_cy: float = L1_min_y - L1_r * sin(L1_a1) L2_a0: float = L1_a0 - pi * 3.0 / 2.0 # pi*-5/12 # -75 degrees = -45 - 60/2 L2_a1: float = L1_a1 - pi * 3.0 / 2.0 # pi*-1/12 # -15 degrees L2_r: float = L1_r L2_cx: float = -L1_cx L2_cy: float = L1_cy L3_a0: float = L1_a0 - pi # pi*1/12 L3_a1: float = L1_a1 - pi # pi*5/12 L3_r: float = L1_r L3_cx: float = -L1_cx L3_cy: float = -L1_cy L4_a0: float = L1_a0 - pi / 2.0 # pi*7/12 L4_a1: float = L1_a1 - pi / 2.0 # pi*11/12 L4_r: float = L1_r L4_cx: float = L1_cx L4_cy: float = -L1_cy Fname: str = "%s%s%s%s_%dx%dx%d_%d_%d_%g%c.stl" % (Partname, Version, Parity, Half, Length, Width, Height, Separation, Radius, Mesh_step, Mesh_type[0]) # E.g.: Fname = "F12EvenLow_108x38x10_1_1_0.1s.stl" Globals: list[str] = dir() # this is used in the following function def show_params() -> str: """Print out all parameters""" from geometry3d.near3d import near0 assert Parity in ("Even", "Odd") assert Half in ("Top", "Low") assert Grid in ("square", "triangular") assert Mesh_type in ("square", "triangular") assert near0(sin_alpha ** 2 + cos_alpha ** 2 - 1.0) assert near0(sin_beta ** 2 + cos_beta ** 2 - 1.0) assert Height > 2.0 * B_height and Height > 2.0 * P_height assert near0(B_dint_radius ** 2 + (B_radius - B_dint) ** 2 - B_radius ** 2) res: str = f"{__doc__ if __doc__ is not None else "No __doc__ found!!!"}\n" for ind in sorted(Globals): if ind in ("Xx", "Yy"): tuple4 = eval(f"{ind!r}, {ind}.size, {ind}[0], {ind}[-1]") res += "%s.size = %r [%g..%g]\n" % tuple4 elif not (ind.startswith("__") and ind.endswith("__") or ind in ("acos", "annotations", "asin", "cos", "degrees", "logging", "near", "numpy", "pi", "print_function", "sin", "sqrt", "tan")): res += "%s = %r.\n" % (ind, eval(ind)) res += f"{degrees(acos(cos_alpha)) = }\n" res += f"{degrees(asin(sin_alpha)) = }\n" res += f"{degrees(acos(cos_beta)) = }\n" res += f"{degrees(asin(sin_beta)) = }\n" res += f"{degrees(acos(cos_gamma)) = }\n" res += f"{degrees(asin(sin_gamma)) = }\n" return res if __name__ == "__main__": from geometry3d.LogError3D import log log.critical(show_params())