ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBCollisionSetup.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 collision model setup definitions for
25 * @ref walberla::LBWalberlaImpl.
26 */
27
28#include <memory>
29#include <stdexcept>
30#include <utility>
31
32namespace walberla {
33
34template <typename FloatType, lbmpy::Arch Architecture>
35FloatType
36LBWalberlaImpl<FloatType, Architecture>::shear_mode_relaxation_rate() const {
37 return FloatType{2} / (FloatType{6} * m_viscosity + FloatType{1});
38}
39
40template <typename FloatType, lbmpy::Arch Architecture>
41FloatType LBWalberlaImpl<FloatType, Architecture>::odd_mode_relaxation_rate(
42 FloatType shear_relaxation, FloatType magic_number) const {
43 return (FloatType{4} - FloatType{2} * shear_relaxation) /
44 (FloatType{4} * magic_number * shear_relaxation + FloatType{2} -
46}
47
48/**
49 * @brief Set up the thermalized collision model.
50 * Configures MRT relaxation rates from the viscosity and initializes the
51 * random number generator for fluctuating LB.
52 * When @p kT is zero, fluctuations are suppressed but the thermalized
53 * kernel is still used (required for RNG state tracking).
54 */
55template <typename FloatType, lbmpy::Arch Architecture>
57 double kT, unsigned int seed) {
58 auto const omega = shear_mode_relaxation_rate();
59 auto const omega_odd = odd_mode_relaxation_rate(omega);
60 auto const blocks = get_lattice().get_blocks();
61 m_kT = FloatType_c(kT);
62 m_seed = seed;
64 m_last_applied_force_field_id, m_pdf_field_id, zero_centered_to_lb(m_kT),
65 omega, omega, omega_odd, omega, seed, uint32_t{0u});
66 m_collision_model = std::make_shared<CollisionModel>(std::move(obj));
67 m_run_stream_collide_sweep = StreamCollideSweepVisitor(blocks);
68 setup_streaming_communicator();
69}
70
71/**
72 * @brief Set up the Lees-Edwards collision model.
73 * Configures a modified collision step that applies the shear velocity
74 * at the Lees-Edwards boundary planes, and sets up the interpolation
75 * sweeps for PDFs, velocities, and forces at those boundaries.
76 * Currently restricted to shear_plane_normal="y" and no domain
77 * decomposition along the shear direction.
78 */
79template <typename FloatType, lbmpy::Arch Architecture>
81 std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack) {
82 assert(m_kT == 0.);
83#if defined(__CUDACC__) and defined(WALBERLA_BUILD_WITH_CUDA)
84 if constexpr (Architecture == lbmpy::Arch::GPU) {
85 throw std::runtime_error("Lees-Edwards LB doesn't support GPU yet");
86 }
87#endif
88 auto const shear_direction = lees_edwards_pack->shear_direction;
89 auto const shear_plane_normal = lees_edwards_pack->shear_plane_normal;
90 auto const shear_vel = FloatType_c(lees_edwards_pack->get_shear_velocity());
91 auto const omega = shear_mode_relaxation_rate();
92 auto const omega_odd = odd_mode_relaxation_rate(omega);
93 if (shear_plane_normal != 1u) {
94 throw std::domain_error(
95 "Lees-Edwards LB only supports shear_plane_normal=\"y\"");
96 }
97 auto const &lattice = get_lattice();
98 auto const n_ghost_layers = lattice.get_ghost_layers();
99 auto const blocks = lattice.get_blocks();
100 if (lattice.get_node_grid()[shear_direction] != 1 or
101 blocks->getSize(shear_direction) != 1ul or
102 blocks->getSize(shear_plane_normal) !=
103 lattice.get_node_grid()[shear_plane_normal]) {
104 throw std::domain_error("LB LEbc doesn't support domain decomposition "
105 "along the shear direction, nor multiple blocks "
106 "along the normal direction");
107 }
108 auto const &grid_dimensions = lattice.get_grid_dimensions();
109 auto const block_origin = lattice.get_local_grid_range(false).first;
110 auto const lebc_slab_origin = block_origin[shear_plane_normal];
111 auto const lebc_slab_total_thickness = grid_dimensions[shear_plane_normal];
112 auto const lebc_bot_index = 0 - lebc_slab_origin;
113 auto const lebc_top_index = lebc_slab_total_thickness - lebc_slab_origin;
114 m_collision_model = std::make_shared<CollisionModel>(
116 m_last_applied_force_field_id, m_pdf_field_id, lebc_bot_index,
117 lebc_top_index, omega, omega, omega_odd, omega, shear_vel));
118 m_lees_edwards_callbacks = std::move(lees_edwards_pack);
119 m_run_stream_collide_sweep =
120 StreamCollideSweepVisitor(blocks, m_lees_edwards_callbacks);
121 m_lees_edwards_pdf_interpol_sweep =
122 std::make_shared<InterpolateAndShiftAtBoundary<_PdfField, FloatType>>(
123 blocks, m_pdf_field_id, m_pdf_tmp_field_id, n_ghost_layers,
124 shear_direction, shear_plane_normal,
125 m_lees_edwards_callbacks->get_pos_offset);
126 m_lees_edwards_vel_interpol_sweep =
127 std::make_shared<InterpolateAndShiftAtBoundary<_VectorField, FloatType>>(
128 blocks, m_velocity_field_id, m_vel_tmp_field_id, n_ghost_layers,
129 shear_direction, shear_plane_normal,
130 m_lees_edwards_callbacks->get_pos_offset,
131 m_lees_edwards_callbacks->get_shear_velocity);
132 m_lees_edwards_last_applied_force_interpol_sweep =
133 std::make_shared<InterpolateAndShiftAtBoundary<_VectorField, FloatType>>(
134 blocks, m_last_applied_force_field_id, m_vel_tmp_field_id,
135 n_ghost_layers, shear_direction, shear_plane_normal,
136 m_lees_edwards_callbacks->get_pos_offset);
137 setup_streaming_communicator();
138}
139
140/** @brief Verify that MD and LB Lees-Edwards parameters are consistent. */
141template <typename FloatType, lbmpy::Arch Architecture>
143 unsigned int shear_direction, unsigned int shear_plane_normal) const {
144 if (m_lees_edwards_callbacks) {
145 if (m_lees_edwards_callbacks->shear_direction != shear_direction or
146 m_lees_edwards_callbacks->shear_plane_normal != shear_plane_normal) {
147 throw std::runtime_error(
148 "MD and LB Lees-Edwards boundary conditions disagree");
149 }
150 }
151}
152
153} // namespace walberla
void set_collision_model(double kT, unsigned int seed) override
Set up the thermalized collision model.
void check_lebc(unsigned int shear_direction, unsigned int shear_plane_normal) const override
Verify that MD and LB Lees-Edwards parameters are consistent.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
\file PackInfoPdfDoublePrecision.cpp \author pystencils