MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_mesh.h
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 #ifndef __test__mast_mesh__
21 #define __test__mast_mesh__
22 
23 // MAST includes
24 #include "base/mast_data_types.h"
25 
26 // libMesh includes
27 #include "libmesh/libmesh.h"
28 #include "libmesh/replicated_mesh.h"
29 #include "libmesh/distributed_mesh.h"
30 #include "libmesh/face_quad4.h"
31 #include "libmesh/edge_edge2.h"
32 
33 // Test includes
34 #include "catch.hpp"
35 #include "test_helpers.h"
36 
37 extern libMesh::LibMeshInit* p_global_init;
38 
39 namespace TEST {
40 
47  public:
48  int n_elems;
49  int n_nodes;
50  int n_dim;
51  libMesh::Elem* reference_elem;
52  libMesh::ReplicatedMesh mesh;
53  // Convert this to pointer to enable both Replicated/Distributed Mesh
54  // libMesh::UnstructuredMesh* mesh;
55  // ---> currently can't run this with DistributedMesh. On second processor this.reference_elem doesn't exist!
56 
68  TestMeshSingleElement(libMesh::ElemType e_type, RealMatrixX& coordinates):
69  mesh(p_global_init->comm()) {
70  n_elems = 1;
71  n_nodes = coordinates.cols();
72 
73  mesh.reserve_elem(n_elems);
74  mesh.reserve_nodes(n_nodes);
75  mesh.set_spatial_dimension(3);
76 
77  for (auto i = 0; i < n_nodes; i++) {
78  mesh.add_point(libMesh::Point(coordinates(0,i),coordinates(1,i), coordinates(2,i)), i, 0);
79  }
80 
81  switch (e_type) {
82  case libMesh::EDGE2:
83  n_dim = 1;
84  reference_elem = new libMesh::Edge2;
85  break;
86  case libMesh::QUAD4:
87  n_dim = 2;
88  reference_elem = new libMesh::Quad4;
89  break;
90  default:
91  libmesh_error_msg("Invalid element type; " << __PRETTY_FUNCTION__
92  << " in " << __FILE__ << " at line number " << __LINE__);
93  }
94 
95  mesh.set_mesh_dimension(n_dim);
96  reference_elem->set_id(0);
97  reference_elem->subdomain_id() = 0;
98  reference_elem = mesh.add_elem(reference_elem);
99 
100  for (int i=0; i<n_nodes; i++) {
101  reference_elem->set_node(i) = mesh.node_ptr(i);
102  }
103 
104  mesh.prepare_for_use();
105  };
106 
113  void update_coordinates(RealMatrixX& new_coordinates) {
114  for (int i=0; i<n_nodes; i++)
115  {
116  *mesh.node_ptr(i) = libMesh::Point(new_coordinates(0,i), new_coordinates(1,i), new_coordinates(2,i));
117  }
118  };
119  };
120 } // TEST namespace
121 
122 #endif // __test__mast_mesh__
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
int n_nodes
Number of nodes per element in the test mesh.
Definition: mast_mesh.h:49
Definition: mast_mesh.h:39
Matrix< Real, Dynamic, Dynamic > RealMatrixX
libMesh::LibMeshInit * p_global_init
Definition: init_catch2.cpp:26
int n_dim
Dimension of the test element (1, 2, 3)
Definition: mast_mesh.h:50
TestMeshSingleElement(libMesh::ElemType e_type, RealMatrixX &coordinates)
Construct a single element mesh using the specified type and nodal coordinates.
Definition: mast_mesh.h:68
int n_elems
Number of elements in the test mesh.
Definition: mast_mesh.h:48
void update_coordinates(RealMatrixX &new_coordinates)
Update the nodal coordinates in the mesh.
Definition: mast_mesh.h:113
libMesh::ReplicatedMesh mesh
The actual libMesh mesh object.
Definition: mast_mesh.h:52