Detect mismatch between maxNodes and Nodes in a gmsh block. Fixes #2342

PiperOrigin-RevId: 745967745
Change-Id: If1b5fcd71079a0e6a6def9b442758678e31a5828
This commit is contained in:
Mohammad Hamid
2025-04-10 04:14:34 -07:00
committed by Copybara-Service
parent eadd13038a
commit 3429a4881a
4 changed files with 111 additions and 0 deletions
+5
View File
@@ -1167,6 +1167,11 @@ void mjCFlexcomp::LoadGMSH41(char* buffer, int binary, int nodeend,
throw mjCError(NULL, "All nodes must be in single block");
}
// require maximum number of nodes be equal to maximum number of nodes in a block
if (maxNodeTag != numNodesInBlock){
throw mjCError(NULL, "Maximum number of nodes must be equal to number of nodes in a block");
}
// check dimensionality and save
if (entityDim < 1 || entityDim > 3) {
throw mjCError(NULL, "Entity must be 1D, 2D or 3D");
@@ -0,0 +1,67 @@
$MeshFormat
4.1 0 8
$EndMeshFormat
$Entities
0 0 0 1
1 -0.5 -0.5 0 0.5 0.5 1 0 0
$EndEntities
$Nodes
1 14 1 100
3 1 0 14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
-0.5 -0.5 0
0.5 -0.5 0
0.5 0.5 0
-0.5 0.5 0
-0.5 -0.5 1
0.5 -0.5 1
0.5 0.5 1
-0.5 0.5 1
0 0 0
0 -0.5 0.5
0.5 0 0.5
0 0.5 0.5
-0.5 0 0.5
0 0 1
$EndNodes
$Elements
1 24 1 24
3 1 4 24
1 10 9 12 11
2 10 12 13 14
3 9 10 12 13
4 10 12 14 11
5 9 10 1 2
6 7 11 12 3
7 4 1 9 13
8 13 12 4 8
9 1 10 13 5
10 13 8 5 14
11 12 8 14 7
12 14 5 10 6
13 14 6 11 7
14 9 4 12 3
15 3 11 9 2
16 11 6 10 2
17 6 10 14 11
18 1 10 9 13
19 12 4 9 13
20 5 10 13 14
21 8 13 12 14
22 12 14 11 7
23 9 12 11 3
24 10 9 11 2
$EndElements
@@ -0,0 +1,27 @@
<mujoco model="gmsh">
<option timestep="0.01" integrator="implicitfast" solver="CG" />
<asset>
<texture type="skybox" builtin="gradient" rgb1=".3 .5 .7" rgb2="0 0 0" width="512" height="512" />
<texture name="grid" type="2d" builtin="checker" width="512" height="512" rgb1=".1 .2 .3"
rgb2=".2 .3 .4" />
<material name="grid" texture="grid" texrepeat="1 1" texuniform="true" reflectance=".2" />
</asset>
<visual>
<headlight diffuse="0.9 0.9 0.9" ambient="0.3 0.3 0.3" specular="0 0 0" />
<map force="0.1" zfar="30" />
<rgba haze="0.15 0.25 0.35 1" />
<quality shadowsize="4096" />
<global offwidth="800" offheight="800" />
</visual>
<worldbody>
<geom name="floor" size="20 20 .05" type="plane" material="grid" condim="3" />
<light directional="false" diffuse=".2 .2 .2" specular="0 0 0" pos="0 0 5" dir="0 0 -1" />
<flexcomp name="cube" type="gmsh" dim="3" rgba=".8 .2 .2 1" radius="0.001" pos="0 0 4" mass="10"
scale="1 1 1" file="malformed_cube_41_ascii_mismatch_between_max_nodes_and_nodes_in_block.msh">
<edge equality="true" />
</flexcomp>
</worldbody>
</mujoco>
+12
View File
@@ -697,6 +697,18 @@ TEST_F(UserFlexTest, LoadMSHASCII_41_MissingElement_Fail) {
mj_deleteModel(m);
}
TEST_F(UserFlexTest,
LoadMSHASCII_41_MismatchBetweenMaxNodesAndNodesInBlock_Fail) {
const std::string xml_path =
GetTestDataFilePath(
"user/testdata/malformed_cube_41_ascii_mismatch_between_max_nodes_and_nodes_in_block.xml");
std::array<char, 1024> error;
mjModel* m = mj_loadXML(xml_path.c_str(), 0, error.data(), error.size());
EXPECT_THAT(error.data(), HasSubstr(
"XML Error: Error: Maximum number of nodes must be equal to number of nodes in a block\nElement 'flexcomp', line 22\n"));
mj_deleteModel(m);
}
TEST_F(UserFlexTest, LoadMSHASCII_22_MissingNumNodes_Fail) {
const std::string xml_path =
GetTestDataFilePath(