You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

59 lines
1.9 KiB

%--------------------------
% @Author: Jingqiao Hu
% @Date: 2021-08-25 20:20:38
% @LastEditTime: 2021-09-28 12:25:56
%--------------------------
function [regulated_matrix, dFdx] = precomputation_mmc(nele_macro, microx, rho, bezier_B, ke1, iK_mi, jK_mi, ...
bdofs_num, dofid, edofMat_mi, dx)
nele_micro = microx^2;
regulated_matrix = cell(nele_macro, 1);
dFdx = cell(nele_macro);
bezier_B = sparse(bezier_B);
order1 = reshape(edofMat_mi', [], 1);
vdofs_num = size(bezier_B, 2);
% NOTE: Nh is ordered as
% 2 4
% 1 3
[~, dNh_ele, ~] = shape_gradient_ele(dx/2, dx/2, 4);
for ele = 1 : nele_macro
rho_penal = rho{ele}(:);
% Assemble the micro global stiffness as the order of [dofid]
% i.e. [4-borders, inner], to be specific, [bottom, right, up, left, inner]
% this order is determined by bezier_B
K = assemble_micro_k_mmc(dofid, rho_penal, microx, ke1, iK_mi, jK_mi);
phi = build_M_simply(bdofs_num, K, bezier_B);
Re = [bezier_B; phi]; % NOTE: current order of ndofs is as of [dofid]
R1 = Re(dofid(order1), :);
R2 = reshape(R1, 8, []); % [8, nele*v]
%% sensitivities
dFe_gp = zeros(3, vdofs_num, nele_micro, 4);
for gp = 1:4
dNe_g = dNh_ele{gp}; % [3, 8]
dFe = dNe_g * R2; % [3, nele*v]
dF1 = reshape(dFe, 3, nele_micro, vdofs_num); % [3, nele, v]
dFe_gp(:, :, :, gp) = permute(dF1, [1,3,2]); % [3, v, nele]
end
dFdx{ele} = dFe_gp;
regulated_matrix{ele} = Re;
end
end
% dK is dK_dx_micro
function [K] = assemble_micro_k_mmc(dofid, rho_e, microx, ke, iK, jK)
new_iK = dofid(iK);
new_jK = dofid(jK);
sK = reshape(ke(:) * rho_e(:)', 64 * microx^2, 1);
K = sparse(new_iK, new_jK, sK(:));
K = (K + K') / 2;
end