ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
thermalized_bond_kernel.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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 "thermalized_bond.hpp"
25
26#include "Particle.hpp"
27#include "random.hpp"
28#include "system/System.hpp"
29#include "thermostat.hpp"
30
31#include <utils/Vector.hpp>
32
33#include <boost/optional.hpp>
34
35#include <cmath>
36#include <tuple>
37
38/** Separately thermalizes the com and distance of a particle pair.
39 * @param[in] p1 First particle.
40 * @param[in] p2 Second particle.
41 * @param[in] dx Distance between the particles.
42 * @return the forces on @p p1 and @p p2
43 */
44inline boost::optional<std::tuple<Utils::Vector3d, Utils::Vector3d>>
46 Utils::Vector3d const &dx) const {
47 // Bond broke?
48 if (r_cut > 0.0 && dx.norm() > r_cut) {
49 return {};
50 }
51
52 auto const mass_tot = p1.mass() + p2.mass();
53 auto const mass_tot_inv = 1.0 / mass_tot;
54 auto const sqrt_mass_tot = sqrt(mass_tot);
55 auto const sqrt_mass_red = sqrt(p1.mass() * p2.mass() / mass_tot);
56 auto const com_vel = mass_tot_inv * (p1.mass() * p1.v() + p2.mass() * p2.v());
57 auto const dist_vel = p2.v() - p1.v();
58 auto const &thermalized_bond =
59 *::System::get_system().thermostat->thermalized_bond;
60
61 Utils::Vector3d force1{};
62 Utils::Vector3d force2{};
63 auto const noise = Random::noise_uniform<RNGSalt::THERMALIZED_BOND>(
64 thermalized_bond.rng_counter(), thermalized_bond.rng_seed(), p1.id(),
65 p2.id());
66
67 for (unsigned int i = 0u; i < 3u; ++i) {
68 double force_lv_com, force_lv_dist;
69
70 // Langevin thermostat for center of mass
71 if (pref2_com > 0.0) {
72 force_lv_com =
73 -pref1_com * com_vel[i] + sqrt_mass_tot * pref2_com * noise[i];
74 } else {
75 force_lv_com = -pref1_com * com_vel[i];
76 }
77
78 // Langevin thermostat for distance p1->p2
79 if (pref2_dist > 0.0) {
80 force_lv_dist =
81 -pref1_dist * dist_vel[i] + sqrt_mass_red * pref2_dist * noise[i];
82 } else {
83 force_lv_dist = -pref1_dist * dist_vel[i];
84 }
85 // Add forces
86 force1[i] = p1.mass() * mass_tot_inv * force_lv_com - force_lv_dist;
87 force2[i] = p2.mass() * mass_tot_inv * force_lv_com + force_lv_dist;
88 }
89
90 return std::make_tuple(force1, force2);
91}
Vector implementation and trait types for boost qvm interoperability.
float u[3]
std::shared_ptr< Thermostat::Thermostat > thermostat
T norm() const
Definition Vector.hpp:131
System & get_system()
Random number generation using Philox.
Struct holding all information for one particle.
Definition Particle.hpp:393
auto const & mass() const
Definition Particle.hpp:450
auto const & v() const
Definition Particle.hpp:431
auto const & id() const
Definition Particle.hpp:412
boost::optional< std::tuple< Utils::Vector3d, Utils::Vector3d > > forces(Particle const &p1, Particle const &p2, Utils::Vector3d const &dx) const
Separately thermalizes the com and distance of a particle pair.
Routines to thermalize the center of mass and distance of a particle pair.