PSCF v1.1
Mesh.h
1#ifndef PSCF_MESH_H
2#define PSCF_MESH_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <pscf/math/IntVec.h> // member
12#include <iostream> // interface
13#include <util/format/Int.h> // operator << implementation
14
15namespace Pscf
16{
17
18 using namespace Util;
19
20 // Forward declaration
21 template <int D> class Mesh;
22
30 template <int D>
31 std::istream& operator >> (std::istream& in, Mesh<D>& mesh);
32
40 template <int D>
41 std::ostream& operator << (std::ostream& out, Mesh<D> const & mesh);
42
59 template <int D>
60 class Mesh
61 {
62
63 public:
64
72 Mesh();
73
79 Mesh(Mesh<D> const & other);
80
86 Mesh(IntVec<D> const & dimensions);
87
93 Mesh<D>& operator = (Mesh<D> const & other);
94
100 void setDimensions(IntVec<D> const & dimensions);
101
105 IntVec<D> dimensions() const;
106
112 int dimension(int i) const;
113
121 int size() const;
122
129 IntVec<D> position(int rank) const;
130
137 int rank(IntVec<D> const & position) const;
138
146 bool isInMesh(int coordinate, int i) const;
147
156 bool isInMesh(IntVec<D> const & position) const;
157
170 int shift(int& coordinate, int i) const;
171
184
191 template <class Archive>
192 void serialize(Archive& ar, const unsigned int version);
193
194 private:
195
197 IntVec<D> dimensions_;
198
200 IntVec<D> offsets_;
201
203 int size_;
204
205 //friends:
206
207 friend std::istream& operator >> <>(std::istream&, Mesh<D> & );
208
209 friend std::ostream& operator << <>(std::ostream&, Mesh<D> const & );
210
211
212 };
213
214 // Inline member function implementations
215
216 template <int D>
218 { return dimensions_; }
219
220 template <int D>
221 inline int Mesh<D>::dimension(int i) const
222 {
223 assert(i >=0);
224 assert(i < Dimension);
225 return dimensions_[i];
226 }
227
228 template <int D>
229 inline int Mesh<D>::size() const
230 { return size_; }
231
232 /*
233 * Serialize Mesh to/from an archive.
234 */
235 template <int D>
236 template <class Archive>
237 void Mesh<D>::serialize(Archive& ar, const unsigned int version)
238 {
239 for (int i=0; i < D; ++i) {
240 ar & dimensions_[0];
241 }
242 }
243
244 template <int D>
245 std::istream& operator >> (std::istream& in, Mesh<D>& mesh)
246 {
247 IntVec<D> dimensions;
248 in >> dimensions;
249 for (int i = 0; i < D; ++i) {
250 UTIL_CHECK(dimensions[i] > 0);
251 }
252 mesh.setDimensions(dimensions);
253 return in;
254 }
255
256 template <int D>
257 std::ostream& operator << (std::ostream& out, Mesh<D> const & mesh)
258 {
259 for (int i = 0; i < D; ++i) {
260 out << " " << Int(mesh.dimensions_[i], 6);
261 }
262 return out;
263 }
264
265 #ifndef PSCF_MESH_TPP
266 // Suppress implicit instantiation
267 extern template class Mesh<1>;
268 extern template class Mesh<2>;
269 extern template class Mesh<3>;
270 #endif
271
272}
273//#include "Mesh.tpp"
274#endif
An IntVec<D, T> is a D-component vector of elements of integer type T.
Definition: IntVec.h:27
Description of a regular grid of points in a periodic domain.
Definition: Mesh.h:61
IntVec< D > dimensions() const
Get an IntVec<D> of the grid dimensions.
Definition: Mesh.h:217
Mesh< D > & operator=(Mesh< D > const &other)
Assignment operator.
Definition: Mesh.tpp:45
int size() const
Get total number of grid points.
Definition: Mesh.h:229
int rank(IntVec< D > const &position) const
Get the rank of a grid point with specified position.
Definition: Mesh.tpp:72
bool isInMesh(int coordinate, int i) const
Is this coordinate in range?
Definition: Mesh.tpp:105
IntVec< D > position(int rank) const
Get the position IntVec<D> of a grid point with a specified rank.
Definition: Mesh.tpp:89
int shift(int &coordinate, int i) const
Shift a periodic coordinate into range.
Definition: Mesh.tpp:131
void setDimensions(IntVec< D > const &dimensions)
Set the grid dimensions for an existing mesh.
Definition: Mesh.tpp:53
void serialize(Archive &ar, const unsigned int version)
Serialize to/from an archive.
Definition: Mesh.h:237
Mesh()
Default constructor.
Definition: Mesh.tpp:21
int dimension(int i) const
Get grid dimension along Cartesian direction i.
Definition: Mesh.h:221
Wrapper for an int, for formatted ostream output.
Definition: Int.h:37
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition: global.h:68
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.
Definition: accumulators.mod:1
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition: Pair.h:57