@@ -2116,6 +2116,138 @@ class ModelicaSystem(ModelicaSystemOMC):
21162116 Compatibility class.
21172117 """
21182118
2119+ def __init__ (
2120+ self ,
2121+ fileName : Optional [str | os .PathLike | pathlib .Path ] = None ,
2122+ modelName : Optional [str ] = None ,
2123+ lmodel : Optional [list [str | tuple [str , str ]]] = None ,
2124+ commandLineOptions : Optional [list [str ]] = None ,
2125+ variableFilter : Optional [str ] = None ,
2126+ customBuildDirectory : Optional [str | os .PathLike ] = None ,
2127+ omhome : Optional [str ] = None ,
2128+ omc_process : Optional [OMCSessionLocal ] = None ,
2129+ build : bool = True ,
2130+ ) -> None :
2131+ super ().__init__ (
2132+ command_line_options = commandLineOptions ,
2133+ work_directory = customBuildDirectory ,
2134+ omhome = omhome ,
2135+ session = omc_process ,
2136+ )
2137+ self .model (
2138+ model_name = modelName ,
2139+ model_file = fileName ,
2140+ libraries = lmodel ,
2141+ variable_filter = variableFilter ,
2142+ build = build ,
2143+ )
2144+ self ._getconn = self ._session
2145+
2146+ def setCommandLineOptions (self , commandLineOptions : str ):
2147+ super ().set_command_line_options (command_line_option = commandLineOptions )
2148+
2149+ def setContinuous ( # type: ignore[override]
2150+ self ,
2151+ cvals : str | list [str ] | dict [str , Any ],
2152+ ) -> bool :
2153+ if isinstance (cvals , dict ):
2154+ return super ().setContinuous (** cvals )
2155+ raise ModelicaSystemError ("Only dict input supported for setContinuous()" )
2156+
2157+ def setParameters ( # type: ignore[override]
2158+ self ,
2159+ pvals : str | list [str ] | dict [str , Any ],
2160+ ) -> bool :
2161+ if isinstance (pvals , dict ):
2162+ return super ().setParameters (** pvals )
2163+ raise ModelicaSystemError ("Only dict input supported for setParameters()" )
2164+
2165+ def setOptimizationOptions ( # type: ignore[override]
2166+ self ,
2167+ optimizationOptions : str | list [str ] | dict [str , Any ],
2168+ ) -> bool :
2169+ if isinstance (optimizationOptions , dict ):
2170+ return super ().setOptimizationOptions (** optimizationOptions )
2171+ raise ModelicaSystemError ("Only dict input supported for setOptimizationOptions()" )
2172+
2173+ def setInputs ( # type: ignore[override]
2174+ self ,
2175+ name : str | list [str ] | dict [str , Any ],
2176+ ) -> bool :
2177+ if isinstance (name , dict ):
2178+ return super ().setInputs (** name )
2179+ raise ModelicaSystemError ("Only dict input supported for setInputs()" )
2180+
2181+ def setSimulationOptions ( # type: ignore[override]
2182+ self ,
2183+ simOptions : str | list [str ] | dict [str , Any ],
2184+ ) -> bool :
2185+ if isinstance (simOptions , dict ):
2186+ return super ().setSimulationOptions (** simOptions )
2187+ raise ModelicaSystemError ("Only dict input supported for setSimulationOptions()" )
2188+
2189+ def setLinearizationOptions ( # type: ignore[override]
2190+ self ,
2191+ linearizationOptions : str | list [str ] | dict [str , Any ],
2192+ ) -> bool :
2193+ if isinstance (linearizationOptions , dict ):
2194+ return super ().setLinearizationOptions (** linearizationOptions )
2195+ raise ModelicaSystemError ("Only dict input supported for setLinearizationOptions()" )
2196+
2197+ def getContinuous (
2198+ self ,
2199+ names : Optional [str | list [str ]] = None ,
2200+ ):
2201+ retval = super ().getContinuous (names = names )
2202+ if self ._simulated :
2203+ return retval
2204+
2205+ if isinstance (retval , dict ):
2206+ retval2 : dict = {}
2207+ for key , val in retval .items ():
2208+ if np .isnan (val ):
2209+ retval2 [key ] = None
2210+ else :
2211+ retval2 [key ] = str (val )
2212+ return retval2
2213+ if isinstance (retval , list ):
2214+ retval3 : list [str | None ] = []
2215+ for val in retval :
2216+ if np .isnan (val ):
2217+ retval3 .append (None )
2218+ else :
2219+ retval3 .append (str (val ))
2220+ return retval3
2221+
2222+ raise ModelExecutionException ("Invalid data!" )
2223+
2224+ def getOutputs (
2225+ self ,
2226+ names : Optional [str | list [str ]] = None ,
2227+ ):
2228+ retval = super ().getOutputs (names = names )
2229+ if self ._simulated :
2230+ return retval
2231+
2232+ if isinstance (retval , dict ):
2233+ retval2 : dict = {}
2234+ for key , val in retval .items ():
2235+ if np .isnan (val ):
2236+ retval2 [key ] = None
2237+ else :
2238+ retval2 [key ] = str (val )
2239+ return retval2
2240+ if isinstance (retval , list ):
2241+ retval3 : list [str | None ] = []
2242+ for val in retval :
2243+ if np .isnan (val ):
2244+ retval3 .append (None )
2245+ else :
2246+ retval3 .append (str (val ))
2247+ return retval3
2248+
2249+ raise ModelExecutionException ("Invalid data!" )
2250+
21192251
21202252class ModelicaDoEABC (metaclass = abc .ABCMeta ):
21212253 """
@@ -2687,3 +2819,50 @@ def _prepare_structure_parameters(
26872819 "pre-compiled binary of model." )
26882820
26892821 return {}
2822+
2823+
2824+ class ModelicaSystemCmd (ModelExecutionCmd ):
2825+ # TODO: docstring
2826+
2827+ def __init__ (
2828+ self ,
2829+ runpath : pathlib .Path ,
2830+ modelname : str ,
2831+ timeout : float = 10.0 ,
2832+ ) -> None :
2833+ super ().__init__ (
2834+ runpath = runpath ,
2835+ timeout = timeout ,
2836+ cmd_prefix = [],
2837+ model_name = modelname ,
2838+ )
2839+
2840+ def get_exe (self ) -> pathlib .Path :
2841+ """Get the path to the compiled model executable."""
2842+ # TODO: move to the top
2843+ import platform
2844+
2845+ path_run = pathlib .Path (self ._runpath )
2846+ if platform .system () == "Windows" :
2847+ path_exe = path_run / f"{ self ._model_name } .exe"
2848+ else :
2849+ path_exe = path_run / self ._model_name
2850+
2851+ if not path_exe .exists ():
2852+ raise ModelicaSystemError (f"Application file path not found: { path_exe } " )
2853+
2854+ return path_exe
2855+
2856+ def get_cmd (self ) -> list :
2857+ """Get a list with the path to the executable and all command line args.
2858+
2859+ This can later be used as an argument for subprocess.run().
2860+ """
2861+
2862+ cmdl = [self .get_exe ().as_posix ()] + self .get_cmd_args ()
2863+
2864+ return cmdl
2865+
2866+ def run (self ):
2867+ cmd_definition = self .definition ()
2868+ return cmd_definition .run ()
0 commit comments