function [localX, localV] = padLocalGrid(X, V, padSz)
%PADLOCALGRID adds padding to local parts of distributed arrays.  The
%"padding" is actually grid points and their corresponding values from
%adjacent workers.
%   X and V are arrays distributed with the same distribution scheme.  X is
%   a cell array of column vectors, but V can be of any dimensionality.

%   Copyright 2021-2022 The MathWorks, Inc.

codistributed.pVerifyUsing1d('padLocalGrid', V);
codV = getCodistributor(V);
distDimV = codV.Dimension;
localX = getLocalPart(X{distDimV});

if max(padSz) == 0
    return
elseif isscalar(padSz)
    padSz = [padSz padSz];
end

[localV, ~, localX] = stencilCommPad(V, padSz, localX);
end
