ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LatticeSlice.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 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
22#include "config/config.hpp"
23
24#ifdef WALBERLA
25
26#include "LatticeIndices.hpp"
27
29
31
32#include <utils/Vector.hpp>
33
34#include <cassert>
35#include <tuple>
36#include <vector>
37
39
40template <class FieldSerializer> class LatticeSlice : public LatticeIndices {
41protected:
44 std::vector<int> m_shape;
45
46public:
47 virtual ::LatticeWalberla const &get_lattice() const = 0;
48
49private:
50 auto get_sentinel_index(::LatticeWalberla const &lattice) const {
51 return -(static_cast<int>(lattice.get_ghost_layers()) + 1);
52 }
53
54 auto get_slices_bounding_boxes() const {
55 auto const &lattice = get_lattice();
56 auto const &slice_lower_corner = m_slice_lower_corner;
57 auto const &slice_upper_corner = m_slice_upper_corner;
58 assert(slice_upper_corner <= lattice.get_grid_dimensions());
59 assert(slice_lower_corner >= Utils::Vector3i::broadcast(0));
60 auto const sentinel = get_sentinel_index(lattice);
61 auto [local_lower_corner, local_upper_corner] =
62 lattice.get_local_grid_range();
63 for (auto const i : {0, 1, 2}) {
64 if (local_lower_corner[i] >= slice_upper_corner[i] or
65 slice_lower_corner[i] >= local_upper_corner[i]) {
66 local_lower_corner[i] = sentinel;
67 local_upper_corner[i] = sentinel;
68 } else {
69 if (slice_lower_corner[i] > local_lower_corner[i]) {
70 local_lower_corner[i] = slice_lower_corner[i];
71 }
72 if (slice_upper_corner[i] < local_upper_corner[i]) {
73 local_upper_corner[i] = slice_upper_corner[i];
74 }
75 }
76 }
77 return std::make_tuple(slice_lower_corner, slice_upper_corner,
78 local_lower_corner, local_upper_corner);
79 }
80
81protected:
82 template <class LatticeModel, typename T>
83 Variant gather_3d(VariantMap const &params, std::vector<int> const &data_dims,
84 LatticeModel const &lattice_model,
85 std::vector<T> (LatticeModel::*getter)(
86 Utils::Vector3i const &, Utils::Vector3i const &) const,
87 double units_conversion = 1.) const;
88
89 template <class LatticeModel, typename T>
90 void scatter_3d(VariantMap const &params, std::vector<int> const &data_dims,
91 LatticeModel &lattice_model,
92 void (LatticeModel::*setter)(Utils::Vector3i const &,
93 Utils::Vector3i const &,
94 std::vector<T> const &),
95 double units_conversion = 1.);
96};
97} // namespace ScriptInterface::walberla
98
99#endif // WALBERLA
Vector implementation and trait types for boost qvm interoperability.
Abstract representation of a lattice-based model.
Class that runs and controls the BlockForest in waLBerla.
Interface to carry out simple operations on lattice indices.
Variant gather_3d(VariantMap const &params, std::vector< int > const &data_dims, LatticeModel const &lattice_model, std::vector< T >(LatticeModel::*getter)(Utils::Vector3i const &, Utils::Vector3i const &) const, double units_conversion=1.) const
void scatter_3d(VariantMap const &params, std::vector< int > const &data_dims, LatticeModel &lattice_model, void(LatticeModel::*setter)(Utils::Vector3i const &, Utils::Vector3i const &, std::vector< T > const &), double units_conversion=1.)
virtual ::LatticeWalberla const & get_lattice() const =0
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value)
Create a vector that has all entries set to the same value.
Definition Vector.hpp:110
This file contains the defaults for ESPResSo.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
VectorXi< 3 > Vector3i
Definition Vector.hpp:173
std::vector< T, allocator< T > > vector
Definition vector.hpp:52
static SteepestDescentParameters params
Currently active steepest descent instance.