-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathalltypes.py
More file actions
52 lines (38 loc) · 1.6 KB
/
alltypes.py
File metadata and controls
52 lines (38 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pythonfmu3 import Fmi3Causality, Fmi3Variability, Dimension, Fmi3Slave, Fmi3Status, Float64, Int32, Int64, UInt64, String, Boolean
TYPES = [UInt64, Float64, Boolean, Int32, Int64]
CAUSALITY = [Fmi3Causality.output, Fmi3Causality.input]
type_map = {
UInt64: int,
Float64: float,
Int32: int,
Int64: int,
Boolean: bool
}
def var_names(var_type, causality):
return f"{var_type.__name__.lower()}_{causality.name.lower()}"
def init_var(var_type, causality):
return type_map[var_type]()
def create_vars(self):
for var_type in TYPES:
for causality in CAUSALITY:
name = var_names(var_type, causality)
if var_type == Float64:
var = var_type(name, causality=causality, variability=Fmi3Variability.continuous)
else:
var = var_type(name, causality=causality, variability=Fmi3Variability.discrete)
setattr(self, name, init_var(var_type, causality))
self.register_variable(var)
class AllTypes(Fmi3Slave):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.author = "Stephen Smith"
self.description = "All types example"
self.time = 0.0
self.register_variable(Float64("time", causality=Fmi3Causality.independent, variability=Fmi3Variability.continuous))
create_vars(self)
def do_step(self, current_time: float, step_size: float) -> Fmi3Status:
# feedthrough
for var_type in TYPES:
input_var = getattr(self, var_names(var_type, Fmi3Causality.input))
setattr(self, var_names(var_type, Fmi3Causality.output), input_var)
return True