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  int rank,
38  template<int> class CheckingPolicy = GridNoArgCheck,
39  template<typename, int> 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 GridBase<T, rank, CheckingPolicy<rank>, StoragePolicy<T,rank> > BaseType;
51  private:
52  RangeType range;
53  Stagger stagger;
54  int ghostCells;
55  public:
57  Field();
58 
62  template<
63  template<int> class ArrayCheckingPolicy,
64  template<int> class RangeCheckingPolicy,
65  template<int> class StaggerCheckingPolicy>
68  const Array<bool, rank, StaggerCheckingPolicy> &stagger_, int ghostCells_);
69 
70  template<
71  template<int> class ArrayCheckingPolicy,
72  template<int> class RangeCheckingPolicy,
73  template<int> class StaggerCheckingPolicy>
77  const Array<bool, rank, StaggerCheckingPolicy> &stagger_, int ghostCells_);
78 
80  Field(const FieldType&);
81 
83  IndexType getInnerLo() {return this->getLo()+ghostCells;}
84 
86  IndexType getInnerHi() {return this->getHi()-ghostCells;}
87 
92  void positionToIndex(int dim, double pos, int &index, double &offset);
93 
98  int positionToIndex(int dim, double pos);
99 
101  double indexToPosition(int dim, int index);
102 
104  Stagger& getStagger() { return stagger; }
105 
107  bool getStagger(int i) { return stagger[i]; }
108 
110  FieldType& operator=(const T &val)
111  {
112  BaseType::operator=(val);
113  return *this;
114  }
115 
117  FieldType& operator=(const FieldType &grid)
118  {
119  BaseType::operator=(grid);
120  range = grid.range;
121  stagger = grid.stagger;
122  ghostCells = grid.ghostCells;
123  return *this;
124  }
125 
127  template<
128  typename T2,
129  template<int> class CheckingPolicy2,
130  template<typename, int> class StoragePolicy2
131  >
133  {
134  BaseType::operator=(grid);
135  range = grid.range;
136  stagger = grid.stagger;
137  ghostCells = grid.ghostCells;
138  return *this;
139  }
140 
142  template<
143  typename T2,
144  class CheckingPolicy2,
145  class StoragePolicy2
146  >
148  {
149  BaseType::operator=(grid);
150  return *this;
151  }
152 
156  template<
157  template<int> class ArrayCheckingPolicy,
158  template<int> class RangeCheckingPolicy,
159  template<int> class StaggerCheckingPolicy>
162  const Array<bool, rank, StaggerCheckingPolicy> &stagger_, int ghostCells_);
163 
164  template<
165  template<int> class ArrayCheckingPolicy,
166  template<int> class RangeCheckingPolicy,
167  template<int> class StaggerCheckingPolicy>
171  const Array<bool, rank, StaggerCheckingPolicy> &stagger_, int ghostCells_);
172 
173 };
174 
175 } //namespace
176 
177 #include "field.t"
178 
179 #endif // SCHNEK_FIELD_HPP_
Definition: field.hpp:41
IndexType getInnerLo()
Definition: field.hpp:83
Definition: grid.hpp:54
double indexToPosition(int dim, int index)
Calculates the position of a grid point.
FieldType & operator=(const FieldType &grid)
Definition: field.hpp:117
IndexType getInnerHi()
Definition: field.hpp:86
FieldType & operator=(const Field< T2, rank, CheckingPolicy2, StoragePolicy2 > &grid)
Definition: field.hpp:132
GridBase< T, rank, CheckingPolicy< rank >, StoragePolicy< T, rank > > & operator=(const GridBase< T, rank, CheckingPolicy< rank >, StoragePolicy< T, rank > > &)
Definition: algo.hpp:30
void resize(const Array< int, rank, ArrayCheckingPolicy > &size, const Range< double, rank, RangeCheckingPolicy > &range_, const Array< bool, rank, StaggerCheckingPolicy > &stagger_, int ghostCells_)
FieldType & operator=(const GridBase< T2, rank, CheckingPolicy2, StoragePolicy2 > &grid)
Definition: field.hpp:147
Stagger & getStagger()
Get all three components of the grid stagger.
Definition: field.hpp:104
FieldType & operator=(const T &val)
Definition: field.hpp:110
Definition: grid.hpp:235
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:107