Пример #1
0
/*
 * 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_fmi2, int numberOfValueReferences, double* realValuesReferences, double flowStatesInput, double* realValues, int fmiType)
{
  if (fmiType == 1) {
    FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2;
    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);
  } else if (fmiType == 2) {

  }
}
Пример #2
0
/*
 * Wrapper for the FMI function fmi2GetReal.
 * parameter flowStatesInput is dummy and is only used to run the equations in sequence.
 * Returns realValues.
 */
void fmi2GetReal_OMC(void* in_fmi2, int numberOfValueReferences, double* realValuesReferences, double flowStatesInput, double* realValues, int fmiType)
{
  if (fmiType == 1) {
    FMI2ModelExchange* FMI2ME = (FMI2ModelExchange*)in_fmi2;
    fmi2_value_reference_t* valuesReferences_int = real_to_fmi2_value_reference(numberOfValueReferences, realValuesReferences);
    fmi2_status_t status = fmi2_import_get_real(FMI2ME->FMIImportInstance, valuesReferences_int, numberOfValueReferences, (fmi2_real_t*)realValues);
    free(valuesReferences_int);
    if (status != fmi2_status_ok && status != fmi2_status_warning) {
      ModelicaFormatError("fmi2GetReal failed with status : %s\n", fmi2_status_to_string(status));
    }
  } else if (fmiType == 2) {

  }
}
Пример #3
0
int test_simulate_cs(fmi2_import_t* fmu)
{
	fmi2_status_t fmistatus;
	jm_status_enu_t jmstatus;

	fmi2_string_t instanceName = "Test CS model instance";
	fmi2_string_t fmuGUID;
	fmi2_string_t fmuLocation = "";
	fmi2_boolean_t visible = fmi2_false;
	fmi2_real_t relativeTol = 1e-4;
/*	fmi2_boolean_t loggingOn = fmi2_true; */
	
	/* fmi2_real_t simulation_results[] = {-0.001878, -1.722275}; */
	fmi2_real_t simulation_results[] = {0.0143633,   -1.62417};
	fmi2_value_reference_t compare_real_variables_vr[] = {0, 1};
	size_t k;

	fmi2_real_t tstart = 0.0;
	fmi2_real_t tcur = tstart;
	fmi2_real_t hstep = 0.1;
	fmi2_real_t tend = 2.0;
	fmi2_boolean_t StopTimeDefined = fmi2_false;

	if (sizeof(compare_real_variables_vr)/sizeof(fmi2_value_reference_t) != sizeof(simulation_results)/sizeof(fmi2_real_t)) {
		printf("Number of simulation values and reference values are different\n");
		do_exit(CTEST_RETURN_FAIL);
	}

	printf("Version returned from FMU:   %s\n", fmi2_import_get_version(fmu));
	printf("Platform type returned:      %s\n", fmi2_import_get_types_platform(fmu));

	fmuGUID = fmi2_import_get_GUID(fmu);
    printf("GUID:      %s\n", fmuGUID);


    jmstatus = fmi2_import_instantiate(fmu, instanceName, fmi2_cosimulation, fmuLocation, visible);
	if (jmstatus == jm_status_error) {
		printf("fmi2_import_instantiate failed\n");
		do_exit(CTEST_RETURN_FAIL);
	}

        fmistatus = fmi2_import_setup_experiment(fmu, fmi2_true,
            relativeTol, tstart, StopTimeDefined, tend);
    if(fmistatus != fmi2_status_ok) {
        printf("fmi2_import_setup_experiment failed\n");
        do_exit(CTEST_RETURN_FAIL);
    }

        fmistatus = fmi2_import_enter_initialization_mode(fmu);
    if(fmistatus != fmi2_status_ok) {
        printf("fmi2_import_enter_initialization_mode failed\n");
        do_exit(CTEST_RETURN_FAIL);
    }

        fmistatus = fmi2_import_exit_initialization_mode(fmu);
    if(fmistatus != fmi2_status_ok) {
        printf("fmi2_import_exit_initialization_mode failed\n");
        do_exit(CTEST_RETURN_FAIL);
    }        

	tcur = tstart;
	printf("%10s %10s\n", "Ball height", "Ball speed");
	while (tcur < tend) {
		fmi2_boolean_t newStep = fmi2_true;
#if 0 /* Prints a real value.. */
		fmi2_real_t rvalue;
		fmi2_value_reference_t vr = 0;

		fmistatus = fmi2_import_get_real(fmu, &vr, 1, &rvalue);
		printf("rvalue = %f\n", rvalue);
#endif 
		fmistatus = fmi2_import_do_step(fmu, tcur, hstep, newStep);

		for (k = 0; k < sizeof(compare_real_variables_vr)/sizeof(fmi2_value_reference_t); k++) {
			fmi2_value_reference_t vr = compare_real_variables_vr[k];
			fmi2_real_t rvalue;
			fmistatus = fmi2_import_get_real(fmu, &vr, 1, &rvalue);
		}
		{
			fmi2_real_t val[2];
			fmi2_import_get_real(fmu, compare_real_variables_vr, 2, val);
			printf("%10g %10g\n", val[0],val[1]);
		}

		tcur += hstep;
	}

	printf("Simulation finished. Checking results\n");

	/* Validate result */
	for (k = 0; k < sizeof(compare_real_variables_vr)/sizeof(fmi2_value_reference_t); k++) {
		fmi2_value_reference_t vr = compare_real_variables_vr[k];
		fmi2_real_t rvalue;
		fmi2_real_t res;	
		fmistatus = fmi2_import_get_real(fmu, &vr, 1, &rvalue);
		res = rvalue - simulation_results[k];
		res = res > 0 ? res: -res; /* Take abs */
		if (res > 3e-3) {
			printf("Simulation results is wrong!\n");
			printf("State [%u]  %g != %g, |res| = %g\n", (unsigned)k, rvalue, simulation_results[k], res);
			printf("\n");
			do_exit(CTEST_RETURN_FAIL);
		}
	}

	fmistatus = fmi2_import_terminate(fmu);

	fmi2_import_free_instance(fmu);

	return 0;
}