Skip to content

Commit 0aac44e

Browse files
authored
Merge pull request #19 from dnv-opensource/eis
Updated code base with latest changes in python_project_template v0.2.6
2 parents f18e771 + b97c86f commit 0aac44e

40 files changed

Lines changed: 725 additions & 644 deletions

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e
88
* -/-
99

1010

11-
## [0.3.2] - 2026-01-16
11+
## [0.3.2] - 2026-02-02
1212

1313
### Added
14+
* Added new module unit.py, containing class `Unit`, a helper class to store and manage units and display units. One `Unit` object represents one scalar variable.
15+
* Added new module range.py, containing class `Range`, a utility class to store and handle the variable range of a single-valued variable.
1416
* Sphinx documentation:
15-
* Added docs for modules variable_naming.py, enums.py, analytic.py and plotter.py
17+
* Added docs for modules variable_naming.py, unit.py, range.py, enums.py and analytic.py
1618
* Added Visual Studio Code settings
1719

20+
### Removed
21+
* Removed module plotter.py
22+
1823
### Changed
1924
* Updated code base with latest changes in python_project_template v0.2.6
2025
* pyproject.toml:

docs/source/component_model.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Modules
2323
component_model.model
2424
component_model.variable
2525
component_model.variable_naming
26+
component_model.unit
27+
component_model.range
2628
component_model.enums
2729
component_model.analytic
28-
component_model.plotter

examples/DrivingForce.fmu

-1.03 KB
Binary file not shown.

examples/DrivingForce6D.fmu

-959 Bytes
Binary file not shown.

examples/HarmonicOscillator.fmu

-1.33 KB
Binary file not shown.

examples/HarmonicOscillator6D.fmu

-480 Bytes
Binary file not shown.

examples/axle.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def init_drive(self):
2929
self.wheels[0].pos = np.array([0.0, 0.0], float)
3030
self.wheels[1].pos = np.array([self.a, 0.0], float)
3131
for i in range(2):
32-
self.wheels[i].track = None
32+
self.wheels[i].track_reset()
3333
self.times = []
3434

3535
def drive(self, time: float, dt: float):
@@ -90,22 +90,21 @@ def pos(self) -> np.ndarray:
9090
return self._pos
9191

9292
@pos.setter
93-
def pos(self, newpos: list[float] | np.ndarray):
94-
self.track = newpos
93+
def pos(self, newpos: np.ndarray):
94+
self.track_add(newpos)
9595
self._pos = np.array(newpos, float)
9696

9797
@property
9898
def track(self) -> list[list[float]]:
9999
return self._track
100100

101-
@track.setter
102-
def track(self, newpos: list[float] | np.ndarray | None):
103-
"""Remember the track. None: start new track."""
104-
if newpos is None: # reset
105-
self._track = [[], []]
106-
else:
107-
for i in range(2):
108-
self._track[i].append(newpos[i])
101+
def track_reset(self):
102+
self._track = [[], []]
103+
104+
def track_add(self, newpos: np.ndarray):
105+
"""Remember the track."""
106+
for i in range(2):
107+
self._track[i].append(newpos[i])
109108

110109

111110
class Motor:

examples/bouncing_ball_3d.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
# pyright: reportAttributeAccessIssue=false
2-
# pyright: reportOptionalMemberAccess=false
31
from math import sqrt
2+
from typing import Any
43

54
import numpy as np
65

@@ -30,26 +29,29 @@ class BouncingBall3D(Model):
3029
def __init__(
3130
self,
3231
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,
3837
min_speed_z: float = 1e-6,
39-
**kwargs,
38+
**kwargs: Any,
4039
):
4140
super().__init__(name, description, author="DNV, SEACo project", **kwargs)
41+
self.pos: np.ndarray
4242
self._pos = self._interface("pos", pos)
4343
self._speed = self._interface("speed", speed)
44+
self.g: float
4445
self._g = self._interface("g", g)
4546
self.a = np.array((0, 0, -self.g), float)
47+
self.e: float
4648
self._e = self._interface("e", e)
4749
self.min_speed_z = min_speed_z
4850
self.stopped = False
4951
self.time = 0.0
5052
self._p_bounce = self._interface("p_bounce", ("0m", "0m", "0m")) # Note: 3D, but z always 0
5153
# 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)
5355

5456
def do_step(self, current_time: float, step_size: float) -> bool:
5557
"""Perform a simulation step from `self.time` to `self.time + step_size`.
@@ -110,7 +112,7 @@ def exit_initialization_mode(self):
110112
super().exit_initialization_mode()
111113
self.a = np.array((0, 0, -self.g), float)
112114

113-
def _interface(self, name: str, start: str | float | tuple) -> Variable:
115+
def _interface(self, name: str, start: str | float | tuple[str | float, ...]) -> Variable:
114116
"""Define a FMU2 interface variable, using the variable interface.
115117
116118
Args:

examples/bouncing_ball_3d_pythonfmu.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from math import sqrt
2+
from typing import Any
23

34
import numpy as np
45
from pythonfmu import Fmi2Causality, Fmi2Slave, Real # type: ignore[import-untyped]
@@ -16,7 +17,7 @@ class BouncingBall3D(Fmi2Slave):
1617
* Internal units are assumed as SI (m,s,rad)
1718
"""
1819

19-
def __init__(self, **kwargs):
20+
def __init__(self, **kwargs: Any):
2021
super().__init__(
2122
name="BouncingBall3D",
2223
description="Another Python-based BouncingBall model, using Model and Variable to construct a FMU",
@@ -63,7 +64,7 @@ def __init__(self, **kwargs):
6364
self.accelerationY = 0.0
6465
self.accelerationZ = -self.g
6566

66-
def do_step(self, current_time, step_size) -> bool:
67+
def do_step(self, current_time: float, step_size: float) -> bool:
6768
"""Perform a simulation step from `self.time` to `self.time + step_size`.
6869
6970
With respect to bouncing (self.t_bounce should be initialized to a negative value)

examples/driving_force_fmu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(
6666
self.freq = np.array((1.0,) * self.dim, float)
6767
self.d_freq = np.array((0.0,) * self.dim, float)
6868
self.function = func
69-
self.func: Callable
69+
self.func: Callable # type: ignore[reportMissingTypeArgument] ## kwargs
7070
self.f = np.array((0.0,) * self.dim, float)
7171
self.v_osc = (0.0,) * self.dim
7272
self._ampl = Variable(self, "ampl", "The amplitude of the force in N", start=_ampl)
@@ -102,7 +102,7 @@ def exit_initialization_mode(self):
102102
self.func = partial(
103103
self.function,
104104
ampl=np.array(self.ampl, float),
105-
omega=np.array(2 * np.pi * self.freq, float), # type: ignore # it is an ndarray!
106-
d_omega=np.array(2 * np.pi * self.d_freq, float), # type: ignore # it is an ndarray!
105+
omega=np.array(2 * np.pi * self.freq, float),
106+
d_omega=np.array(2 * np.pi * self.d_freq, float),
107107
)
108108
logger.info(f"Initial settings: ampl={self.ampl}, freq={self.freq}, d_freq={self.d_freq}")

0 commit comments

Comments
 (0)