## 6.2. Description

In the BCVTB, data is exchanged between the different clients using a fixed synchronization time step. There is no iteration between the clients. In the co-simulation literature, this coupling scheme is referred to as quasi-dynamic coupling, loose coupling or ping-pong coupling. See [Hensen (1999)] and [Zhai and Chen (2005)] for details. The algorithm for exchanging data between clients is as follows: Suppose we have a system with two clients, where each client solves an initial value ordinary differential equation that is coupled to the ordinary differential equation of the other client. Let $N\in \mathbb{N}$ denote the number of time steps and let $k\in \left\{0,\dots ,N\right\}$ denote the time steps. For some ${n}_{1},{n}_{2}\in ℕ$, let ${f}_{1}\phantom{\rule{0.167em}{0ex}}:\phantom{\rule{0.167em}{0ex}}{\Re }^{{n}_{1}}×{\Re }^{{n}_{2}}\to {\Re }^{{n}_{1}}$ and ${f}_{2}\phantom{\rule{0.167em}{0ex}}:\phantom{\rule{0.167em}{0ex}}{\Re }^{{n}_{2}}×{\Re }^{{n}_{1}}\to {\Re }^{{n}_{2}}$ denote the functions that compute the next value of the state variables in simulator 1 and 2. Note that these functions are defined by the sequence of code instructions executed in the respective simulator. The simulator 1 computes, for $k\in \left\{0,\dots ,N-1\right\}$, the sequence

$\phantom{\rule{1.00em}{0ex}}{x}_{1}\left(k+1\right)={f}_{1}\left({x}_{1}\left(k\right),\phantom{\rule{0.167em}{0ex}}{x}_{2}\left(k\right)\right),$,

and, similarly, the simulator 2 computes the sequence

$\phantom{\rule{1.00em}{0ex}}{x}_{2}\left(k+1\right)={f}_{2}\left({x}_{2}\left(k\right),\phantom{\rule{0.167em}{0ex}}{x}_{1}\left(k\right)\right),$

with initial conditions ${x}_{1}\left(0\right)={x}_{1,0}$ and ${x}_{2}\left(0\right)={x}_{2,0}$. An implementation difficulty is presented by the situation that ${f}_{1}\left(\cdot ,\cdot \right)$ and ${f}_{2}\left(\cdot ,\cdot \right)$ need to know the initial value of the other simulator. Thus, at $\mathrm{k=0}$, both simulators exchange their initial value ${x}_{1,0}$ and ${x}_{2,0}$. To advance from time $k$ to $\mathrm{k+1}$, each simulator uses its own time integration algorithm. At the end of the time step, the simulator 1 sends the new state ${x}_{1}\mathrm{\left(k+1\right)}$ to the BCVTB and it receives the state ${x}_{2}\mathrm{\left(k+1\right)}$ from the BCVTB. The same procedure is done by the simulator 2. The BCVTB synchronizes the data in such a way that it does not matter which of the two simulators is called first.

In terms of numerical methods for ordinary differential equations, this scheme is identical to an explicit Euler integration, which is an integration algorithm for a differential equation

$\phantom{\rule{1.00em}{0ex}}\stackrel{˙}{x}=h\left(x\right),x\left(0\right)={x}_{0},$

where $h\phantom{\rule{0.167em}{0ex}}:\phantom{\rule{0.167em}{0ex}}{\Re }^{n}\to {\Re }^{n}$ for some $n\in ℕ$. On the time interval $t\in \left[0,\phantom{\rule{0.167em}{0ex}}1\right]$, the explicit Euler integration algorithm leads to the following sequence:

 Step 0: Initialize counter $\mathrm{k = 0}$ and number of steps $n\in ℕ$. Set initial state ${\mathrm{x\left(k\right)=x}}_{0}$ and set time step $\mathrm{\Delta t = 1/N}$. Step 1: Compute new state $\mathrm{x\left(k+1\right) = x\left(k\right) +}h\mathrm{\left(x\left(k\right)\right) \Delta t}$. Replace $k$ by $\mathrm{k+1}$. Step 2: If $\mathrm{k=N}$ stop, else go to Step 1.

In the situation where the differential equation is integrated over time using co-simulation, the above algorithm becomes:

 Step 0: Initialize counter $\mathrm{k = 0}$ and number of steps $n\in ℕ$ Set initial states ${x}_{1}\mathrm{\left(k\right)=}{x}_{1,0}$ and ${x}_{2}\mathrm{\left(k\right)=}{x}_{2,0}$. Set time step $\mathrm{\Delta t = 1/N}$. Step 1: Compute new states $\phantom{\rule{1.00em}{0ex}}{x}_{1}\left(k+1\right)={x}_{1}\left(k\right)+{f}_{1}\left({x}_{1}\left(k\right),\phantom{\rule{0.167em}{0ex}}{x}_{2}\left(k\right)\right)\phantom{\rule{0.167em}{0ex}}\Delta t$, and $\phantom{\rule{1.00em}{0ex}}{x}_{2}\left(k+1\right)={x}_{2}\left(k\right)+{f}_{2}\left({x}_{2}\left(k\right),\phantom{\rule{0.167em}{0ex}}{x}_{1}\left(k\right)\right)\phantom{\rule{0.167em}{0ex}}\Delta t$. Replace $k$ by $\mathrm{k+1}$. Step 2: If $\mathrm{k=N}$ stop, else go to Step 1.

This algorithm is implemented in the BCVTB. It does not require an iteration between the two simulators.

We note that other data synchronizations may be possible. For example, in strong coupling, within each time step, simulators exchange data until a convergence criteria is satisfied. This implementation requires the numerical solution of a nonlinear system of equations in which the termination criteria is a function of the state variables of the coupled simulators. However, many building simulation programs contain solvers that compute with relatively coarse precision. This can introduce significant numerical noise which may cause convergence problems for the co-simulation. The computing time of strong coupling vs. loose coupling of EnergyPlus and TRNSYS was compared by [Trcka et al. (2007)]. Although loose coupling required shorter synchronization time steps, the work per time step was smaller (as no iterations were needed) which caused loose coupling to compute faster than strong coupling. An additional implementation benefit of loose coupling is that state variables need not be reset to previous values. Thus, loose coupling is easier to implement, is numerically more robust and it computed faster in the experiments reported by [Trcka et al. (2007)].