ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
data_struct.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <config/config.hpp>
25
26#if defined(ESPRESSO_P3M) or defined(ESPRESSO_DP3M)
27
28#include "common.hpp"
29#include "communication.hpp"
30
32
33#include <array>
34#include <cassert>
35#include <memory>
36#include <tuple>
37#include <utility>
38#include <vector>
39
40/** @brief State of the p3m methods, the part which applies to both,
41 electrostatic and dipolar p3m */
42template <typename FloatType, Arch Architecture = Arch::CPU>
44 using value_type = FloatType;
45
48
49 /** @brief P3M base parameters. */
51 /** @brief Local mesh geometry information for this MPI rank */
53
54 /**
55 * @brief Spatial differential operator in k-space.
56 * We use an i*k differentiation.
57 * TODO: RW: I think this is not the differential operator but the mapping
58 * between index in the GLOBAL mesh and the corresponding
59 * k-vector with a few pre-factors missing.
60 */
61 std::array<std::vector<int>, 3> d_op;
62
63 /** Calculate the Fourier transformed differential operator.
64 * Remark: This is done on the level of n-vectors and not k-vectors,
65 * i.e. the prefactor @f$ 2i\pi/L @f$ is missing!
66 */
70
71 /** @brief Force optimised influence function (k-space) */
72 std::vector<FloatType> g_force;
73 /** @brief Energy optimised influence function (k-space) */
74 std::vector<FloatType> g_energy;
75};
76
77#if defined(ESPRESSO_DP3M)
78
79/**
80 * @brief API for the legacy FFT backend of the P3M algorithm.
81 */
82template <typename FloatType> class FFTBackend {
83protected:
85
86public:
89 virtual ~FFTBackend() = default;
90 virtual void init(P3MParameters const &params) = 0;
91 virtual int get_ca_mesh_size() const noexcept = 0;
93 /** @brief Carry out the forward FFT of the scalar mesh. */
94 virtual void forward_fft(FloatType *rs_mesh) = 0;
95 /** @brief Carry out the backward FFT of the scalar mesh. */
96 virtual void backward_fft(FloatType *rs_mesh) = 0;
97 virtual std::array<int, 3u> const &get_mesh_size() const = 0;
98 virtual std::array<int, 3u> const &get_mesh_start() const = 0;
99};
100
101/**
102 * @brief API for the legacy FFT mesh buffers.
103 */
105protected:
107
108public:
111 virtual HOST_ONLY_QUALIFIER ~FFTBuffers() = default;
112 /** @brief Initialize the meshes. */
113 virtual void init_meshes(int ca_mesh_size) = 0;
114 /** @brief Initialize the halo buffers. */
115 virtual void init_halo() = 0;
116 /** @brief Update vector mesh halo with data from neighbors (accumulation). */
117 virtual void perform_vector_halo_gather() = 0;
118 /** @brief Update scalar mesh halo of all neighbors. */
119 virtual void perform_scalar_halo_spread() = 0;
120 /** @brief Update vector mesh halo of all neighbors. */
121 virtual void perform_vector_halo_spread() = 0;
122 /**
123 * @brief Get pointer to scalar mesh begin.
124 * Should only be used by @ref FFTBackend.
125 */
126 virtual FloatType *get_scalar_mesh() = 0;
127 /**
128 * @brief Get pointer to vector mesh begin.
129 * Should only be used by @ref FFTBackend.
130 */
131 virtual std::array<FloatType *, 3u> get_vector_mesh() = 0;
132 /**
133 * @brief Update the scalar and vector mesh views in @ref P3MFFTMesh
134 * to point to the new underlying data structures.
135 */
137};
138
139#endif // defined(ESPRESSO_DP3M)
140
141#endif // defined(ESPRESSO_P3M) or defined(ESPRESSO_DP3M)
API for the legacy FFT backend of the P3M algorithm.
virtual void init(P3MParameters const &params)=0
virtual int get_ca_mesh_size() const noexcept=0
virtual ~FFTBackend()=default
virtual void backward_fft(FloatType *rs_mesh)=0
Carry out the backward FFT of the scalar mesh.
virtual std::array< int, 3u > const & get_mesh_size() const =0
P3MLocalMesh const & local_mesh
virtual int get_ks_pnum() const noexcept=0
virtual void forward_fft(FloatType *rs_mesh)=0
Carry out the forward FFT of the scalar mesh.
virtual std::array< int, 3u > const & get_mesh_start() const =0
FFTBackend(P3MLocalMesh const &local_mesh)
API for the legacy FFT mesh buffers.
P3MLocalMesh const & local_mesh
virtual void init_meshes(int ca_mesh_size)=0
Initialize the meshes.
virtual void perform_vector_halo_gather()=0
Update vector mesh halo with data from neighbors (accumulation).
virtual std::array< FloatType *, 3u > get_vector_mesh()=0
Get pointer to vector mesh begin.
virtual void perform_vector_halo_spread()=0
Update vector mesh halo of all neighbors.
virtual void init_halo()=0
Initialize the halo buffers.
virtual void update_mesh_views(P3MFFTMesh< FloatType > &out)=0
Update the scalar and vector mesh views in P3MFFTMesh to point to the new underlying data structures.
FFTBuffers(P3MLocalMesh const &local_mesh)
virtual void perform_scalar_halo_spread()=0
Update scalar mesh halo of all neighbors.
virtual FloatType * get_scalar_mesh()=0
Get pointer to scalar mesh begin.
virtual HOST_ONLY_QUALIFIER ~FFTBuffers()=default
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
#define HOST_ONLY_QUALIFIER
STL namespace.
Common functions for dipolar and charge P3M.
std::array< std::vector< int >, 3 > calc_p3m_mesh_shift(Utils::Vector3i const &mesh_size, bool zero_out_midpoint=false)
Calculate indices that shift P3MParameters::mesh by mesh/2.
Local mesh FFT buffers.
Properties of the local mesh and halo region.
Structure to hold P3M parameters and some dependent variables.
Utils::Vector3i mesh
number of mesh points per coordinate direction (>0), in real space.
State of the p3m methods, the part which applies to both, electrostatic and dipolar p3m.
std::vector< FloatType > g_energy
Energy optimised influence function (k-space)
P3MLocalMesh local_mesh
Local mesh geometry information for this MPI rank.
P3MStateCommon(P3MParameters &&parameters)
void calc_differential_operator()
Calculate the Fourier transformed differential operator.
P3MParameters params
P3M base parameters.
std::array< std::vector< int >, 3 > d_op
Spatial differential operator in k-space.
FloatType value_type
std::vector< FloatType > g_force
Force optimised influence function (k-space)