function theta = adjointShapeMap(xinit,e,IDD,IDD1,IDD2,Ishape,shapeDisplacements,tau)

% theta = adjointShapeMap(xinit,e,IDD,IDD1,IDD2,Ishape,shapeDisplacements,tau)
%            applies gradient of the grid displacement, calculation of which
%            is based on a solution
%            to the 2d linear elasticity problem with inhomogeneous
%            Dirichlet b.c. that corresponds to shape displacement,
%            to a vector tau and the result is stored to theta.

global K;

beta = K\tau;

theta = adjointAssemble_el(xinit,e,IDD,IDD1,IDD2,Ishape,shapeDisplacements,beta);

for i=1:max(size(Ishape))
    theta(2*i-1) = theta(2*i-1) + tau(2*Ishape(i)-1);
    theta(2*i) = theta(2*i) + tau(2*Ishape(i));
    
%    gridDisplacements(:,Ishape(i)) = shapeDisplacements(:,i);
end
