Skip to content

Commit b22c417

Browse files
With updated plot utilities (#70)
1 parent 5e95ff0 commit b22c417

File tree

5 files changed

+61
-27
lines changed

5 files changed

+61
-27
lines changed

Code/output/OutState.m

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,24 @@
8686

8787
opt = struct(varargin{:});
8888
if isfield(opt, 'flagMatFile'), obj.writeSolution = logical(opt.flagMatFile); end
89-
if isfield(opt, 'writeVtk'), obj.writeVtk = logical(opt.writeVtk); end
90-
if isfield(opt, 'folderName'), obj.vtkFileName = string(opt.folderName); end
89+
if isfield(opt, 'folderName')
90+
obj.vtkFileName = string(opt.folderName);
91+
obj.writeVtk = true;
92+
end
9193
if isfield(opt, 'matFileName'), obj.matFileName = string(opt.matFileName); end
9294
if isfield(opt, 'timeList'), tList = opt.timeList; end
95+
9396
end
9497

9598
% ------------------------------------------------------------
9699
% Object setup
97100
% ------------------------------------------------------------
98101

102+
99103
% Time list handling
100104
if obj.writeVtk
101105
% vtm file document node
106+
obj.vtkFile = com.mathworks.xml.XMLUtils.createDocument('VTKFile');
102107
assert(~isempty(tList), ...
103108
"Print times have not been specified for output.");
104109
end
@@ -258,8 +263,6 @@ function createVTKFolder(obj)
258263
% Merge output variable coming from a field to the global output
259264
% structure
260265
% Concatenate the two structure arrays
261-
strA = reshape(strA,[],1);
262-
strB = reshape(strB,[],1);
263266

264267
if isempty(strA)
265268
mergeStruct = strB;

Code/unittest/Mesh/testMesh.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ function testReadVTK(testCase)
1010
testCase.verifyEqual(mesh.nCells,560);
1111
testCase.verifyEqual(mesh.nSurfaces,624);
1212
end
13+
14+
function testStructuredGrids(testCase)
15+
mesh = structuredMesh(5,5,5,[0 1],[0 1],[0 1]);
16+
testCase.verifyEqual(mesh.nCells,5^3);
17+
testCase.verifyEqual(mesh.nNodes,6^3);
18+
testCase.verifyEqual(mesh.cells(2,:),[2 3 9 8 38 39 45 44]);
19+
20+
b = BlockStructuredMesh(2,2,2,[0 1],[0 1],[0 1],3);
21+
b.refineRecursive([1 1 1],2);
22+
b.refineRecursive([2 2 2],2);
23+
b.refineRecursive([2 1 2],1);
24+
mesh =b.processGeometry();
25+
testCase.verifyEqual(mesh.nNodes,305);
26+
testCase.verifyEqual(mesh.nDim,3);
27+
testCase.verifyEqual(mesh.nCells,141);
28+
testCase.verifyEqual(mesh.cells(10,:),[28 32 33 29 30 34 35 31]);
29+
end
1330
end
1431

1532

Tutorial/meshInput/meshIO.mlx

46 Bytes
Binary file not shown.
Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,42 @@
1-
function plotFunction(mesh, foldName, funct, varargin)
1+
function plotFunction(mesh, foldName, time, funct, varargin)
22
% PLOTFUNCTION Summary of this function goes here
33
% Detailed explanation goes here
4-
outVTK = VTKOutput(mesh, foldName); % create VTK object
5-
pointData.name = 'solution';
6-
pointData.data = funct;
7-
outVTK.writeVTKFile(0, [], [], [], []);
4+
5+
out = OutState('folderName',foldName,'timeList',time);
6+
out.prepareOutputFolders();
7+
8+
[~, vtuName, ~] = fileparts(foldName);
9+
10+
toc = out.vtkFile.getDocumentElement;
11+
toc.setAttribute('type', 'vtkMultiBlockDataSet');
12+
toc.setAttribute('version', '1.0');
13+
blocks = out.vtkFile.createElement('vtkMultiBlockDataSet');
14+
15+
16+
% inner block with vtu dataset to append to vtm file
17+
block = out.vtkFile.createElement('Block');
18+
19+
var.name = 'solution';
20+
var.data = funct;
21+
% outVTK.writeVTKFile(0, [], [], [], []);
822
if isempty(varargin) || strcmpi(varargin{1},'node')
9-
if ~isempty(mesh.cells)
10-
outVTK.writeVTKFile(0, pointData, [], [], []);
11-
else
12-
outVTK.writeVTKFile(0, [], [], pointData, []);
13-
end
23+
if ~isempty(mesh.cells)
24+
writeVTKfile(out,block,vtuName,mesh,time,var,[],[],[]);
25+
else
26+
writeVTKfile(out,block,vtuName,mesh,time,[],[],var,[]);
27+
end
1428
elseif strcmpi(varargin{1},'elem')
15-
if ~isempty(mesh.cells)
16-
outVTK.writeVTKFile(0, [], pointData, [], []);
17-
else
18-
outVTK.writeVTKFile(0, [], [], [], pointData);
19-
end
29+
if ~isempty(mesh.cells)
30+
writeVTKfile(out,block,vtuName,mesh,time,[],var,[],[]);
31+
else
32+
writeVTKfile(out,block,vtuName,mesh,time,[],[],[],var);
33+
end
2034
end
21-
outVTK.finalize()
35+
36+
blocks.appendChild(block);
37+
toc.appendChild(blocks);
38+
39+
out.writeVTMFile();
40+
2241
end
2342

Utilities/ParaviewPlot/plotMesh.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
function plotMesh(mesh, foldName)
2-
% PLOTFUNCTION Summary of this function goes here
3-
% Detailed explanation goes here
4-
outVTK = VTKOutput(mesh, foldName); % create VTK object
5-
pointData.name = 'field';
6-
pointData.data = zeros(mesh.nNodes,1);
7-
outVTK.writeVTKFile(0, pointData, [], [], []);
8-
outVTK.finalize()
2+
3+
plotFunction(mesh,foldName,0.0,zeros(mesh.nNodes,1))
94
end
105

0 commit comments

Comments
 (0)