ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBSliceAccess.impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2026 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/**
23 * @file
24 * Out-of-class slice access definitions for
25 * @ref walberla::LBWalberlaImpl.
26 */
27
28#include <utils/Vector.hpp>
29
30#include <span>
31#include <vector>
32
33namespace walberla {
34
35template <typename FloatType, lbmpy::Arch Architecture>
38 Utils::Vector3i const &upper_corner) const {
39 std::vector<double> out;
41 get_lattice(), lower_corner, upper_corner,
42 [&](auto &block, auto const &bci, auto const &ci,
43 auto const &block_offset) {
44 if (out.empty())
45 out.resize(3u * ci.numCells());
46 auto const field =
47 block.template getData<VectorField>(m_velocity_field_id);
49
50 auto kernel = [&values, &out, this](unsigned const block_index,
51 unsigned const local_index,
52 Utils::Vector3i const &node) {
53 if (m_boundary->node_is_boundary(node)) {
54 auto const &vec = m_boundary->get_node_value_at_boundary(node);
55 for (uint_t f = 0u; f < 3u; ++f) {
56 out[3u * local_index + f] = vec[f];
57 }
58 } else {
59 for (uint_t f = 0u; f < 3u; ++f) {
60 out[3u * local_index + f] =
61 double_c(values[3u * block_index + f]);
62 }
63 }
64 };
65
67 });
68 return out;
69}
70
71template <typename FloatType, lbmpy::Arch Architecture>
74 std::vector<double> const &velocity) {
75 m_pending_ghost_comm.set(GhostComm::PDF);
76 m_pending_ghost_comm.set(GhostComm::VEL);
78 get_lattice(), lower_corner, upper_corner,
79 [&](auto &block, auto const &bci, auto const &ci,
80 auto const &block_offset) {
81 assert(velocity.size() == 3u * ci.numCells());
82 auto pdf_field = block.template getData<PdfField>(m_pdf_field_id);
83 auto force_field =
84 block.template getData<VectorField>(m_last_applied_force_field_id);
85 auto vel_field =
86 block.template getData<VectorField>(m_velocity_field_id);
87 std::vector<FloatType> values(3u * bci.numCells());
88
89 auto kernel = [&values, &velocity](unsigned const block_index,
90 unsigned const local_index,
91 Utils::Vector3i const &) {
92 for (uint_t f = 0u; f < 3u; ++f) {
93 values[3u * block_index + f] =
95 }
96 };
97
100 bci);
101 });
102}
103
104template <typename FloatType, lbmpy::Arch Architecture>
105std::vector<double>
108 Utils::Vector3i const &upper_corner) const {
109 std::vector<double> out;
111 get_lattice(), lower_corner, upper_corner,
112 [&](auto const &block, auto const &bci, auto const &ci,
113 auto const &block_offset) {
114 if (out.empty())
115 out.resize(3u * ci.numCells());
116 auto const field =
117 block.template getData<VectorField>(m_last_applied_force_field_id);
118 auto const values = lbm::accessor::Vector::get(field, bci);
119
120 auto kernel = [&values, &out](unsigned const block_index,
121 unsigned const local_index,
122 Utils::Vector3i const &) {
123 for (uint_t f = 0u; f < 3u; ++f) {
124 out[3u * local_index + f] = values[3u * block_index + f];
125 }
126 };
127
129 });
130 zero_centered_to_md_in_place(out);
131 return out;
132}
133
134template <typename FloatType, lbmpy::Arch Architecture>
137 std::vector<double> const &force) {
138 m_pending_ghost_comm.set(GhostComm::VEL);
139 m_pending_ghost_comm.set(GhostComm::LAF);
141 get_lattice(), lower_corner, upper_corner,
142 [&](auto &block, auto const &bci, auto const &ci,
143 auto const &block_offset) {
144 assert(force.size() == 3u * ci.numCells());
145 auto pdf_field = block.template getData<PdfField>(m_pdf_field_id);
146 auto force_field =
147 block.template getData<VectorField>(m_last_applied_force_field_id);
148 auto vel_field =
149 block.template getData<VectorField>(m_velocity_field_id);
150 std::vector<FloatType> values(3u * bci.numCells());
151
152 auto kernel = [&values, &force](unsigned const block_index,
153 unsigned const local_index,
154 Utils::Vector3i const &) {
155 for (uint_t f = 0u; f < 3u; ++f) {
156 values[3u * block_index + f] =
157 numeric_cast<FloatType>(force[3u * local_index + f]);
158 }
159 };
160
163 m_density, bci);
164 });
165}
166
167template <typename FloatType, lbmpy::Arch Architecture>
168std::vector<double>
171 Utils::Vector3i const &upper_corner) const {
172 std::vector<double> out;
174 get_lattice(), lower_corner, upper_corner,
175 [&](auto const &block, auto const &bci, auto const &ci,
176 auto const &block_offset) {
177 if (out.empty())
178 out.resize(stencil_size() * ci.numCells());
179 auto const pdf_field = block.template getData<PdfField>(m_pdf_field_id);
181
182 auto kernel = [&values, &out, this](unsigned const block_index,
183 unsigned const local_index,
184 Utils::Vector3i const &) {
185 for (uint_t f = 0u; f < stencil_size(); ++f) {
186 out[stencil_size() * local_index + f] =
187 values[stencil_size() * block_index + f];
188 }
189 };
190
192 });
193 return out;
194}
195
196template <typename FloatType, lbmpy::Arch Architecture>
199 std::vector<double> const &population) {
201 get_lattice(), lower_corner, upper_corner,
202 [&](auto &block, auto const &bci, auto const &ci,
203 auto const &block_offset) {
204 assert(population.size() == stencil_size() * ci.numCells());
205 auto pdf_field = block.template getData<PdfField>(m_pdf_field_id);
206 auto force_field =
207 block.template getData<VectorField>(m_last_applied_force_field_id);
208 auto vel_field =
209 block.template getData<VectorField>(m_velocity_field_id);
210 std::vector<FloatType> values(stencil_size() * bci.numCells());
211
212 auto kernel = [&values, &population, this](unsigned const block_index,
213 unsigned const local_index,
214 Utils::Vector3i const &) {
215 for (uint_t f = 0u; f < stencil_size(); ++f) {
216 values[stencil_size() * block_index + f] = numeric_cast<FloatType>(
217 population[stencil_size() * local_index + f]);
218 }
219 };
220
223 values, bci);
224 });
225}
226
227template <typename FloatType, lbmpy::Arch Architecture>
230 Utils::Vector3i const &upper_corner) const {
231 std::vector<double> out;
233 get_lattice(), lower_corner, upper_corner,
234 [&](auto const &block, auto const &bci, auto const &ci,
235 auto const &block_offset) {
236 if (out.empty())
237 out.resize(ci.numCells());
238 auto const pdf_field = block.template getData<PdfField>(m_pdf_field_id);
239 auto const values =
241
242 auto kernel = [&values, &out](unsigned const block_index,
243 unsigned const local_index,
244 Utils::Vector3i const &) {
246 };
247
249 });
250 return out;
251}
252
253template <typename FloatType, lbmpy::Arch Architecture>
256 std::vector<double> const &density) {
257 m_pending_ghost_comm.set(GhostComm::PDF);
259 get_lattice(), lower_corner, upper_corner,
260 [&](auto &block, auto const &bci, auto const &ci,
261 auto const &block_offset) {
262 assert(density.size() == ci.numCells());
263 auto pdf_field = block.template getData<PdfField>(m_pdf_field_id);
264 std::vector<FloatType> values(bci.numCells());
265
266 auto kernel = [&values, &density](unsigned const block_index,
267 unsigned const local_index,
268 Utils::Vector3i const &) {
270 };
271
274 });
275}
276
277template <typename FloatType, lbmpy::Arch Architecture>
278std::vector<double>
281 Utils::Vector3i const &upper_corner) const {
282 std::vector<double> out;
284 get_lattice(), lower_corner, upper_corner,
285 [&](auto const &block, auto const &bci, auto const &ci,
286 auto const &block_offset) {
287 if (out.empty())
288 out.resize(9u * ci.numCells());
289 auto const pdf_field = block.template getData<PdfField>(m_pdf_field_id);
290 auto values =
292
293 auto kernel = [&values, &out, this](unsigned const block_index,
294 unsigned const local_index,
295 Utils::Vector3i const &) {
296 pressure_tensor_correction(
297 std::span<FloatType, 9ul>(&values[9u * block_index], 9ul));
298 for (uint_t f = 0u; f < 9u; ++f) {
299 out[9u * local_index + f] = values[9u * block_index + f];
300 }
301 };
302
304 });
305 return out;
306}
307
308} // namespace walberla
Vector implementation and trait types for boost qvm interoperability.
DEVICE_QUALIFIER constexpr size_type size() const noexcept
Definition Array.hpp:166
std::vector< double > get_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
void set_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &velocity) override
std::vector< double > get_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
std::vector< double > get_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
std::vector< double > get_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
std::vector< double > get_slice_pressure_tensor(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const override
void set_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &density) override
void set_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &force) override
void set_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &population) override
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static double * block(double *p, std::size_t index, std::size_t size)
Definition elc.cpp:177
void set(GhostLayerField< double, uint_t{19u}> *pdf_field, double const rho_in, double const density, Cell const &cell)
double get(GhostLayerField< double, uint_t{19u}> const *pdf_field, double const density, Cell const &cell)
void set(GhostLayerField< double, uint_t{19u}> const *pdf_field, GhostLayerField< double, uint_t{3u}> *velocity_field, GhostLayerField< double, uint_t{3u}> *force_field, Vector3< double > const &force, double const density, Cell const &cell)
void set(GhostLayerField< double, uint_t{19u}> *pdf_field, std::array< double, 19u > const &pop, Cell const &cell)
auto get(GhostLayerField< double, uint_t{19u}> const *pdf_field, Cell const &cell)
auto get(GhostLayerField< double, uint_t{19u}> const *pdf_field, double const density, Cell const &cell)
auto get(GhostLayerField< double, uint_t{3u}> const *vec_field, Cell const &cell)
void set(GhostLayerField< double, uint_t{19u}> *pdf_field, GhostLayerField< double, uint_t{3u}> *velocity_field, GhostLayerField< double, uint_t{3u}> const *force_field, Vector3< double > const &u, Cell const &cell)
\file PackInfoPdfDoublePrecision.cpp \author pystencils
void copy_block_buffer(CellInterval const &bci, CellInterval const &ci, Utils::Vector3i const &block_offset, Utils::Vector3i const &lower_corner, auto &&kernel)
Synchronize data between a sliced block and a container.
void for_each_block_in_slice(::LatticeWalberla const &lattice, Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, auto &&visitor)
Iterate over all local blocks that overlap a given 3D slice, invoking a visitor for each such block.
static Utils::Vector3d velocity(Particle const &p_ref, Particle const &p_vs)
Velocity of the virtual site.
Definition relative.cpp:64