@@ -732,6 +732,34 @@ def wasmJitAcceptsFlag(flagVal):
732732 haveFlagCheckModel = True
733733 return bool ((sendExpressionOldOrNew ('simulate(OMLibTestFlagCheck,simflags="%s")' % flagVal ) or {}).get ("resultFile" ))
734734
735+ commandLineOptionsRe = re .compile (r'__OpenModelica_commandLineOptions\s*=\s*\\?"([^"\\]*)' )
736+ daeModeRe = re .compile (r'(?:^|[\s"])(?:--|\+)daeMode(?:=(\w*))?(?![\w=])' , re .IGNORECASE )
737+
738+ def modelCommandLineOptions ():
739+ """The flags the model's __OpenModelica_commandLineOptions annotation sets.
740+
741+ omc applies them itself inside simulate()/buildModelFMU(); the testing needs to
742+ know about them beforehand to pick how the model can be run at all.
743+ """
744+ if not sendExpressionOldOrNew ('classAnnotationExists(%s, __OpenModelica_commandLineOptions)' % conf ["modelName" ]):
745+ return ""
746+ opts = []
747+ for i in range (1 , (sendExpressionOldOrNew ('getAnnotationCount(%s)' % conf ["modelName" ]) or 0 ) + 1 ):
748+ text = sendExpressionOldOrNew ('getNthAnnotationString(%s, %d)' % (conf ["modelName" ], i )) or ""
749+ opts += commandLineOptionsRe .findall (text )
750+ return " " .join (opts )
751+
752+ def compiledInDaeMode ():
753+ """Whether omc translates the model with --daeMode. The custom commands set
754+ flags before the annotation does, and omc keeps the last value."""
755+ values = daeModeRe .findall (" " .join (str (c ) for c in conf ["customCommands" ]) + " " + modelCommandLineOptions ())
756+ return bool (values ) and values [- 1 ].lower () in ("" , "true" , "yes" )
757+
758+ # The runtimes integrate a --daeMode model only with IDA, so -s=ida is the last -s
759+ # of every run of one, whatever the annotation, the job or the solver asks for.
760+ daeMode = conf ["simCodeTarget" ] in ("C" ,"C+Rust" ,"wasm-jit" ) and compiledInDaeMode ()
761+ daeModeSimFlags = "-s=ida" if daeMode else ""
762+
735763annotationSimFlags = ""
736764cmd = 'getSimulationOptions(%s,defaultTolerance=%s,defaultNumberOfIntervals=%s)' % (conf ["modelName" ], conf ["defaultTolerance" ], max (conf ["defaultNumberOfIntervals" ], numberOfIntervalsInReference ))
737765try :
@@ -746,34 +774,19 @@ def wasmJitAcceptsFlag(flagVal):
746774 continue
747775 val = sendExpressionOldOrNew ('getAnnotationModifierValue(%s,"__OpenModelica_simulationFlags","%s")' % (conf ["modelName" ],flag ))
748776 flagVal = " -noemit -%s=%s" % (flag ,val )
777+ if daeMode and flag == "s" :
778+ if val != "ida" :
779+ with open (errFile , 'a+' ) as fp :
780+ fp .write ("Ignoring simflag -s=%s since the model is compiled with --daeMode, which needs -s=ida\n " % val )
781+ continue
749782 if wasmJitAcceptsFlag ("-%s=%s" % (flag ,val )) if isWasmJit else shared .simulationAcceptsFlag (flagVal , checkOutput = False , cwd = ".." , isWin = isWin ):
750783 annotationSimFlags += " -%s=%s" % (flag ,val )
751784 else :
752785 with open (errFile , 'a+' ) as fp :
753786 fp .write ("Ignoring simflag %s since the simulation runtime does not accept it\n " % flagVal )
754787
755- commandLineOptionsRe = re .compile (r'__OpenModelica_commandLineOptions\s*=\s*\\?"([^"\\]*)' )
756-
757- def modelCommandLineOptions ():
758- """The flags the model's __OpenModelica_commandLineOptions annotation sets.
759-
760- omc applies them itself inside simulate()/buildModelFMU(); the testing needs to
761- know about them beforehand to pick how the model can be run at all.
762- """
763- if not sendExpressionOldOrNew ('classAnnotationExists(%s, __OpenModelica_commandLineOptions)' % conf ["modelName" ]):
764- return ""
765- opts = []
766- for i in range (1 , (sendExpressionOldOrNew ('getAnnotationCount(%s)' % conf ["modelName" ]) or 0 ) + 1 ):
767- text = sendExpressionOldOrNew ('getNthAnnotationString(%s, %d)' % (conf ["modelName" ], i )) or ""
768- opts += commandLineOptionsRe .findall (text )
769- return " " .join (opts )
770-
771- # A --daeMode model's Model Exchange interface is a DAE one (fmi-ls-dae): the
772- # runners that care say how to drive it.
773- daeMode = useWasmFmu and "--daeMode" in (modelCommandLineOptions () + " " + " " .join (str (c ) for c in conf ["customCommands" ]))
774-
775788def simulateCmd (resimulate ):
776- simflags = ("%s %s %s -lv LOG_STATS" % (annotationSimFlags ,conf ["simFlags" ],emit_protected )).strip ()
789+ simflags = ("%s %s %s -lv LOG_STATS %s " % (annotationSimFlags ,conf ["simFlags" ],emit_protected , daeModeSimFlags )).strip ()
777790 return 'simulate(%s,startTime=%g,stopTime=%g,tolerance=%g,numberOfIntervals=%d,outputFormat="%s",variableFilter="%s",fileNamePrefix="%s",simflags="%s"%s)' % (conf ["modelName" ],startTime ,stopTime ,tolerance ,numberOfIntervals ,outputFormat ,variableFilter ,conf ["fileName" ],simflags ,(',resimulateExecutable="%s"' % conf ["fileName" ]) if resimulate else "" )
778791
779792# TODO: Detect and handle the case where RT_CLOCK is not available in OMC
@@ -939,6 +952,8 @@ def simulateCmd(resimulate):
939952# The model is built once and its executable run once per solver; the solvers are
940953# described in configs/solvers.json.
941954solverRunners = shared .parseSolvers (conf .get ("solvers" )) if not conf .get ("fmi" ) and not isWasmJit else []
955+ # A --daeMode model's Model Exchange interface is a DAE one (fmi-ls-dae): the
956+ # runners that care say how to drive it.
942957if daeMode :
943958 wasmfmurunners = [(name , shared .wasmFmuRunner (name ).get ("daeModeSimflags" ) or flags ) for (name , flags ) in wasmfmurunners ]
944959# One build, several runs: an FMU simulated by several tools, a wasm FMU run
@@ -1076,7 +1091,7 @@ def wasmFmuCmd(runnerFlags, resFile, runDir):
10761091 simflags = " " .join (x for x in (annotationSimFlags , conf ["simFlags" ], emit_protected ,
10771092 "-lv LOG_STATS" ,
10781093 "-startTime=%g -stopTime=%g -tolerance=%g -stepSize=%g" % (startTime ,stopTime ,tolerance ,stepSize ),
1079- filterArgument , resultArgument , runnerFlags ) if x .strip ())
1094+ filterArgument , resultArgument , runnerFlags , daeModeSimFlags ) if x .strip ())
10801095 return 'simulate(%s,startTime=%g,stopTime=%g,tolerance=%g,numberOfIntervals=%d,outputFormat="%s",variableFilter="%s",fileNamePrefix="%s",simflags="%s",resimulateExecutable="%s")' % (
10811096 conf ["modelName" ],startTime ,stopTime ,tolerance ,numberOfIntervals ,outputFormat ,variableFilter ,conf ["fileName" ],simflags ,fromRunnerDir (runDir , "%s.fmu" % conf ["fileName" ].replace ("." ,"_" )))
10821097
@@ -1123,7 +1138,7 @@ def simulateExecutable(name, solverFlags, resFile, simFile):
11231138 setupArgument = "-inputPath=.." if runDir else ""
11241139 cmd = inRunnerDir (runDir , " " .join (x for x in (exe , annotationSimFlags , conf ["simFlags" ], emit_protected ,
11251140 "-lv LOG_STATS" if conf ["simCodeTarget" ] in ("C" ,"C+Rust" ) else "" ,
1126- setupArgument , resultArgument , solverFlags ) if x .strip ()))
1141+ setupArgument , resultArgument , solverFlags , daeModeSimFlags ) if x .strip ()))
11271142 with open (simFile ,"w" ) as fp :
11281143 fp .write ("Environment - simulationEnvironment:\n " )
11291144 for e in conf ["environmentSimulation" ]:
0 commit comments