Class Simulator

    • Field Detail

      • programArguments

        public Parameter programArguments
        Arguments of program that starts the simulation.
      • programName

        public FileParameter programName
        Name of program that starts the simulation.
      • socketPortNumber

        public Parameter socketPortNumber
        Port number for BSD socket (used if non-negative).
      • simulationLogFile

        public FileParameter simulationLogFile
        File name to which this actor writes the simulation log.
      • socketConfigurationFile

        public FileParameter socketConfigurationFile
        File name to which this actor writes the socket configuration.
      • socketTimeout

        public Parameter socketTimeout
        Socket time out in milliseconds.
      • workingDirectory

        public FileParameter workingDirectory
        Working directory of the simulation.
      • showConsoleWindow

        public Parameter showConsoleWindow
        If true (the default), a window will be created that shows the console output.
      • synchronizeWithClient

        public Parameter synchronizeWithClient
        If true, attempts to sychronize timing with the client.
      • dblWri

        protected double[] dblWri
        Double values that were written to the socket.
      • cliPro

        protected ClientProcess cliPro
        Thread that runs the simulation.
      • porNo

        protected int porNo
        Port number that is actually used for BSD socket.
      • server

        protected Server server
        Server used for data exchange.
      • worDir

        protected java.lang.String worDir
        Working directory of the subprocess.
      • flagWri

        protected int flagWri
        Simulation flag to be written in socket.
      • simTimPre

        protected double simTimPre
        Ptolemy's time at the last call of the fire method. Only used by the legacy firing method.
      • simTimReaPre

        protected double simTimReaPre
        Time read from the simulation program at the last call of the fire method. Only used by the legacy firing method.
      • outTokStale

        protected boolean outTokStale
      • clientTerminated

        protected boolean clientTerminated
        Flag, set to true when the clients terminates the communication.
      • warWin

        protected java.lang.Thread warWin
        Thread that is used if a warning window need to be shown.
      • terminationMessage

        protected java.lang.String terminationMessage
        Message that will be displayed in the warning window when the client terminated, but Ptolemy continues with the simulation.
      • isHeadless

        protected boolean isHeadless
        Flag, set the true if Ptolemy is run without any graphical interface. If isHeadless=true, this actor will not open any windows for reporting outputs or warnings.
      • firstFire

        protected boolean firstFire
        Flag that is true during the first firing of this actor/.
      • LS

        protected static final java.lang.String LS
        System dependent line separator.
      • tokTim

        protected Time tokTim
        Time of token that will be written to the client. This is equal to the Ptolemy time minus one time step, because at time t_k, a client gets the output of other clients at t_{k-1}, which allows the client to compute the states and outputs at t_k
      • simTimAbsTol

        protected double simTimAbsTol
        Absolute floating-point tolerance for events assumed to be simultaneous.
    • Method Detail

      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone the actor into the specified workspace. This calls the base class and then sets the init and step public members to the parameters of the new actor.
        Overrides:
        clone in class TypedAtomicActor
        Parameters:
        workspace - The workspace for the new object.
        Returns:
        A new actor.
        Throws:
        java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)
      • fireAndSanityCheck

        public void fireAndSanityCheck()
                                throws IllegalActionException
        The legacy firing behavior. Checks that the client and the simulator are synchronized. Maintained only for backwards-compatibility.
        Throws:
        IllegalActionException - If thrown while checking the input for a token, reading or writing to the server, getting the input or if there are problems with the time.
      • fireAndSynchronize

        public void fireAndSynchronize()
                                throws IllegalActionException
        The new firing behavior. Attempts to synchronize the simulator's timing with that of the client.
        Throws:
        IllegalActionException - If thrown while checking the input for a token, reading or writing to the server, getting the input or if there are problems with the time.
      • _outputInitToken

        protected void _outputInitToken()
                                 throws IllegalActionException
        Output the first token during initialize.
        Throws:
        IllegalActionException - If there the client flag is non-zero, or the double array returned by the server is null.
      • _writeToServer

        protected void _writeToServer()
                               throws IllegalActionException
        Write the data to the server instance, which will send it to the client program.
        Throws:
        IllegalActionException - If there was an error when writing to the server.
      • _readFromServer

        protected void _readFromServer()
                                throws IllegalActionException
        Read the data from the server instance, which will read it from the client program.
        Throws:
        IllegalActionException - If there was an error when reading from the server.
      • resolveCommandName

        public static java.lang.String resolveCommandName​(java.io.File programName)
                                                   throws IllegalActionException
        Resolve the command string. This method replaces $CLASSPATH, relative file names and adds .exe to the command (under Windows)
        Parameters:
        programName - Name of program that starts the simulation.
        Returns:
        The command line string.
        Throws:
        IllegalActionException - If the simulation process arguments are invalid.
      • resolveDirectory

        public static java.lang.String resolveDirectory​(NamedObj namedObj,
                                                        java.lang.String dir)
                                                 throws IllegalActionException
        Resolve the working string. This method adds the path of the MoML file to its argument if the argument is a relative directory.
        Parameters:
        namedObj - A named object, typically the container of the model
        dir - The directory to be resolved.
        Returns:
        The resolved working string.
        Throws:
        IllegalActionException - If an attribute is found with the name "_uri" that is not an instance of the URIAttribute class
      • cutQuotationMarks

        public static java.lang.String cutQuotationMarks​(java.lang.String str)
        Cut the leading and terminating quotation marks if present.
        Parameters:
        str - The string.
        Returns:
        The string with leading and terminating quotation marks removed if present
      • _getDoubleArray

        protected double[] _getDoubleArray​(Token t)
                                    throws IllegalActionException
        Get a double array from the Token.
        Parameters:
        t - the token which must be a type that can be converted to an ArrayToken
        Returns:
        the double[] array with the elements of the Token
        Throws:
        IllegalActionException - If the base class throws it.