-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathfmi3.pxd
More file actions
225 lines (195 loc) · 9.24 KB
/
Copy pathfmi3.pxd
File metadata and controls
225 lines (195 loc) · 9.24 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2025 Modelon AB
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Module containing the FMI3 interface Python wrappers.
import numpy as np
cimport numpy as np
cimport pyfmi.fmil_import as FMIL
cimport pyfmi.fmil3_import as FMIL3
cimport pyfmi.fmi_base as FMI_BASE
cdef class FMI3ModelVariable:
""" Class defining data structure based on the XML elements for ModelVariables. """
cdef FMIL3.fmi3_value_reference_t _value_reference
cdef FMIL3.fmi3_base_type_enu_t _type
cdef FMIL3.fmi3_variability_enu_t _variability
cdef FMIL3.fmi3_causality_enu_t _causality
cdef FMIL3.fmi3_initial_enu_t _initial
cdef object _name
cdef object _description
cdef FMIL3.fmi3_boolean_t _alias
cdef class FMI3EventInfo:
cdef public FMIL3.fmi3_boolean_t newDiscreteStatesNeeded
cdef public FMIL3.fmi3_boolean_t terminateSimulation
cdef public FMIL3.fmi3_boolean_t nominalsOfContinuousStatesChanged
cdef public FMIL3.fmi3_boolean_t valuesOfContinuousStatesChanged
cdef public FMIL3.fmi3_boolean_t nextEventTimeDefined
cdef public FMIL3.fmi3_float64_t nextEventTime
# This will be populated further once we add support for CS and Clocks in particular.
cdef class DeclaredType3:
cdef str _name
cdef str _description
cdef str _quantity
cdef class EnumerationType3(DeclaredType3):
cdef dict _items
cdef class FMUState3:
"""Class representing the FMU state, used with get and set FMU state. """
cdef FMIL3.fmi3_FMU_state_t fmu_state
cdef dict _internal_state_variables
cdef class FMUModelBase3(FMI_BASE.ModelBase):
# FMIL related variables
cdef FMIL.fmi_import_context_t* _context
cdef FMIL3.fmi3_import_t* _fmu
cdef FMIL3.fmi3_fmu_kind_enu_t _fmu_kind
cdef FMIL.fmi_version_enu_t _version
cdef FMIL.size_t _nEventIndicators # format with snake case?
cdef FMIL.size_t _nContinuousStates # format with snake case?
cdef FMIL3.fmi3_boolean_t _event_info_new_discrete_states_needed
cdef FMIL3.fmi3_boolean_t _event_info_terminate_simulation
cdef FMIL3.fmi3_boolean_t _event_info_nominals_of_continuous_states_changed
cdef FMIL3.fmi3_boolean_t _event_info_values_of_continuous_states_changed
cdef FMIL3.fmi3_boolean_t _event_info_next_event_time_defined
cdef FMIL3.fmi3_float64_t _event_info_next_event_time
cdef FMI3EventInfo _eventInfo
# Internal values
cdef public float _last_accepted_time
cdef public object _enable_logging
cdef public object _loaded_with_log_level
cdef public object _event_info
cdef object _fmu_full_path
cdef object _modelName
cdef object _t
cdef int _allow_unzipped_fmu
cdef int _allocated_context, _allocated_dll, _allocated_fmu, _allocated_xml
cdef _WorkerClass3 _worker_object
# Caching
cdef list _states_references
cdef list _derivatives_references
cdef list _inputs_references
cdef list _outputs_references
cdef dict _outputs_states_dependencies
cdef dict _outputs_inputs_dependencies
cdef dict _outputs_states_dependencies_kind
cdef dict _outputs_inputs_dependencies_kind
cdef dict _derivatives_states_dependencies
cdef dict _derivatives_inputs_dependencies
cdef dict _derivatives_states_dependencies_kind
cdef dict _derivatives_inputs_dependencies_kind
cdef dict _group_A
cdef dict _group_B
cdef dict _group_C
cdef dict _group_D
cdef int _initialized_fmu
cdef object _has_entered_init_mode # XXX: this is public in FMI2 but I don't see why
cdef public np.ndarray _preinit_nominal_continuous_states
cpdef set_float64(self, valueref, values)
cpdef set_float32(self, valueref, values)
cpdef set_int64 (self, valueref, values)
cpdef set_int32 (self, valueref, values)
cpdef set_int16 (self, valueref, values)
cpdef set_int8 (self, valueref, values)
cpdef set_uint64 (self, valueref, values)
cpdef set_uint32 (self, valueref, values)
cpdef set_uint16 (self, valueref, values)
cpdef set_uint8 (self, valueref, values)
cpdef set_boolean(self, valueref, values)
cpdef set_string (self, valueref, values)
cpdef set_enum (self, valueref, values)
cpdef np.ndarray get_float64(self, valueref)
cpdef np.ndarray get_float32(self, valueref)
cpdef np.ndarray get_int64 (self, valueref)
cpdef np.ndarray get_int32 (self, valueref)
cpdef np.ndarray get_int16 (self, valueref)
cpdef np.ndarray get_int8 (self, valueref)
cpdef np.ndarray get_uint64 (self, valueref)
cpdef np.ndarray get_uint32 (self, valueref)
cpdef np.ndarray get_uint16 (self, valueref)
cpdef np.ndarray get_uint8 (self, valueref)
cpdef np.ndarray get_boolean(self, valueref)
cpdef list get_string (self, valueref)
cpdef np.ndarray get_enum (self, valueref)
cpdef FMIL3.fmi3_value_reference_t get_variable_valueref(self, variable_name) except *
cdef FMIL3.fmi3_base_type_enu_t _get_variable_data_type(self, variable_name) except *
cdef FMIL3.fmi3_causality_enu_t _get_variable_causality(self, variable_name) except *
cpdef get_variable_description(self, variable_name)
cdef _add_variable(self, FMIL3.fmi3_import_variable_t* variable)
cdef FMIL3.fmi3_status_t _get_directional_derivative(self, np.ndarray v_ref, np.ndarray z_ref, np.ndarray dv, np.ndarray dz) except *
cpdef get_variable_unbounded(self, str variable_name)
cdef _get_variable_description(self, FMIL3.fmi3_import_variable_t*)
cdef _get_alias_description(self, FMIL3.fmi3_import_alias_variable_t*)
cdef _get_variable_nominal(self, FMIL3.fmi3_import_variable_t* variable, int _override_erroneous_nominal)
cpdef get_variable_start(self, str variable_name)
cpdef get_variable_min(self, str variable_name)
cpdef get_variable_max(self, str variable_name)
cpdef serialize_fmu_state(self, FMUState3 state)
cpdef deserialize_fmu_state(self, list serialized_fmu)
cpdef serialized_fmu_state_size(self, FMUState3 state)
cpdef get_output_dependencies(self)
cpdef get_output_dependencies_kind(self)
cpdef get_derivatives_dependencies(self)
cpdef get_derivatives_dependencies_kind(self)
# internal methods for efficiency
cdef FMIL3.fmi3_status_t _set_float64(self, FMIL3.fmi3_value_reference_t*, FMIL3.fmi3_float64_t*, size_t)
cdef FMIL3.fmi3_status_t _get_float64(self, FMIL3.fmi3_value_reference_t*, size_t, FMIL3.fmi3_float64_t*)
cdef class FMUModelME3(FMUModelBase3):
cdef public FMIL3.fmi3_boolean_t force_finite_differences
cdef public int finite_differences_method
cpdef _get_time(self)
cpdef _set_time(self, FMIL3.fmi3_float64_t t)
cpdef get_derivatives(self)
cdef FMIL3.fmi3_status_t _get_derivatives(self, FMIL3.fmi3_float64_t[:] values)
cdef FMIL3.fmi3_status_t _get_continuous_states_fmil(self, FMIL3.fmi3_float64_t[:] ndx)
cdef FMIL3.fmi3_status_t _set_continuous_states_fmil(self, FMIL3.fmi3_float64_t[:] ndx)
cdef FMIL3.fmi3_status_t _get_event_indicators(self, FMIL3.fmi3_float64_t[:] ndx)
cdef FMIL3.fmi3_status_t _completed_integrator_step(self,
FMIL3.fmi3_boolean_t no_set_FMU_state_prior_to_current_point,
FMIL3.fmi3_boolean_t* enter_event_mode,
FMIL3.fmi3_boolean_t* terminate_simulation
)
cdef FMIL3.fmi3_status_t _get_nominal_continuous_states_fmil(self, FMIL3.fmi3_float64_t* xnominal, size_t nx)
cdef class FMUModelCS3(FMUModelBase3):
cdef public bool do_step_terminated
cdef FMIL3.fmi3_boolean_t _instantiated_with_early_return
cpdef _get_time(self)
cpdef _set_time(self, FMIL3.fmi3_float64_t t)
cpdef FMIL3.fmi3_status_t do_step(self, FMIL3.fmi3_float64_t current_t, FMIL3.fmi3_float64_t step_size, new_step=*)
cdef FMIL3.fmi3_status_t _get_output_derivatives(self, np.ndarray value_refs, np.ndarray values, np.ndarray orders)
cdef class _WorkerClass3:
cdef int _dim
cdef np.ndarray _tmp1_val, _tmp2_val, _tmp3_val, _tmp4_val
cdef np.ndarray _tmp1_ref, _tmp2_ref, _tmp3_ref, _tmp4_ref
cdef FMIL3.fmi3_float64_t* get_real_vector(self, int index)
cdef FMIL3.fmi3_value_reference_t* get_value_reference_vector(self, int index)
cdef np.ndarray get_value_reference_numpy_vector(self, int index)
cdef np.ndarray get_real_numpy_vector(self, int index)
cpdef verify_dimensions(self, int dim)
cdef void _cleanup_on_load_error(
FMIL3.fmi3_import_t* fmu_3,
FMIL.fmi_import_context_t* context,
int allow_unzipped_fmu,
FMIL.jm_callbacks callbacks,
bytes fmu_temp_dir,
list log_data
)
cdef object _load_fmi3_fmu(
fmu,
object log_file_name,
str kind,
int log_level,
int allow_unzipped_fmu,
FMIL.fmi_import_context_t* context,
bytes fmu_temp_dir,
FMIL.jm_callbacks callbacks,
list log_data
)