Control API

The control API is responsible for sequencing the coupled simulation, ensuring synchronization while advancing the coupled simulation.

This page discusses:

The control API should be called after defining the interface model.

The control API is embedded in a client in an opaque manner; that is, it is embedded in the client independent of how many clients are part of the coupled simulation and what numerical algorithms are employed (all of which is controlled through the SIMULIA Co-Simulation Services Director).

The control API can be split into two main tasks:

  • exchange of initial conditions at the start of the coupled simulation; and
  • solution advancement of the coupled simulation during the time integration loop.

Initial Conditions

Initial conditions need to be exchanged at the start of a coupled simulation. Use the SMACseInitialConditionsStart and SMACseInitialConditionsEnd functions to exchange initial conditions. Both functions take no arguments.

All fields that are exchanged must be defined using the initial condition category (Connection Groups). You must call both functions whether or not initial conditions are exchanged.

In general, SMACseInitialConditionsStart sends the client’s initial outgoing fields, and SMACseInitialConditionsEnd receives a remote client’s fields.

In some cases, a client might need the remote client’s initial fields to compute its initial conditions. In this case, you can use the <initCondSeqIsSendRecv> element in the Configuration file (see Component Instances) to reverse the send and receive operations. Only one of the clients can receive initial fields first.

When you embed the SIMULIA Co-Simulation Services in parallel mode, you must call these functions collectively on all compute ranks.

Example

The following example illustrates the exchange of initials conditions:

//
// After the initial fields have been computed by the application, exchange
// the initial fields at the start of the simulation.
//
if ( SMACseInitialConditionsStart(  ) == SMACseSolutionStatus_InitialConditionsReceived) {
   // May use SMACseGetField to retrieve fields from CSS.
};
                    :
if ( SMACseInitialConditionsEnd(  ) == SMACseSolutionStatus_InitalConditionsReceived) {
     // May use SMACseGetField to retrieve fields from CSS 
}

Solution Advancement

A coupled simulation consists of a series of coupling steps. The coupling step is the period between two consecutive exchanges, which directly influences the solution stability and accuracy.

The coupling step size can evolve during the simulation, taking into account a client’s solution stability and accuracy. A client can march in lockstep manner, or it can subcycle. In lockstep, the client’s increment size must be equal to the coupling step size that the SIMULIA Co-Simulation Services Director specifies. When subcycling, a client can take one or more increments per coupling step.

For every client's increment, whether or not a coupling step is reached, the client must call the following functions in the order listed below:

SMACseGetTargetTime
Synchronizes and establishes a new coupling step size if required.
SMACseNotifyStart
Notifies the SIMULIA Co-Simulation Services Director it is ready to begin an increment.
SMACseNotifyEnd
Notifies the SIMULIA Co-Simulation Services Director that it has completed an increment.

Optionally, implicit solvers can call the SMACseNotifyIteration function to enable implicit-iterative coupling.

Synchronizing and Establishing the Next Coupling Step Size

Use the SMACseGetTargetTime function to synchronize and establish the next coupling step size and target time. The SMACseGetTargetTime function takes the following arguments:

iIncrStartTime
Start time of the client's increment.
iClientDt
Client’s preferred time step size for the next increment.
oTargetTime
Target time for the current coupling step.

A new target time is computed when a coupling step is reached. Otherwise, the existing target time is returned while the client is subcycling.

oPreferredDt
Preferred time step size that the SIMULIA Co-Simulation Services Director suggests.

For most negotiation methods, oPreferredDt never exceeds the iClientDt value. However, it can be smaller than the iClientDt value when the remote client enforces a smaller coupling step size for a certain negotiation method or when the SIMULIA Co-Simulation Services Director smooths out increment sizes such that they are evenly distributed when the client is subcycling.

oLockstep
If the value is one, the client needs to use oPreferredDt for its increment size to march in lockstep. If the client cannot adhere to oPreferredDt, it must raise an error and end the simulation. The lockstep behavior is controlled through the Co-Simulation Configuration file (see Component Instances).
ioControls
Control flags array that specifies controls at the beginning of a coupling step to be enforced at the upcoming coupling step target time.

Set ioControls[0] to 1 to synchronize restart at the next coupling step. If ioControls[0] is 1 on return, write restart information at the upcoming target time. The ioControls argument is a vector..

