﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
4871	Avoid using DIVISION macros in the dynamic equations if the denominator is a parameter-dependent expression	Francesco Casella	Lennart Ochel	"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 4X."	enhancement	new	high	2.0.0	Code Generation				
