ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
lb_tracers.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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#include "config/config.hpp"
20
21#ifdef VIRTUAL_SITES_INERTIALESS_TRACERS
22
23#include "BoxGeometry.hpp"
24#include "LocalBox.hpp"
26#include "errorhandling.hpp"
27#include "forces.hpp"
28#include "lb/Solver.hpp"
30
31static bool lb_sanity_checks(LB::Solver const &lb) {
32 if (not lb.is_solver_set()) {
33 runtimeErrorMsg() << "LB needs to be active for inertialess tracers.";
34 return true;
35 }
36 return false;
37}
38
40 BoxGeometry const &box_geo,
41 LocalBox const &local_box,
42 LB::Solver &lb) {
43 if (lb_sanity_checks(lb)) {
44 return;
45 }
46 auto const agrid = lb.get_agrid();
47
48 // Distribute summed-up forces from physical particles to ghosts
49 init_forces_ghosts(cell_structure.ghost_particles());
51
52 // Keep track of ghost particles (ids) that have already been coupled
53 LB::CouplingBookkeeping bookkeeping{cell_structure};
54 // Apply particle forces to the LB fluid at particle positions.
55 // For physical particles, also set particle velocity = fluid velocity.
56 for (auto const &particle_range :
57 {cell_structure.local_particles(), cell_structure.ghost_particles()}) {
58 for (auto const &p : particle_range) {
59 if (!LB::is_tracer(p))
60 continue;
61 if (bookkeeping.should_be_coupled(p)) {
62 for (auto const &pos :
63 positions_in_halo(p.pos(), box_geo, local_box, agrid)) {
64 lb.add_force_density(pos, p.force());
65 }
66 }
67 }
68 }
69
70 // Clear ghost forces to avoid double counting later
71 init_forces_ghosts(cell_structure.ghost_particles());
72}
73
74void lb_tracers_propagate(CellStructure &cell_structure, LB::Solver const &lb,
75 double time_step) {
76 if (lb_sanity_checks(lb)) {
77 return;
78 }
79 auto const verlet_skin = cell_structure.get_verlet_skin();
80 auto const verlet_skin_sq = verlet_skin * verlet_skin;
81
82 // Advect particles
83 for (auto &p : cell_structure.local_particles()) {
84 if (!LB::is_tracer(p))
85 continue;
86 p.v() = lb.get_coupling_interpolated_velocity(p.pos());
87 for (auto i = 0u; i < 3u; i++) {
88 if (!p.is_fixed_along(i)) {
89 p.pos()[i] += p.v()[i] * time_step;
90 }
91 }
92 // Verlet list update check
93 if ((p.pos() - p.pos_at_last_verlet_update()).norm2() > verlet_skin_sq) {
95 }
96 }
97}
98#endif // VIRTUAL_SITES_INERTIALESS_TRACERS
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
float u[3]
Keep track of ghost particles that have already been coupled once.
This file contains the defaults for ESPResSo.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
void init_forces_ghosts(ParticleRange const &particles)
Set forces of all ghosts to zero.
Definition forces.cpp:102
Force calculation.
void lb_tracers_propagate(CellStructure &cell_structure, LB::Solver const &lb, double time_step)
void lb_tracers_add_particle_force_to_fluid(CellStructure &cell_structure, BoxGeometry const &box_geo, LocalBox const &local_box, LB::Solver &lb)
static bool lb_sanity_checks(LB::Solver const &lb)
@ DATA_PART_FORCE
Particle::f.
bool is_tracer(Particle const &p)
std::vector< Utils::Vector3d > positions_in_halo(Utils::Vector3d const &pos, BoxGeometry const &box_geo, LocalBox const &local_box, double agrid)
Return a vector of positions shifted by +,- box length in each coordinate.
Describes a cell structure / cell system.
ParticleRange ghost_particles() const
void update_ghosts_and_resort_particle(unsigned data_parts)
Update ghost particles, with particle resort if needed.
void set_resort_particles(Cells::Resort level)
Increase the local resort level at least to level.
auto get_verlet_skin() const
Get the Verlet skin.
ParticleRange local_particles() const
void add_force_density(Utils::Vector3d const &pos, Utils::Vector3d const &force_density)
Add a force density to the fluid at the given position.
Utils::Vector3d get_coupling_interpolated_velocity(Utils::Vector3d const &pos) const
Calculate the interpolated fluid velocity in MD units.
bool is_solver_set() const
Return true if a LB solver is active.
Definition lb/Solver.cpp:64
double get_agrid() const
Get the LB grid spacing.