%-------------------------- % @Author: Jingqiao Hu % @Date: 2021-09-27 11:00:42 % @LastEditTime: 2021-10-06 17:27:12 % t0 is the initial value, t1 is the max-value of thickness % 9 10 % !!!!!!!!!!!!!!!!!!!! % | 1\/2 | 3\/4 | % 15| /\ |17 /\ |19 % | 11 12 | % !!!!!!!!!!!!!!!!!!!! % | 5\/6 | 7\/8 | % 16| /\ |18 /\ |20 % !!!!!!!!!!!!!!!!!!!! % 13 14 % saves [t1,t2,t3, x, y, len, sin(theta)] %-------------------------- function [MMCs, MMCs_max, MMCs_min] = MMC_init(nelx, nely, lx, t, t_min, t_max, vnum, local_cnum) % MMCs = repmat(t, 20, nely, nelx); % 20 components in one coarse-ele % MMCs_min = repmat(t0, 20, nely, nelx); % MMCs_max = repmat(t1, 20, nely, nelx); MMCs = zeros(local_cnum, nelx*nely, vnum); % saves [t1,t2,t3, x, y, len, sin(theta)] MMCs_max = zeros(local_cnum, nelx*nely, vnum); MMCs_min = zeros(local_cnum, nelx*nely, vnum); mmc = zeros(local_cnum, vnum); % 1-8: xxxx mmc(1:2, 4:5) = repmat(lx/4, 2, 2); mmc(3:4, 4:5) = repmat([lx/4*3, lx/4], 2, 1); mmc(5:6, 4:5) = repmat([lx/4, lx/4*3], 2, 1); mmc(7:8, 4:5) = repmat(lx/4*3, 2, 2); mmc(1:8, 6) = 0.38; lx/2 * sqrt(2) / 2; mmc(1:2:8, 7) = -0.7; 1 / sqrt(2); mmc(2:2:8, 7) = 0.7; 1 / sqrt(2); if local_cnum > 8 % 9-20: vertical & horizontal mmc(15:16, 4) = 0; mmc(17:18, 4) = lx/2; mmc(19:20, 4) = lx; mmc([15,17,19], 5) = lx/4; mmc([16,18,20], 5) = lx/4*3; mmc( 9:10, 5) = 0; mmc(11:12, 5) = lx/2; mmc(13:14, 5) = lx; mmc( [9,11,13], 4) = lx/4; mmc([10,12,14], 4) = lx/4*3; mmc(9:end, 6) = lx/2 / 2; mmc( 9:14, 7) = 0; mmc(15:20, 7) = 1; end mmc(:, 1:3) = t; mmc_min = repmat([t_min, t_min, t_min, 0, 0, 0.01, -1], local_cnum, 1); mmc_max = repmat([t_max, t_max, t_max, lx, lx, lx, 1], local_cnum, 1); for i = 1:nelx for j = 1:nely mmc_new = mmc; % transform to global coordinates: mmc_new(:, 4) = mmc(:, 4) + lx * (i-1); mmc_new(:, 5) = mmc(:, 5) + lx * (j-1); MMCs(:, j+(i-1)*nely, :) = mmc_new; % the min & max of position of component must be in this block mmc_new = mmc_max; mmc_new(:, 4) = mmc_max(:, 4) + lx * (i-1); mmc_new(:, 5) = mmc_max(:, 5) + lx * (j-1); MMCs_max(:, j+(i-1)*nely, :) = mmc_new; mmc_new = mmc_min; mmc_new(:, 4) = mmc_min(:, 4) + lx * (i-1); mmc_new(:, 5) = mmc_min(:, 5) + lx * (j-1); MMCs_min(:, j+(i-1)*nely, :) = mmc_new; end end MMCs = permute(MMCs, [3,1,2]); % [7,20,nelx*nely] MMCs_max = permute(MMCs_max, [3,1,2]); MMCs_min = permute(MMCs_min, [3,1,2]); MMCs = reshape(MMCs, vnum, []); % [7, 20*nele], note the order is local MMCs_max = reshape(MMCs_max, vnum, []); MMCs_min = reshape(MMCs_min, vnum, []); end % the variable only takes thickness function [MMCs, MMCs_max, MMCs_min, mmc_descriptor] = MMC_init2(nelx, nely, lx, t0, t1, t) MMCs = repmat(t, 20, nely, nelx); % 20 components in one coarse-ele MMCs_min = repmat(t0, 20, nely, nelx); MMCs_max = repmat(t1, 20, nely, nelx); mmc_descriptor = cell(nelx, nely); % saves [x,y,len,sin(theta)] mmc = zeros(20,4); % 1-8: xxxx mmc(1:2, 1:2) = repmat(lx/4, 2, 2); mmc(3:4, 1:2) = repmat([lx/4*3, lx/4], 2, 1); mmc(5:6, 1:2) = repmat([lx/4, lx/4*3], 2, 1); mmc(7:8, 1:2) = repmat(lx/4*3, 2, 2); mmc(1:8, 3) = lx/2 * sqrt(2) / 2; mmc(1:2:8, 4) = 1 / sqrt(2); mmc(2:2:8, 4) = -1 / sqrt(2); % 9-20: vertical & horizontal mmc(15:16, 1) = 0; mmc(17:18, 1) = lx/2; mmc(19:20, 1) = lx; mmc([15,17,19], 2) = lx/4; mmc([16,18,20], 2) = lx/4*3; mmc( 9:10, 2) = 0; mmc(11:12, 2) = lx/2; mmc(13:14, 2) = lx; mmc( [9,11,13], 1) = lx/4; mmc([10,12,14], 1) = lx/4*3; mmc(9:end, 3) = lx/2 / 2; mmc( 9:14, 4) = 0; mmc(15:20, 4) = 1; for i = 1:nelx for j = 1:nely mmc_new = mmc; % transform to global coordinates: % y % | % 0 -- x mmc_new(:, 1) = mmc(:, 1) + lx * (i-1); mmc_new(:, 2) = mmc(:, 2) + lx * (j-1); mmc_descriptor{j,i} = mmc_new; end end end