Opened 8 years ago
Last modified 8 years ago
#4871 new enhancement
Avoid using DIVISION macros in the dynamic equations if the denominator is a parameter-dependent expression — at Initial Version
| Reported by: | Francesco Casella | Owned by: | Lennart Ochel |
|---|---|---|---|
| Priority: | high | Milestone: | 2.0.0 |
| Component: | Code Generation | Version: | |
| Keywords: | Cc: |
Description
Please consider the attached test case, a simple RC circuit fed by a sinusoidal voltage source.
The Test.c file contains the following function
/*
equation index: 14
type: SIMPLE_ASSIGN
der(C._v) = DIVISION(-source.i, C.C)
*/
void Test_eqFunction_14(DATA *data, threadData_t *threadData)
{
TRACE_PUSH
const int equationIndexes[2] = {1,14};
data->localData[0]->realVars[1] /* der(C.v) STATE_DER */ = DIVISION_SIM((-data->localData[0]->realVars[7] /* source.i variable */),data->simulationInfo->realParameter[0],"C.C",equationIndexes);
TRACE_POP
}
This function needs to compute der(C._v) = -source.i/C.C. The denominator of this expression is a parameter-dependent expression, so it should be checked to be non-zero only once during initialization, and then computed with a plain division during simulation. With the current implementation, the check that it is non-zero is re-done times and again at each f(x,t) evaluation.
The overhead of this macro in models that have lots of divisions can be substantial: a comparison with the mu-Modelica tool on a simple ODE model, using the same DASSL solver, showed that the slow-down factor can be as high as 6X.
