function [A,D,B,Qamb,Jvec] = computeRadiosity(s2sObj,emissivity,SBC,ambientT,ambientFactor,T)
% computeRadiosity - Internal function to assemble surface-to-surface radiation related matrices

% Copyright 2023 The MathWorks, Inc.

F = s2sObj.ViewFactors;
B = s2sObj.ElementsToNodesProjection;
Avg = s2sObj.NodesToElementProjection;

TfacetsAvg = Avg*T;
numFacets = size(F,1);
I = eye(numFacets);

A = F + (I-F)./emissivity.';
D = SBC* (I-F).*TfacetsAvg.'.^3*Avg;
Qamb = -(SBC*ambientFactor.*(I-diag(sum(F,2)))*(ambientT.^4)); % Ambient radiosity.

if nargout > 4
    % For transient solver and IC.
    E = SBC*(TfacetsAvg.^4);
    Jvec = A\((I-F)*E);
    Qamb = -B*(emissivity.*Qamb);
end
end