Skip to content

Commit

Permalink
Update FMI 3.0 headers and schema to v3.0-rc.2
Browse files Browse the repository at this point in the history
and use Reference FMUs v0.0.15 in CI
  • Loading branch information
t-sommer committed Apr 27, 2022
1 parent 3588bd7 commit ac7d0ca
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 56 deletions.
17 changes: 2 additions & 15 deletions fmpy/c-code/fmi3FunctionTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "fmi3PlatformTypes.h"

/*
This header file defines the data and function types of FMI 3.0-beta.5.
This header file defines the data and function types of FMI 3.0-rc.2.
It must be used when compiling an FMU or an FMI importer.
Copyright (C) 2011 MODELISAR consortium,
Expand Down Expand Up @@ -78,14 +78,6 @@ typedef enum {
} fmi3IntervalQualifier;
/* end::IntervalQualifier[] */

/* tag::EventQualifier[] */
typedef enum {
fmi3EventFalse,
fmi3EventTrue,
fmi3EventUnknown
} fmi3EventQualifier;
/* end::EventQualifier[] */

/* tag::CallbackLogMessage[] */
typedef void (*fmi3LogMessageCallback) (fmi3InstanceEnvironment instanceEnvironment,
fmi3Status status,
Expand Down Expand Up @@ -190,12 +182,7 @@ typedef fmi3Status fmi3ExitInitializationModeTYPE(fmi3Instance instance);
/* end::ExitInitializationMode[] */

/* tag::EnterEventMode[] */
typedef fmi3Status fmi3EnterEventModeTYPE(fmi3Instance instance,
fmi3EventQualifier stepEvent,
fmi3EventQualifier stateEvent,
const fmi3Int32 rootsFound[],
size_t nEventIndicators,
fmi3EventQualifier timeEvent);
typedef fmi3Status fmi3EnterEventModeTYPE(fmi3Instance instance);
/* end::EnterEventMode[] */

/* tag::Terminate[] */
Expand Down
35 changes: 28 additions & 7 deletions fmpy/c-code/fmi3Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define fmi3Functions_h

/*
This header file declares the functions of FMI 3.0-beta.5.
This header file declares the functions of FMI 3.0-rc.2.
It must be used when compiling an FMU.
In order to have unique function names even if several FMUs
Expand Down Expand Up @@ -60,10 +60,24 @@ extern "C" {
#include "fmi3FunctionTypes.h"
#include <stdlib.h>

/*
Allow override of FMI3_FUNCTION_PREFIX: If FMI3_OVERRIDE_FUNCTION_PREFIX
is defined, then FMI3_ACTUAL_FUNCTION_PREFIX will be used, if defined,
or no prefix if undefined. Otherwise FMI3_FUNCTION_PREFIX will be used,
if defined.
*/
#if !defined(FMI3_OVERRIDE_FUNCTION_PREFIX) && defined(FMI3_FUNCTION_PREFIX)
#define FMI3_ACTUAL_FUNCTION_PREFIX FMI3_FUNCTION_PREFIX
#endif

/*
Export FMI3 API functions on Windows and under GCC.
This definition has been changed to always export the symbols.
If custom linking is desired then the FMI3_Export must be
defined before including this file. For instance,
it may be set to __declspec(dllimport).
*/
#if !defined(FMI3_Export)
#if !defined(FMI3_ACTUAL_FUNCTION_PREFIX)
#if defined _WIN32 || defined __CYGWIN__
/* Note: both gcc & MSVC on Windows support this syntax. */
#define FMI3_Export __declspec(dllexport)
Expand All @@ -74,15 +88,22 @@ This definition has been changed to always export the symbols.
#define FMI3_Export
#endif
#endif
#else
#define FMI3_Export
#endif
#endif

/*
Macro to construct the real function name.
This definition has been changed to add no prefix.
*/
/* Macros to construct the real function name (prepend function name by FMI3_FUNCTION_PREFIX) */
#if defined(FMI3_ACTUAL_FUNCTION_PREFIX)
#define fmi3Paste(a,b) a ## b
#define fmi3PasteB(a,b) fmi3Paste(a,b)
#define fmi3FullName(name) fmi3PasteB(FMI3_ACTUAL_FUNCTION_PREFIX, name)
#else
#define fmi3FullName(name) name
#endif

/* FMI version */
#define fmi3Version "3.0-beta.5"
#define fmi3Version "3.0-rc.2"

/***************************************************
Common Functions
Expand Down
2 changes: 1 addition & 1 deletion fmpy/c-code/fmi3PlatformTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define fmi3PlatformTypes_h

/*
This header file defines the data types of FMI 3.0-beta.5.
This header file defines the data types of FMI 3.0-rc.2.
It must be used by both FMU and FMI master.
Copyright (C) 2008-2011 MODELISAR consortium,
Expand Down
29 changes: 3 additions & 26 deletions fmpy/fmi3.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
fmi3IntervalUnchanged = 1
fmi3IntervalChanged = 2

# enum fmi3EventQualifier
fmi3EventQualifier = c_int
fmi3EventFalse = 0
fmi3EventTrue = 1
fmi3EventUnknown = 2

# callback functions
fmi3LogMessageCallback = CFUNCTYPE(None, fmi3InstanceEnvironment, fmi3Status, fmi3String, fmi3String)
fmi3ClockUpdateCallback = CFUNCTYPE(None, fmi3InstanceEnvironment)
Expand Down Expand Up @@ -169,14 +163,7 @@ def __init__(self, **kwargs):

self._fmi3Function('fmi3ExitInitializationMode', [(fmi3Instance, 'instance')])

self._fmi3Function('fmi3EnterEventMode', [
(fmi3Instance, 'instance'),
(fmi3EventQualifier, 'stepEvent'),
(fmi3EventQualifier, 'stateEvent'),
(POINTER(fmi3Int32), 'rootsFound'),
(c_size_t, 'nEventIndicators'),
(fmi3EventQualifier, 'timeEvent'),
])
self._fmi3Function('fmi3EnterEventMode', [(fmi3Instance, 'instance')])

self._fmi3Function('fmi3Terminate', [(fmi3Instance, 'instance')])

Expand Down Expand Up @@ -591,18 +578,8 @@ def setIntervalDecimal(self, valueReferences, intervals):
def setIntervalFraction(self, valueReferences, intervalCounters, resolutions):
self.fmi3SetIntervalFraction(self.component, valueReferences, len(valueReferences), intervalCounters, resolutions, len(intervalCounters))

def enterEventMode(self, stepEvent=False, stateEvent=False, rootsFound=[], timeEvent=False):

rootsFound = (fmi3Int32 * len(rootsFound))(*rootsFound)

return self.fmi3EnterEventMode(
self.component,
fmi3EventQualifier(stepEvent),
fmi3EventQualifier(stateEvent),
rootsFound,
len(rootsFound),
fmi3EventQualifier(timeEvent)
)
def enterEventMode(self):
self.fmi3EnterEventMode(self.component)

def updateDiscreteStates(self):

Expand Down
2 changes: 1 addition & 1 deletion fmpy/schema/fmi3/fmi3ModelDescription.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</xs:element>
<xs:element ref="Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="fmiVersion" fixed="3.0-beta.5" use="required"/>
<xs:attribute name="fmiVersion" fixed="3.0-rc.2" use="required"/>
<xs:attribute name="modelName" type="xs:string" use="required"/>
<xs:attribute name="instantiationToken" type="xs:normalizedString" use="required"/>
<xs:attribute name="description" type="xs:string"/>
Expand Down
2 changes: 1 addition & 1 deletion fmpy/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def simulateME(model_description, fmu, start_time, stop_time, solver_name, step_

else:

fmu.enterEventMode(stepEvent=step_event, rootsFound=roots_found, timeEvent=time_event)
fmu.enterEventMode()

if input_event:
input.apply(time=time, after_event=True)
Expand Down
7 changes: 6 additions & 1 deletion fmpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,6 @@ def compile_dll(model_description, sources_dir, compiler=None, target_platform=N
compiler = 'gcc'

include_dir = os.path.join(os.path.dirname(__file__), 'c-code')
preprocessor_definitions = []

source_files = []

Expand All @@ -770,6 +769,12 @@ def compile_dll(model_description, sources_dir, compiler=None, target_platform=N

source_files += source_file_set.sourceFiles

preprocessor_definitions = []

if model_description.fmiVersion.startswith('3.0'):
preprocessor_definitions.append('FMI3_OVERRIDE_FUNCTION_PREFIX')
preprocessor_definitions.append('FMI3_FUNCTION_PREFIX=""')

for definition in source_file_set.preprocessorDefinitions:
literal = definition.name
if definition.value is not None:
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def resources_dir():
@pytest.fixture(scope='session')
def reference_fmus_dist_dir(resources_dir):

version = '0.0.14'
checksum = 'a4a4916702d2bb6b300da9120ecfa62f5091c8a53926b0afe1f04b1933e04f03'
version = '0.0.15'
checksum = '845a065c5dff16fee59211d52e63f1207c728fce478876aa9e50a6ba2ec15fcb'

zip_file = download_file(
url=f'https://github.com/modelica/Reference-FMUs/releases/download/v{version}/Reference-FMUs-{version}.zip',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_reference_fmus.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def test_fmi3(reference_fmus_dist_dir, reference_fmus_repo_dir):

if model_name == 'Feedthrough':
start_values = {
'real_fixed_param': 1,
'string_param': "FMI is awesome!"
'Float64_fixed_parameter': 1,
'String_parameter': "FMI is awesome!"
}
output_interval = 1e-3
in_csv = reference_fmus_repo_dir / model_name / f'{model_name}_in.csv'
Expand Down

0 comments on commit ac7d0ca

Please sign in to comment.