Schnek
fieldtools.hpp
1 /*
2  * fieldtools.hpp
3  *
4  * Created on: 31 Aug 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_FIELDTOOLS_HPP_
28 #define SCHNEK_FIELDTOOLS_HPP_
29 
30 #include "../grid/field.hpp"
31 #include "../variables/dependencies.hpp"
32 
33 namespace schnek {
34 
35 template<
36  typename T,
37  int rank,
38  template<int> class GridCheckingPolicy,
39  template<int> class ArrayCheckingPolicy,
40  template<typename, int> class StoragePolicy
41 >
42 void fill_field(
43  Field<T, rank, GridCheckingPolicy, StoragePolicy> &field,
44  Array<double, rank, ArrayCheckingPolicy> &coords,
45  T &value,
46  DependencyUpdater &updater);
47 
48 template<
49  typename T,
50  int rank,
51  template<int> class GridCheckingPolicy,
52  template<int> class ArrayCheckingPolicy,
53  template<typename, int> class StoragePolicy
54 >
55 void fill_field(
56  Field<T, rank, GridCheckingPolicy, StoragePolicy> &field,
57  Array<double, rank, ArrayCheckingPolicy> &coords,
58  T &value,
59  DependencyUpdater &updater,
60  pParameter dependent);
61 
62 
64 {
65  private:
66 
67  class implBase
68  {
69  public:
70  virtual void fill() = 0;
71  };
72 
73  template<
74  typename T,
75  int rank,
76  template<int> class GridCheckingPolicy,
77  template<int> class ArrayCheckingPolicy,
78  template<typename, int> class StoragePolicy
79  >
80  class impl : public implBase
81  {
82  private:
85  T &value;
86  DependencyUpdater &updater;
87 
88  public:
91  T &value_,
92  DependencyUpdater &updater_)
93  : field(field_), coords(coords_), value(value_), updater(updater_) {}
94 
95  void fill()
96  {
97  fill_field(field, coords, value, updater);
98  }
99  };
100 
101  typedef boost::shared_ptr<implBase> pImplBase;
102  std::list<pImplBase> implementations;
103  public:
104 
105  template<
106  int rank,
107  template<int> class ArrayCheckingPolicy
108  >
110  {
111  private:
112  friend class FieldFiller;
114  DependencyUpdater &updater;
115  std::list<pImplBase> &implementations;
116 
118  DependencyUpdater &updater_,
119  std::list<pImplBase> &implementations_)
120  : coords(coords_), updater(updater_), implementations(implementations_) {}
121 
122  public:
123 
124  template<
125  typename T,
126  template<int> class GridCheckingPolicy,
127  template<typename, int> class StoragePolicy
128  >
130  {
131  pImplBase i(new impl<T, rank, GridCheckingPolicy, ArrayCheckingPolicy, StoragePolicy>(
132  field, coords, value, updater
133  ));
134  implementations.push_back(i);
135  return *this;
136  }
137  };
138 
139  FieldFiller() {}
140 
141  template<
142  int rank,
143  template<int> class ArrayCheckingPolicy
144  >
146  {
147  static fieldAdder<rank,ArrayCheckingPolicy> adder(coords, updater, implementations);
148  return adder;
149  }
150 
151  void clear() { implementations.clear(); }
152 
153  void fillFields()
154  {
155  BOOST_FOREACH(pImplBase i, implementations) i->fill();
156  }
157 
158 };
159 
160 } // namespace
161 
162 #include "fieldtools.t"
163 
164 #endif // FIELDFILLER_HPP_
Definition: algo.hpp:30
Definition: dependencies.hpp:102
Definition: fieldtools.hpp:63
Definition: fieldtools.hpp:109