-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreshapenek.m
50 lines (39 loc) · 1.15 KB
/
reshapenek.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function varargout = reshapenek(data,nelx,nely)
%
% Reshape data from nekread to a meshgrid
%
% [meshgrid1,meshgrid2,...] = reshapenek(data,nelx,nely)
%
% INPUT
% - data: nek5000 data ordered as (iel,inode,[x|y|(z)|u|v|(w)|p|T|s_i])
% - nelx: number of element in the first direction (second index)
% - nely: number of element in the second direction (first index)
%
% OUTPUT
% - meshgridn: meshgrid of the n-th field in data
%
% Last edit: 20151028 Nicolo Fabbiane ([email protected])
%
% get dimension and check number of elements
[nel,N2,nfld] = size(data); N = sqrt(N2);
if nel ~= nelx*nely
disp('Error: nel ~= nelx*nely.');
return
end
% check output
if nfld < nargout
disp('Error: nfld < outputs.');
return
end
% reshape data
for ifld = 1:min([nfld,nargout])
mesh = zeros((N-1)*nely+1,(N-1)*nelx+1);
for iel = 1:nel
ielx = floor((iel-1)/nely) + 1;
iely = mod(iel-1,nely) + 1;
ii = (0:N-1) + (N-1)*(ielx-1) + 1;
jj = (0:N-1) + (N-1)*(iely-1) + 1;
mesh(jj,ii) = reshape(data(iel,:,ifld),N,N)';
end
varargout{ifld} = mesh;
end