You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.0 KiB
77 lines
2.0 KiB
function hexvtkwrite(base_path,filename,MESH,V, point_data, cell_data, opt)
|
|
%vtkwrite 此处显示有关此函数的摘要
|
|
% 此处显示详细说明
|
|
|
|
% Write Paraview VTK Hex File
|
|
% Author: Hu Xinzhuo
|
|
% Create Time: 2021-01-11
|
|
% Update Time: 2021-01-11
|
|
|
|
% MESH: num_elems X 8
|
|
% V: num_nodes X 3
|
|
|
|
num_ele=size(MESH,1);
|
|
num_nod=size(V,1);
|
|
|
|
MESH = MESH-1; % vtk从0开始编号
|
|
OUTP2 = [8.*ones(num_ele,1),MESH];
|
|
|
|
vtkf = [filename,'.vtk'];
|
|
myfile = fullfile(base_path,vtkf);
|
|
fileID = fopen(myfile,'w');
|
|
|
|
fprintf(fileID,'# vtk DataFile Version 3.0\n');
|
|
fprintf(fileID,'Volume Mesh\n');
|
|
fprintf(fileID,'ASCII\n');
|
|
fprintf(fileID,'DATASET UNSTRUCTURED_GRID\n');
|
|
|
|
fprintf(fileID,'POINTS %d double\n',num_nod);
|
|
fprintf(fileID,'%f %f %f \n',V.');
|
|
|
|
fprintf(fileID,'CELLS %d %d\n',num_ele,num_ele*(8+1));
|
|
fprintf(fileID,'%d %d %d %d %d %d %d %d %d\n',OUTP2.');
|
|
|
|
fprintf(fileID,'CELL_TYPES %d\n',num_ele);
|
|
fprintf(fileID,'%d\n',12.*ones(num_ele,1));
|
|
% 10 for tet mesh; 12 for hex mesh
|
|
|
|
switch opt
|
|
|
|
case 'POINT_DATA'
|
|
|
|
fprintf(fileID,'POINT_DATA %d\n',num_nod);
|
|
fprintf(fileID,'SCALARS point_scalars float 1\n');
|
|
fprintf(fileID,'LOOKUP_TABLE default\n');
|
|
fprintf(fileID,'%d\n',point_data);
|
|
|
|
case 'CELL_DATA'
|
|
|
|
fprintf(fileID,'CELL_DATA %d\n',num_ele);
|
|
fprintf(fileID,'SCALARS cell_scalars float 1\n');
|
|
fprintf(fileID,'LOOKUP_TABLE default\n');
|
|
fprintf(fileID,'%d\n',cell_data);
|
|
|
|
case 'ALL'
|
|
|
|
% POINT_DATA
|
|
fprintf(fileID,'POINT_DATA %d\n',num_nod);
|
|
fprintf(fileID,'SCALARS point_scalars float 1\n');
|
|
fprintf(fileID,'LOOKUP_TABLE default\n');
|
|
fprintf(fileID,'%d\n',point_data);
|
|
|
|
% CELL_DATA
|
|
fprintf(fileID,'CELL_DATA %d\n',num_ele);
|
|
fprintf(fileID,'SCALARS cell_scalars float 1\n');
|
|
fprintf(fileID,'LOOKUP_TABLE default\n');
|
|
fprintf(fileID,'%d\n',cell_data);
|
|
|
|
case 'None'
|
|
fclose(fileID);
|
|
return;
|
|
|
|
end
|
|
|
|
fclose(fileID);
|
|
|
|
end
|
|
|
|
|