From bd4623a2a3eade3ce15539ba75fbcf6d1cb0b1b4 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 25 Sep 2021 19:42:00 -0500 Subject: [PATCH] [Mesh] Improve unit tests Add a test for the CTRIA3 element, and add code to check the used nodes and cancel the file load if they don't all exist. --- src/Mod/Mesh/App/Core/MeshIO.cpp | 22 +++++++++++++++++- src/Mod/Mesh/App/MeshTestsApp.py | 5 ++++ .../TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf | 10 ++++---- .../App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf | 23 +++++++++++++++++++ src/Mod/Mesh/CMakeLists.txt | 1 + 5 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 src/Mod/Mesh/App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf diff --git a/src/Mod/Mesh/App/Core/MeshIO.cpp b/src/Mod/Mesh/App/Core/MeshIO.cpp index cb23619c94..0d5328395c 100644 --- a/src/Mod/Mesh/App/Core/MeshIO.cpp +++ b/src/Mod/Mesh/App/Core/MeshIO.cpp @@ -1808,7 +1808,27 @@ bool MeshInput::LoadNastran (std::istream &rstrIn) } if (badElementCounter > 0) { - Base::Console().Warning("Found bad elements while reading NASTRAN file."); + Base::Console().Warning("Found bad elements while reading NASTRAN file.\n"); + } + + // Check the triangles to make sure the vertices they refer to actually exist: + for (const auto& tri : mTria) { + for (int i = 0; i < 3; ++i) { + if (mNode.find(tri.second.iV[i]) == mNode.end()) { + Base::Console().Error("CTRIA3 element refers to a node that does not exist, or could not be read.\n"); + return false; + } + } + } + + // Check the quads to make sure the vertices they refer to actually exist: + for (const auto& quad : mQuad) { + for (int i = 0; i < 4; ++i) { + if (mNode.find(quad.second.iV[i]) == mNode.end()) { + Base::Console().Error("CQUAD4 element refers to a node that does not exist, or could not be read.\n"); + return false; + } + } } float fLength[2]; diff --git a/src/Mod/Mesh/App/MeshTestsApp.py b/src/Mod/Mesh/App/MeshTestsApp.py index 7d932b9484..9091e4d74e 100644 --- a/src/Mod/Mesh/App/MeshTestsApp.py +++ b/src/Mod/Mesh/App/MeshTestsApp.py @@ -356,5 +356,10 @@ class NastranReader(unittest.TestCase): self.assertEqual(m.CountPoints,4) self.assertEqual(m.CountFacets,2) # Quads split into two triangles + def testCTRIA3Element(self): + m = Mesh.read(f"{self.test_dir}/NASTRAN_Test_GRID_CTRIA3.bdf") + self.assertEqual(m.CountPoints,3) + self.assertEqual(m.CountFacets,1) + def tearDown(self): pass diff --git a/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf b/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf index 5891b060c5..589d3d45e2 100644 --- a/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf +++ b/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf @@ -16,14 +16,14 @@ $ Case control section $------------------------------------------------------------------------------- MAXLINES = 1000000 TITLE = TESTCASE -SUBTITLE = Test case for FreeCAD Mesh NASTRAN input +SUBTITLE = Test case for FreeCAD Mesh NASTRAN input -GRID* 1 0.00000000000000-1. +GRID* 1 0.00000000000000-1. * 0. -GRID* 2 1.00000000000000-1. +GRID* 2 1.00000000000000-1. * 0. -GRID* 3 0.000000000000001. +GRID* 3 0.000000000000001. * 0. -GRID* 4 1.000000000000001. +GRID* 4 1.000000000000001. * 0. CQUAD4 1 400 1 2 4 3 diff --git a/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf b/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf new file mode 100644 index 0000000000..3b98056097 --- /dev/null +++ b/src/Mod/Mesh/App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf @@ -0,0 +1,23 @@ +$------------------------------------------------------------------------------- +$ Nastran case control file +$ Part of the FreeCAD unit test system. Tests the CTRIA3 grid element. +$------------------------------------------------------------------------------- +$ Exec control section +$------------------------------------------------------------------------------- +ID TESTCASE,Nastran +APP DISP +SOL 1 +TIME 20 +CEND +$------------------------------------------------------------------------------- +$ Case control section +$------------------------------------------------------------------------------- +MAXLINES = 1000000 +TITLE = TESTCASE +SUBTITLE = Test case for FreeCAD Mesh NASTRAN input + +GRID 1 0.00E+000.00E+000.00E+00 +GRID 2 0.00E+001.0000000.00E+00 +GRID 3 1.00E+001.0000000.00E+00 +CTRIA3 1 400 1 2 3 +ENDDATA diff --git a/src/Mod/Mesh/CMakeLists.txt b/src/Mod/Mesh/CMakeLists.txt index c53218a8c1..55da64b28e 100644 --- a/src/Mod/Mesh/CMakeLists.txt +++ b/src/Mod/Mesh/CMakeLists.txt @@ -14,6 +14,7 @@ set(MeshTestDataFiles App/TestData/NASTRAN_Test_GRID_CQUAD4.bdf App/TestData/NASTRAN_Test_Delimited_GRID_CQUAD4.bdf App/TestData/NASTRAN_Test_GRIDSTAR_CQUAD4.bdf + App/TestData/NASTRAN_Test_GRID_CTRIA3.bdf ) if(BUILD_GUI)