@@ -3538,31 +3538,34 @@ public function addInitialStmtsToAlgorithms "
35383538 - A non-discrete variable is initialized with its start value (i.e. the value of the start-attribute).
35393539 - A discrete variable v is initialized with pre(v)."
35403540 input BackendDAE . BackendDAE inDAE;
3541+ input Boolean isInitialSystem;
35413542 output BackendDAE . BackendDAE outDAE;
35423543algorithm
3543- outDAE := BackendDAEUtil . mapEqSystem (inDAE, addInitialStmtsToAlgorithms1);
3544+ outDAE := BackendDAEUtil . mapEqSystem1 (inDAE, addInitialStmtsToAlgorithms1, isInitialSystem );
35443545end addInitialStmtsToAlgorithms;
35453546
35463547protected function addInitialStmtsToAlgorithms1 "Helper function to addInitialStmtsToAlgorithms."
35473548 input BackendDAE . EqSystem syst;
3549+ input Boolean isInitialSystem;
35483550 input BackendDAE . Shared shared ;
35493551 output BackendDAE . EqSystem osyst = syst;
35503552 output BackendDAE . Shared oshared = shared ;
35513553protected
3552- BackendDAE . Variables ordvars;
3554+ BackendDAE . Variables ordvars, allVars ;
35533555 BackendDAE . EquationArray ordeqns;
3556+ BackendDAE . EquationArray initEqns;
35543557algorithm
35553558 BackendDAE . EQSYSTEM (orderedVars= ordvars, orderedEqs= ordeqns) := osyst;
3556- BackendEquation . traverseEquationArray_WithUpdate(ordeqns, eaddInitialStmtsToAlgorithms1Helper, ordvars);
3559+ BackendEquation . traverseEquationArray_WithUpdate(ordeqns, eaddInitialStmtsToAlgorithms1Helper, ( ordvars, isInitialSystem) );
35573560end addInitialStmtsToAlgorithms1;
35583561
35593562protected function eaddInitialStmtsToAlgorithms1Helper "Helper function to addInitialStmtsToAlgorithms1."
35603563 input BackendDAE . Equation inEq;
3561- input BackendDAE . Variables inVars ;
3564+ input tuple < BackendDAE . Variables , Boolean > inTpl ;
35623565 output BackendDAE . Equation outEq;
3563- output BackendDAE . Variables outVars ;
3566+ output tuple < BackendDAE . Variables , Boolean > outTpl = inTpl ;
35643567algorithm
3565- (outEq,outVars ) := match (inEq,inVars )
3568+ (outEq) := match (inEq, inTpl )
35663569 local
35673570 DAE . Algorithm alg;
35683571 list< DAE . Statement > statements;
@@ -3574,49 +3577,53 @@ algorithm
35743577 list< DAE . ComponentRef > crlst;
35753578 DAE . Expand crExpand;
35763579 BackendDAE . EquationAttributes attr;
3580+ Boolean isInitialEquations;
35773581
3578- case (BackendDAE . ALGORITHM (size= size, alg= alg as DAE . ALGORITHM_STMTS (statements), source= source, expand= crExpand, attr= attr), vars)
3582+ case (BackendDAE . ALGORITHM (size= size, alg= alg as DAE . ALGORITHM_STMTS (statements), source= source, expand= crExpand, attr= attr), ( vars, isInitialEquations) )
35793583 equation
35803584 crlst = CheckModel . checkAndGetAlgorithmOutputs(alg, source, crExpand);
35813585 outputs = List . map(crlst, Expression . crefExp);
3582- statements = expandAlgorithmStmts(statements, outputs, vars);
3583- then ( BackendDAE . ALGORITHM (size, DAE . ALGORITHM_STMTS (statements), source, crExpand, attr), vars );
3586+ statements = expandAlgorithmStmts(statements, outputs, vars, isInitialEquations );
3587+ then BackendDAE . ALGORITHM (size, DAE . ALGORITHM_STMTS (statements), source, crExpand, attr);
35843588
3585- else ( inEq,inVars) ;
3589+ else inEq;
35863590 end match;
35873591end eaddInitialStmtsToAlgorithms1Helper;
35883592
35893593protected function expandAlgorithmStmts "Helper function to eaddInitialStmtsToAlgorithms1Helper."
35903594 input list< DAE . Statement > inAlg;
35913595 input list< DAE . Exp > inOutputs;
35923596 input BackendDAE . Variables inVars;
3597+ input Boolean isInitialEquation;
35933598 output list< DAE . Statement > outAlg;
35943599algorithm
35953600 outAlg := match(inAlg, inOutputs, inVars)
35963601 local
35973602 DAE . Exp out, initExp;
35983603 list< DAE . Exp > rest;
35993604 DAE . ComponentRef cref;
3600- BackendDAE . Var var ;
3605+ list < BackendDAE . Var > vars ;
36013606 DAE . Statement stmt;
36023607 DAE . Type type_;
36033608 list< DAE . Statement > statements;
36043609
36053610 case (statements, {}, _)
36063611 then statements;
36073612
3608- case (statements, out::rest, _) equation
3609- cref = Expression . expCref(out);
3610- type_ = Expression . typeof(out);
3611- type_ = Expression . arrayEltType(type_);
3612- (var ::_, _) = BackendVariable . getVar(cref, inVars);
3613- if BackendVariable . isVarDiscrete(var ) then
3614- initExp = Expression . makePureBuiltinCall("pre" , {out}, type_);
3615- else
3616- initExp = Expression . crefExp(ComponentReference . crefPrefixStart(cref));
3617- end if ;
3618- stmt = Algorithm . makeAssignment(DAE . CREF (cref, type_), DAE . PROP (type_, DAE . C_VAR ()), initExp, DAE . PROP (type_, DAE . C_VAR ()), DAE . dummyAttrVar, SCode . NON_INITIAL (), DAE . emptyElementSource);
3619- then expandAlgorithmStmts(stmt::statements, rest, inVars);
3613+ case (statements, out::rest, _) algorithm
3614+ cref := Expression . expCref(out);
3615+ (vars, _) := BackendVariable . getVar(cref, inVars);
3616+ for v in vars loop
3617+ type_ := v. varType;
3618+ if BackendVariable . isVarDiscrete(v) and not isInitialEquation then
3619+ initExp := Expression . makePureBuiltinCall("pre" , {Expression . crefExp(v. varName)}, type_);
3620+ else
3621+ initExp := Expression . crefExp(ComponentReference . crefPrefixStart(v. varName));
3622+ end if ;
3623+ stmt := Algorithm . makeAssignment(DAE . CREF (v. varName, type_), DAE . PROP (type_, DAE . C_VAR ()), initExp, DAE . PROP (type_, DAE . C_VAR ()), DAE . dummyAttrVar, SCode . NON_INITIAL (), DAE . emptyElementSource);
3624+ statements := stmt::statements;
3625+ end for ;
3626+ then expandAlgorithmStmts(statements, rest, inVars, isInitialEquation);
36203627 end match;
36213628end expandAlgorithmStmts;
36223629
0 commit comments