| 1 |
% |
| 2 |
% vel_pres_vtk2d(vtkfile, xy, t, vel, pressure) |
| 3 |
% vel_pres_vtk2d(vtkfile, xy, t, vel, pressure, vort, stream) |
| 4 |
% |
| 5 |
% |
| 6 |
% INPUT: |
| 7 |
% vtkfile base name of file |
| 8 |
% vel_pres_vtk2d generates vtkfile_vel.vtu |
| 9 |
% and vel_pres_vtk2d_pres.vtu |
| 10 |
% |
| 11 |
% xy real nx x 2 |
| 12 |
% x-y-coordinates of the vertices in the triangulation. |
| 13 |
% xy(i,1) x-coordinate of node i, |
| 14 |
% xy(i,2) y-coordinate of node i. |
| 15 |
% |
| 16 |
% t real nt x 6 |
| 17 |
% indices of the vertices in a triangle |
| 18 |
% t(i,j) index of the j-th vertex in triangle i |
| 19 |
% |
| 20 |
% vel real nn x 2 |
| 21 |
% velocity at nodes |
| 22 |
% |
| 23 |
% pressure real nv x 1 |
| 24 |
% pressure at vertices |
| 25 |
% |
| 26 |
% vort real nn x 2 |
| 27 |
% vorticity at nodes [optional] |
| 28 |
% |
| 29 |
% stream real nn x 2 |
| 30 |
% streamfunction at nodes [optional] |
| 31 |
% |
| 32 |
% |
| 33 |
% AUTHOR: Denis Ridzal and Matthias Heinkenschloss |
| 34 |
% Department of Computational and Applied Mathematics |
| 35 |
% Rice University |
| 36 |
% Novemer 15, 2005 |
| 37 |
% |
| 38 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 39 |
function [] = vel_pres_vtk2d(vtkfile, xy, t, vel, pressure, varargin) |
| 40 |
|
| 41 |
|
| 42 |
% Write pressures |
| 43 |
% open file |
| 44 |
filename = [vtkfile,'_pres.vtk']; |
| 45 |
fid = fopen(filename,'w'); |
| 46 |
|
| 47 |
% write header |
| 48 |
fprintf(fid, '%s\n', '# vtk DataFile Version 3.0'); |
| 49 |
fprintf(fid, '%s\n', 'created by vel_pres_vtk2d.m'); |
| 50 |
fprintf(fid, '%s\n', 'ASCII'); |
| 51 |
fprintf(fid, '%s\n\n', 'DATASET UNSTRUCTURED_GRID'); |
| 52 |
|
| 53 |
nv = max(max(t(:,1:3))); % number of vertices, assumes that vertices |
| 54 |
% are first in xy, followed by mid points |
| 55 |
% (true for meshes generated by triangle |
| 56 |
fprintf(fid, '%s%d%s\n', 'POINTS ', nv, ' double'); |
| 57 |
for i = 1:nv |
| 58 |
fprintf(fid, '%13.6e %13.6e %13.6e \n', xy(i,:), 0); |
| 59 |
end |
| 60 |
fprintf(fid, '\n'); |
| 61 |
fprintf(fid, '%s %d %d\n', 'CELLS ', size(t,1), 4*size(t,1)); |
| 62 |
for i = 1:size(t,1) |
| 63 |
fprintf(fid, '%d %d %d %d \n', 3, t(i,1:3)-1); |
| 64 |
end |
| 65 |
fprintf(fid, '\n'); |
| 66 |
fprintf(fid, '%s %d \n', 'CELL_TYPES ', size(t,1)); |
| 67 |
for i = 1:size(t,1) |
| 68 |
fprintf(fid, '%d \n', 5); |
| 69 |
end |
| 70 |
fprintf(fid, '\n'); |
| 71 |
fprintf(fid, '%s %d \n', 'POINT_DATA ', nv); |
| 72 |
fprintf(fid, '%s \n', 'SCALARS pressure double 1'); |
| 73 |
fprintf(fid, '%s \n', 'LOOKUP_TABLE default'); |
| 74 |
for i = 1:nv |
| 75 |
fprintf(fid, '%13.6e \n', pressure(i)); |
| 76 |
end |
| 77 |
fprintf(fid, '%s \n', 'VECTORS velocities double'); |
| 78 |
for i = 1:nv |
| 79 |
fprintf(fid, '%13.6e %13.6e %13.6e\n', vel(i,:), 0); |
| 80 |
end |
| 81 |
|
| 82 |
fclose(fid); |
| 83 |
fprintf('... pressure data written to %s \n', filename) |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
% Write velocities |
| 88 |
% open file |
| 89 |
filename = [vtkfile,'_vel.vtk']; |
| 90 |
fid = fopen(filename,'w'); |
| 91 |
|
| 92 |
% write header |
| 93 |
fprintf(fid, '%s\n', '# vtk DataFile Version 3.0'); |
| 94 |
fprintf(fid, '%s\n', 'created by vel_pres_vtk2d.m'); |
| 95 |
fprintf(fid, '%s\n', 'ASCII'); |
| 96 |
fprintf(fid, '%s\n\n', 'DATASET UNSTRUCTURED_GRID'); |
| 97 |
|
| 98 |
fprintf(fid, '%s%d%s\n', 'POINTS ', size(xy,1), ' double'); |
| 99 |
for i = 1:size(xy,1) |
| 100 |
fprintf(fid, '%13.6e %13.6e %13.6e \n', xy(i,:), 0); |
| 101 |
end |
| 102 |
fprintf(fid, '\n'); |
| 103 |
fprintf(fid, '%s %d %d\n', 'CELLS ', 4*size(t,1), 16*size(t,1)); |
| 104 |
for i = 1:size(t,1) |
| 105 |
fprintf(fid, '%d %d %d %d \n', 3, t(i,[1,6,5])-1); |
| 106 |
fprintf(fid, '%d %d %d %d \n', 3, t(i,[4,5,6])-1); |
| 107 |
fprintf(fid, '%d %d %d %d \n', 3, t(i,[2,4,6])-1); |
| 108 |
fprintf(fid, '%d %d %d %d \n', 3, t(i,[5,4,3])-1); |
| 109 |
end |
| 110 |
fprintf(fid, '\n'); |
| 111 |
fprintf(fid, '%s %d \n', 'CELL_TYPES ', 4*size(t,1)); |
| 112 |
for i = 1:4*size(t,1) |
| 113 |
fprintf(fid, '%d \n', 5); |
| 114 |
end |
| 115 |
fprintf(fid, '\n'); |
| 116 |
fprintf(fid, '%s %d \n', 'POINT_DATA ', size(xy,1)); |
| 117 |
if( nargin > 5 ) |
| 118 |
vort = varargin{1}; |
| 119 |
stream = varargin{2}; |
| 120 |
fprintf(fid, '%s \n', 'SCALARS vorticity double 1'); |
| 121 |
fprintf(fid, '%s \n', 'LOOKUP_TABLE default'); |
| 122 |
for i = 1:size(xy,1) |
| 123 |
fprintf(fid, '%13.6e \n', vort(i)); |
| 124 |
end |
| 125 |
fprintf(fid, '\n'); |
| 126 |
fprintf(fid, '%s \n', 'SCALARS stream_fucntion double 1'); |
| 127 |
fprintf(fid, '%s \n', 'LOOKUP_TABLE default'); |
| 128 |
for i = 1:size(xy,1) |
| 129 |
fprintf(fid, '%13.6e \n', stream(i)); |
| 130 |
end |
| 131 |
end |
| 132 |
fprintf(fid, '\n'); |
| 133 |
fprintf(fid, '%s \n', 'VECTORS velocities double'); |
| 134 |
for i = 1:size(xy,1) |
| 135 |
fprintf(fid, '%13.6e %13.6e %13.6e\n', vel(i,:), 0); |
| 136 |
end |
| 137 |
|
| 138 |
% close file |
| 139 |
fclose(fid); |
| 140 |
|
| 141 |
if( nargin > 5 ) |
| 142 |
fprintf('... velocity, vorticity and streamfunction data written to %s \n', filename); |
| 143 |
else |
| 144 |
fprintf('... velocity data written to %s \n', filename); |
| 145 |
end |
| 146 |
|
| 147 |
|