  We describe in this paper an optimal control strategy for shaping a
large-scale swarm of particles using boundary global actuation. This problem
arises as a key challenge in many swarm robotics applications, especially when
the robots are passive particles that need to be guided by external control
fields. The system is large-scale and underactuated, making the control
strategy at the microscopic particle level infeasible. We consider the
Kolmogorov forward equation associated to the stochastic process of the single
particle to encode the macroscopic behaviour of the particles swarm. The
control inputs shape the velocity field of the density dynamics according to
the physical model of the actuators. We find the optimal actuation considering
an optimal control problem whose state dynamics is governed by a linear
parabolic advection-diffusion equation where the control induces a transport
field. From a theoretical standpoint, we show the existence of a solution to
the resulting nonlinear optimal control problem. From a numerical standpoint,
we employ the discrete adjoint method to accurately compute the reduced
gradient and we show how it commutes with the optimize-then-discretize
approach. Finally, numerical simulations show the effectiveness of the control
strategy in driving the density sufficiently close to the target.
