20 #include "config_test.h" 27 printf(
"Press 'Enter' to exit\n");
36 fmi1_real_t tstart = 0.0;
39 fmi1_real_t hdef = 0.1;
40 fmi1_real_t tend = 2.0;
42 size_t n_event_indicators;
44 fmi1_real_t states_end_results[] = {0.362000, -3.962000};
45 fmi1_real_t* states_der;
46 fmi1_real_t* event_indicators;
47 fmi1_real_t* event_indicators_prev;
48 fmi1_boolean_t callEventUpdate;
49 fmi1_boolean_t toleranceControlled =
fmi1_true;
50 fmi1_real_t relativeTolerance = 0.001;
52 fmi1_boolean_t intermediateResults =
fmi1_false;
61 if (
sizeof(states_end_results)/
sizeof(fmi1_real_t) != n_states) {
62 printf(
"Number of states and results have different length n_states = %u n_results = %u\n", (
unsigned)n_states, (
unsigned)
sizeof(states_end_results));
66 states = calloc(n_states,
sizeof(
double));
67 states_der = calloc(n_states,
sizeof(
double));
68 event_indicators = calloc(n_event_indicators,
sizeof(
double));
69 event_indicators_prev = calloc(n_event_indicators,
sizeof(
double));
73 printf(
"fmi1_import_instantiate_model failed\n");
94 int zero_crossning_event = 0;
100 for (k = 0; k < n_event_indicators; k++) {
101 if (event_indicators[k]*event_indicators_prev[k] < 0) {
102 zero_crossning_event = 1;
126 if(tcur > tend - hcur/1e16) {
128 hcur = (tend - tcur);
133 for (k = 0; k < n_states; k++) {
134 states[k] = states[k] + hcur*states_der[k];
135 if (k == 0) printf(
"Ball hight state[%u] = %f\n", (
unsigned)k, states[k]);
145 for (k = 0; k < n_states; k++) {
146 fmi1_real_t res = states[k] - states_end_results[k];
147 res = res > 0 ? res: -res;
149 printf(
"Simulation results is wrong states[%u] %f != %f, |res| = %f\n", (
unsigned)k, states[k], states_end_results[k], res);
161 free(event_indicators);
162 free(event_indicators_prev);
183 static int isunzipped;
188 printf(
"Usage: %s <fmu_file> <temporary_dir>\n", argv[0]);
197 callbacks->
malloc = malloc;
198 callbacks->
calloc = calloc;
200 callbacks->
free = free;
209 #ifdef FMILIB_GENERATE_BUILD_STAMP 210 printf(
"Library build stamp:\n%s\n", fmilib_get_build_stamp());
216 if (isunzipped == 0) {
219 printf(
"Only version 1.0 is supported so far\n");
228 printf(
"Error parsing XML, exiting\n");
234 printf(
"Could not create the DLL loading mechanism(C-API test).\n");
240 printf(
"Everything seems to be OK since you got this far=)!\n");
256 memset(fmus, 0,
sizeof(
fmul_t));
260 #define NUMBER_OF_TESTS 150 261 int main(
int argc,
char *argv[])
267 fmul[k] =
load(argc, argv);
FMILIB_EXPORT jm_status_enu_t fmi1_import_instantiate_model(fmi1_import_t *fmu, fmi1_string_t instanceName)
Wrapper for the FMI function fmiInstantiateModel(...)
FMILIB_EXPORT fmi1_status_t fmi1_import_terminate(fmi1_import_t *fmu)
Wrapper for the FMI function fmiTerminate(...)
FMILIB_EXPORT unsigned int fmi1_import_get_number_of_event_indicators(fmi1_import_t *fmu)
Get the number of event indicators.
jm_calloc_f calloc
Allocate zero initialized memory.
int test_simulate_me(fmi1_import_t *fmu)
FMILIB_EXPORT fmi1_status_t fmi1_import_completed_integrator_step(fmi1_import_t *fmu, fmi1_boolean_t *callEventUpdate)
Wrapper for the FMI function fmiCompletedIntegratorStep(...)
FMILIB_EXPORT fmi1_status_t fmi1_import_initialize(fmi1_import_t *fmu, fmi1_boolean_t toleranceControlled, fmi1_real_t relativeTolerance, fmi1_event_info_t *eventInfo)
Wrapper for the FMI function fmiInitialize(...)
FMILIB_EXPORT fmi1_status_t fmi1_import_get_event_indicators(fmi1_import_t *fmu, fmi1_real_t eventIndicators[], size_t ni)
Wrapper for the FMI function fmiGetEventIndicators(...)
fmi1_callback_functions_t callBackFunctions
fmi_version_enu_t
Suported versions of FMI standard.
FMILIB_EXPORT fmi1_status_t fmi1_import_eventUpdate(fmi1_import_t *fmu, fmi1_boolean_t intermediateResults, fmi1_event_info_t *eventInfo)
Wrapper for the FMI function fmiEventUpdate(...)
fmi1_callback_logger_ft logger
fmi1_callback_allocate_memory_ft allocateMemory
FMILIB_EXPORT void fmi1_log_forwarding(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message,...)
An implementation of FMI 1.0 logger that forwards the messages to logger function inside jm_callbacks...
fmi1_real_t nextEventTime
FMILIB_EXPORT fmi1_status_t fmi1_import_set_time(fmi1_import_t *fmu, fmi1_real_t time)
Wrapper for the FMI function fmiSetTime(...)
FMILIB_EXPORT fmi1_status_t fmi1_import_get_continuous_states(fmi1_import_t *fmu, fmi1_real_t states[], size_t nx)
Wrapper for the FMI function fmiGetContinuousStates(...)
FMILIB_EXPORT void fmi1_import_destroy_dllfmu(fmi1_import_t *fmu)
Free a C-API struct. All memory allocated since the struct was created is freed.
jm_log_level_enu_t log_level
Logging level.
fmi1_boolean_t upcomingTimeEvent
fmi_import_context_t * context
FMILIB_EXPORT unsigned int fmi1_import_get_number_of_continuous_states(fmi1_import_t *fmu)
Get the number of contnuous states.
FMILIB_EXPORT jm_status_enu_t fmi1_import_create_dllfmu(fmi1_import_t *fmu, fmi1_callback_functions_t callBackFunctions, int registerGlobally)
Create a C-API struct. The C-API struct is a placeholder for the FMI DLL functions.
FMILIB_EXPORT fmi1_import_t * fmi1_import_parse_xml(fmi_import_context_t *c, const char *dirName)
Parse FMI 1.0 XML file found in the directory dirName.
FMILIB_EXPORT fmi1_status_t fmi1_import_get_derivatives(fmi1_import_t *fmu, fmi1_real_t derivatives[], size_t nx)
Wrapper for the FMI function fmiGetDerivatives(...)
Include file to be used in client applications of the FMI Library.
jm_malloc_f malloc
Allocate non-initialized memory.
jm_voidp context
Arbitrary context pointer passed to the logger function.
void destroy(fmul_t *fmus)
FMILIB_EXPORT void jm_default_logger(jm_callbacks *c, jm_string module, jm_log_level_enu_t log_level, jm_string message)
The default logger implementation prints messages to stderr.
The callbacks struct is sent to all the modules in the library.
struct fmi_xml_context_t fmi_import_context_t
FMI version independent library context. Opaque struct returned from fmi_import_allocate_context() ...
FMILIB_EXPORT const char * fmi1_import_get_version(fmi1_import_t *fmu)
Wrapper for the FMI function fmiGetVersion()
FMILIB_EXPORT fmi_import_context_t * fmi_import_allocate_context(jm_callbacks *callbacks)
Create fmi_import_context_t structure.
fmi1_callback_free_memory_ft freeMemory
fmul_t load(int argc, char *argv[])
struct fmi1_import_t fmi1_import_t
FMU version 1.0 object.
FMILIB_EXPORT fmi1_status_t fmi1_import_set_continuous_states(fmi1_import_t *fmu, const fmi1_real_t x[], size_t nx)
Wrapper for the FMI function fmiSetContinuousStates(...)
FMILIB_EXPORT fmi_version_enu_t fmi_import_get_fmi_version(fmi_import_context_t *c, const char *fileName, const char *dirName)
Unzip an FMU specified by the fileName into directory dirName and parse XML to get FMI standard versi...
FMILIB_EXPORT const char * fmi1_status_to_string(fmi1_status_t status)
FMILIB_EXPORT void fmi_import_free_context(fmi_import_context_t *c)
Free memory allocated for the library context.
FMILIB_EXPORT fmi1_status_t fmi1_import_set_debug_logging(fmi1_import_t *fmu, fmi1_boolean_t loggingOn)
Wrapper for the FMI function fmiSetDebugLogging(...)
jm_realloc_f realloc
Re-allocate memory.
jm_status_enu_t
Return status codes.
FMILIB_EXPORT void fmi1_import_free(fmi1_import_t *fmu)
Release the memory allocated.
FMILIB_EXPORT void fmi1_import_free_model_instance(fmi1_import_t *fmu)
Wrapper for the FMI function fmiFreeModelInstance(...)
jm_free_f free
Free-allocated memory.
jm_logger_f logger
Logging callback.
FMILIB_EXPORT const char * fmi1_import_get_model_types_platform(fmi1_import_t *fmu)
Wrapper for the FMI function fmiGetModelTypesPlatform(...)
int main(int argc, char *argv[])