Yin-Yang Schwarz coupling
The 3-D shell is covered by two identical patches, Yin and Yang, each a latitude-longitude block of the sphere (see Yin-Yang grid for the geometry and the coordinate transforms). Each patch has its own Stokes matrix. MILEVA does not assemble one global matrix for the shell; it solves the two patches separately and couples them through their walls by an overlapping Schwarz iteration, the coupling used for Yin-Yang mantle convection by Kageyama and Sato (2004) and Tackley (2008).
One Schwarz round
multigrid_stokes(::MutableGrid3D, ETA, buoy, cfg; n_schwarz, buoy_yang) keeps a current solution n_schwarz rounds (default 5; the time loop uses the default). Each round:
Yang to Yin.
yy_compute_th_bcssamples Yang's current velocity at the positions Yin's -walls need and rotates the tangential components into Yin's local basis. The result is Dirichlet values for on Yin's wall faces and ghost values for and next to them.Solve Yin. Only the right-hand side depends on those values, so it is rebuilt with
assemble_stokes_3d(...; rhs_only = true)and Yin is solved with FGMRES and the multigrid preconditioner of Geometric multigrid. The matrix, its Galerkin hierarchy and the coarse factor are built once per call and reused by every round.Yin to Yang. The same is done for Yang, from the new Yin solution.
Measure. The Schwarz residual is the largest change of any Yin velocity component over the round, divided by the largest velocity, and is appended to
info.schwarz_residuals.
The Yin solution is returned as the primary field and Yang's in info.yang. Interpolation between patches is bilinear in _bilinear_sample_3d).

Schwarz residual per round for one Yin-Yang shell at docs/scripts/solvers_3d.jl.
On this grid the residual falls by nearly three orders of magnitude in the first three or four rounds, to
Which walls are coupled
On the multigrid path only the yy_compute_ph_bcs) would feed one wall from the other; it exists and is used by the single-level direct path.
Halo shift. Sampling the peer exactly at the ghost position does not contract: near the corners of the overlap that position lies on or next to the peer's own wall. yy_compute_th_bcs therefore samples the peer a fixed 30° of arc past the destination wall,

(A) The walls of both patches in global coordinates, from MILEVA's yy_yang_to_yin. Yin is the band of latitudes ±45° over longitudes ±135°; the Yang walls lie inside it, and the patches overlap between the two outlines. On the equator (circles) Yin's yy_yin_to_yang): the geometric ghost positions (grey) lie on the edge of Yang's patch, while the positions shifted by yy_compute_th_bcs, lie well inside it (blue). Script: docs/scripts/solvers_yinyang_schwarz_sections.jl.
Fixed round count
The Schwarz loop runs a fixed number of rounds with no tolerance test, and more rounds are not always better (figure above). The residuals are written to the log at the log cadence ([stokes 3-D] lines); check that they still fall at the last round before changing n_schwarz or the resolution.
Temperature
The energy equation is coupled the same way with fewer steps. In the time loop yy_compute_T_wall_bcs samples the peer temperature at each patch's cfg.nTSchwarz times per step (default 3), and yy_sync_T_walls! then overwrites each patch's wall-cell row with the peer value at that cell centre. See Energy equation.

Temperature at mid-depth along longitude 50°, where the patches overlap from 33° to 45° N (shaded where both have cell centres), after 60 explicit conduction steps (2.7 Gyr) on a shell with yy_compute_T_wall_bcs, cfg.nTSchwarz = 3, yy_sync_T_walls!) the difference falls to 6 K on this coarse grid. Script: docs/scripts/solvers_yinyang_schwarz_sections.jl.
Where in the code
| Topic | File | Function |
|---|---|---|
| Schwarz loop | solvers/multigrid_stokes.jl | multigrid_stokes(::MutableGrid3D, ...) |
| Wall values from the peer | utils/yy_interp.jl | yy_compute_th_bcs, yy_compute_ph_bcs, _bilinear_sample_3d |
| Vector rotation | utils/yy_interp.jl | yy_rotation_yin_to_yang, yy_rotation_yang_to_yin |
| Temperature coupling | utils/yy_interp.jl | yy_compute_T_wall_bcs, yy_sync_T_walls! |
| Two-rank version | solvers/multigrid_stokes_mpi.jl | multigrid_stokes_mpi! (see Parallel solvers) |
| Tests | tests/ | test_yy_rotation_vs_ks2004.jl, test_yinyang_phi_coupling_ab.jl, smoke_stokes_3d_mg.jl |
References
Kageyama, A. and Sato, T. (2004), "Yin-Yang grid": an overset grid in spherical geometry, Geochem. Geophys. Geosyst. 5, Q09005.
Tackley, P. J. (2008), Modelling compressible mantle convection with large viscosity contrasts in a three-dimensional spherical shell using the yin-yang grid, Phys. Earth Planet. Inter. 171, 7-18.