Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 5682249

Browse files
ptaeuberOpenModelica-Hudson
authored andcommitted
Warn about iteration variables with no nominal attribute
Activate warning with: -d=warnNoNominal see ticket:4512
1 parent 3d27c59 commit 5682249

File tree

3 files changed

+93
-2
lines changed

3 files changed

+93
-2
lines changed

Compiler/BackEnd/BackendDAEUtil.mo

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6882,6 +6882,9 @@ algorithm
68826882

68836883
// generate system for initialization
68846884
(outInitDAE, outInitDAE_lambda0_option, outRemovedInitialEquationLst, globalKnownVars) := Initialization.solveInitialSystem(dae);
6885+
if Flags.isSet(Flags.WARN_NO_NOMINAL) then
6886+
warnAboutIterationVariablesWithNoNominal(outInitDAE);
6887+
end if;
68856888

68866889
// use function tree from initDAE further for simDAE
68876890
simDAE := BackendDAEUtil.setFunctionTree(dae, BackendDAEUtil.getFunctions(outInitDAE.shared));
@@ -6897,6 +6900,9 @@ algorithm
68976900

68986901
// post-optimization phase
68996902
simDAE := postOptimizeDAE(simDAE, postOptModules, matchingAlgorithm, daeHandler);
6903+
if Flags.isSet(Flags.WARN_NO_NOMINAL) then
6904+
warnAboutIterationVariablesWithNoNominal(simDAE);
6905+
end if;
69006906

69016907
// sort the globalKnownVars
69026908
simDAE := sortGlobalKnownVarsInDAE(simDAE);
@@ -9235,5 +9241,53 @@ algorithm
92359241
names := stringDelimitList(list(ComponentReference.printComponentRefStr(BackendVariable.varCref(BackendVariable.getVarAt(varsArray, v))) for v in vars), ", ");
92369242
end getVariableNamesForErrorMessage;
92379243

9244+
// =============================================================================
9245+
// warn about iteration variables with no nominal attribute
9246+
//
9247+
// =============================================================================
9248+
9249+
protected function warnAboutIterationVariablesWithNoNominal
9250+
" author: ptaeuber"
9251+
input BackendDAE.BackendDAE inDAE;
9252+
protected
9253+
BackendDAE.StrongComponents comps;
9254+
String daeTypeStr, compKind;
9255+
list<Integer> vlst = {};
9256+
list<BackendDAE.Var> vars;
9257+
algorithm
9258+
daeTypeStr := BackendDump.printBackendDAEType2String(inDAE.shared.backendDAEType);
9259+
for syst in inDAE.eqs loop
9260+
BackendDAE.EQSYSTEM(matching=BackendDAE.MATCHING(comps=comps)) := syst;
9261+
9262+
// Go through all the strongly connected components.
9263+
for comp in comps loop
9264+
// Get the component's variables.
9265+
(compKind, vlst) := match(comp)
9266+
case BackendDAE.EQUATIONSYSTEM(vars = vlst, jacType = BackendDAE.JAC_NONLINEAR())
9267+
then ("nonlinear equation system in the " + daeTypeStr + " DAE:", vlst);
9268+
case BackendDAE.EQUATIONSYSTEM(vars = vlst, jacType = BackendDAE.JAC_GENERIC())
9269+
then ("equation system w/o analytic Jacobian in the " + daeTypeStr + " DAE:", vlst);
9270+
case BackendDAE.EQUATIONSYSTEM(vars = vlst, jacType = BackendDAE.JAC_NO_ANALYTIC())
9271+
then ("equation system w/o analytic Jacobian in the " + daeTypeStr + " DAE:", vlst);
9272+
case BackendDAE.TORNSYSTEM(BackendDAE.TEARINGSET(tearingvars = vlst), linear = false)
9273+
then ("torn nonlinear equation system in the " + daeTypeStr + " DAE:", vlst);
9274+
// If the component is none of these types, do nothing.
9275+
else ("", {});
9276+
end match;
9277+
9278+
if not listEmpty(vlst) then
9279+
// Filter out the variables that are missing start values.
9280+
vars := List.map1r(vlst, BackendVariable.getVarAt, syst.orderedVars);
9281+
vars := list(v for v guard(not BackendVariable.varHasNominalValue(v)) in vars);
9282+
9283+
// Print a warning if we found any variables with missing start values.
9284+
if not listEmpty(vars) then
9285+
Error.addCompilerWarning(BackendDump.varListStringIndented(vars, "Iteration variables with no nominal value in " + compKind));
9286+
end if;
9287+
end if;
9288+
end for;
9289+
end for;
9290+
end warnAboutIterationVariablesWithNoNominal;
9291+
92389292
annotation(__OpenModelica_Interface="backend");
92399293
end BackendDAEUtil;

