ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LatticeIndices.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
23
24#include <utils/Vector.hpp>
25
26#include <initializer_list>
27#include <sstream>
28#include <stdexcept>
29
30namespace ScriptInterface {
31
32/** @brief Interface to carry out simple operations on lattice indices. */
34protected:
36 Utils::Vector3i const &shape) const {
38 }
39
41 Utils::Vector3i const &shape) const {
42 if (context()->is_head_node()) {
43 auto constexpr formatter = Utils::Vector3i::formatter(", ");
44 std::stringstream ss;
45 ss << "provided index [" << formatter << index << "] is out of range "
46 << "for shape [" << formatter << shape << "]";
47 throw std::out_of_range(ss.str());
48 }
49 throw Exception("");
50 }
51
54 Utils::Vector3i const &shape) const {
55 auto output = index;
56 for (auto i : {0u, 1u, 2u}) {
57 if (output[i] < 0) {
58 output[i] += shape[i];
59 }
60 }
61 if (not is_index_valid(output, shape)) {
62 throw_invalid_index(index, shape);
63 }
64 return output;
65 }
66};
67
68} // namespace ScriptInterface
Vector implementation and trait types for boost qvm interoperability.
Interface to carry out simple operations on lattice indices.
void throw_invalid_index(Utils::Vector3i const &index, Utils::Vector3i const &shape) const
bool is_index_valid(Utils::Vector3i const &index, Utils::Vector3i const &shape) const
Utils::Vector3i get_mapped_index(Utils::Vector3i const &index, Utils::Vector3i const &shape) const
Base class for interface handles.
Context * context() const
Responsible context.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
static constexpr detail::ArrayFormatter formatter(char const *sep=" ")
Definition Array.hpp:173