Skip to content

Commit

Permalink
[test] add unit tests for utility functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Dec 22, 2024
1 parent e4b12ed commit 35cbf66
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions test/run_iso2mesh_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function run_iso2mesh_test(tests)
test_iso2mesh('meshanellip face', @savejson, round_to_digits(sum(elemvolume(no, fc)), 4), '[62.4487]');
test_iso2mesh('meshanellip elem', @savejson, round_to_digits(sum(elemvolume(no, el(:, 1:4))), 4), '[32.5608]');

%[no, fc, el] = meshacylinder([1 1 1], [2 3 4], [10, 12], 0.1, 10);
%test_iso2mesh('meshacylinder face', @savejson, round_to_digits(sum(elemvolume(no, fc)), 4), '[1045.2322]');
%test_iso2mesh('meshacylinder elem', @savejson, round_to_digits(sum(elemvolume(no, el(:, 1:4))), 4), '[1402.8993]');
% [no, fc, el] = meshacylinder([1 1 1], [2 3 4], [10, 12], 0.1, 10);
% test_iso2mesh('meshacylinder face', @savejson, round_to_digits(sum(elemvolume(no, fc)), 4), '[1045.2322]');
% test_iso2mesh('meshacylinder elem', @savejson, round_to_digits(sum(elemvolume(no, el(:, 1:4))), 4), '[1402.8993]');

[no, fc] = meshacylinder([1 1 1], [2 3 4], [0.5, 0.8], 0, 0, 8);
test_iso2mesh('meshacylinder plc', @savejson, fc, '[[[[1,9,10,2],1]],[[[2,10,11,3],1]],[[[3,11,12,4],1]],[[[4,12,13,5],1]],[[[5,13,14,6],1]],[[[6,14,15,7],1]],[[[7,15,16,8],1]],[[[8,16,9,1],1]],[[[1,2,3,4,5,6,7,8],2]],[[[9,10,11,12,13,14,15,16],3]]]');
Expand Down Expand Up @@ -101,3 +101,36 @@ function run_iso2mesh_test(tests)
test_iso2mesh('v2m face', @savejson, round_to_digits(sum(elemvolume(no, fc(:, 1:3))), 4), '[5.0082]');
test_iso2mesh('v2m elem', @savejson, round_to_digits(sum(elemvolume(no, el(:, 1:4))), 4), '[0.8786]');
end

%%
if (ismember('utils', tests))
fprintf(sprintf('%s\n', char(ones(1, 79) * 61)));
fprintf('Test utilities\n');
fprintf(sprintf('%s\n', char(ones(1, 79) * 61)));

[no, el] = meshgrid6(1:2, -1:0, 2:0.5:3);
fc = volface(el);

