> ## 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 should be traversed. 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.

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

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

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

As described in the introduction, co-simulation and mapping workflows can be combined. To perform mapping while doing the coupled analysis, an additional step, *mapping setup*, is required prior to *heavyweight data access and initialization* step. See details of the mapping setup step in [Steps to perform mapping](https://developer.synopsys.com/docs/system-coupling/system-coupling-python-library/md_04_ParticipantStepsForMapping.md). Mapping will be performed during inputs update step, inside the coupled analysis loop.

### 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-python-library/md_09_ParallelExecution.md) for more details.

#### C++

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

...

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

#### C

```python 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

```python 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-python-library/md_11_HeavyweightDataAccess.md) and [Creating restart points and restarting a coupled analysis](https://developer.synopsys.com/docs/system-coupling/system-coupling-python-library/md_13_Restarts.md) for more details.

#### C++

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

#### C

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

#### Fortran

```python 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-python-library/md_10_ParameterDataAccess.md) for more details.

#### C++

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

#### C

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

#### Fortran

```python 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 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++

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

##### C

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

##### Fortran

```python 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++

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

##### C

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

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

##### Fortran

```python 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++

```python 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++

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

#### C

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

#### Fortran

```python theme={null}
type(SyscErrorF) :: ret
ret = syscdisconnectf()
```

#### Python

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