Skip to content

Commit

Permalink
Introducing the GetSpecificDerivatives in the FMU and the correspondi…
Browse files Browse the repository at this point in the history
…ng debug flag
  • Loading branch information
fbergero committed Oct 9, 2015
1 parent b570c96 commit 886ec2b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
1 change: 1 addition & 0 deletions Compiler/Template/CodegenFMU.tpl
Expand Up @@ -1242,6 +1242,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
<%fileNamePrefix%>_fmiGetEventIndicators @33
<%fileNamePrefix%>_fmiGetContinuousStates @34
<%fileNamePrefix%>_fmiGetNominalsOfContinuousStates @35
<%fileNamePrefix%>_fmiGetSpecificDerivatives @36
>>
else
<<
Expand Down
18 changes: 18 additions & 0 deletions Compiler/Template/CodegenFMU2.tpl
Expand Up @@ -64,6 +64,8 @@ case SIMCODE(__) then
<%fmiModelDescriptionAttributes(simCode,guid)%>>
<%ModelExchange(simCode)%>
<%fmiTypeDefinitions(modelInfo, "2.0")%>
<% if Flags.isSet(Flags.FMU_EXPERIMENTAL) then
<<
<LogCategories>
<Category name="logEvents" description="logEvents" />
<Category name="logSingularLinearSystems" description="logSingularLinearSystems" />
Expand All @@ -77,6 +79,22 @@ case SIMCODE(__) then
<Category name="logAll" description="logAll" />
<Category name="logFmi2Call" description="logFmi2Call" />
</LogCategories>
>> else
<<
<LogCategories>
<Category name="logEvents" />
<Category name="logSingularLinearSystems" />
<Category name="logNonlinearSystems" />
<Category name="logDynamicStateSelection" />
<Category name="logStatusWarning" />
<Category name="logStatusDiscard" />
<Category name="logStatusError" />
<Category name="logStatusFatal" />
<Category name="logStatusPending" />
<Category name="logAll" />
<Category name="logFmi2Call" />
</LogCategories>
>> %>
<%DefaultExperiment(simulationSettingsOpt)%>
<%fmiModelVariables(modelInfo, "2.0")%>
<%ModelStructureHelper(modelStructure)%>
Expand Down
2 changes: 1 addition & 1 deletion Compiler/Util/Flags.mo
Expand Up @@ -464,7 +464,7 @@ constant DebugFlag BUILD_STATIC_SOURCE_FMU = DEBUG_FLAG(148, "buildStaticSourceF
Util.gettext("A temporary flag to not link the C run-time system when building an FMU; instead compiling the run-time sources into the FMU. The goal is to make this a truly static shared object, depending on nothing outside the FMU (all sources will be included)."));

constant DebugFlag FMU_EXPERIMENTAL = DEBUG_FLAG(149, "fmuExperimental", false,
Util.gettext("Include an extra function in the FMU fmi2GetOneDerivative."));
Util.gettext("Include an extra function in the FMU fmi2GetSpecificDerivatives."));


// This is a list of all debug flags, to keep track of which flags are used. A
Expand Down
4 changes: 4 additions & 0 deletions SimulationRuntime/fmi/export/fmi2/fmi2FunctionTypes.h
Expand Up @@ -212,6 +212,10 @@ Types for Functions for FMI2 for Model Exchange

/* Evaluation of the model equations */
typedef fmi2Status fmi2GetDerivativesTYPE (fmi2Component, fmi2Real[], size_t);
#ifdef FMU_EXPERIMENTAL
typedef fmi2Status fmi2GetSpecificDerivativesTYPE (fmi2Component, fmi2Real[], const fmi2ValueReference [], size_t);
#endif

