ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
forces_init.cpp
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// Force initialization and Langevin thermostat live in their own translation
23// unit. Keeping the init tree out of forces.cpp leaves the whole-TU
24// inline-growth budget of forces.cpp for the hot pair kernel
25// (forces_cabana.hpp) and the Verlet-list build.
26
27#include "forces_init.hpp"
28
29#include <config/config.hpp>
30
31#include "Particle.hpp"
32#include "PropagationMode.hpp"
36#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
38#endif
39#include "rotation.hpp"
40#include "system/System.hpp"
41#include "thermostat.hpp"
43
44#ifdef ESPRESSO_CALIPER
45#include <caliper/cali.h>
46#endif
47
48/** External particle forces */
50 ParticleForce f = {};
51
52#ifdef ESPRESSO_EXTERNAL_FORCES
53 f.f += p.ext_force();
54#ifdef ESPRESSO_ROTATION
55 f.torque += p.ext_torque();
56#endif
57#endif
58
59#ifdef ESPRESSO_ENGINE
60 // apply a swimming force in the direction of
61 // the particle's orientation axis
62 if (p.swimming().swimming and !p.swimming().is_engine_force_on_fluid) {
63 f.f += p.swimming().f_swim * p.calc_director();
64 }
65#endif
66
67 return f;
68}
69
70/** Combined force initialization and Langevin noise application */
72#ifdef ESPRESSO_CALIPER
74#endif
75
76 auto &cell_structure = *system.cell_structure;
77 auto const &propagation = *system.propagation;
78 auto const &thermostat = *system.thermostat;
79 auto const kT = thermostat.kT;
80 auto const time_step = system.get_time_step();
81
82 // Check if Langevin thermostat is active
83 bool const langevin_active =
84 thermostat.langevin &&
85 (propagation.used_propagations &
87
88 // Single pass over all local particles
89 cell_structure.for_each_local_particle([&](Particle &p) {
90 // Initialize force with external forces
92
93 // Apply Langevin noise if thermostat is active
94 if (langevin_active) {
95 auto const &langevin = *thermostat.langevin;
96 if (propagation.should_propagate_with(p, PropagationMode::TRANS_LANGEVIN))
97 p.force() += friction_thermo_langevin(langevin, p, time_step, kT);
98#ifdef ESPRESSO_ROTATION
99 if (propagation.should_propagate_with(p, PropagationMode::ROT_LANGEVIN))
101 p, friction_thermo_langevin_rotation(langevin, p, time_step, kT));
102#endif
103 }
104 });
105 cell_structure.reset_local_force_and_torque();
106
107 // Initialize ghost forces
108 cell_structure.ghosts_reset_forces();
109#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
110 if (system.dipoles.impl->solver.has_value()) {
111 cell_structure.ghosts_reset_dipole_field();
112 }
113#endif
114}
Main system class.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static ParticleForce external_force(Particle const &p)
External particle forces.
void init_forces_and_thermostat(System::System const &system)
Combined force initialization and Langevin noise application.
Utils::Vector3d friction_thermo_langevin(LangevinThermostat const &langevin, Particle const &p, double time_step, double kT)
Langevin thermostat for particle translational velocities.
Utils::Vector3d friction_thermo_langevin_rotation(LangevinThermostat const &langevin, Particle const &p, double time_step, double kT)
Langevin thermostat for particle angular velocities.
This file contains all subroutines required to process rotational motion.
Utils::Vector3d convert_vector_body_to_space(const Particle &p, const Utils::Vector3d &vec)
Definition rotation.hpp:58
Force information on a particle.
Definition Particle.hpp:331
Utils::Vector3d torque
torque.
Definition Particle.hpp:361
Utils::Vector3d f
force.
Definition Particle.hpp:357
Struct holding all information for one particle.
Definition Particle.hpp:436
constexpr auto calc_director() const
Definition Particle.hpp:537
constexpr auto const & swimming() const
Definition Particle.hpp:653
constexpr auto const & ext_force() const
Definition Particle.hpp:646
constexpr auto const & ext_torque() const
Definition Particle.hpp:534
constexpr auto const & force() const
Definition Particle.hpp:480
constexpr auto const & force_and_torque() const
Definition Particle.hpp:482
constexpr auto const & torque() const
Definition Particle.hpp:529