|
| 1 | +from shapely import difference |
| 2 | +from shapely.ops import linemerge |
| 3 | + |
| 4 | +from ..base import BaseRollPass |
| 5 | +from ...config import Config |
| 6 | +from ...rotator import Rotator |
| 7 | + |
| 8 | + |
| 9 | +@BaseRollPass.rotation |
| 10 | +def auto_rotation(self: BaseRollPass): |
| 11 | + return Config.ROLL_PASS_AUTO_ROTATION |
| 12 | + |
| 13 | + |
| 14 | +@BaseRollPass.rotation |
| 15 | +def detect_already_rotated(self: BaseRollPass): |
| 16 | + if Config.ROLL_PASS_AUTO_ROTATION and self.parent is not None: |
| 17 | + try: |
| 18 | + prev = self.prev |
| 19 | + except IndexError: |
| 20 | + return True |
| 21 | + |
| 22 | + while True: |
| 23 | + if isinstance(prev, BaseRollPass): |
| 24 | + return True |
| 25 | + if isinstance(prev, Rotator): |
| 26 | + return False |
| 27 | + try: |
| 28 | + prev = prev.prev |
| 29 | + except IndexError: |
| 30 | + return True |
| 31 | + |
| 32 | + |
| 33 | +@BaseRollPass.orientation |
| 34 | +def default_orientation(self: BaseRollPass): |
| 35 | + return 0 |
| 36 | + |
| 37 | + |
| 38 | +@BaseRollPass.volume |
| 39 | +def volume(self: BaseRollPass): |
| 40 | + return (self.in_profile.cross_section.area + 2 * self.out_profile.cross_section.area |
| 41 | + ) / 3 * self.length |
| 42 | + |
| 43 | + |
| 44 | +@BaseRollPass.surface_area |
| 45 | +def surface_area(self: BaseRollPass): |
| 46 | + return (self.in_profile.cross_section.perimeter + 2 * self.out_profile.cross_section.perimeter |
| 47 | + ) / 3 * self.length |
| 48 | + |
| 49 | + |
| 50 | +@BaseRollPass.duration |
| 51 | +def duration(self: BaseRollPass): |
| 52 | + return self.length / self.velocity |
| 53 | + |
| 54 | + |
| 55 | +@BaseRollPass.length |
| 56 | +def length(self: BaseRollPass): |
| 57 | + return -self.entry_point + self.exit_point |
| 58 | + |
| 59 | + |
| 60 | +@BaseRollPass.displaced_cross_section |
| 61 | +def displaced_cross_section(self: BaseRollPass): |
| 62 | + return difference(self.in_profile.cross_section, self.usable_cross_section) |
| 63 | + |
| 64 | + |
| 65 | +@BaseRollPass.reappearing_cross_section |
| 66 | +def reappearing_cross_section(self: BaseRollPass): |
| 67 | + return difference(self.out_profile.cross_section, self.in_profile.cross_section) |
| 68 | + |
| 69 | + |
| 70 | +@BaseRollPass.elongation_efficiency |
| 71 | +def elongation_efficiency(self: BaseRollPass): |
| 72 | + return 1 - self.reappearing_cross_section.area / self.displaced_cross_section.area |
| 73 | + |
| 74 | + |
| 75 | +@BaseRollPass.target_filling_ratio(trylast=True) |
| 76 | +def default_target_filling(self: BaseRollPass): |
| 77 | + return 1 |
| 78 | + |
| 79 | + |
| 80 | +@BaseRollPass.target_width |
| 81 | +def target_width_from_target_filling_ratio(self: BaseRollPass): |
| 82 | + if self.has_value("target_filling_ratio"): |
| 83 | + return self.target_filling_ratio * self.usable_width |
| 84 | + |
| 85 | + |
| 86 | +@BaseRollPass.target_filling_ratio |
| 87 | +def target_filling_ratio_from_target_width(self: BaseRollPass): |
| 88 | + if self.has_set_or_cached("target_width"): |
| 89 | + return self.target_width / self.usable_width |
| 90 | + |
| 91 | + |
| 92 | +@BaseRollPass.target_cross_section_area |
| 93 | +def target_cross_section_area_from_target_cross_section_filling_ratio(self: BaseRollPass): |
| 94 | + if self.has_set_or_cached("target_cross_section_filling_ratio"): |
| 95 | + return self.target_cross_section_filling_ratio * self.usable_cross_section.area |
| 96 | + |
| 97 | + |
| 98 | +@BaseRollPass.target_cross_section_filling_ratio |
| 99 | +def target_cross_section_filling_ratio_from_target_cross_section_area(self: BaseRollPass): |
| 100 | + if self.has_value("target_cross_section_area"): # important has_value for computing from target_width |
| 101 | + return self.target_cross_section_area / self.usable_cross_section.area |
| 102 | + |
| 103 | + |
| 104 | +@BaseRollPass.exit_point |
| 105 | +def exit_point(self: BaseRollPass): |
| 106 | + return 0 |
| 107 | + |
| 108 | + |
| 109 | +@BaseRollPass.Profile.contact_lines |
| 110 | +def contact_contour_lines(self: BaseRollPass.Profile): |
| 111 | + rp = self.roll_pass |
| 112 | + return [linemerge(cl.intersection(self.cross_section.exterior.buffer(1e-9))) for cl in rp.contour_lines] |
| 113 | + |
| 114 | + |
| 115 | +@BaseRollPass.front_tension |
| 116 | +def default_front_tension(self: BaseRollPass): |
| 117 | + return 0 |
| 118 | + |
| 119 | + |
| 120 | +@BaseRollPass.back_tension |
| 121 | +def default_back_tension(self: BaseRollPass): |
| 122 | + return 0 |
| 123 | + |
| 124 | + |
0 commit comments