Skip to content

Commit

Permalink
More fixes to1.18 (#7679)
Browse files Browse the repository at this point in the history
* Avoid declaration of StatArray with unknown dimension (#7664)

See PowerSystems.Examples.AC3ph.Precalculation.Z_matrixEqCirc0

./OMCppPowerSystems_cpp_PowerSystems.Examples.AC3ph.Precalculation.Z_matrixEqCirc0Initialize.cpp:198:31:
 note: in instantiation of template class 'StatArrayDim1<double, 18446744073709551615, false>' requested here
     StatArrayDim1<double, -1> tmp3;

* Fix AssertionLevel (#7665)

- Swap the order of warning and error in AssertionLevel so they're the
  same order as in the specification.

* Extend Cpp template expTypeFromExpFlag according to C version (#7658)

In particular add TSUB and RSUB.

See ModelicaTest.Math.TestMatrices2:
./OMCppModelicaTest_trunk_cpp_ModelicaTest.Math.TestMatrices2Functions.cpp:4729:9:
 error: unknown type name 'expTypeFromExpFlag'
 ERROR:expTypeFromExpFlag Modelica.Math.Matrices.realSchur(A1)[1]  tmp557;

* Updated documentation of --linkType (#7659)

* Don't consider variability when filtering elements

  - Fixes the immediate issue in #7660.
    The model still does not compile but it is now due to an undefined
    function ``data_of_boolean_f77_array`

  - We were checking `variability` as well when what we actually interested
    in was just the `direction` of the element.

    It is an unfortunate mixup in terminology.

* Fix editing of legend titles (#7670)

Fixes #7627

* Clean up SimCode a bit (#7668)

- Modernise some parts of SimCode to make it easier to see what's going
  on in SimCode.addVarToArrayIndexMapping.

* Distinguish array slice of size 1 from reduction (#7675)

See PowerSystems.Examples.AC3ph.Precalculation.TransDatFromEqCirc

* Updated libraries
* libraries ac8d5d4...0f47ccf (1):
  > Bump libraries

* Improve treatment of unknown dimensions in Cpp runtime (#7677)

See ModelicaTest.Math.TestMatrices3 (MSL 4.0.0)
ERROR  : init  : SimManager: Could not initialize system
ERROR  : init  : SimManager: std::bad_alloc

Co-authored-by: rfranke <rfranke@users.noreply.github.com>
Co-authored-by: perost <perost86@gmail.com>
Co-authored-by: Francesco Casella <francesco.casella@polimi.it>
Co-authored-by: Mahder Gebremedhin <mahder.gebremedhin@liu.se>
Co-authored-by: Adeel Asghar <adeel.asghar@liu.se>
Co-authored-by: hudson <openmodelica@ida.liu.se>
  • Loading branch information
7 people committed Jul 9, 2021
1 parent 3c6bead commit 6c8d85a
Show file tree
Hide file tree
Showing 20 changed files with 244 additions and 201 deletions.
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/BackEnd/BackendDAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ algorithm
then ();
case (_,_,_,_)
equation
failure(DAE.ENUM_LITERAL(index=1) = level);
failure(DAE.ENUM_LITERAL(index=2) = level);
then ();
case(_,_,_,_)
equation
Expand Down
22 changes: 11 additions & 11 deletions OMCompiler/Compiler/BackEnd/HpcOmMemory.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1958,8 +1958,8 @@ import Util;

currentVarIndices = arrayCreate(4,1);
//The first array elements are reserved for state and state derivative variables
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iStateVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_FLOAT), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iDerivativeVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_FLOAT), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMappings(iStateVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) =SimCodeUtil.addVarToArrayIndexMappings(iDerivativeVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);

stateAndStateDerSize = intAdd(listLength(iStateVars), listLength(iDerivativeVars));
if(intEq(intMod(stateAndStateDerSize, maxNumElemsFloat), 0)) then
Expand Down Expand Up @@ -1987,16 +1987,16 @@ import Util;
arrayUpdate(currentVarIndices, 3, intMul(listLength(cacheLinesBool), maxNumElemsBool) + 1);
arrayUpdate(currentVarIndices, 4, 1);

((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(listReverse(notOptimizedVarsFloat), function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_FLOAT), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(listReverse(notOptimizedVarsInt), function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_INTEGER), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(listReverse(notOptimizedVarsBool), function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_BOOLEAN), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(listReverse(notOptimizedVarsString), function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_STRING), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMappings(listReverse(notOptimizedVarsFloat), VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMappings(listReverse(notOptimizedVarsInt), VARDATATYPE_INTEGER, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMappings(listReverse(notOptimizedVarsBool), VARDATATYPE_BOOLEAN, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
(currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMappings(listReverse(notOptimizedVarsString), VARDATATYPE_STRING, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);

//BaseHashTable.dumpHashTable(varArrayIndexMappingHashTable);
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iAliasVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_FLOAT), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iIntAliasVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_INTEGER), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iBoolAliasVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_BOOLEAN), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = List.fold(iStringAliasVars, function SimCodeUtil.addVarToArrayIndexMapping(iVarType=VARDATATYPE_STRING), (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = SimCodeUtil.addVarToArrayIndexMappings(iAliasVars, VARDATATYPE_FLOAT, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = SimCodeUtil.addVarToArrayIndexMappings(iIntAliasVars, VARDATATYPE_INTEGER, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = SimCodeUtil.addVarToArrayIndexMappings(iBoolAliasVars, VARDATATYPE_BOOLEAN, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
((currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable)) = SimCodeUtil.addVarToArrayIndexMappings(iStringAliasVars, VARDATATYPE_STRING, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);

varSizeFloat = varSizeFloat + intMul(listLength(cacheLinesFloat), maxNumElemsFloat) + listLength(notOptimizedVarsFloat);
//SimCodeUtil.dumpVarLst(notOptimizedVarsFloat, "convertCacheToVarArrayMapping: Not optimized float vars");
Expand Down Expand Up @@ -2084,7 +2084,7 @@ import Util;
//print("convertCacheMapToMemoryMap2: offset=" + intString(offset) + " array-index=" + intString(iArrayIdx) + " array-position=" + intString(arrayPosition) + "\n");
currentVarIndices = arrayCreate(4,arrayPosition);
//print("convertCacheMapToMemoryMap2: number of variables=" + intString(arrayLength(iCacheVariables)) + " arrayPosition=" + intString(arrayPosition) + "\n");
(_, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMapping(arrayGet(iCacheVariables, arrayLength(iCacheVariables) - scVarIdx + 1), iArrayIdx, (currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable));
(_, varArrayIndexMappingHashTable, varIndexMappingHashTable) = SimCodeUtil.addVarToArrayIndexMapping(arrayGet(iCacheVariables, arrayLength(iCacheVariables) - scVarIdx + 1), iArrayIdx, currentVarIndices, varArrayIndexMappingHashTable, varIndexMappingHashTable);
//iPositionMappingList = (realScVarIdx,arrayPosition,iArrayIdx)::iPositionMappingList;
//for arridx in listRange(arrayLength(iVarIdxOffsets)) loop
// _ = arrayUpdate(iVarIdxOffset, intDiv(clSize, size));
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/FrontEnd/DAE.mo
Original file line number Diff line number Diff line change
Expand Up @@ -391,9 +391,9 @@ public uniontype Element

end Element;

public constant Type T_ASSERTIONLEVEL = T_ENUMERATION(NONE(), Absyn.FULLYQUALIFIED(Absyn.IDENT("AssertionLevel")), {"error","warning"}, {}, {});
public constant Exp ASSERTIONLEVEL_ERROR = ENUM_LITERAL(Absyn.QUALIFIED("AssertionLevel",Absyn.IDENT("error")),1);
public constant Exp ASSERTIONLEVEL_WARNING = ENUM_LITERAL(Absyn.QUALIFIED("AssertionLevel",Absyn.IDENT("warning")),2);
public constant Type T_ASSERTIONLEVEL = T_ENUMERATION(NONE(), Absyn.FULLYQUALIFIED(Absyn.IDENT("AssertionLevel")), {"warning","error"}, {}, {});
public constant Exp ASSERTIONLEVEL_WARNING = ENUM_LITERAL(Absyn.QUALIFIED("AssertionLevel",Absyn.IDENT("warning")),1);
public constant Exp ASSERTIONLEVEL_ERROR = ENUM_LITERAL(Absyn.QUALIFIED("AssertionLevel",Absyn.IDENT("error")),2);

public uniontype Function
record FUNCTION " A Modelica function"
Expand Down
38 changes: 31 additions & 7 deletions OMCompiler/Compiler/FrontEnd/DAEUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,13 @@ algorithm
vl_1 := getMatchingElements(vl, isOutputVar);
end getOutputVars;

public function getOutputElements
input list<DAE.Element> vl;
output list<DAE.Element> vl_1;
algorithm
vl_1 := getMatchingElements(vl, isOutputElement);
end getOutputElements;

public function getProtectedVars "
author: PA

Expand All @@ -1635,6 +1642,13 @@ algorithm
vl_1 := getMatchingElements(vl, isBidirVar);
end getBidirVars;

public function getBidirElements
input list<DAE.Element> vl;
output list<DAE.Element> vl_1;
algorithm
vl_1 := getMatchingElements(vl, isBidirElement);
end getBidirElements;

public function getInputVars "
Retrieve all input variables from an Element list.
"
Expand Down Expand Up @@ -1689,6 +1703,16 @@ algorithm
end match;
end isOutputVar;

public function isOutputElement
input DAE.Element inElement;
output Boolean outMatch;
algorithm
outMatch := match (inElement)
case DAE.VAR(direction = DAE.OUTPUT()) then true;
else false;
end match;
end isOutputElement;

public function assertProtectedVar
"Succeeds if Element is a protected variable."
input DAE.Element inElement;
Expand Down Expand Up @@ -1733,15 +1757,15 @@ algorithm
end match;
end isBidirVar;

public function isBidirVarDirection
input DAE.VarDirection inVarDirection;
output Boolean outIsBidir;
public function isBidirElement
input DAE.Element inElement;
output Boolean outMatch;
algorithm
outIsBidir := match(inVarDirection)
case DAE.BIDIR() then true;
outMatch := match (inElement)
case DAE.VAR(direction = DAE.BIDIR()) then true;
else false;
end match;
end isBidirVarDirection;
end isBidirElement;

public function isInputVar "
Succeeds if Element is an input variable.
Expand Down Expand Up @@ -2882,7 +2906,7 @@ protected
list<DAE.Element> elements;
algorithm
elements := getFunctionElements(fn);
outEls := List.filterOnTrue(elements, isOutputVar);
outEls := List.filterOnTrue(elements, isOutputElement);
end getFunctionOutputVars;

public function getFunctionProtectedVars
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ annotation(__OpenModelica_Impure=true, Documentation(info="<html>
</html>"));
end terminal;

type AssertionLevel = enumeration(error, warning) annotation(__OpenModelica_builtin=true,
type AssertionLevel = enumeration(warning, error) annotation(__OpenModelica_builtin=true,
Documentation(info="<html>Used by <a href=\"modelica://assert\">assert()</a></html>"));

function assert "Check an assertion condition"
Expand Down
6 changes: 3 additions & 3 deletions OMCompiler/Compiler/NFFrontEnd/NFBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,12 @@ constant Type STATESELECT_TYPE = Type.ENUMERATION(
Absyn.IDENT("StateSelect"), {"never", "avoid", "default", "prefer", "always"});

constant Type ASSERTIONLEVEL_TYPE = Type.ENUMERATION(
Absyn.IDENT("AssertionLevel"), {"error", "warning"});
Absyn.IDENT("AssertionLevel"), {"warning", "error"});

constant Expression ASSERTIONLEVEL_ERROR = Expression.ENUM_LITERAL(
constant Expression ASSERTIONLEVEL_WARNING = Expression.ENUM_LITERAL(
ASSERTIONLEVEL_TYPE, "error", 1);

constant Expression ASSERTIONLEVEL_WARNING = Expression.ENUM_LITERAL(
constant Expression ASSERTIONLEVEL_ERROR = Expression.ENUM_LITERAL(
ASSERTIONLEVEL_TYPE, "error", 2);

constant Type UNCERTAINTY_TYPE = Type.ENUMERATION(
Expand Down
2 changes: 1 addition & 1 deletion OMCompiler/Compiler/NFFrontEnd/NFModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ annotation(__OpenModelica_builtin=true, __OpenModelica_Impure=true, Documentatio
</html>"));
end terminal;

type AssertionLevel = enumeration(error, warning) annotation(__OpenModelica_builtin=true,
type AssertionLevel = enumeration(warning, error) annotation(__OpenModelica_builtin=true,
Documentation(info="<html>Used by <a href=\"modelica://assert\">assert()</a></html>"));

function assert "Check an assertion condition"
Expand Down
12 changes: 6 additions & 6 deletions OMCompiler/Compiler/SimCode/SimCodeFunctionUtil.mo
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ algorithm

DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_NON_PARALLEL()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
outVars = List.map(DAEUtil.getOutputElements(daeElts), daeInOutSimVar);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filterOnTrue(daeElts, isVarQ);
Expand All @@ -728,7 +728,7 @@ algorithm

DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_KERNEL_FUNCTION()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
outVars = List.map(DAEUtil.getOutputElements(daeElts), daeInOutSimVar);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filterOnTrue(daeElts, isVarNotInputNotOutput);
Expand All @@ -747,7 +747,7 @@ algorithm

DAE.FUNCTION_ATTRIBUTES(functionParallelism=DAE.FP_PARALLEL_FUNCTION()) = funAttrs;

outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
outVars = List.map(DAEUtil.getOutputElements(daeElts), daeInOutSimVar);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
vars = List.filterOnTrue(daeElts, isVarQ);
Expand All @@ -764,13 +764,13 @@ algorithm
equation
DAE.EXTERNALDECL(name=extfnname, args=extargs,
returnArg=extretarg, language=lang, ann=ann) = extdecl;
// outvars = DAEUtil.getOutputVars(daeElts);
// outvars = DAEUtil.getOutputElements(daeElts);
// invars = DAEUtil.getInputVars(daeElts);
// bivars = DAEUtil.getBidirVars(daeElts);
funArgs = List.map1(args, typesSimFunctionArg, NONE());
outVars = List.map(DAEUtil.getOutputVars(daeElts), daeInOutSimVar);
outVars = List.map(DAEUtil.getOutputElements(daeElts), daeInOutSimVar);
inVars = List.map(DAEUtil.getInputVars(daeElts), daeInOutSimVar);
biVars = List.map(DAEUtil.getBidirVars(daeElts), daeInOutSimVar);
biVars = List.map(DAEUtil.getBidirElements(daeElts), daeInOutSimVar);
(recordDecls, rt_1) = elaborateRecordDeclarations(daeElts, recordDecls, rt);
info = ElementSource.getElementSourceFileInfo(source);
(fn_includes, fn_includeDirs, fn_libs, fn_paths,dynamicLoad) = generateExtFunctionIncludes(program, fpath, ann, info);
Expand Down

0 comments on commit 6c8d85a

Please sign in to comment.