MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_mesh.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 // MAST includes
21 #include "base/mast_data_types.h"
22 #include "catch.hpp"
23 
24 // Test includes
25 #include "test_helpers.h"
26 #include "base/mast_mesh.h"
27 
28 
29 TEST_CASE("libmesh_mesh_generation_1d",
30  "[mesh][1D]")
31 {
32  RealMatrixX coords = RealMatrixX::Zero(3, 2);
33  coords << -1.0, 1.0, 0.0,
34  0.0, 0.0, 0.0;
35 
36  SECTION("Creation of a single 2-node 1D element (EDGE2) in a libMesh::ReplicatedMesh")
37  {
38  TEST::TestMeshSingleElement test_mesh(libMesh::EDGE2, coords);
39  // Compare element against true volume (actually length for 1D elements)
40  REQUIRE(test_mesh.reference_elem->volume() == 2.0);
41  }
42 }
43 
44 
45 TEST_CASE("libmesh_mesh_generation_2d",
46  "[mesh],[2D]")
47 {
48  RealMatrixX coords = RealMatrixX::Zero(3,4);
49  coords << -1.0, 1.0, 1.0, -1.0,
50  -1.0, -1.0, 1.0, 1.0,
51  0.0, 0.0, 0.0, 0.0;
52 
53  SECTION("Creation of a single 4-node 2D element (QUAD4) in a libMesh::ReplicatedMesh")
54  {
55  TEST::TestMeshSingleElement test_mesh(libMesh::QUAD4, coords);
56  // Compare element against true volume (actually area for 2D elements)
57  const Real true_volume = TEST::get_shoelace_area(coords);
58  REQUIRE(test_mesh.reference_elem->volume() == true_volume);
59  }
60 
61  // TODO Need to test distributed mesh generation as well.
62  // Note this will require some special consideration to account for actual
63  // parallel nature of the mesh.
64 }
libMesh::Elem * reference_elem
Pointer to the actual libMesh element object.
Definition: mast_mesh.h:51
Storage class for a mesh consisting of a single element used in testing.
Definition: mast_mesh.h:46
Real get_shoelace_area(RealMatrixX X)
Calcualtes the area of a 2D polygon using the shoelace formula.
libMesh::Real Real
Matrix< Real, Dynamic, Dynamic > RealMatrixX
TEST_CASE("libmesh_mesh_generation_1d", "[mesh][1D]")
Definition: mast_mesh.cpp:29