From 05db17586f608d1101dcc48459a346f21ce7759d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Fri, 10 Nov 2023 13:23:05 +0100 Subject: [PATCH] Don't warn about vendor experiment options (#11544) - Clean up CevalScriptBackend.populateSimulationOptions. - Don't print warnings about unknown experiment options in they're vendor-specific options that begin with `__`. - Spelling defaulSimOpt => defaultSimOpt. --- .../Compiler/Script/CevalScriptBackend.mo | 153 ++++++------------ .../modelica/connectors/Ticket4062.mo | 3 - 2 files changed, 48 insertions(+), 108 deletions(-) diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index b29e2553475..4b960d7ce81 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -499,108 +499,51 @@ algorithm end getConst; protected function populateSimulationOptions -"@auhtor: adrpo - populate simulation options" - input GlobalScript.SimulationOptions inSimOpt; - input list inExperimentSettings; - output GlobalScript.SimulationOptions outSimOpt; -algorithm - outSimOpt := matchcontinue(inSimOpt, inExperimentSettings) - local - Absyn.Exp exp; - list rest; - GlobalScript.SimulationOptions simOpt; - DAE.Exp startTime; - DAE.Exp stopTime; - DAE.Exp numberOfIntervals; - DAE.Exp stepSize; - DAE.Exp tolerance; - DAE.Exp method; - DAE.Exp fileNamePrefix; - DAE.Exp options; - DAE.Exp outputFormat; - DAE.Exp variableFilter, cflags, simflags; - Real rStepSize, rStopTime, rStartTime; - Integer iNumberOfIntervals; - String name,msg; - - case (_, {}) then inSimOpt; - - case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags), - Absyn.NAMEDARG(argName = "Tolerance", argValue = exp)::rest) - equation - tolerance = getConst(exp, DAE.T_REAL_DEFAULT); - simOpt = populateSimulationOptions( - GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags), - rest); - then - simOpt; - - case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags), - Absyn.NAMEDARG(argName = "StartTime", argValue = exp)::rest) - equation - startTime = getConst(exp, DAE.T_REAL_DEFAULT); - simOpt = populateSimulationOptions( - GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags), - rest); - then - simOpt; - - case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags), - Absyn.NAMEDARG(argName = "StopTime", argValue = exp)::rest) - equation - stopTime = getConst(exp, DAE.T_REAL_DEFAULT); - simOpt = populateSimulationOptions( - GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags), - rest); - then - simOpt; - - case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags), - Absyn.NAMEDARG(argName = "NumberOfIntervals", argValue = exp)::rest) - equation - numberOfIntervals = getConst(exp, DAE.T_INTEGER_DEFAULT); - simOpt = populateSimulationOptions( - GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags), - rest); - then - simOpt; - - case (GlobalScript.SIMULATION_OPTIONS(startTime, stopTime, numberOfIntervals, stepSize, tolerance, method, fileNamePrefix, options, outputFormat, variableFilter, cflags, simflags), - Absyn.NAMEDARG(argName = "Interval", argValue = exp)::rest) - equation - DAE.RCONST(rStepSize) = getConst(exp, DAE.T_REAL_DEFAULT); - // a bit different for Interval, handle it LAST!!!! - GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags) = - populateSimulationOptions(inSimOpt, rest); - - DAE.RCONST(rStartTime) = startTime; - DAE.RCONST(rStopTime) = stopTime; - iNumberOfIntervals = realInt(realDiv(realSub(rStopTime, rStartTime), rStepSize)); - - numberOfIntervals = DAE.ICONST(iNumberOfIntervals); - stepSize = DAE.RCONST(rStepSize); - - simOpt = GlobalScript.SIMULATION_OPTIONS(startTime,stopTime,numberOfIntervals,stepSize,tolerance,method, - fileNamePrefix,options,outputFormat,variableFilter,cflags,simflags); - then - simOpt; + input output GlobalScript.SimulationOptions options; + input list args; +protected + String name; + Absyn.Exp value; + Option interval = NONE(); +algorithm + for arg in args loop + Absyn.NAMEDARG(argName = name, argValue = value) := arg; + + () := match name + case "Tolerance" algorithm options.tolerance := getConst(value, DAE.T_REAL_DEFAULT); then (); + case "StartTime" algorithm options.startTime := getConst(value, DAE.T_REAL_DEFAULT); then (); + case "StopTime" algorithm options.stopTime := getConst(value, DAE.T_REAL_DEFAULT); then (); + case "NumberOfIntervals" algorithm options.numberOfIntervals := getConst(value, DAE.T_INTEGER_DEFAULT); then (); + case "Interval" algorithm interval := SOME(getConst(value, DAE.T_REAL_DEFAULT)); then (); + else + algorithm + if not StringUtil.startsWith(name, "__") then + Error.addCompilerWarning("Ignoring unknown experiment annotation option: " + + name + " = " + Dump.printExpStr(value)); + end if; + then + (); + end match; + end for; - case (_,Absyn.NAMEDARG(argName = name, argValue = exp)::rest) - equation - msg = "Ignoring unknown experiment annotation option: " + name + " = " + Dump.printExpStr(exp); - Error.addCompilerWarning(msg); - simOpt = populateSimulationOptions(inSimOpt, rest); - then - simOpt; - end matchcontinue; + // Interval needs to be handled last since it depends on the start and stop time. + if isSome(interval) then + options := setSimulationOptionsInterval(options, Expression.toReal(Util.getOption(interval))); + end if; end populateSimulationOptions; +function setSimulationOptionsInterval + input output GlobalScript.SimulationOptions options; + input Real interval; +protected + Real start_time, stop_time; +algorithm + start_time := Expression.toReal(options.startTime); + stop_time := Expression.toReal(options.stopTime); + options.stepSize := DAE.RCONST(interval); + options.numberOfIntervals := DAE.ICONST(realInt((stop_time - start_time) / interval)); +end setSimulationOptionsInterval; + protected function simOptionsAsString "@author: adrpo Gets the simulation options as string" @@ -3457,15 +3400,15 @@ algorithm list args; Boolean haveAnnotation; SimCode.SimulationSettings simSettings; - GlobalScript.SimulationOptions defaulSimOpt; + GlobalScript.SimulationOptions defaultSimOpt; case (cache,env,_,fileNamePrefix,_) algorithm if isSome(inSimSettingsOpt) then SOME(simSettings) := inSimSettingsOpt; else - defaulSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, fileNamePrefix, SOME(defaultSimulationOptions)); - simSettings := convertSimulationOptionsToSimCode(defaulSimOpt); + defaultSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, fileNamePrefix, SOME(defaultSimulationOptions)); + simSettings := convertSimulationOptionsToSimCode(defaultSimOpt); end if; if Config.ignoreCommandLineOptionsAnnotation() then @@ -3999,7 +3942,7 @@ protected Boolean staticSourceCodeFMU, success; String filenameprefix, fmutmp, logfile, configureLogFile, dir, cmd; String fmuTargetName; - GlobalScript.SimulationOptions defaulSimOpt; + GlobalScript.SimulationOptions defaultSimOpt; SimCode.SimulationSettings simSettings; list libs; Boolean isWindows; @@ -4034,8 +3977,8 @@ algorithm if isSome(inSimSettings) then SOME(simSettings) := inSimSettings; else - defaulSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, filenameprefix, SOME(defaultSimulationOptions)); - simSettings := convertSimulationOptionsToSimCode(defaulSimOpt); + defaultSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(className, filenameprefix, SOME(defaultSimulationOptions)); + simSettings := convertSimulationOptionsToSimCode(defaultSimOpt); end if; FlagsUtil.setConfigBool(Flags.BUILDING_FMU, true); FlagsUtil.setConfigString(Flags.FMI_VERSION, FMUVersion); diff --git a/testsuite/flattening/modelica/connectors/Ticket4062.mo b/testsuite/flattening/modelica/connectors/Ticket4062.mo index 3c1e93d8b31..15d905c6825 100644 --- a/testsuite/flattening/modelica/connectors/Ticket4062.mo +++ b/testsuite/flattening/modelica/connectors/Ticket4062.mo @@ -486,7 +486,4 @@ end Ticket4062; // serialReceive.pkgOut.userPkgBitSize = unpackInt.pkgIn.userPkgBitSize; // integerToReal.u = unpackInt.y; // end Ticket4062; -// Warning: Ignoring unknown experiment annotation option: __Dymola_fixedstepsize = 0.001 -// Warning: Ignoring unknown experiment annotation option: __Dymola_Algorithm = "Euler" -// // endResult