Opened 7 years ago
#4870 new enhancement
Do not evaluate parameter-dependent assertions at each time step.
Reported by: | Francesco Casella | Owned by: | Lennart Ochel |
---|---|---|---|
Priority: | high | Milestone: | 2.0.0 |
Component: | Code Generation | Version: | |
Keywords: | Cc: | Martin Sjölund, Willi Braun |
Description
Please consider the attached simple test case (an RC circuit fed by sinusoidal voltage source).
The main Test.c file contains this function
/* equation index: 15 type: ALGORITHM assert(1.0 + R.alpha * (R.T - R.T_ref) >= 1e-015, "Temperature outside scope of model!"); */ void Test_eqFunction_15(DATA *data, threadData_t *threadData) { TRACE_PUSH const int equationIndexes[2] = {1,15}; modelica_boolean tmp1; static const MMC_DEFSTRINGLIT(tmp2,35,"Temperature outside scope of model!"); static int tmp3 = 0; { tmp1 = GreaterEq(1.0 + (data->simulationInfo->realParameter[4]) * (data->simulationInfo->realParameter[2] - data->simulationInfo->realParameter[3]),1e-015); if(!tmp1) { { FILE_INFO info = {"C:/OpenModelica1.13.0-dev-64bit/lib/omlibrary/Modelica 3.2.2/Electrical/Analog/Basic.mo",66,5,67,45,0}; omc_assert_warning(info, "The following assertion has been violated %sat time %f\n1.0 + R.alpha * (R.T - R.T_ref) >= 1e-015", initial() ? "during initialization " : "", data->localData[0]->timeValue); omc_assert_withEquationIndexes(threadData, info, equationIndexes, MMC_STRINGDATA(MMC_REFSTRINGLIT(tmp2))); } } } TRACE_POP
which test the assertion at each time step. In fact, since the thermal port is disabled in this case (as in most circuits using the resistor component), the expression in the assert statement turns out to be parameter-dependent. As such, its evaluation should not end up here, but rather together with the initial equations.
Furthermore, the corresponding file may be compiled without optimizations, since it will only be executed once, so the additional time spent for the optimization is never justified.