ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
langevin_inline.hpp
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#pragma once
23
24#include "config/config.hpp"
25
26#include "Particle.hpp"
27#include "random.hpp"
28#include "rotation.hpp"
29#include "thermostat.hpp"
30
31#include <utils/Vector.hpp>
32#include <utils/matrix.hpp>
33
34/** Langevin thermostat for particle translational velocities.
35 * @param[in] langevin Parameters
36 * @param[in] p Particle
37 * @param[in] time_step Time step
38 * @param[in] kT Thermal energy
39 */
40inline Utils::Vector3d
42 double time_step, double kT) {
43 using namespace Thermostat;
44 // Determine prefactors for the friction and the noise term
45#ifdef ESPRESSO_THERMOSTAT_PER_PARTICLE
46 auto const gamma = handle_particle_gamma(p.gamma(), langevin.gamma);
47 auto const pref_friction = -gamma;
48 auto const pref_noise = LangevinThermostat::sigma(kT, time_step, gamma);
49#else
50 auto const pref_friction = langevin.pref_friction;
51 auto const pref_noise = langevin.pref_noise;
52#endif // ESPRESSO_THERMOSTAT_PER_PARTICLE
53
55 langevin.rng_counter(), langevin.rng_seed(), p.id());
56#ifdef ESPRESSO_PARTICLE_ANISOTROPY
57 auto const aniso_flag = (pref_friction[0] != pref_friction[1]) ||
58 (pref_friction[1] != pref_friction[2]);
59 if (aniso_flag) {
60 // Apply (O * diag(g) * O^T) * v as O * (g ⊙ (O^T * v)) using a single
61 // rotation matrix shared between the friction and noise terms.
62 auto const O = rotation_matrix(p.quat());
63 auto const Ot = O.transposed();
64 auto const v_body = Ot * p.v();
65 auto const noise_body = Ot * noise;
66 return O * (hadamard_product(pref_friction, v_body) +
67 hadamard_product(pref_noise, noise_body));
68 }
69#endif
70 return hadamard_product(pref_friction, p.v()) +
71 hadamard_product(pref_noise, noise);
72}
73
74#ifdef ESPRESSO_ROTATION
75/** Langevin thermostat for particle angular velocities.
76 * @param[in] langevin Parameters
77 * @param[in] p Particle
78 * @param[in] time_step Time step
79 * @param[in] kT Thermal energy
80 */
81inline Utils::Vector3d
83 Particle const &p, double time_step,
84 double kT) {
85 using namespace Thermostat;
86
87#ifdef ESPRESSO_THERMOSTAT_PER_PARTICLE
88 auto const gamma =
90 auto const pref_friction = gamma;
91 auto const pref_noise = LangevinThermostat::sigma(kT, time_step, gamma);
92#else
93 auto const pref_friction = langevin.gamma_rotation;
94 auto const pref_noise = langevin.pref_noise_rotation;
95#endif // ESPRESSO_THERMOSTAT_PER_PARTICLE
96
98 langevin.rng_counter(), langevin.rng_seed(), p.id());
99 return -hadamard_product(pref_friction, p.omega()) +
100 hadamard_product(pref_noise, noise);
101}
102#endif // ESPRESSO_ROTATION
Vector implementation and trait types for boost qvm interoperability.
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.
Matrix implementation and trait types for boost qvm interoperability.
DEVICE_QUALIFIER auto noise_uniform(uint64_t counter, uint32_t seed, int key1, int key2=0)
Generator for random uniform noise.
Definition random.hpp:114
auto const & handle_particle_gamma(GammaType const &particle_gamma, GammaType const &default_gamma)
VectorXd< 3 > Vector3d
Definition Vector.hpp:207
Random number generation using Philox.
This file contains all subroutines required to process rotational motion.
uint64_t rng_counter() const
Get current value of the RNG.
uint32_t rng_seed() const
Thermostat for Langevin dynamics.
GammaType pref_friction
Prefactor for the friction.
static GammaType sigma(double kT, double time_step, GammaType const &gamma)
Calculate the noise prefactor.
GammaType gamma_rotation
Rotational friction coefficient .
GammaType gamma
Translational friction coefficient .
GammaType pref_noise
Prefactor for the translational velocity noise.
GammaType pref_noise_rotation
Prefactor for the angular velocity noise.
Struct holding all information for one particle.
Definition Particle.hpp:436
constexpr auto const & quat() const
Definition Particle.hpp:527
constexpr auto const & omega() const
Definition Particle.hpp:531
constexpr auto const & gamma() const
Definition Particle.hpp:621
constexpr auto const & gamma_rot() const
Definition Particle.hpp:624
constexpr auto const & id() const
Definition Particle.hpp:455
constexpr auto const & v() const
Definition Particle.hpp:478