Interpolation of sparse pointwise and integral geographical Data over Time/assemble lattice.m
Jump to navigation
Jump to search
function lattice = assemble_lattice(nodes, cells)
lattice.points = nodes;
lattice.cells = cells;
lattice.neighbour_matrix = zeros(size(lattice.points, 1));
% precalculate neighbouring points
for node = 1:size(lattice.points, 1)
idx = (lattice.cells(:,1)==node)|(lattice.cells(:,2)==node)|(lattice.cells(:,3)==node);
nbhd = lattice.cells(idx,:);
nbhd = nbhd(:)';
lattice.neighbour_nodes{node} = unique(nbhd(nbhd ~= node));
lattice.neighbour_matrix(node, lattice.neighbour_nodes{node}) = 1;
end;
% precalculate cell volumes
p1 = lattice.points(lattice.cells(:,1),:);
p2 = lattice.points(lattice.cells(:,2),:);
p3 = lattice.points(lattice.cells(:,3),:);
lattice.cell_volumes = 1/2*abs((p1(:,1)-p3(:,1)).*(p2(:,2)-p1(:,2)) ...
- (p1(:,1)-p2(:,1)).*(p3(:,2)-p1(:,2)));