> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Participant steps in a coupled analysis

During a coupled analysis, a specific sequence of steps must be traversed by the participant.

This process is depicted in Figure 1 for a steady analysis, Figure 2 for a transient
analysis with iterations (implicit time integration), and Figure 3 for transient analysis
without iterations (explicit time integration). Each step is described in more detail below.

It is important that these steps are traversed in this exact sequence as shown below.

## Flowchart diagrams for participant steps in a coupled analysis

### Participant steps in a mapping coupled analysis

This sequence of steps is required for a participant which is doing a mapping analysis.
Note that in comparison with the other analyses described below, a participant which has
an analysis type of mapping does not call `updateInputs()` or `updateOutputs()`. The data
are mapped to/from the participant during `initializeAnalysis()` and may not be changed after
this time. It must traverse this sequence of steps.

![Figure 1: Sequence of participant steps for a mapping analysis](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/system-coupling/system-coupling-participant-library/images/ParticipantStepsInCoupledAnalysisFigure1.png?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=05f57d2aa593f02e66b1b537ebe5ba23)\
*Figure 1: Sequence of participant steps for a mapping analysis*

### Participant steps in a steady coupled analysis

This sequence of steps is required for the participant which is doing a steady analysis.
Note that the coupled analysis type may or may not be steady. The important part is that
if this participant is steady, it must traverse this sequence of steps.

![Figure 2: Sequence of participant steps for a steady analysis](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/system-coupling/system-coupling-participant-library/images/ParticipantStepsInCoupledAnalysisFigure2.png?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=85bb4feb117981b8a3cac9125a1c655a)\
*Figure 2: Sequence of participant steps for a steady analysis*

### Participant steps in a transient coupled analysis with iterations

This sequence of steps is required for the participant which is doing a transient (unsteady)
analysis and performs implicit time integration. As shown on the diagram, this participant
must be able to redo the same coupling time step multiple times. In other words,
this participant must be able to iterate until all convergence criteria are met
(when all convergence criteria are met, the participant will not be asked to
perform another coupling iteration). The inputs provided to this participant
will correspond to the time value at the end of the current coupling time step. Likewise,
this participant should produce outputs that correspond to the time
value at the end of the current coupling time step.

![Figure 3: Sequence of participant steps for a transient analysis with iterations](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/system-coupling/system-coupling-participant-library/images/ParticipantStepsInCoupledAnalysisFigure3.png?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=87c6110b7a40de429fa874f6e725cd94)\
*Figure 3: Sequence of participant steps for a transient analysis with iterations*

### Participant steps in a transient coupled analysis without iterations

This sequence of steps is required for the participant which is doing a transient (unsteady)
analysis and performs explicit time integration. The explicit participants do not iterate
within the coupling time step. The inputs provided to this participants will correspond
to the time value at the beginning of the current coupling time step, and after solving,
the participant should produce outputs that correspond to the time value at the
end of the current coupling time step.

