Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62248127
grid.hh
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, May 11, 22:27
Size
1 KB
Mime Type
text/x-c++
Expires
Mon, May 13, 22:27 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17624449
Attached To
rSCMINICLUSTER SCITAS Mini Cluster
grid.hh
View Options
#include <cstddef>
#ifndef GRID_H
#define GRID_H
class Grid {
typedef char T;
public:
Grid(std::size_t m, std::size_t n, std::size_t ghosts)
: _dims{m, n}, _offsets{0, 0}, _ghosts(ghosts),
_grid(new T[(m + 2 * _ghosts) * (n + 2 * _ghosts)]) {}
Grid(const Grid &other)
: _dims{other._dims[0], other._dims[1]},
_offsets{other._offsets[0], other._offsets[1]}, _ghosts(other._ghosts),
_grid(new T[(_dims[0] + 2 * _ghosts) * (_dims[1] + 2 * _ghosts)]) {}
~Grid() { delete[] _grid; }
T &operator()(std::size_t i, std::size_t j) {
return *(_grid + (i + _ghosts) * _dims[1] + (j + _ghosts));
}
void swap(Grid &other) {
T *tmp = _grid;
_grid = other._grid;
other._grid = tmp;
}
void setOffsets(std::size_t offsets[2]) {
_offsets[0] = offsets[0];
_offsets[1] = offsets[1];
}
std::size_t size(std::size_t i) const { return _dims[i]; }
std::size_t size() const { return _dims[0] * _dims[1]; }
std::size_t fullSize(std::size_t i) const { return (_dims[i]+2*_ghosts); }
std::size_t fullSize() const { return (_dims[0]+2*_ghosts) * (_dims[1]+2*_ghosts); }
std::size_t offset(std::size_t i) const { return _offsets[i]; }
std::size_t ghost() const { return _ghosts; }
const T * data() const { return _grid; }
private:
std::size_t _dims[2];
std::size_t _offsets[2];
std::size_t _ghosts;
T *_grid;
};
#endif /* GRID_H */
Event Timeline
Log In to Comment