function wp = plate_pad(w, bc) % PLATE_PAD Extend a displacement field by one ghost layer according to the edge condition. % % wp = plate_pad(w, bc) returns the (ny+2) x (nx+2) array whose interior is w. % Along each edge w = 0 is imposed on the edge nodes themselves; the ghost % values encode the second condition: % % 'simply-supported' w = 0 and w_nn = 0 -> ghost = -(first interior value) % (odd reflection: the Laplacian vanishes on the edge) % 'clamped' w = 0 and w_n = 0 -> ghost = +(first interior value) % (even reflection: zero slope on the edge) % % Finite-difference stencils evaluated on wp are then valid at every node of % the original grid, including the edges. [ny, nx] = size(w); wp = zeros(ny + 2, nx + 2); wp(2:ny + 1, 2:nx + 1) = w; switch bc case 'simply-supported' sgn = -1; case 'clamped' sgn = 1; otherwise error('plate_pad: unknown boundary condition "%s"', bc); end wp(1, 2:nx + 1) = sgn * w(2, :); wp(ny + 2, 2:nx + 1) = sgn * w(ny - 1, :); wp(2:ny + 1, 1) = sgn * w(:, 2); wp(2:ny + 1, nx + 2) = sgn * w(:, nx - 1); % Corner ghosts: reflect twice (sgn^2 = 1 for both conditions) wp(1, 1) = w(2, 2); wp(1, nx + 2) = w(2, nx - 1); wp(ny + 2, 1) = w(ny - 1, 2); wp(ny + 2, nx + 2) = w(ny - 1, nx - 1); end