Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Generate the Modelica code for FMI 2.0 Model Exchange fmus.
- Added Wrapper functions for FMI 2.0 in libOpenModelicaFMIRuntimeC. git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16631 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
- Loading branch information
Showing
10 changed files
with
639 additions
and
186 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* This file is part of OpenModelica. | ||
* | ||
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), | ||
* c/o Linköpings universitet, Department of Computer and Information Science, | ||
* SE-58183 Linköping, Sweden. | ||
* | ||
* All rights reserved. | ||
* | ||
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR | ||
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. | ||
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE | ||
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
* | ||
* The OpenModelica software and the Open Source Modelica | ||
* Consortium (OSMC) Public License (OSMC-PL) are obtained | ||
* from OSMC, either from the above address, | ||
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or | ||
* http://www.openmodelica.org, and in the OpenModelica distribution. | ||
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This program is distributed WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
* | ||
* See the full OSMC Public License conditions for more details. | ||
* | ||
*/ | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "FMI2Common.h" | ||
|
||
/* | ||
* Used for logging import messages. | ||
*/ | ||
void importlogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message) | ||
{ | ||
printf("module = %s, log level = %s: %s\n", module, jm_log_level_to_string(log_level), message);fflush(NULL); | ||
} | ||
|
||
/* | ||
* Used for logging FMU messages. | ||
* Logger function used by the FMU 2.0 internally. | ||
*/ | ||
void fmi2logger(fmi2_component_t c, fmi2_string_t instanceName, fmi2_status_t status, fmi2_string_t category, fmi2_string_t message, ...) | ||
{ | ||
va_list argp; | ||
va_start(argp, message); | ||
fmi2_log_forwarding_v(c, instanceName, status, category, message, argp); | ||
va_end(argp); | ||
fflush(NULL); | ||
} | ||
|
||
/* | ||
* OpenModelica uses signed integers and according to FMI specifications the value references should be unsigned integers. | ||
* So to overcome this we use value references as Real in the Modelica code. | ||
* This function converts back the value references from double to int and use them in FMI specific functions. | ||
*/ | ||
fmi2_value_reference_t* real_to_fmi2_value_reference(int numberOfValueReferences, double* valuesReferences) | ||
{ | ||
fmi2_value_reference_t* valuesReferences_int = malloc(sizeof(fmi2_value_reference_t)*numberOfValueReferences); | ||
int i; | ||
for (i = 0 ; i < numberOfValueReferences ; i++) | ||
valuesReferences_int[i] = (int)valuesReferences[i]; | ||
return valuesReferences_int; | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiGetReal. | ||
* parameter flowStatesInput is dummy and is only used to run the equations in sequence. | ||
* Returns realValues. | ||
*/ | ||
void fmi2GetReal_OMC(void* in_fmi2me, int numberOfValueReferences, double* realValuesReferences, double flowStatesInput, double* realValues) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, realValuesReferences); | ||
fmi2_import_get_real(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_real_t*)realValues); | ||
free(valuesReferences_int); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiSetReal. | ||
* Returns status. | ||
*/ | ||
void fmi2SetReal_OMC(void* in_fmi2me, int numberOfValueReferences, double* realValuesReferences, double* realValues, double* out_Values) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, realValuesReferences); | ||
fmi2_import_set_real(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_real_t*)realValues); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiGetInteger. | ||
* parameter flowStatesInput is dummy and is only used to run the equations in sequence. | ||
* Returns integerValues. | ||
*/ | ||
void fmi2GetInteger_OMC(void* in_fmi2me, int numberOfValueReferences, double* integerValuesReferences, double flowStatesInput, int* integerValues) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, integerValuesReferences); | ||
fmi2_import_get_integer(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_integer_t*)integerValues); | ||
free(valuesReferences_int); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiSetInteger. | ||
* Returns status. | ||
*/ | ||
void fmi2SetInteger_OMC(void* in_fmi2me, int numberOfValueReferences, double* integerValuesReferences, int* integerValues, double* out_Values) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, integerValuesReferences); | ||
fmi2_import_set_integer(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_integer_t*)integerValues); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiGetBoolean. | ||
* parameter flowStatesInput is dummy and is only used to run the equations in sequence. | ||
* Returns booleanValues. | ||
*/ | ||
void fmi2GetBoolean_OMC(void* in_fmi2me, int numberOfValueReferences, double* booleanValuesReferences, double flowStatesInput, int* booleanValues) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, booleanValuesReferences); | ||
fmi2_import_get_boolean(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_boolean_t*)booleanValues); | ||
free(valuesReferences_int); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiSetBoolean. | ||
* Returns status. | ||
*/ | ||
void fmi2SetBoolean_OMC(void* in_fmi2me, int numberOfValueReferences, double* booleanValuesReferences, int* booleanValues, double* out_Values) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, booleanValuesReferences); | ||
fmi2_import_set_boolean(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_boolean_t*)booleanValues); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiGetString. | ||
* parameter flowStatesInput is dummy and is only used to run the equations in sequence. | ||
* Returns stringValues. | ||
*/ | ||
void fmi2GetString_OMC(void* in_fmi2me, int numberOfValueReferences, double* stringValuesReferences, double flowStatesInput, char** stringValues) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, stringValuesReferences); | ||
fmi2_import_get_string(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_string_t*)stringValues); | ||
free(valuesReferences_int); | ||
} | ||
|
||
/* | ||
* Wrapper for the FMI function fmiSetString. | ||
* Returns status. | ||
*/ | ||
void fmi2SetString_OMC(void* in_fmi2me, int numberOfValueReferences, double* stringValuesReferences, char** stringValues, double* out_Values) | ||
{ | ||
FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2me; | ||
fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, stringValuesReferences); | ||
fmi2_import_set_string(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_string_t*)stringValues); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file is part of OpenModelica. | ||
* | ||
* Copyright (c) 1998-CurrentYear, Open Source Modelica Consortium (OSMC), | ||
* c/o Linköpings universitet, Department of Computer and Information Science, | ||
* SE-58183 Linköping, Sweden. | ||
* | ||
* All rights reserved. | ||
* | ||
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3 LICENSE OR | ||
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2. | ||
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE | ||
* OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3, ACCORDING TO RECIPIENTS CHOICE. | ||
* | ||
* The OpenModelica software and the Open Source Modelica | ||
* Consortium (OSMC) Public License (OSMC-PL) are obtained | ||
* from OSMC, either from the above address, | ||
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or | ||
* http://www.openmodelica.org, and in the OpenModelica distribution. | ||
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html. | ||
* | ||
* This program is distributed WITHOUT ANY WARRANTY; without | ||
* even the implied warranty of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH | ||
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS OF OSMC-PL. | ||
* | ||
* See the full OSMC Public License conditions for more details. | ||
* | ||
*/ | ||
|
||
#ifndef FMI2COMMON__H_ | ||
#define FMI2COMMON__H_ | ||
|
||
#include "FMICommon.h" | ||
|
||
/* | ||
* Structure used as an External Object in the generated Modelica code of the imported FMU. | ||
* Used for FMI 2.0 Model Exchange. | ||
*/ | ||
typedef struct { | ||
int FMILogLevel; | ||
jm_callbacks JMCallbacks; | ||
fmi_import_context_t* FMIImportContext; | ||
fmi2_callback_functions_t FMICallbackFunctions; | ||
char* FMIWorkingDirectory; | ||
fmi2_import_t* FMIImportInstance; | ||
char* FMIInstanceName; | ||
int FMIDebugLogging; | ||
int FMIToleranceControlled; | ||
double FMIRelativeTolerance; | ||
fmi2_event_info_t* FMIEventInfo; | ||
} FMI2ModelExchange; | ||
|
||
void importlogger(jm_callbacks* c, jm_string module, jm_log_level_enu_t log_level, jm_string message); | ||
void fmi2logger(fmi2_component_t c, fmi2_string_t instanceName, fmi2_status_t status, fmi2_string_t category, fmi2_string_t message, ...); | ||
|
||
#endif |
Oops, something went wrong.