Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions testmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def createOmcSessionNew():
variableFilter=shared.variableFilterOf(referenceVars)
# get the number of intervals from the file
numberOfIntervalsInReference = omc_new.sendExpression('readSimulationResultSize("%s")' % referenceFile)
emit_protected="-emit_protected"
emit_protected="-emit_protected -ignoreHideResult"
except:
referenceFile=""
if referenceFile=="":
Expand Down Expand Up @@ -1269,8 +1269,15 @@ def verifyAgainstReference(resFile, prefix, stat):
# diffSimulationResults fails on a variable it cannot find in the result.
dymolaOnlyVars=[v for v in diffVars if shared.isDymolaOnlyVariable(v)]
diffVars=[v for v in diffVars if not shared.isDymolaOnlyVariable(v)]
resVars=omc_new.sendExpression('readSimulationResultVars("%s", readParameters=true, openmodelicaStyle=true)' % resFile) or []
# OpenModelica writes no constants; Dymola writes them as parameters.
constantVars=constantsInReference([v for v in diffVars if v not in set(resVars)])
diffVars=[v for v in diffVars if v not in constantVars]
if constantVars:
with open(errFile, 'a+') as fp:
fp.write("Not compared, constant in the reference and not in the result: %s\n" % ",".join(sorted(constantVars)))
stat["diff"] = {"time":monotonic()-start, "vars":[], "numCompared":len(referenceVars)}
if len(diffVars)==0 and (referenceOK or dymolaOnlyVars):
if len(diffVars)==0 and (referenceOK or dymolaOnlyVars or constantVars):
stat["phase"]=7
with open(errFile, 'a+') as fp:
fp.write("Reference file matches\n")
Expand All @@ -1279,7 +1286,6 @@ def verifyAgainstReference(resFile, prefix, stat):
fp.write(omc_new.sendExpression('OpenModelica.Scripting.getErrorString()', parsed = False))
fp.write("\nVariables in the reference:" )
fp.write(",".join(referenceVars)+"\n")
resVars=omc_new.sendExpression('readSimulationResultVars("%s", readParameters=true, openmodelicaStyle=true)' % resFile)
fp.write("\nVariables in the result:" )
fp.write(",".join(resVars)+"\n")
stat["diff"]["vars"]=diffVars
Expand All @@ -1288,6 +1294,21 @@ def verifyAgainstReference(resFile, prefix, stat):
filterDiffVars(resFile, prefix + ".mat", diffVars)
filterDiffVars(referenceFile, prefix + ".ref.mat", diffVars)

def constantsInReference(names):
"""The names whose reference value does not change over time."""
if not names:
return set()
if referenceFile.endswith(".mat"):
timeVarying = set(omc_new.sendExpression('readSimulationResultVars("%s", readParameters=false, openmodelicaStyle=true)' % referenceFile) or [])
return {v for v in names if v not in timeVarying}
constants = set()
# One call per name: a name that is not a component reference fails alone.
for v in names:
values = omc_new.sendExpression('readSimulationResult("%s", {%s}, %d)' % (referenceFile, v, numberOfIntervalsInReference))
if values and len(set(values[0])) == 1:
constants.add(v)
return constants

def filterDiffVars(inFile, outFile, diffVars):
vars = ", ".join('"%s"' % v.replace('\\', '\\\\').replace('"', '\\"') for v in diffVars)
try:
Expand Down
Loading