Coupled Systems

Consider two coupled LorenzSystems. The first system evolves by

\[\begin{array}{l} \dot{x}_{1,1} = \sigma (x_{1,2} - x_{1,1}) + \epsilon (x_{2,1} - x_{1,1}) \\[0.25cm] \dot{x}_{1,2} = x_{1,1} (\rho - x_{1,3}) - x_{1,2} \\[0.25cm] \dot{x}_{1,3} = x_{1,1} x_{1,2} - \beta x_{1,3} \end{array}\]

and the second one evolves by

\[\begin{array}{l} \dot{x}_{2,1} = \sigma (x_{2,2} - x_{2,1}) + \epsilon (x_{1,1} - x_{2,1}) \\[0.25cm] \dot{x}_{2,2} = x_{2,1} (\rho - x_{2,3}) - x_{2,2} \\[0.25cm] \dot{x}_{2,3} = x_{2,1} x_{2,2} - \beta x_{2,3} \end{array}\]

where $x_1 = [x_{1,1}, x_{1,2}, x_{1,3}]$, $x_2 = [x_{2,1}, x_{2,2}, x_{2,3}]$ are the state vectors of the first and second system, respectively. The coupled system can be written more compactly as,

\[\begin{array}{l} \dot{X} = F(X) + \epsilon (A ⊗ P) X \end{array}\]

where $X = [x_{1}, x_{2}]$, $F(X) = [f(x_{1}), f(x_{2})]$,

\[ A = \begin{bmatrix} -1 & 1 \\ 1 & -1 \\ \end{bmatrix}\]
\[ P = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \\ \end{bmatrix}\]

and $f$ is the Lorenz dynamics given by

\[\begin{array}{l} \dot{x}_1 = \sigma (x_2 - x_1) \\[0.25cm] \dot{x}_2 = x_1 (\rho - x_3) - x_2 \\[0.25cm] \dot{x}_3 = x_1 x_2 - \beta x_3 \end{array}\]

The script below constructs and simulates the model

using Jusdl

# Construct the model
ε = 10.
model = Model(clock=Clock(0., 0.01, 100.))
addnode!(model, LorenzSystem(Inport(3), Outport(3)), label=:ds1)
addnode!(model, LorenzSystem(Inport(3), Outport(3)), label=:ds2)
addnode!(model, Coupler(ε * [-1 1; 1 -1], [1 0 0; 0 0 0; 0 0 0]), label=:coupler)
addnode!(model,  Writer(Inport(6)), label=:writer)
addbranch!(model, :ds1 => :coupler, 1:3 => 1:3)
addbranch!(model, :ds2 => :coupler, 1:3 => 4:6)
addbranch!(model, :coupler => :ds1, 1:3 => 1:3)
addbranch!(model, :coupler => :ds2, 4:6 => 1:3)
addbranch!(model, :ds1 => :writer, 1:3 => 1:3)
addbranch!(model, :ds2 => :writer, 1:3 => 4:6)
nothing # hide

To construct the model, we added ds1 and ds2 each of which has input ports of length 3 and output port of length 3. To couple them together, we constructed a coupler which has input port of length 6 and output port of length 6. The output port of ds1 is connected to the first 3 pins of coupler input port, and the output of ds2 is connected to last 3 pins of coupler input port. Then, the first 3 pins of coupler output is connected to the input port of ds1 and last 3 pins of coupler output is connected to the input port of ds2. The block diagram of the model is given below.

model

The the signal-flow graph of the model has 4 directed branches and each of these branches has 3 links.

It also worths pointing out that the model has two algebraic loops. The first loop consists of ds1 and coupler, and the second loop consists of ds2 and coupler. During the simulation these loops are broken automatically without requiring any user intervention.

The model is ready for simulation. The code block below simulates the model and plots the simulation data.

using Plots

# Simulate the model
simulate!(model, withbar=false)

# Read simulation data
t, x = read(getnode(model, :writer).component)

# Compute errors
err = x[:, 1] - x[:, 4]

# Plot the results.
p1 = plot(x[:, 1], x[:, 2], label="ds1")
p2 = plot(x[:, 4], x[:, 5], label="ds2")
p3 = plot(t, err, label="err")
plot(p1, p2, p3, layout=(3, 1))
[ Info: 2020-05-08T01:34:24.843 Started simulation...
[ Info: 2020-05-08T01:34:24.843 Inspecting model...
┌ Info: 	The model has algrebraic loops:[[1, 3], [3, 2]]
└ 		Trying to break these loops...
[ Info: 	Loop [1, 3] is broken
[ Info: 	Loop [2, 3] is broken
[ Info: 2020-05-08T01:34:25.111 Done.
[ Info: 2020-05-08T01:34:25.111 Initializing the model...
[ Info: 2020-05-08T01:34:26.278 Done...
[ Info: 2020-05-08T01:34:26.278 Running the simulation...
[ Info: 2020-05-08T01:34:28.264 Done...
[ Info: 2020-05-08T01:34:28.264 Terminating the simulation...
[ Info: 2020-05-08T01:34:28.28 Done.