Skip to content

Commit 3429a48

Browse files
Mohammad Hamidcopybara-github
authored andcommitted
Detect mismatch between maxNodes and Nodes in a gmsh block. Fixes #2342
PiperOrigin-RevId: 745967745 Change-Id: If1b5fcd71079a0e6a6def9b442758678e31a5828
1 parent eadd130 commit 3429a48

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

src/user/user_flexcomp.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,11 @@ void mjCFlexcomp::LoadGMSH41(char* buffer, int binary, int nodeend,
11671167
throw mjCError(NULL, "All nodes must be in single block");
11681168
}
11691169

1170+
// require maximum number of nodes be equal to maximum number of nodes in a block
1171+
if (maxNodeTag != numNodesInBlock){
1172+
throw mjCError(NULL, "Maximum number of nodes must be equal to number of nodes in a block");
1173+
}
1174+
11701175
// check dimensionality and save
11711176
if (entityDim < 1 || entityDim > 3) {
11721177
throw mjCError(NULL, "Entity must be 1D, 2D or 3D");
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
$MeshFormat
2+
4.1 0 8
3+
$EndMeshFormat
4+
$Entities
5+
0 0 0 1
6+
1 -0.5 -0.5 0 0.5 0.5 1 0 0
7+
$EndEntities
8+
$Nodes
9+
1 14 1 100
10+
3 1 0 14
11+
1
12+
2
13+
3
14+
4
15+
5
16+
6
17+
7
18+
8
19+
9
20+
10
21+
11
22+
12
23+
13
24+
14
25+
-0.5 -0.5 0
26+
0.5 -0.5 0
27+
0.5 0.5 0
28+
-0.5 0.5 0
29+
-0.5 -0.5 1
30+
0.5 -0.5 1
31+
0.5 0.5 1
32+
-0.5 0.5 1
33+
0 0 0
34+
0 -0.5 0.5
35+
0.5 0 0.5
36+
0 0.5 0.5
37+
-0.5 0 0.5
38+
0 0 1
39+
$EndNodes
40+
$Elements
41+
1 24 1 24
42+
3 1 4 24
43+
1 10 9 12 11
44+
2 10 12 13 14
45+
3 9 10 12 13
46+
4 10 12 14 11
47+
5 9 10 1 2
48+
6 7 11 12 3
49+
7 4 1 9 13
50+
8 13 12 4 8
51+
9 1 10 13 5
52+
10 13 8 5 14
53+
11 12 8 14 7
54+
12 14 5 10 6
55+
13 14 6 11 7
56+
14 9 4 12 3
57+
15 3 11 9 2
58+
16 11 6 10 2
59+
17 6 10 14 11
60+
18 1 10 9 13
61+
19 12 4 9 13
62+
20 5 10 13 14
63+
21 8 13 12 14
64+
22 12 14 11 7
65+
23 9 12 11 3
66+
24 10 9 11 2
67+
$EndElements
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<mujoco model="gmsh">
2+
<option timestep="0.01" integrator="implicitfast" solver="CG" />
3+
4+
<asset>
5+
<texture type="skybox" builtin="gradient" rgb1=".3 .5 .7" rgb2="0 0 0" width="512" height="512" />
6+
<texture name="grid" type="2d" builtin="checker" width="512" height="512" rgb1=".1 .2 .3"
7+
rgb2=".2 .3 .4" />
8+
<material name="grid" texture="grid" texrepeat="1 1" texuniform="true" reflectance=".2" />
9+
</asset>
10+
11+
<visual>
12+
<headlight diffuse="0.9 0.9 0.9" ambient="0.3 0.3 0.3" specular="0 0 0" />
13+
<map force="0.1" zfar="30" />
14+
<rgba haze="0.15 0.25 0.35 1" />
15+
<quality shadowsize="4096" />
16+
<global offwidth="800" offheight="800" />
17+
</visual>
18+
19+
<worldbody>
20+
<geom name="floor" size="20 20 .05" type="plane" material="grid" condim="3" />
21+
<light directional="false" diffuse=".2 .2 .2" specular="0 0 0" pos="0 0 5" dir="0 0 -1" />
22+
<flexcomp name="cube" type="gmsh" dim="3" rgba=".8 .2 .2 1" radius="0.001" pos="0 0 4" mass="10"
23+
scale="1 1 1" file="malformed_cube_41_ascii_mismatch_between_max_nodes_and_nodes_in_block.msh">
24+
<edge equality="true" />
25+
</flexcomp>
26+
</worldbody>
27+
</mujoco>

test/user/user_flex_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@ TEST_F(UserFlexTest, LoadMSHASCII_41_MissingElement_Fail) {
697697
mj_deleteModel(m);
698698
}
699699

700+
TEST_F(UserFlexTest,
701+
LoadMSHASCII_41_MismatchBetweenMaxNodesAndNodesInBlock_Fail) {
702+
const std::string xml_path =
703+
GetTestDataFilePath(
704+
"user/testdata/malformed_cube_41_ascii_mismatch_between_max_nodes_and_nodes_in_block.xml");
705+
std::array<char, 1024> error;
706+
mjModel* m = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size());
707+
EXPECT_THAT(error.data(), HasSubstr(
708+
"XML Error: Error: Maximum number of nodes must be equal to number of nodes in a block\nElement 'flexcomp', line 22\n"));
709+
mj_deleteModel(m);
710+
}
711+
700712
TEST_F(UserFlexTest, LoadMSHASCII_22_MissingNumNodes_Fail) {
701713
const std::string xml_path =
702714
GetTestDataFilePath(

0 commit comments

Comments
 (0)