function [m1, m2, K11, K12, K21, K22] = partition_matrix_vec(m, K, n1, n2, domain, bs)
% PARTITION_MATRIX_VEC Partition a vector and matrix into blocks.
% [m1, m2, K11, K12, K21, K22] = partition_matrix_vec(m, K, blocks1, blocks2, domain, bs)
%
% Example: Let domain = [2 4 5], bs = [1 2 1],
% m = [1 2 3 4], K = some 4*4 matrix
% [m1, m2] = partition(m, K, [4], [2 5], [2 4 5], bs).
% m1 = [2 3] (the parts of m corresponding to X4), m2 = [1 4].

%domain = union(n1,n2); % slow
%assert(isequal(domain, union(n1,n2)));

nn1 = find_equiv_posns(n1, domain); % local names
nn2 = find_equiv_posns(n2, domain);
n1i = block(nn1,bs); % local indices
n2i = block(nn2,bs);
m1 = m(n1i); m2 = m(n2i);
K11 = K(n1i, n1i); K12 = K(n1i, n2i); K21 = K(n2i, n1i); K22 = K(n2i, n2i);