test_iso2mesh('volface', @savejson, fc, '[[2,1,4],[1,2,6],[1,3,4],[3,1,7],[5,1,6],[1,5,7],[2,4,8],[2,8,6],[3,8,4],[3,7,8],[5,6,10],[7,5,11],[9,5,10],[5,9,11],[6,8,12],[6,12,10],[7,12,8],[7,11,12],[9,10,12],[9,12,11]]');
test_iso2mesh('uniqfaces', @savejson, uniqfaces(el), '[[1,2,4],[1,2,6],[1,2,8],[1,3,4],[1,3,7],[1,3,8],[1,8,4],[1,5,6],[1,5,7],[1,5,8],[1,6,8],[1,8,7],[2,8,4],[2,6,8],[3,4,8],[3,8,7],[5,6,8],[5,6,10],[5,6,12],[5,7,8],[5,7,11],[5,7,12],[5,12,8],[5,9,10],[5,9,11],[5,9,12],[5,10,12],[5,12,11],[6,12,8],[6,10,12],[7,8,12],[7,12,11],[9,12,10],[9,11,12]]');
test_iso2mesh('meshedge', @savejson, unique(meshedge(el), 'rows'), '[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[2,4],[2,6],[2,8],[3,4],[3,7],[3,8],[4,8],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[6,8],[6,10],[6,12],[7,8],[7,11],[7,12],[8,4],[8,6],[8,7],[8,12],[9,10],[9,11],[9,12],[10,12],[11,12],[12,8],[12,10],[12,11]]');
test_iso2mesh('uniqedges', @savejson, uniqedges(el), '[[1,2],[1,3],[1,4],[1,5],[1,6],[1,7],[1,8],[2,4],[2,6],[2,8],[3,4],[3,7],[3,8],[8,4],[5,6],[5,7],[5,8],[5,9],[5,10],[5,11],[5,12],[6,8],[6,10],[6,12],[7,8],[7,11],[7,12],[12,8],[9,10],[9,11],[9,12],[10,12],[12,11]]');
test_iso2mesh('meshconn', @savejson, meshconn(el, size(no, 1)), '[[[2,3,4,5,6,7,8]],[[1,4,6,8]],[[1,4,7,8]],[[1,2,3,8]],[[1,6,7,8,9,10,11,12]],[[1,2,5,8,10,12]],[[1,3,5,8,11,12]],[[1,2,3,4,5,6,7,12]],[[5,10,11,12]],[[5,6,9,12]],[[5,7,9,12]],[[5,6,7,8,9,10,11]]]');
test_iso2mesh('neighborelem', @savejson, neighborelem(el, size(no, 1)), '[[[1,3,5,7,9,11]],[[1,5]],[[3,9]],[[1,3]],[[2,4,6,7,8,10,11,12]],[[2,5,6,7]],[[4,9,10,11]],[[1,2,3,4,5,7,9,11]],[[8,12]],[[6,8]],[[10,12]],[[2,4,6,8,10,12]]]');
test_iso2mesh('faceneighbors', @savejson, faceneighbors(el), '[[5,0,3,0],[6,7,4,0],[0,9,1,0],[11,10,2,0],[0,1,7,0],[0,2,8,0],[11,0,5,2],[12,0,6,0],[3,0,11,0],[4,0,12,0],[0,7,9,4],[0,8,10,0]]');
test_iso2mesh('faceneighbors surface', @savejson, faceneighbors(el, 'surface'), '[[1,3,4],[1,2,6],[5,6,10],[1,5,7],[5,9,11],[1,2,4],[1,5,6],[5,9,10],[1,3,7],[5,7,11],[2,4,8],[6,8,12],[3,4,8],[7,8,12],[2,6,8],[6,10,12],[9,10,12],[3,7,8],[7,11,12],[9,11,12]]');
test_iso2mesh('edgeneighbors', @savejson, edgeneighbors(fc), '[[2,3,7],[1,8,5],[4,9,1],[3,6,10],[6,2,11],[5,12,4],[1,9,8],[7,15,2],[10,7,3],[4,17,9],[5,16,13],[6,14,18],[14,11,19],[13,20,12],[8,17,16],[15,19,11],[18,15,10],[12,20,17],[13,16,20],[19,18,14]]');
test_iso2mesh('edgeneighbors general', @savejson, edgeneighbors(uniqfaces(el), 'general'), '[[[2,3,4,7,13]],[[1,3,8,11,14]],[[1,2,6,7,10,11,12,13,14]],[[1,5,6,7,15]],[[4,6,9,12,16]],[[3,4,5,7,10,11,12,15,16]],[[1,3,4,6,10,11,12,13,15]],[[2,9,10,11,17,18,19]],[[5,8,10,12,20,21,22]],[[3,6,7,8,9,11,12,17,20,23]],[[2,3,6,7,8,10,12,14,17,29]],[[3,5,6,7,9,10,11,16,20,31]],[[1,3,7,14,15]],[[2,3,11,13,17,29]],[[4,6,7,13,16]],[[5,6,12,15,20,31]],[[8,10,11,14,18,19,20,23,29]],[[8,17,19,24,27,30]],[[8,17,18,22,23,26,27,28,29,30]],[[9,10,12,16,17,21,22,23,31]],[[9,20,22,25,28,32]],[[9,19,20,21,23,26,27,28,31,32]],[[10,17,19,20,22,26,27,28,29,31]],[[18,25,26,27,33]],[[34,21,24,26,28]],[[34,19,22,23,24,25,27,28,33]],[[18,19,22,23,24,26,28,30,33]],[[34,19,21,22,23,25,26,27,32]],[[11,14,17,19,23,30,31]],[[18,19,27,29,33]],[[12,16,20,22,23,29,32]],[[34,21,22,28,31]],[[34,24,26,27,30]],[[25,26,28,32,33]]]');
test_iso2mesh('meshquality', @savejson, unique(round_to_digits(meshquality(no, el), 6)), '[[0.620322],[0.686786]]');
test_iso2mesh('meshquality face', @savejson, unique(round_to_digits(meshquality(no, fc), 6)), '[[0.69282],[0.866025]]');
test_iso2mesh('meshface', @savejson, unique(sort(meshface(el)), 'rows'), '[[1,2,4],[1,3,6],[1,4,7],[1,5,7],[1,5,8],[1,6,8],[2,6,8],[3,7,8],[5,7,8],[5,8,8],[5,8,10],[5,8,11],[5,9,11],[5,9,12],[5,10,12],[5,11,12],[6,12,12],[7,12,12],[9,12,12]]');
test_iso2mesh('surfacenorm', @savejson, surfacenorm(no, fc), '[[0,0,-1],[0,-1,0],[0,0,-1],[-1,0,0],[0,-1,0],[-1,0,0],[1,0,0],[1,0,0],[0,1,0],[0,1,0],[0,-1,0],[-1,0,0],[0,-1,0],[-1,0,0],[1,0,0],[1,0,0],[0,1,0],[0,1,0],[0,0,1],[0,0,1]]');
test_iso2mesh('nodesurfnorm', @savejson, round_to_digits(nodesurfnorm(no, fc), 6), '[[-0.57735,-0.57735,-0.57735],[0.816497,-0.408248,-0.408248],[-0.408248,0.816497,-0.408248],[0.408248,0.408248,-0.816497],[-0.707107,-0.707107,0],[0.707107,-0.707107,0],[-0.707107,0.707107,0],[0.707107,0.707107,0],[-0.408248,-0.408248,0.816497],[0.408248,-0.816497,0.408248],[-0.816497,0.408248,0.408248],[0.57735,0.57735,0.57735]]');
test_iso2mesh('meshcentroid', @savejson, meshcentroid(no, el), '[[1.75,-0.5,2.125],[1.75,-0.5,2.625],[1.5,-0.25,2.125],[1.5,-0.25,2.625],[1.75,-0.75,2.25],[1.75,-0.75,2.75],[1.5,-0.75,2.375],[1.5,-0.75,2.875],[1.25,-0.25,2.25],[1.25,-0.25,2.75],[1.25,-0.5,2.375],[1.25,-0.5,2.875]]');
test_iso2mesh('meshcentroid face', @savejson, round_to_digits(meshcentroid(no, fc), 3), '[[1.667,-0.667,2],[1.667,-1,2.167],[1.333,-0.333,2],[1,-0.333,2.167],[1.333,-1,2.333],[1,-0.667,2.333],[2,-0.333,2.167],[2,-0.667,2.333],[1.667,0,2.167],[1.333,0,2.333],[1.667,-1,2.667],[1,-0.333,2.667],[1.333,-1,2.833],[1,-0.667,2.833],[2,-0.333,2.667],[2,-0.667,2.833],[1.667,0,2.667],[1.333,0,2.833],[1.667,-0.667,3],[1.333,-0.333,3]]');
test_iso2mesh('nodevolume', @savejson, round_to_digits(nodevolume(no, el), 6), '[[0.125],[0.041667],[0.041667],[0.041667],[0.166667],[0.083333],[0.083333],[0.166667],[0.041667],[0.041667],[0.041667],[0.125]]');
test_iso2mesh('nodevolume face', @savejson, round_to_digits(nodevolume(no, fc), 6), '[[0.666667],[0.416667],[0.416667],[0.5],[0.5],[0.5],[0.5],[0.5],[0.5],[0.416667],[0.416667],[0.666667]]');
test_iso2mesh('elemvolume', @savejson, unique(round_to_digits(elemvolume(no, el), 6)), '[0.083333]');
test_iso2mesh('surfvolume', @savejson, surfvolume(no, fc), '[1]');
test_iso2mesh('insurface', @savejson, insurface(no, fc, [1.5, -0.9, 2.1; 1, 0, 2; -1, 0 2; 1.2, -0, 2.5])', '[1,1,0,1]');
end

0 comments on commit 35cbf66

Please sign in to comment.