![Figure 4: Sequence of participant steps for a transient analysis without iterations](https://mintcdn.com/synopsys-00a47cbc/Srh1_f--TdKCLyqD/docs/system-coupling/system-coupling-participant-library/images/ParticipantStepsInCoupledAnalysisFigure4.png?fit=max\&auto=format\&n=Srh1_f--TdKCLyqD\&q=85\&s=dd9f8fd24d1ea88f8c73bad7afc87efa)\
*Figure 4: Sequence of participant steps for a transient analysis without iterations*

## Connect to System Coupling

The connection is established by providing the host name, port number, participant name,
and build information.

If running in parallel using a supported MPI distribution, MPI communicator should
also be provided. See
[Execution in a parallel environment](https://developer.synopsys.com/docs/system-coupling/system-coupling-participant-library/user-guide/parallel-execution.md)
for more details.

### C++

```cpp theme={null}
std::string host, name, buildInfo;
unsigned short port;

...

sysc::SystemCoupling sc(host, port, name, buildInfo);
```

### C

```c theme={null}
char host[STRING_MAX_SIZE];
unsigned short port;
char name[STRING_MAX_SIZE];
char buildInfo[STRING_MAX_SIZE];

...

SyscError ret = syscConnect(host, port, name, buildInfo);
```

### Fortran

```fortran-free-form theme={null}
character(len=256) :: host
integer :: scPort = 0
character(len=256) :: name
character(len=256) :: buildInfo

...

ret = syscConnectF(scHost, scPort, scName, buildInfo)
```

### Python

```python theme={null}
import pyExt.SystemCouplingParticipant as sysc

host = str()
port = int()
name = str()
buildInfo = str()

...

sc = sysc.SystemCoupling(host, port, name, buildInfo)
```

## Register heavyweight data access

Register access to the participant's mesh and variable values.
Register any other callback functions (for example a callback for creating a restart point).
In the examples below, `getSurfaceMesh`, `getInputScalarData`, and
`createRestartPoint` are functions that conform to provided prototypes that
are to be implemented in the participant solver. See
[Access to heavyweight data](https://developer.synopsys.com/docs/system-coupling/system-coupling-participant-library/user-guide/heavyweight-data-access.md) and
[Creating restart points and restarting a coupled analysis](https://developer.synopsys.com/docs/system-coupling/system-coupling-participant-library/user-guide/restarts.md)
for more details.

### C++

```cpp theme={null}
sc.registerSurfaceMeshAccess(&getSurfaceMesh);
sc.registerInputScalarDataAccess(&getInputScalarData);
sc.registerRestartPointCreation(&createRestartPoint);
```

### C

```c theme={null}
SyscError ret;
ret = syscRegisterSurfMeshAccess(&getSurfaceMesh);
ret = syscRegisterInputScalarDataAccess(&getInputScalarData);
ret = syscRegisterRestartPointCreation(&createRestartPoint);
```

### Fortran

```fortran-free-form theme={null}
type(SyscErrorF) :: ret
ret = syscRegisterSurfMeshAccessF(getSurfaceMesh)
ret = syscRegisterInputScalarDataAccessF(getInputScalarData)
ret = syscRegisterRestartPointCreationF(createRestartPoint)
```

### Python

```python theme={null}
sc.registerSurfaceMeshAccess(getSurfaceMesh)
sc.registerInputScalarDataAccess(getInputScalarData)
sc.registerRestartPointCreation(createRestartPoint)
```

## Initialize the coupled analysis

Notify System Coupling that the analysis can be initialized. Note that if parameters
are used, initial values for output parameters should be set prior to initializing
the analysis. If no initial value is set, the parameter will be initialized to zero. See [Parameter Data Access](https://developer.synopsys.com/docs/system-coupling/system-coupling-participant-library/user-guide/parameter-data-access.md) for more details.

### C++

```cpp theme={null}
// set initial values for any output parameter
sc.setParameterValue(inputParameterName, 12.3);
sc.initializeAnalysis();
```

### C

```c theme={null}
// set initial values for any output parameter
SyscError ret = syscSetParameterValue(inputParameterName, 12.3);
ret = syscInitializeAnalysis();
```

### Fortran

```fortran-free-form theme={null}
type(SyscErrorF) :: ret
ret = syscInitializeAnalysisF()
```

### Python

```python theme={null}
# set initial values for any output parameter
sc.setParameterValue(inputParameterName, 12.3)
sc.initializeAnalysis()
```

## Coupled analysis loop

Enter a coupled analysis loop until the analysis is complete.
This step is different, depending on whether the analysis
is steady or transient.

* For mapping analysis, there is no **coupling time step loop** or **coupling iteration loop**.
  The participant should not enter the coupling time step or iteration loops. Note that calling
  either **Update Inputs** or **Update Outputs** in a mapping participant will throw an error.

* For steady analysis, there is the **coupling iteration loop**.
  The participant should enter the coupling iteration loop
  and exit it only when there are no more coupling iterations
  to be done.

* For transient analysis, there are either one or two nested loops,
  depending on whether the participant uses implicit or explicit
  time integration.
  * The outer loop is the **coupling time step loop**.
    The participant should enter the coupling time step loop
    and exit it only when there are no more coupling time steps
    to be done.

  * The inner loop is the **coupling iteration loop**.
    The participant should enter the coupling iteration loop
    and exit it only when there are no more coupling iterations
    to be done within the current coupling time step. This loop
    is required for implicit time integration but is unnecessary
    if the time integration is explicit.

Inside the coupling iteration loop, the participant
should iteratively update inputs, perform its
solver iterations, and then update outputs. These operations
need only be performed once per time step if the participant is explicit.

* **Update Inputs**. Notify System Coupling that inputs can be updated.
  After inputs update, the inputs are up-to-date for the
  current iteration. The participant solver can perform
  its solver iterations after inputs update.

* **Update Outputs**. Notify System Coupling that outputs are updated and provide solver
  convergence status. Before outputs update, the
  participant must update all output data so that it can be
  consumed by System Coupling.

### Steady analysis loop

#### C++

```cpp theme={null}
while (sc.doIteration()) {
  sc.updateInputs();
  // ... solve here ...
  sc.updateOutputs(sysc::Converged);
}
```

#### C

```c theme={null}
SyscError ret;
...
while (syscDoIteration() == 1) {
  ret = syscUpdateInputs();
  /* ... solve here ... */
  ret = sysc.updateOutputs(SyscConverged);
}
```

#### Fortran

```fortran-free-form theme={null}
type(SyscErrorF) :: ret
do while (syscDoIterationF())
  ret = syscUpdateInputsF()
  ! ... solve here ...
  ret = syscUpdateOutputsF(SyscConverged)
end do
```

#### Python

```python theme={null}
while sc.doIteration():
  sc.updateInputs()
  # ... solve here ...
  sc.updateOutputs(sysc.Converged)
```

### Transient analysis loop with inner iterations (implicit time integration)

#### C++

```cpp theme={null}
while (sc.doTimeStep()) {
  while (sc.doIteration()) {
    sc.updateInputs();
    // ... solve here ...
    sc.updateOutputs(sysc::Converged);
  }
}
```

#### C

```c theme={null}
SyscError ret;
...

while (syscDoTimeStep() == 1) {
  while (syscDoIteration() == 1) {
    ret = syscUpdateInputs();
    /* ... solve here ... */
    ret = sysc.updateOutputs(SyscConverged);
  }
}
```

#### Fortran

```fortran-free-form theme={null}
type(SyscErrorF) :: ret
do while (syscDoTimeStepF())
  do while (syscDoIterationF())
    ret = syscUpdateInputsF()
    ! ... solve here ...
    ret = syscUpdateOutputsF(SyscConverged)
  end do
end do
```

#### Python

```python theme={null}
while sc.doTimeStep():
  while sc.doIteration():
    sc.updateInputs()
    # ... solve here ...
    sc.updateOutputs(sysc.Converged)
```

### Transient analysis loop without iterations (explicit time integration)

#### C++

```cpp theme={null}
while (sc.doTimeStep()) {
  sc.updateInputs();
  // ... solve here ...
  sc.updateOutputs(sysc::Converged);
}
```

## Shutdown the coupled analysis

This step is reached after exiting from coupled analysis loop. System Coupling will be disconnected. The solver should proceed to an orderly shutdown after this step.

### C++

```cpp theme={null}
sc.disconnect();
```

### C

```c theme={null}
SyscError ret = syscDisconnect();
```

### Fortran

```fortran-free-form theme={null}
type(SyscErrorF) :: ret
ret = syscDisconnectF()
```

### Python

```python theme={null}
sc.disconnect()
```
