/ proof-of-concept / plate-mechanics-sim
Sign in
proof-of-concept / plate-mechanics-sim
plate-mechanics-sim / packages / core / src / m / plate_pad.m
36 lines · 1.3 KBBlameHistoryRaw
1function wp = plate_pad(w, bc)
2% PLATE_PAD Extend a displacement field by one ghost layer according to the edge condition.
3%
4% wp = plate_pad(w, bc) returns the (ny+2) x (nx+2) array whose interior is w.
5% Along each edge w = 0 is imposed on the edge nodes themselves; the ghost
6% values encode the second condition:
7%
8% 'simply-supported' w = 0 and w_nn = 0 -> ghost = -(first interior value)
9% (odd reflection: the Laplacian vanishes on the edge)
10% 'clamped' w = 0 and w_n = 0 -> ghost = +(first interior value)
11% (even reflection: zero slope on the edge)
13% Finite-difference stencils evaluated on wp are then valid at every node of
14% the original grid, including the edges.
16[ny, nx] = size(w);
17wp = zeros(ny + 2, nx + 2);
18wp(2:ny + 1, 2:nx + 1) = w;
19switch bc
20 case 'simply-supported'
21 sgn = -1;
22 case 'clamped'
23 sgn = 1;
24 otherwise
25 error('plate_pad: unknown boundary condition "%s"', bc);
26end
27wp(1, 2:nx + 1) = sgn * w(2, :);
28wp(ny + 2, 2:nx + 1) = sgn * w(ny - 1, :);
29wp(2:ny + 1, 1) = sgn * w(:, 2);
30wp(2:ny + 1, nx + 2) = sgn * w(:, nx - 1);
31% Corner ghosts: reflect twice (sgn^2 = 1 for both conditions)
32wp(1, 1) = w(2, 2);
33wp(1, nx + 2) = w(2, nx - 1);
34wp(ny + 2, 1) = w(ny - 1, 2);
35wp(ny + 2, nx + 2) = w(ny - 1, nx - 1);
36end
↑↓ move↵openescclose