10 #ifndef SRC_INCLUDE_LATTICE_H_ 11 #define SRC_INCLUDE_LATTICE_H_ 66 const std::array<int, 3>&
n,
67 const std::array<double, 3>& orig,
bool per,
76 const auto& log = logger<LogArea::Lattice>();
77 log.debug(
"Rectangular lattice created: sizes[fm] = (",
lattice_sizes_[0],
85 throw std::invalid_argument(
86 "Lattice sizes should be positive, " 87 "lattice dimensions should be > 0.");
160 using iterator =
typename std::vector<T>::iterator;
186 T&
node(
int ix,
int iy,
int iz) {
217 value =
node(ix, iy, iz);
232 template <
typename F>
234 const std::array<int, 3>& upper_bounds, F&& func) {
235 const auto& log = logger<LogArea::Lattice>();
236 log.debug(
"Iterating sublattice with lower bound index (", lower_bounds[0],
237 ",", lower_bounds[1],
",", lower_bounds[2],
238 "), upper bound index (", upper_bounds[0],
",", upper_bounds[1],
239 ",", upper_bounds[2],
")");
242 for (
int iz = lower_bounds[2]; iz < upper_bounds[2]; iz++) {
244 for (
int iy = lower_bounds[1]; iy < upper_bounds[1]; iy++) {
247 for (
int ix = lower_bounds[0]; ix < upper_bounds[0]; ix++) {
254 for (
int iz = lower_bounds[2]; iz < upper_bounds[2]; iz++) {
255 const int z_offset = iz *
n_cells_[1];
256 for (
int iy = lower_bounds[1]; iy < upper_bounds[1]; iy++) {
257 const int y_offset =
n_cells_[0] * (iy + z_offset);
258 for (
int ix = lower_bounds[0]; ix < upper_bounds[0]; ix++) {
259 func(
lattice_[ix + y_offset], ix, iy, iz);
278 template <
typename F>
281 std::array<int, 3> l_bounds, u_bounds;
286 for (
int i = 0; i < 3; i++) {
294 for (
int i = 0; i < 3; i++) {
295 if (l_bounds[i] < 0) {
301 if (l_bounds[i] >
n_cells_[i] || u_bounds[i] < 0) {
317 template <
typename L>
319 return n_cells_[0] == lat->dimensions()[0] &&
320 n_cells_[1] == lat->dimensions()[1] &&
321 n_cells_[2] == lat->dimensions()[2] &&
364 return (i + (
n << 8)) %
n;
370 #endif // SRC_INCLUDE_LATTICE_H_
The ThreeVector class represents a physical three-vector with the components .
constexpr double really_small
Numerical error tolerance.
const_iterator begin() const
bool out_of_bounds(int ix, int iy, int iz) const
Checks if 3D index is out of lattice bounds.
T & node(int ix, int iy, int iz)
Take the value of a cell given its 3-D indices.
const std::array< int, 3 > & dimensions() const
int positive_modulo(int i, int n) const
Returns division modulo, which is always between 0 and n-1 in is not suitable, because it returns res...
const_iterator end() const
T & operator[](std::size_t i)
LatticeUpdate
Enumerator option for lattice updates.
std::vector< T > lattice_
The lattice itself, array containing physical quantities.
typename std::vector< smash::EnergyMomentumTensor >::iterator iterator
Iterator of lattice.
const LatticeUpdate when_update_
When the lattice should be recalculated.
const std::array< double, 3 > lattice_sizes_
Lattice sizes in x, y, z directions.
void iterate_in_radius(const ThreeVector &point, const double r_cut, F &&func)
Iterates only nodes, whose cell centers lie not further than r_cut in x, y, z directions from the giv...
Generic numerical functions.
LatticeUpdate when_update() const
const std::array< double, 3 > origin_
Coordinates of the left down nearer corner.
A container class to hold all the arrays on the lattice and access them.
typename std::vector< smash::EnergyMomentumTensor >::const_iterator const_iterator
Const interator of lattice.
bool identical_to_lattice(const L *lat) const
Checks if lattices of possibly different types have identical structure.
const bool periodic_
Whether the lattice is periodic.
void reset()
Sets all values on lattice to zeros.
RectangularLattice(const std::array< double, 3 > &l, const std::array< int, 3 > &n, const std::array< double, 3 > &orig, bool per, const LatticeUpdate upd)
Rectangular lattice constructor.
const std::array< double, 3 > & origin() const
const std::array< double, 3 > & cell_sizes() const
bool value_at(const ThreeVector &r, T &value)
Interpolates lattice quantity to coordinate r.
const std::array< double, 3 > cell_sizes_
Cell sizes in x, y, z directions.
const std::array< double, 3 > & lattice_sizes() const
ThreeVector cell_center(int ix, int iy, int iz) const
Find the coordinates of a given cell.
const T & operator[](std::size_t i) const
ThreeVector cell_center(int index) const
Find the coordinate of cell center given the 1d index of the cell.
void iterate_sublattice(const std::array< int, 3 > &lower_bounds, const std::array< int, 3 > &upper_bounds, F &&func)
A sub-lattice iterator, which iterates in a 3D-structured manner and calls a function on every cell...
const std::array< int, 3 > n_cells_
Number of cells in x,y,z directions.