MAST3
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
indexing.hpp
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 __mast_material_point_libmesh_indexing_h__
21 #define __mast_material_point_libmesh_indexing_h__
22 
23 // MAST includes
25 #include <mast/base/exceptions.hpp>
26 
27 // libMesh includes
28 #include <libmesh/mesh_base.h>
29 
30 namespace MAST {
31 namespace Base {
32 namespace MaterialPoint {
33 namespace libMeshWrapper {
34 
41 class Indexing {
42 
43 public:
44 
46  _initialized (false),
47  _mesh (nullptr),
48  _n_points (0),
49  _begin_local_id (0),
50  _end_local_id (0) {
51 
52  }
53 
54  virtual ~Indexing() { }
55 
56  inline uint_t n_local_points() const {
57 
58  Assert0(_initialized, "Object must be initialized");
60  }
61 
62  inline void init(const libMesh::MeshBase &mesh, uint_t n_points_per_elem) {
63 
64  Assert0(!_initialized, "Object already initialized");
65 
66  _mesh = &mesh;
67  _n_points = n_points_per_elem;
68 
69  libMesh::MeshBase::const_element_iterator
70  it = mesh.active_local_elements_begin(),
71  end = mesh.active_local_elements_end();
72 
73  for ( ; it != end; it++) {
74 
75  const libMesh::Elem* e = *it;
77  _end_local_id += n_points_per_elem;
78  }
79 
80  uint_t
81  comm_rank = mesh.comm().rank(),
82  comm_size = mesh.comm().size();
83 
84 
85  std::vector<uint_t>
86  n_ids_on_rank(comm_size);
87 
88  // number of points on this rank
89  n_ids_on_rank[comm_rank] = _end_local_id;
90 
91  mesh.comm().sum(n_ids_on_rank);
92 
93  for (uint_t i=1; i<comm_size; i++)
94  n_ids_on_rank[i] += n_ids_on_rank[i-1];
95 
96  if (comm_rank > 0)
97  _begin_local_id = n_ids_on_rank[comm_rank-1];
98  _end_local_id = n_ids_on_rank[comm_rank];
99 
100  _initialized = true;
101  }
102 
103  inline uint_t
104  local_id_for_point_on_elem(const libMesh::Elem *e,
105  uint_t i) const {
106 
107  Assert0(_initialized, "Object must be initialized");
108  Assert2(i < _n_points, i, _n_points,
109  "Index must be less than points per element");
110 
111  std::map<const libMesh::Elem*, uint_t>::const_iterator
112  it = _elem_id_map.find(e);
113 
114  Assert0( it != _elem_id_map.end(), "Element not in map");
115 
116  return it->second + i;
117  }
118 
119 
120  inline uint_t
121  global_id_for_point_on_elem(const libMesh::Elem *e,
122  uint_t i) const {
123 
124  return _begin_local_id + this->local_id_for_point_on_elem(e, i);
125  }
126 
127 private:
128 
130  const libMesh::MeshBase *_mesh;
134  std::map<const libMesh::Elem*, uint_t> _elem_id_map;
135 };
136 
137 } // namespace libMeshWrapper
138 } // namespace MaterialPoint
139 } // namespace Base
140 } // namespace MAST
141 
142 #endif // __mast_material_point_libmesh_indexing_h__
indexes the material point ID to quadrature points on each element.
Definition: indexing.hpp:41
uint_t local_id_for_point_on_elem(const libMesh::Elem *e, uint_t i) const
Definition: indexing.hpp:104
#define Assert0(cond, msg)
Definition: exceptions.hpp:134
std::map< const libMesh::Elem *, uint_t > _elem_id_map
Definition: indexing.hpp:134
unsigned int uint_t
#define Assert2(cond, v1, v2, msg)
Definition: exceptions.hpp:152
uint_t global_id_for_point_on_elem(const libMesh::Elem *e, uint_t i) const
Definition: indexing.hpp:121
void init(const libMesh::MeshBase &mesh, uint_t n_points_per_elem)
Definition: indexing.hpp:62