Establishing connection to and disconnecting from the SIMULIA Co-Simulation Services Director

At the start of the coupled simulation, the client needs to establish connections with the SIMULIA Co-Simulation Services Director and the other clients participating in the coupled simulation. At the end of the coupled simulation or when an error occurs, the client should disconnect to end the coupled simulation properly.

This page discusses:

Establishing Connections

When establishing connections, each client connects to the SIMULIA Co-Simulation Services Director process in charge of the coupled simulation by specifying the host the SIMULIA Co-Simulation Services Director is running on and the port number used for the particular coupled simulation.

Use the SMACseConnect function to establish connections. The SMACseConnect function has the following arguments:

iCodeName
Name of your application.

It must correspond to one of the components in the Co-Simulation Configuration file.

iJobName
Analysis job name.

It must correspond to one of the component instances in the Co-Simulation Configuration file.

iWorkDir
Folder where the SIMULIA Co-Simulation Services writes the diagnostics.
iDirectorConnection
SIMULIA Co-Simulation Services Director process in charge of the coupled simulation.

The connection is specified as a host:port pair, where the host specifies the host name or IPV4/IPV6 TCP/IP address the SIMULIA Co-Simulation Services Director is running on, and the port is the listener port of the SIMULIA Co-Simulation Services Director.

iTimeout
Timeout period in seconds.

SMACseConnect returns a failure if the clients do not connect within the specified timeout period.

iStartTime
Set this argument to zero.
iUserPutFieldFunction
putField call-back function (see Transferring Field Data from the Client to the Co-Simulation Services).
iUserData
Your userData object.

This is an opaque pointer that is passed to the putField callback function to allow access to your client's data.

iUserMessageHandlerFunction
Message handler callback function (see Message Handler).

The SIMULIA Co-Simulation Services uses this function to raise any informational, warning, and error messages.

SMACseConnect returns with success if all participants in a coupled simulation have established the required communication channels within a specified timeout period.

In serial mode, call SMACseConnect on the root process; in parallel mode, call SMACseConnect on all compute ranks.

Disconnecting

When the end of the simulation is reached, or an error occurs, you should disconnect the client to inform the other clients that your application ended the coupled simulation.

You can provide a message to be sent to the other clients. The exception message can be communicated to the remote clients only if all connections are established. If a client should fail prior to establishing connections with the remote clients (for example, due to input file errors, client error, core dump, etc.), the message cannot be communicated.

Use the SMACseDisconnectExt function to end the coupled simulation. The SMACseDisconnectExt function takes the following argument:

iExceptionMessage
Constant character string containing an exception message, or NULL if no message should be sent.

In serial mode, call SMACseDisconnectExt on the root process; in parallel mode, call SMACseDisconnectExt collectively on all compute ranks. Only the message on the root process is conveyed by the SIMULIA Co-Simulation Services Director.

Example

The following example illustrates how to connect and disconnect the client:

// Co-Simulation Services header files
#include <SMACseApi.h>
#include <SMACseApiEnums.h>

int main(int argc, char** argv)
{
            :
   // Initialize the CSE API
   SMACseInitialize( NULL );

   // Connect to Co-Simulation Services
   const char* codeName = “myApplication”;
   const char* jobName = “myJob”;
   const char* workDir = “.//”;
   const char* CSSDirectorConn = “localhost:21000”;
   const int timeout = 300;
   double startTime = 0.0;
   void* userData = NULL;
             :
   SMACseConnectionStatus cStatus = SMACseConnect(codeName, jobName, workDir, 
           directorConnection, timeout, startTime,
           myPutField, userData, myMessageHandler);
   if (cStatus == SMACseConnectStatus_failure) {
       // You do not need to disconnect, since connection were never established.
       SMACseFinalize( );
       exit(1);
   }
           :

   // End of analysis; disconnect and finalize
   SMACseDisconnectExt("The coupled simulation completed successfully.");
   SMACseFinalize( );
            :
}