Schnek
field.hpp
1 /*
2  * field.hpp
3  *
4  * Created on: 14 May 2012
5  * Author: Holger Schmitz
6  * Email: holger@notjustphysics.com
7  *
8  * Copyright 2012 Holger Schmitz
9  *
10  * This file is part of Schnek.
11  *
12  * Schnek is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation, either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * Schnek is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with Schnek. If not, see <http://www.gnu.org/licenses/>.
24  *
25  */
26 
27 #ifndef SCHNEK_FIELD_HPP_
28 #define SCHNEK_FIELD_HPP_
29 
30 #include "range.hpp"
31 #include "grid.hpp"
32 
33 namespace schnek {
34 
35 template<
36  typename T,
37  size_t rank,
38  template<size_t> class CheckingPolicy = GridNoArgCheck,
39  template<typename, size_t> class StoragePolicy = SingleArrayGridStorage
40 >
41 class Field : public Grid<T, rank, CheckingPolicy, StoragePolicy>
42 {
43  public:
44  typedef T value_type;
46  typedef typename Range<double, rank>::LimitType RangeLimit;
47  typedef Array<bool, rank> Stagger;
50  typedef typename BaseType::IndexType IndexType;
51  typedef typename BaseType::RangeType RangeType;
52  private:
53  DomainType domain;
54  Stagger stagger;
55  int ghostCells;
56  public:
58  Field();
59 
63  template<
64  template<size_t> class ArrayCheckingPolicy,
65  template<size_t> class RangeCheckingPolicy,
66  template<size_t> class StaggerCheckingPolicy>
67  Field(
71  int ghostCells
72  );
73 
74  template<
75  template<size_t> class ArrayCheckingPolicy,
76  template<size_t> class RangeCheckingPolicy,
77  template<size_t> class StaggerCheckingPolicy>
78  Field(
83  int ghostCells
84  );
85 
86  template<
87  template<size_t> class ArrayCheckingPolicy,
88  template<size_t> class RangeCheckingPolicy,
89  template<size_t> class StaggerCheckingPolicy>
90  Field(
94  int ghostCells
95  );
96 
98  Field(const FieldType&);
99 
101  IndexType getInnerLo() { return this->getLo() + ghostCells; }
102 
104  IndexType getInnerHi() { return this->getHi() - ghostCells; }
105 
107  RangeType getInnerRange() { return RangeType{this->getLo() + ghostCells, this->getHi() - ghostCells}; }
108 
113  void positionToIndex(int dim, double pos, int &index, double &offset);
114 
119  int positionToIndex(int dim, double pos);
120 
122  double indexToPosition(int dim, int index);
123 
125  Stagger& getStagger() { return stagger; }
126 
128  bool getStagger(int i) { return stagger[i]; }
129 
133  const DomainType& getDomain() { return domain; }
134 
138  FieldType &operator=(const FieldType&) = default;
139 
141  FieldType& operator=(const T &val)
142  {
143  BaseType::operator=(val);
144  return *this;
145  }
146 
150  template<
151  template<size_t> class ArrayCheckingPolicy,
152  template<size_t> class RangeCheckingPolicy,
153  template<size_t> class StaggerCheckingPolicy>
154  void resize(
158  int ghostCells
159  );
160 
161  template<
162  template<size_t> class ArrayCheckingPolicy,
163  template<size_t> class RangeCheckingPolicy,
164  template<size_t> class StaggerCheckingPolicy>
165  void resize(
170  int ghostCells
171  );
172 
173  template<
174  template<size_t> class ArrayCheckingPolicy,
175  template<size_t> class RangeCheckingPolicy,
176  template<size_t> class StaggerCheckingPolicy>
177  void resize(
181  int ghostCells
182  );
183 
184 };
185 
186 } //namespace
187 
188 #include "field.t"
189 
190 #endif // SCHNEK_FIELD_HPP_
Definition: field.hpp:41
RangeType getInnerRange()
Definition: field.hpp:107
IndexType getInnerLo()
Definition: field.hpp:101
double indexToPosition(int dim, int index)
Calculates the position of a grid point.
IndexType getInnerHi()
Definition: field.hpp:104
GridType & operator=(const T &val)
Definition: grid.hpp:335
Definition: algo.hpp:30
const DomainType & getDomain()
Get the physical domain of the field.
Definition: field.hpp:133
void resize(const Array< int, rank, ArrayCheckingPolicy > &size, const Range< double, rank, RangeCheckingPolicy > &domain, const Array< bool, rank, StaggerCheckingPolicy > &stagger, int ghostCells)
FieldType & operator=(const FieldType &)=default
Assignment operator.
Stagger & getStagger()
Get all three components of the grid stagger.
Definition: field.hpp:125
FieldType & operator=(const T &val)
Definition: field.hpp:141
A multidimensional grid that stores simple data.
Definition: grid.hpp:260
void positionToIndex(int dim, double pos, int &index, double &offset)
bool getStagger(int i)
Get a single component of the grid stagger.
Definition: field.hpp:128