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