|
1 | | -# pyright: reportAttributeAccessIssue=false |
2 | | -# pyright: reportOptionalMemberAccess=false |
3 | 1 | from math import sqrt |
| 2 | +from typing import Any |
4 | 3 |
|
5 | 4 | import numpy as np |
6 | 5 |
|
@@ -30,26 +29,29 @@ class BouncingBall3D(Model): |
30 | 29 | def __init__( |
31 | 30 | self, |
32 | 31 | name: str = "BouncingBall3D", |
33 | | - description="Another Python-based BouncingBall model, using Model and Variable to construct a FMU", |
34 | | - pos: tuple = ("0 m", "0 m", "10 inch"), |
35 | | - speed: tuple = ("1 m/s", "0 m/s", "0 m/s"), |
36 | | - g="9.81 m/s^2", |
37 | | - e=0.9, |
| 32 | + description: str = "Another Python-based BouncingBall model, using Model and Variable to construct a FMU", |
| 33 | + pos: tuple[str | float, ...] = ("0 m", "0 m", "10 inch"), |
| 34 | + speed: tuple[str | float, ...] = ("1 m/s", "0 m/s", "0 m/s"), |
| 35 | + g: str | float = "9.81 m/s^2", |
| 36 | + e: float = 0.9, |
38 | 37 | min_speed_z: float = 1e-6, |
39 | | - **kwargs, |
| 38 | + **kwargs: Any, |
40 | 39 | ): |
41 | 40 | super().__init__(name, description, author="DNV, SEACo project", **kwargs) |
| 41 | + self.pos: np.ndarray |
42 | 42 | self._pos = self._interface("pos", pos) |
43 | 43 | self._speed = self._interface("speed", speed) |
| 44 | + self.g: float |
44 | 45 | self._g = self._interface("g", g) |
45 | 46 | self.a = np.array((0, 0, -self.g), float) |
| 47 | + self.e: float |
46 | 48 | self._e = self._interface("e", e) |
47 | 49 | self.min_speed_z = min_speed_z |
48 | 50 | self.stopped = False |
49 | 51 | self.time = 0.0 |
50 | 52 | self._p_bounce = self._interface("p_bounce", ("0m", "0m", "0m")) # Note: 3D, but z always 0 |
51 | 53 | # provoke an update at simulation start: |
52 | | - self.t_bounce, self.p_bounce = (-1.0, self.pos) # type: ignore |
| 54 | + self.t_bounce, self.p_bounce = (-1.0, self.pos) |
53 | 55 |
|
54 | 56 | def do_step(self, current_time: float, step_size: float) -> bool: |
55 | 57 | """Perform a simulation step from `self.time` to `self.time + step_size`. |
@@ -110,7 +112,7 @@ def exit_initialization_mode(self): |
110 | 112 | super().exit_initialization_mode() |
111 | 113 | self.a = np.array((0, 0, -self.g), float) |
112 | 114 |
|
113 | | - def _interface(self, name: str, start: str | float | tuple) -> Variable: |
| 115 | + def _interface(self, name: str, start: str | float | tuple[str | float, ...]) -> Variable: |
114 | 116 | """Define a FMU2 interface variable, using the variable interface. |
115 | 117 |
|
116 | 118 | Args: |
|
0 commit comments