Compiler/BackEnd/BackendDump.mo

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,40 @@ algorithm
452452
outTpl := (varNo + 1, buffer);
453453
end var1String;
454454

455+
public function varListStringIndented
456+
input list<BackendDAE.Var> inVars;
457+
input String heading;
458+
output String outString;
459+
algorithm
460+
outString := match(inVars, heading)
461+
local
462+
String buffer;
463+
464+
case (_, "") equation
465+
((_, buffer)) = List.fold(inVars, var1StringIndented, (1, ""));
466+
then buffer;
467+
468+
else equation
469+
((_, buffer)) = List.fold(inVars, var1StringIndented, (1, ""));
470+
buffer = heading + "\n" + buffer;
471+
then buffer;
472+
end match;
473+
end varListStringIndented;
474+
475+
protected function var1StringIndented
476+
input BackendDAE.Var inVar;
477+
input tuple<Integer /*inVarNo*/, String /*buffer*/> inTpl;
478+
output tuple<Integer /*outVarNo*/, String /*buffer*/> outTpl;
479+
protected
480+
Integer varNo;
481+
String buffer;
482+
algorithm
483+
(varNo, buffer) := inTpl;
484+
buffer := buffer + " " + intString(varNo) + ": ";
485+
buffer := buffer + varString(inVar) + "\n";
486+
outTpl := (varNo + 1, buffer);
487+
end var1StringIndented;
488+
455489
protected function printExternalObjectClasses "dump classes of external objects"
456490
input BackendDAE.ExternalObjectClasses cls;
457491
algorithm

Compiler/Util/Flags.mo

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,9 @@ constant DebugFlag NF_UNITCHECK = DEBUG_FLAG(168, "frontEndUnitCheck", false,
513513
constant DebugFlag DISABLE_COLORING = DEBUG_FLAG(169, "disableColoring", false,
514514
Util.gettext("Disables coloring algorithm while spasity detection."));
515515
constant DebugFlag MERGE_ALGORITHM_SECTIONS = DEBUG_FLAG(170, "mergeAlgSections", false,
516-
Util.gettext("Disables coloring algorithm while spasity detection."));
516+
Util.gettext("Disables coloring algorithm while sparsity detection."));
517+
constant DebugFlag WARN_NO_NOMINAL = DEBUG_FLAG(171, "warnNoNominal", false,
518+
Util.gettext("Prints the iteration variables in the initialization and simulation DAE, which do not have a nominal value."));
517519

518520

519521
// This is a list of all debug flags, to keep track of which flags are used. A
@@ -691,7 +693,8 @@ constant list<DebugFlag> allDebugFlags = {
691693
EVAL_PARAM_DUMP,
692694
NF_UNITCHECK,
693695
DISABLE_COLORING,
694-
MERGE_ALGORITHM_SECTIONS
696+
MERGE_ALGORITHM_SECTIONS,
697+
WARN_NO_NOMINAL
695698
};
696699

697700
public

0 commit comments

Comments
 (0)