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_utils.hpp"
46
47#include <caliper/cali.h>
48#endif
49
50/** External particle forces */
52 ParticleForce f = {};
53
54#ifdef ESPRESSO_EXTERNAL_FORCES
55 f.f += p.ext_force();
56#ifdef ESPRESSO_ROTATION
57 f.torque += p.ext_torque();
58#endif
59#endif
60
61#ifdef ESPRESSO_ENGINE
62 // apply a swimming force in the direction of
63 // the particle's orientation axis
64 if (p.swimming().swimming and !p.swimming().is_engine_force_on_fluid) {
65 f.f += p.swimming().f_swim * p.calc_director();
66 }
67#endif
68
69 return f;
70}
71
72/** Combined force initialization and Langevin noise application */
74#ifdef ESPRESSO_CALIPER
76#endif
77
78 auto &cell_structure = *system.cell_structure;
79 auto const &propagation = *system.propagation;
80 auto const &thermostat = *system.thermostat;
81 auto const kT = thermostat.kT;
82 auto const time_step = system.get_time_step();
83
84 // Check if Langevin thermostat is active
85 bool const langevin_active =
86 thermostat.langevin &&
87 (propagation.used_propagations &
89
90 // Single pass over all local particles
91 cell_structure.for_each_local_particle([&](Particle &p) {
92 // Initialize force with external forces
94
95 // Apply Langevin noise if thermostat is active
96 if (langevin_active) {
97 auto const &langevin = *thermostat.langevin;
98 if (propagation.should_propagate_with(p, PropagationMode::TRANS_LANGEVIN))
99 p.force() += friction_thermo_langevin(langevin, p, time_step, kT);
100#ifdef ESPRESSO_ROTATION
101 if (propagation.should_propagate_with(p, PropagationMode::ROT_LANGEVIN))
103 p, friction_thermo_langevin_rotation(langevin, p, time_step, kT));
104#endif
105 }
106 });
107 // The local force/torque scatter buffers were already zeroed this force
108 // call by prepare_verlet_list_cabana() (via update_verlet_state).
109
110 // Initialize ghost forces
111 cell_structure.ghosts_reset_forces();
112#ifdef ESPRESSO_DIPOLE_FIELD_TRACKING
113 if (system.dipoles.impl->solver.has_value()) {
114 cell_structure.ghosts_reset_dipole_fields();
115 }
116#endif
117}
Zero-overhead Caliper guards for the inactive (no CALI_CONFIG) case.
#define ESPRESSO_CALI_MARK_FUNCTION
Guarded drop-in replacement for CALI_CXX_MARK_FUNCTION.
Main system class.
auto get_time_step() const
Get time_step.
Dipoles::Solver dipoles
std::shared_ptr< Propagation > propagation
std::shared_ptr< Thermostat::Thermostat > thermostat
std::shared_ptr< CellStructure > cell_structure
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
std::unique_ptr< Implementation > impl
Pointer-to-implementation.
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