%***********************************************************************
%  function ModifiedMasterStiffForDBC
%
%  Modify the global stiffness matrix to impose displacement BCs
%***********************************************************************

function K = ModifiedMasterStiffForDBC(pdof, K)

nk = length(K);      % problem size
np = length(pdof);   % number of prescribed displacement BCs

for k = 1:np
    constr_dof = pdof(k);
    
    K(:,constr_dof) = zeros(nk,1);  % zero stiffness column
    K(constr_dof,:) = zeros(1,nk);  % zero stiffness row
    K(constr_dof,constr_dof) = 1;   % set diagonal to 1.0
end

% Test code and output:
%
% K = rand(6)
%
% K =
%    0.9501    0.4565    0.9218    0.4103    0.1389    0.0153
%    0.2311    0.0185    0.7382    0.8936    0.2028    0.7468
%    0.6068    0.8214    0.1763    0.0579    0.1987    0.4451
%    0.4860    0.4447    0.4057    0.3529    0.6038    0.9318
%    0.8913    0.6154    0.9355    0.8132    0.2722    0.4660
%    0.7621    0.7919    0.9169    0.0099    0.1988    0.4186
%
% K = ModifiedMasterStiffForDBC( [1,2,4], K)
%
% K =
%    1.0000         0         0         0         0         0
%         0    1.0000         0         0         0         0
%         0         0    0.1763         0    0.1987    0.4451
%         0         0         0    1.0000         0         0
%         0         0    0.9355         0    0.2722    0.4660
%         0         0    0.9169         0    0.1988    0.4186
