function F = addCurlComponent(pde,p,t,coefstruct,u0,edgeElem,numEdges)
% utility to compute curl of the source term

% Copyright 2022 The MathWorks, Inc.
narginchk(5,7);
[coefstruct.Coefficients.f,coefstruct.Coefficients.fc] = ...
    deal(coefstruct.Coefficients.fc,coefstruct.Coefficients.f);
coefstruct.ComputeCurlSource = true;
if pde.IsTwoD
    pde.PDESystemSize = 2;
    curlF = assembleSelectedFEMatrices(pde,p,t,coefstruct,[u0;u0],0,'F',false);
    pde.PDESystemSize = 1;
else
    pde.PDESystemSize = 3;
    curlF = formGlobalMatrix(pde,p,t,coefstruct,u0,[],'f',edgeElem,numEdges);
    pde.PDESystemSize = 1;
end
F = curlF.F;
% undo coefstruct changes
[coefstruct.Coefficients.f,coefstruct.Coefficients.fc] = ...
    deal(coefstruct.Coefficients.fc,coefstruct.Coefficients.f);
coefstruct = rmfield(coefstruct,"ComputeCurlSource"); %#ok (resetting coefstruct to regular state)
end