typedef fmi2Status fmi2GetEventIndicatorsTYPE (fmi2Component, fmi2Real[], size_t);
typedef fmi2Status fmi2GetContinuousStatesTYPE (fmi2Component, fmi2Real[], size_t);
typedef fmi2Status fmi2GetNominalsOfContinuousStatesTYPE(fmi2Component, fmi2Real[], size_t);
Expand Down
6 changes: 6 additions & 0 deletions SimulationRuntime/fmi/export/fmi2/fmi2Functions.h
Expand Up @@ -222,6 +222,9 @@ Functions for FMI2 for Model Exchange
#define fmi2SetTime fmi2FullName(fmi2SetTime)
#define fmi2SetContinuousStates fmi2FullName(fmi2SetContinuousStates)
#define fmi2GetDerivatives fmi2FullName(fmi2GetDerivatives)
#ifdef FMU_EXPERIMENTAL
#define fmi2GetSpecificDerivatives fmi2FullName(fmi2GetSpecificDerivatives)
#endif
#define fmi2GetEventIndicators fmi2FullName(fmi2GetEventIndicators)
#define fmi2GetContinuousStates fmi2FullName(fmi2GetContinuousStates)
#define fmi2GetNominalsOfContinuousStates fmi2FullName(fmi2GetNominalsOfContinuousStates)
Expand Down Expand Up @@ -303,6 +306,9 @@ Functions for FMI2 for Model Exchange

/* Evaluation of the model equations */
FMI2_Export fmi2GetDerivativesTYPE fmi2GetDerivatives;
#ifdef FMU_EXPERIMENTAL
FMI2_Export fmi2GetSpecificDerivativesTYPE fmi2GetSpecificDerivatives;
#endif
FMI2_Export fmi2GetEventIndicatorsTYPE fmi2GetEventIndicators;
FMI2_Export fmi2GetContinuousStatesTYPE fmi2GetContinuousStates;
FMI2_Export fmi2GetNominalsOfContinuousStatesTYPE fmi2GetNominalsOfContinuousStates;
Expand Down
17 changes: 9 additions & 8 deletions SimulationRuntime/fmi/export/fmi2/fmu2_model_interface.c
Expand Up @@ -997,8 +997,8 @@ fmi2Status fmi2SetExternalFunction(fmi2Component c, fmi2ValueReference vr[], siz
}

#ifdef FMU_EXPERIMENTAL
fmi2Status fmi2GetOneDerivative(fmi2Component c, fmi2Real derivatives[], size_t nx) {
int i;
fmi2Status fmi2GetSpecificDerivatives(fmi2Component c, fmi2Real derivatives[], const fmi2ValueReference dr[], size_t nvr) {
int i,nx;
ModelInstance* comp = (ModelInstance *)c;
threadData_t *threadData = comp->threadData;
/* TODO
Expand All @@ -1013,14 +1013,15 @@ fmi2Status fmi2GetOneDerivative(fmi2Component c, fmi2Real derivatives[], size_t
/* try */
MMC_TRY_INTERNAL(simulationJumpBuffer)

comp->fmuData->callback->functionODEPartial(comp->fmuData, comp->threadData, nx);

#if NUMBER_OF_STATES>0
//for (i = 0; i < nx; i++) {
fmi2ValueReference vr = vrStatesDerivatives[nx];
derivatives[0] = getReal(comp, vr); // to be implemented by the includer of this file
FILTERED_LOG(comp, fmi2OK, LOG_FMI2_CALL, "fmi2GetDerivatives: #r%d# = %.16g", vr, derivatives[i])
//}
for (i = 0; i < nvr; i++) {
// This assumes that OMC layouts first the states then the derivatives
nx = dr[i]-NUMBER_OF_STATES;
comp->fmuData->callback->functionODEPartial(comp->fmuData, comp->threadData, nx);
derivatives[i] = getReal(comp, dr[i]); // to be implemented by the includer of this file
FILTERED_LOG(comp, fmi2OK, LOG_FMI2_CALL, "fmi2GetSpecificDerivatives: #r%d# = %.16g", dr[i], derivatives[i])
}
#endif

return fmi2OK;
Expand Down

0 comments on commit 886ec2b

Please sign in to comment.