Allium  0.1.0
local_mesh.hpp
1 // Copyright 2021 Hannah Rittich
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ALLIUM_MESH_LOCAL_MESH_HPP
16 #define ALLIUM_MESH_LOCAL_MESH_HPP
17 
18 #include <vector>
19 #include "range.hpp"
20 
21 namespace allium {
22 
26 template <typename N, int D>
27 class LocalMesh
28 {
29  public:
30  using Number = N;
31 
32  LocalMesh(Range<D> range)
33  : m_range(range),
34  m_entries(range.size())
35  {}
36 
37  N& operator[] (Point<int, D> pos) {
38  return m_entries[m_range.index(pos)];
39  }
40 
41  const N& operator[] (Point<int, D> pos) const {
42  return const_cast<LocalMesh&>(*this)[pos];
43  }
44 
45  template <typename ...Args>
46  N& operator() (Args ...args) {
47  return (*this)[Point<int, D>({args...})];
48  }
49 
50  template <typename ...Args>
51  const N& operator() (Args ...args) const {
52  return (*this)[Point<int, D>({args...})];
53  }
54 
55  Range<D> range() const { return m_range; }
56 
57  Number* data() { return m_entries.data(); }
58  const Number* data() const { return m_entries.data(); }
59  private:
60  Range<D> m_range;
61  std::vector<Number> m_entries;
62 };
63 
64 }
65 
66 #endif
A mesh stored locally on the current processor.
Definition: local_mesh.hpp:28
An n-d range.
Definition: range.hpp:28
size_t size() const
Definition: range.hpp:85