@@ -248,7 +248,7 @@ algorithm
248248 end if ;
249249
250250 // warn about iteration variables with default zero start attribute
251- b := warnAboutIterationVariablesWithDefaultZeroStartAttribute(initdae);
251+ (initdae, b) := warnAboutIterationVariablesWithDefaultZeroStartAttribute(initdae);
252252 if b and (not Flags . isSet(Flags . INITIALIZATION )) then
253253 Error . addMessage(Error . INITIALIZATION_ITERATION_VARIABLES , {msg});
254254 end if ;
@@ -624,39 +624,39 @@ end collectPreVariablesTraverseExp2;
624624
625625protected function warnAboutIterationVariablesWithDefaultZeroStartAttribute "author: lochel
626626 This function ... read the function name."
627- input BackendDAE . BackendDAE inDAE;
627+ input output BackendDAE . BackendDAE inDAE;
628628 output Boolean outWarning;
629+ protected
630+ list< BackendDAE . EqSystem > eqs;
629631algorithm
630- outWarning := warnAboutIterationVariablesWithDefaultZeroStartAttribute0(inDAE. eqs, Flags . isSet(Flags . INITIALIZATION ));
632+ (eqs, outWarning) := warnAboutIterationVariablesWithDefaultZeroStartAttribute0(inDAE. eqs, Flags . isSet(Flags . INITIALIZATION ));
633+ inDAE. eqs := eqs;
631634end warnAboutIterationVariablesWithDefaultZeroStartAttribute;
632635
633636protected function warnAboutIterationVariablesWithDefaultZeroStartAttribute0 "author: lochel"
634- input list< BackendDAE . EqSystem > inEqs;
637+ input output list< BackendDAE . EqSystem > inEqs;
635638 input Boolean inShowWarnings;
636639 output Boolean outWarning = false ;
637640protected
638641 Boolean warn;
642+ BackendDAE . Variables orderedVars;
639643algorithm
640644 for eqs in inEqs loop
641- warn := warnAboutIterationVariablesWithDefaultZeroStartAttribute1(eqs, inShowWarnings);
645+ (orderedVars, warn) := warnAboutIterationVariablesWithDefaultZeroStartAttribute1(eqs, inShowWarnings);
646+ eqs. orderedVars := orderedVars;
642647 outWarning := outWarning or warn;
643-
644- // If we found an iteration variable with default zero start attribute but
645- // -d=initialization wasn't given, we don't need to continue searching.
646- if warn and not inShowWarnings then
647- return ;
648- end if ;
649648 end for ;
650649end warnAboutIterationVariablesWithDefaultZeroStartAttribute0;
651650
652651protected function warnAboutIterationVariablesWithDefaultZeroStartAttribute1 "author: lochel"
653652 input BackendDAE . EqSystem inEqSystem;
654653 input Boolean inShowWarnings;
654+ output BackendDAE . Variables orderedVars = inEqSystem. orderedVars;
655655 output Boolean outWarning = false "True if any warnings were printed." ;
656656protected
657657 BackendDAE . StrongComponents comps;
658658 list< Integer > vlst = {};
659- list< BackendDAE . Var > vars;
659+ list< BackendDAE . Var > vars, vars1 = {}, vars2 = {} ;
660660 String err;
661661algorithm
662662 BackendDAE . EQSYSTEM (matching= BackendDAE . MATCHING (comps= comps)) := inEqSystem;
@@ -681,19 +681,34 @@ algorithm
681681 // Filter out the variables that are missing start values.
682682 vars := List . map1r(vlst, BackendVariable . getVarAt, inEqSystem. orderedVars);
683683 // vars := list(BackendVariable.getVarAt(inEqSystem.orderedVars, idx) for idx in vlst);
684- vars := list(v for v guard(not BackendVariable . varHasStartValue(v)) in vars);
685- // vars := List.filterOnTrue(vars, BackendVariable.varHasStartValue);
684+
685+ for v in vars loop
686+ if not BackendVariable . varHasStartValue(v) then
687+ // If the variable has a nominal value, use it as start value
688+ if BackendVariable . varHasNominalValue(v) then
689+ v := BackendVariable . setVarStartValue(v, DAE . RCONST (BackendVariable . varNominal(v)));
690+ orderedVars := BackendVariable . addVar(v, inEqSystem. orderedVars);
691+ vars2 := v::vars2;
692+ else
693+ vars1 := v::vars1;
694+ end if ;
695+ end if ;
696+ end for ;
686697
687698 // Print a warning if we found any variables with missing start values.
688- if not listEmpty(vars) then
699+ if not listEmpty(vars1) then
700+ outWarning := true ;
701+
702+ if inShowWarnings then
703+ Error . addCompilerWarning("Iteration variables with default zero start attribute in " + err + warnAboutVars2(vars1));
704+ end if ;
705+ end if ;
706+
707+ if not listEmpty(vars2) then
689708 outWarning := true ;
690709
691710 if inShowWarnings then
692- Error . addCompilerWarning("Iteration variables with default zero start attribute in " + err + warnAboutVars2(vars));
693- else
694- // If -d=initialization wasn't given we don't need to continue searching
695- // once we've found one.
696- return ;
711+ Error . addCompilerWarning("Iteration variables with nominal value as start attribute in " + err + warnAboutVars2(vars2));
697712 end if ;
698713 end if ;
699714 end if ;
0 commit comments