Skip to content
Snippets Groups Projects
Commit 419b5c11 authored by Bernd Flemisch's avatar Bernd Flemisch
Browse files

add conversion scripts

parent cc57a832
Branches
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ The matrix solution has to be provided in form of a Matlab `mat`-file which has
* `T`: an `nt x nvelem` element connectivity matrix which contains in each row an element's `nvelem` vertex indices with respect to the numbering induced by `Points`.
* `P`: an `nt`-size vector containing the element-wise solution values with respect to the numbering induced by `T`.
Is your original solution data available as a VTK file? A helper function `hdf5_to_mat.m` is provided which extracts the required `mat`-file from an HDF5-file, which in turn can be exported from Paraview: select `File` -> `Save Data...` -> `Files of type: Xdmf Data File`, use the produced `h5`-file.
Is your original solution data available as a VTK file? A helper function `hdf5_to_mat_matrix.m` is provided which extracts the required `mat`-file from an HDF5-file, which in turn can be exported from Paraview: select `File` -> `Save Data...` -> `Files of type: Xdmf Data File`, use the produced `h5`-file. Type `help hdf5_to_mat_matrix` in Matlab for details.
#### 1.2 Performing the comparison
......@@ -27,6 +27,9 @@ function [relativeMatrixError] = compute_2d_error(coarseFile, referenceFile)
The fracture solution has to be provided in form of a Matlab `mat`-file which has to contain a Matlab cell array `fracXAndPCell`. Each cell `fracXAndPCell{i}` provides the solution on fracture branch `i` in form of a `(2.nc) x 3` matrix. As 2x3 block `fracXAndPCell{i}(2*e-1:2*e, :)` describes the solution on fracture element `e` in form of `[xStart, yStart, pStart; xEnd yEnd, pEnd]` where
`xStart, yStart` / `xEnd, yEnd` indicate the two vertices of the fracture element and `pStart` / `pEnd` the corresponding solution values.
Is your original solution data available as a VTK file? A helper function `hdf5_to_mat_fracture.m` is provided which extracts the required `mat`-file from HDF5-files for the fracture branches, which in turn can be exported from Paraview: Perform a plot-over-line for a fracture branch, select `File` -> `Save Data...` -> `Files of type: Xdmf Data File`, use the produced `h5`-file. Type `help hdf5_to_mat_fracture` in Matlab for details.
#### 2.2 Performing the comparison
The function [compute_1d_error](compute_1d_error.m) can be used to calculate a relative L2-error of the fracture solution. It has the signature
......
function hdf5_to_mat_fracture(basefilename, numfractures, solutionname, outfilename)
% hdf5_to_mat_fracture Convert a fracture network solution from HDF5 to Matlab format.
%
% Signature:
% hdf5_to_mat_fracture(basefilename, numfractures, solutionname, outfilename)
%
% Parameters:
% basefilename: the base name of the HDF5 files containing the fracture
% network solution, the individual files for each fracture
% branch are expected to be named 'basefilenameX.h5' where
% 'X' is the index of the fracture branch
% numfractures: the number of individual fracture branches (equal to the
% number of input files)
% solutionname: the name of the solution vector inside the HDF5 file
% outfilename: the name of the output Matlab .mat-file
fracXAndPCell = cell(numfractures, 1);
for fracidx = 1:numfractures
filename = strcat(basefilename, num2str(fracidx), '.h5');
fraccoords = h5read(filename, '/Block_0_t000000/Geometry/Points');
fracpressure = h5read(filename, strcat('/Block_0_t000000/Node/', solutionname));
fraccoords(:, isnan(fracpressure)) = [];
fracpressure(isnan(fracpressure)) = [];
numpoints = size(fraccoords, 2);
Xp = zeros(2*(numpoints-1), 3);
Xp(1:2:end-1, 1:2) = fraccoords(1:2, 1:end-1)';
Xp(2:2:end, 1:2) = fraccoords(1:2, 2:end)';
Xp(1:2:end-1, 3) = fracpressure(1:end-1);
Xp(2:2:end, 3) = fracpressure(2:end)';
fracXAndPCell{fracidx} = Xp;
end
save(outfilename, 'fracXAndPCell');
fprintf('Wrote file %s.\n', outfilename);
return
function hdf5_to_mat_matrix(infilename, cellwise, solutionname, outfilename)
% hdf5_to_mat_matrix Convert a matrix solution from HDF5 to Matlab format.
%
% Signature:
% hdf5_to_mat_matrix(infilename, solutionname, outfilename)
%
% Parameters:
% infilename: the name of the HDF5 file containing the matrix solution
% cellwise: true for a cell-wise solution vector, false for a vertex-wise
% solutionname: the name of the solution vector inside the HDF5 file
% outfilename: the name of the output Matlab .mat-file
T = h5read(infilename, '/Block_0_t000000/Topology');
T = T' + 1;
Points = h5read(infilename, '/Block_0_t000000/Geometry/Coordinates');
Points = Points([1 2], :)';
if cellwise
P = h5read(infilename, strcat('/Block_0_t000000/Cell/', solutionname));
else
pvertex = h5read(infilename, strcat('/Block_0_t000000/Node/', solutionname));
P = zeros(size(T, 1), 1);
factor = 1/size(T, 2);
for i = 1:size(T, 2)
P = P + factor.*pvertex(T(:, i));
end
end
save(outfilename, 'T', 'P', 'Points');
fprintf('Wrote file %s.\n', outfilename);
return
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment