ThunderEgg  1.0.0
ComponentArray.h
Go to the documentation of this file.
1 /***************************************************************************
2  * ThunderEgg, a library for solvers on adaptively refined block-structured
3  * Cartesian grids.
4  *
5  * Copyright (c) 2021 Scott Aiton
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <https://www.gnu.org/licenses/>.
19  ***************************************************************************/
20 
21 #ifndef THUNDEREGG_COMPONENTARRAY_H
22 #define THUNDEREGG_COMPONENTARRAY_H
29 namespace ThunderEgg {
35 template<int D>
37 {
38 private:
39  std::vector<double> vector;
41 
42 public:
49  ComponentArray(const std::array<int, D>& lengths, int num_ghost_cells)
50  {
51  std::array<int, D> strides;
52  strides[0] = 1;
53  for (int i = 1; i < D; i++) {
54  strides[i] = strides[i - 1] * (lengths[i - 1] + 2 * num_ghost_cells);
55  }
56  int size = strides[D - 1] * (lengths[D - 1] + 2 * num_ghost_cells);
57  vector.resize(size);
58  view = ComponentView<double, D>(vector.data(), strides, lengths, num_ghost_cells);
59  }
60 
67  : vector(other.vector)
68  , view(vector.data(),
69  other.getStrides(),
70  other.getGhostStart(),
71  other.getStart(),
72  other.getEnd(),
73  other.getGhostEnd())
74 
75  {}
76 
84  {
85  vector = other.vector;
86  view = ComponentView<double, D>(vector.data(),
87  other.getStrides(),
88  other.getGhostStart(),
89  other.getStart(),
90  other.getEnd(),
91  other.getGhostEnd());
92  return *this;
93  }
103  template<int M>
104  inline View<double, M> getSliceOn(Face<D, M> f, const std::array<int, D - M>& offset)
105  {
106  return view.template getSliceOn<M>(f, offset);
107  }
108 
118  template<int M>
119  inline View<const double, M> getSliceOn(Face<D, M> f, const std::array<int, D - M>& offset) const
120  {
121  return View<const double, M>(view.template getSliceOn<M>(f, offset));
122  }
123 
133  template<int M>
135  const std::array<size_t, D - M>& offset) const
136  {
137  return view.template getGhostSliceOn<M>(f, offset);
138  }
139 
140  inline const double& operator[](const std::array<int, D>& coord) const { return view[coord]; }
141  template<class... Types>
142  inline const double& operator()(Types... args) const
143  {
144  return view(args...);
145  }
146  inline void set(const std::array<int, D>& coord, double value) const { view.set(coord, value); }
147  inline double& operator[](const std::array<int, D>& coord) { return view[coord]; }
148  template<class... Types>
149  inline double& operator()(Types... args)
150  {
151  return view(args...);
152  }
153  inline void set(const std::array<int, D>& coord, double value) { view.set(coord, value); }
154 
158  inline const std::array<int, D>& getStrides() const { return view.getStrides(); }
162  inline const std::array<int, D>& getStart() const { return view.getStart(); }
166  inline const std::array<int, D>& getEnd() const { return view.getEnd(); }
170  inline const std::array<int, D>& getGhostStart() const { return view.getGhostStart(); }
174  inline const std::array<int, D>& getGhostEnd() const { return view.getGhostEnd(); }
175 };
176 extern template class ComponentArray<1>;
177 extern template class ComponentArray<2>;
178 extern template class ComponentArray<3>;
179 } // namespace ThunderEgg
180 #endif
ThunderEgg::View
Array for acessing data of a patch. It supports variable striding.
Definition: View.h:40
ThunderEgg::ComponentArray::ComponentArray
ComponentArray(const ComponentArray< D > &other)
Copy constructor.
Definition: ComponentArray.h:66
ThunderEgg::View::getStrides
const std::array< int, D > & getStrides() const
Get the strides of the patch in each direction.
Definition: View.h:203
ThunderEgg::ComponentArray::getSliceOn
View< double, M > getSliceOn(Face< D, M > f, const std::array< int, D - M > &offset)
Get the slice on a given face.
Definition: ComponentArray.h:104
ThunderEgg::ComponentArray::operator=
ComponentArray< D > & operator=(const ComponentArray< D > &other)
Copy assignment.
Definition: ComponentArray.h:83
ThunderEgg::ComponentArray::getGhostSliceOn
View< double, M > getGhostSliceOn(Face< D, M > f, const std::array< size_t, D - M > &offset) const
Get the gosts slice on a given face.
Definition: ComponentArray.h:134
ThunderEgg::ComponentArray::getStart
const std::array< int, D > & getStart() const
Get the coordinate of the first element.
Definition: ComponentArray.h:162
ThunderEgg::View::getGhostStart
const std::array< int, D > & getGhostStart() const
Get the coordinate of the first ghost cell element.
Definition: View.h:215
ThunderEgg::ComponentView< double, D >
ThunderEgg::ComponentArray::ComponentArray
ComponentArray(const std::array< int, D > &lengths, int num_ghost_cells)
Construct a new View object.
Definition: ComponentArray.h:49
ThunderEgg
The ThunderEgg namespace.
Definition: BiLinearGhostFiller.h:31
ThunderEgg::ComponentArray
Array for acessing data of a patch. It supports variable striding.
Definition: ComponentArray.h:36
ThunderEgg::View::getEnd
const std::array< int, D > & getEnd() const
Get the coordinate of the last element.
Definition: View.h:211
ThunderEgg::ComponentArray::getEnd
const std::array< int, D > & getEnd() const
Get the coordinate of the last element.
Definition: ComponentArray.h:166
ThunderEgg::ComponentArray::getGhostStart
const std::array< int, D > & getGhostStart() const
Get the coordinate of the first ghost cell element.
Definition: ComponentArray.h:170
ThunderEgg::View::set
void set(const std::array< int, D > &coord, T value) const
Set the value at a coordinate to the specified value.
Definition: View.h:174
ComponentView.h
ComponentView class.
ThunderEgg::ComponentArray::getGhostEnd
const std::array< int, D > & getGhostEnd() const
Get the coordinate of the last ghost cell element.
Definition: ComponentArray.h:174
ThunderEgg::ComponentArray::getSliceOn
View< const double, M > getSliceOn(Face< D, M > f, const std::array< int, D - M > &offset) const
Get the slice on a given face.
Definition: ComponentArray.h:119
ThunderEgg::Face
Enum-style class for the faces of an n-dimensional cube.
Definition: Face.h:41
ThunderEgg::ComponentArray::getStrides
const std::array< int, D > & getStrides() const
Get the strides of the patch in each direction.
Definition: ComponentArray.h:158
ThunderEgg::View::getGhostEnd
const std::array< int, D > & getGhostEnd() const
Get the coordinate of the last ghost cell element.
Definition: View.h:219
ThunderEgg::View::getStart
const std::array< int, D > & getStart() const
Get the coordinate of the first element.
Definition: View.h:207