The SMACseGetTargetTime function returns a solution status indicating whether the client has reached a target time, the client is subcycling, the co-simulation event is exceeded, or a system error occurred.

When you run in serial mode, SMACseGetTargetTime is called from the main process if the client is parallel. If you run in parallel mode, call SMACseGetTargetTime collectively on all ranks. In this case, make sure that iIncrStartTime and iClientDt agree on all compute ranks.

Notifying that the Client is Ready to Start Its Increment

Use the SMACseNotifyStart function to notify the SIMULIA Co-Simulation Services Director that the client is ready to start its next increment. This function is blocking at target time; the client's execution is blocked until all incoming fields are available for it to proceed to the next coupling step. The SMACseNotifyStart function takes no arguments.

The SMACseNotifyStart function returns a solution status indicating whether the client has reached a target time, the client is subcycling, the co-simulation event is exceeded, or a system error occurred.

In serial mode, you can use this flag to distribute incoming fields to all compute ranks if the application is parallel.

When you run in serial mode, you should call the SMACseNotifyStart function from the main process if the client is parallel. If you run in parallel mode, call SMACseNotifyStart on all compute ranks.

Notifying that the Client Completed Its Increment

Use the SMACseNotifyEnd function to notify the SIMULIA Co-Simulation Services Director that the client has completed the current increment. Most coupling algorithms do not receive fields at SMACseNotifyEnd; therefore, it is typically non-blocking.

The SMACseNotifyEnd function takes the following argument:

iIncrEndTime
Increment end time.

The SMACseNotifyEnd function returns a solution status indicating whether the client has reached a target time, the client is subcycling, the co-simulation event is exceeded, or a system error occurred.

When you run in serial mode, you should call SMACseNotifyEnd from the main process if the client is parallel. If you run in parallel mode, call SMACseNotifyEnd on all compute processes. In this case, the client must make sure that iIncrEndTime is the same on all compute ranks.

Notifying that the Client Completed an Implicit Coupling Iteration

Implicit-iterative coupling employs multiple exchanges at the coupling step target time until global convergence is achieved, before proceeding with the next coupling step.

Implicit-iterative coupling is relevant between implicit solvers only.

Call the SMACseNotifyIteration function when the client’s solution has converged. This function is blocking at target times; the execution is blocked until all incoming fields are updated to continue with additional coupling iterations. The SMACseNotifyIteration takes the following arguments:

iIncrEndTime
Increment end time.
iTerminateIteration
Set to 1 to end the coupling iteration before the exchange limit is reached or tolerances are achieved.

The SMACseNotifyIteration function returns a solution status indicating whether the client should perform further coupling iterations, whether to complete the time step, or a system error occurred.

The SMACseNotifyIteration function is called after the local convergence (the client’s convergence criteria) is achieved. If the return status indicates to perform further iterations, the incoming fields are corrected based on the latest outgoing fields. In this case, continue performing further iterations with the new incoming fields. If the return status is to complete the increment, finalize the increment and proceed to SMACseNotifyEnd to complete the coupling step.

There are several mechanisms to end the coupling iterations:

  • the simplest method is to specify the maximum exchanges in the Co-Simulation Configuration file;
  • any client can end the iteration by setting iTerminateIteration to 1; and
  • specify convergence tolerances in the Co-Simulation Configuration file when the advanced implicit-iterative coupling algorithm (see Interface Treatment for Implicit-Iterative Coupling is used. The maximum number of exchanges is still in effect.

When you run in serial mode, you should call SMACseNotifyIteration from the main process if the client is parallel. If you run in parallel mode, call SMACseNotifyIteration on all compute processes. In this case, the client must make sure that iIncrEndTime and iTerminateIteration are the same on all compute ranks.

Example

The following example illustrates the control API:

//
// Iteration or time step loop
//
while (SMACseGetTargetTime(t, dt, &targetTime, &dT, &lockstep, controlFlags) != == SMACseSolutionStatus_CosimulationEventExceeded)
{  
   // Notify CSE that you are ready to start an time step
   status = SMACseNotifyStart( );
   
// iteration loop
   do {
      // get field at end of increment
               :
      // Compute solution
               :     
    } while (SMACseNotifyIteration(t+dt,terminate) == SMACseSolutionStatus_DoFurtherIterations);
}