@@ -3139,5 +3139,49 @@ algorithm
31393139 end match;
31403140end getEquationLHS;
31413141
3142+ public function scalarComplexEquations
3143+ "This function splits tuples and record in single equations,
3144+ to avoid non-linear loops.
3145+ e.g.: R(a,b) = R(2*x,3*y) => r.a = 2*x; r.b = 3*y
3146+ (a,b) = (2*g(x)[1],3*g(x)[2]) => a = 2*g(x)[1]; b = 3*g(x)[2]
3147+ Used after some equations have been differentiated.
3148+ "
3149+ input BackendDAE . Equation inEquation;
3150+ input DAE . FunctionTree funcTree;
3151+ output list< BackendDAE . Equation > outEquations;
3152+ algorithm
3153+
3154+ outEquations := match (inEquation)
3155+ local
3156+ DAE . Exp e1, e2;
3157+ DAE . ElementSource source;
3158+ list< DAE . Exp > explst, explst2;
3159+ list< BackendDAE . Equation > eqns;
3160+ BackendDAE . EquationAttributes attr;
3161+
3162+ case (BackendDAE . COMPLEX_EQUATION (left= DAE . TUPLE (explst), right= DAE . TUPLE (explst2), source= source, attr= attr))
3163+ equation
3164+ true = listLength(explst) == listLength(explst2);
3165+ eqns = List . threadMap2(explst, explst2, generateEquation, source, attr);
3166+ then eqns;
3167+
3168+ case (BackendDAE . COMPLEX_EQUATION (left= e1, right= e2, source= source, attr= attr))
3169+ guard ((Expression . isRecordCall(e1, funcTree) or Expression . isRecord(e1)) and
3170+ (Expression . isRecordCall(e2, funcTree) or Expression . isRecord(e2))
3171+ )
3172+ equation
3173+ explst = Expression . splitRecord(e1, Expression . typeof(e1));
3174+ explst2 = Expression . splitRecord(e2, Expression . typeof(e2));
3175+ true = listLength(explst) == listLength(explst2);
3176+ eqns = List . threadMap2(explst, explst2, generateEquation, source, attr);
3177+ then eqns;
3178+
3179+ else
3180+ then {inEquation};
3181+
3182+ end match;
3183+ end scalarComplexEquations;
3184+
3185+
31423186annotation(__OpenModelica_Interface= "backend" );
31433187end BackendEquation ;
0 commit comments