From 993cb26debd577a058680c0e316c9ae1bb70818f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 9 Jan 2024 20:41:22 +0100 Subject: [PATCH] Encapsulate bond parameters --- src/core/bonded_interactions/CMakeLists.txt | 11 +--- src/core/bonded_interactions/angle_common.hpp | 7 +-- src/core/bonded_interactions/angle_cosine.cpp | 35 ----------- src/core/bonded_interactions/angle_cosine.hpp | 14 +++-- .../bonded_interactions/angle_cossquare.cpp | 33 ---------- .../bonded_interactions/angle_cossquare.hpp | 14 +++-- .../bonded_interactions/angle_harmonic.hpp | 7 +-- .../bonded_interactions/bonded_coulomb.hpp | 7 +-- .../bonded_interactions/bonded_coulomb_sr.hpp | 7 +-- .../bonded_interaction_data.cpp | 20 +++++- .../bonded_interaction_data.hpp | 8 +++ .../bonded_interaction_utils.hpp | 6 +- .../bonded_interactions.dox | 6 +- src/core/bonded_interactions/bonded_tab.cpp | 61 ------------------- src/core/bonded_interactions/bonded_tab.hpp | 33 +++++++--- src/core/bonded_interactions/dihedral.hpp | 7 +-- src/core/bonded_interactions/fene.cpp | 37 ----------- src/core/bonded_interactions/fene.hpp | 19 +++--- src/core/bonded_interactions/harmonic.hpp | 7 +-- src/core/bonded_interactions/quartic.hpp | 7 +-- src/core/bonded_interactions/rigid_bond.cpp | 36 ----------- src/core/bonded_interactions/rigid_bond.hpp | 21 +++---- .../bonded_interactions/thermalized_bond.cpp | 47 -------------- .../bonded_interactions/thermalized_bond.hpp | 34 +++++++---- .../thermalized_bond_kernel.hpp | 5 +- .../thermalized_bond_utils.cpp | 39 ------------ .../thermalized_bond_utils.hpp | 31 ---------- src/core/global_ghost_flags.cpp | 4 +- src/core/integrate.cpp | 11 ++-- src/core/thermostat.cpp | 18 +++++- .../interactions/BondedInteraction.hpp | 9 +-- 31 files changed, 167 insertions(+), 434 deletions(-) delete mode 100644 src/core/bonded_interactions/angle_cosine.cpp delete mode 100644 src/core/bonded_interactions/angle_cossquare.cpp delete mode 100644 src/core/bonded_interactions/bonded_tab.cpp delete mode 100644 src/core/bonded_interactions/fene.cpp delete mode 100644 src/core/bonded_interactions/rigid_bond.cpp delete mode 100644 src/core/bonded_interactions/thermalized_bond.cpp delete mode 100644 src/core/bonded_interactions/thermalized_bond_utils.cpp delete mode 100644 src/core/bonded_interactions/thermalized_bond_utils.hpp diff --git a/src/core/bonded_interactions/CMakeLists.txt b/src/core/bonded_interactions/CMakeLists.txt index 3c4ad3afa5..08e44c9a8e 100644 --- a/src/core/bonded_interactions/CMakeLists.txt +++ b/src/core/bonded_interactions/CMakeLists.txt @@ -17,13 +17,4 @@ # along with this program. If not, see . # -target_sources( - espresso_core - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/angle_cosine.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/angle_cossquare.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/bonded_interaction_data.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/bonded_tab.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/fene.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/rigid_bond.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/thermalized_bond.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/thermalized_bond_utils.cpp) +target_sources(espresso_core PRIVATE bonded_interaction_data.cpp) diff --git a/src/core/bonded_interactions/angle_common.hpp b/src/core/bonded_interactions/angle_common.hpp index 8c12849be3..be54f82fbf 100644 --- a/src/core/bonded_interactions/angle_common.hpp +++ b/src/core/bonded_interactions/angle_common.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef ANGLE_COMMON_H -#define ANGLE_COMMON_H + +#pragma once + /** \file * Common code for functions calculating angle forces. */ @@ -95,5 +96,3 @@ angle_generic_force(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2, auto f_mid = -(f_left + f_right); return std::make_tuple(f_mid, f_left, f_right); } - -#endif /* ANGLE_COMMON_H */ diff --git a/src/core/bonded_interactions/angle_cosine.cpp b/src/core/bonded_interactions/angle_cosine.cpp deleted file mode 100644 index 80d0bc818e..0000000000 --- a/src/core/bonded_interactions/angle_cosine.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** \file - * - * Implementation of \ref angle_cosine.hpp - */ -#include "angle_cosine.hpp" - -#include - -AngleCosineBond::AngleCosineBond(double bend, double phi0) { - - this->bend = bend; - this->phi0 = phi0; - this->cos_phi0 = cos(phi0); - this->sin_phi0 = sin(phi0); -} diff --git a/src/core/bonded_interactions/angle_cosine.hpp b/src/core/bonded_interactions/angle_cosine.hpp index 4e455b0b1f..c67e76ee9c 100644 --- a/src/core/bonded_interactions/angle_cosine.hpp +++ b/src/core/bonded_interactions/angle_cosine.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef ANGLE_COSINE_H -#define ANGLE_COSINE_H + +#pragma once + /** \file * Routines to calculate the angle energy or/and and force * for a particle triple using the potential described in @@ -50,7 +51,12 @@ struct AngleCosineBond { static constexpr int num = 2; - AngleCosineBond(double bend, double phi0); + AngleCosineBond(double bend, double phi0) { + this->bend = bend; + this->phi0 = phi0; + this->cos_phi0 = cos(phi0); + this->sin_phi0 = sin(phi0); + } std::tuple forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const; @@ -98,5 +104,3 @@ inline double AngleCosineBond::energy(Utils::Vector3d const &vec1, // trig identity: cos(phi - phi0) = cos(phi)cos(phi0) + sin(phi)sin(phi0) return bend * (1 - (cos_phi * cos_phi0 + sin_phi * sin_phi0)); } - -#endif /* ANGLE_COSINE_H */ diff --git a/src/core/bonded_interactions/angle_cossquare.cpp b/src/core/bonded_interactions/angle_cossquare.cpp deleted file mode 100644 index 27ab9c3b2d..0000000000 --- a/src/core/bonded_interactions/angle_cossquare.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** \file - * - * Implementation of \ref angle_cossquare.hpp - */ -#include "angle_cossquare.hpp" - -#include - -AngleCossquareBond::AngleCossquareBond(double bend, double phi0) { - this->bend = bend; - this->phi0 = phi0; - this->cos_phi0 = cos(phi0); -} diff --git a/src/core/bonded_interactions/angle_cossquare.hpp b/src/core/bonded_interactions/angle_cossquare.hpp index b29d6c9cbe..1b59aa53ac 100644 --- a/src/core/bonded_interactions/angle_cossquare.hpp +++ b/src/core/bonded_interactions/angle_cossquare.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef ANGLE_COSSQUARE_H -#define ANGLE_COSSQUARE_H + +#pragma once + /** \file * Routines to calculate the angle energy or/and and force * for a particle triple using the potential described in @@ -31,6 +32,7 @@ #include #include +#include #include /** Parameters for three-body angular potential (cossquare). */ @@ -46,7 +48,11 @@ struct AngleCossquareBond { static constexpr int num = 2; - AngleCossquareBond(double bend, double phi0); + AngleCossquareBond(double bend, double phi0) { + this->bend = bend; + this->phi0 = phi0; + this->cos_phi0 = cos(phi0); + } std::tuple forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const; @@ -87,5 +93,3 @@ inline double AngleCossquareBond::energy(Utils::Vector3d const &vec1, auto const cos_phi = calc_cosine(vec1, vec2, true); return 0.5 * bend * Utils::sqr(cos_phi - cos_phi0); } - -#endif /* ANGLE_COSSQUARE_H */ diff --git a/src/core/bonded_interactions/angle_harmonic.hpp b/src/core/bonded_interactions/angle_harmonic.hpp index f0c813d376..407209e525 100644 --- a/src/core/bonded_interactions/angle_harmonic.hpp +++ b/src/core/bonded_interactions/angle_harmonic.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef ANGLE_HARMONIC_H -#define ANGLE_HARMONIC_H + +#pragma once + /** \file * Routines to calculate the angle energy or/and and force * for a particle triple using the potential described in @@ -91,5 +92,3 @@ inline double AngleHarmonicBond::energy(Utils::Vector3d const &vec1, auto const phi = acos(cos_phi); return 0.5 * bend * Utils::sqr(phi - phi0); } - -#endif /* ANGLE_HARMONIC_H */ diff --git a/src/core/bonded_interactions/bonded_coulomb.hpp b/src/core/bonded_interactions/bonded_coulomb.hpp index f341012f14..d34496047a 100644 --- a/src/core/bonded_interactions/bonded_coulomb.hpp +++ b/src/core/bonded_interactions/bonded_coulomb.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_BONDED_COULOMB_HPP -#define CORE_BN_IA_BONDED_COULOMB_HPP + +#pragma once + /** \file * Routines to calculate the bonded Coulomb potential between * particle pairs. @@ -85,5 +86,3 @@ BondedCoulomb::energy(double const q1q2, Utils::Vector3d const &dx) const { return .0; #endif } - -#endif diff --git a/src/core/bonded_interactions/bonded_coulomb_sr.hpp b/src/core/bonded_interactions/bonded_coulomb_sr.hpp index 2c3d5aa4f9..0e4023b8c1 100644 --- a/src/core/bonded_interactions/bonded_coulomb_sr.hpp +++ b/src/core/bonded_interactions/bonded_coulomb_sr.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_BONDED_COULOMB_SR_HPP -#define CORE_BN_IA_BONDED_COULOMB_SR_HPP + +#pragma once + /** \file * Routines to calculate the short-range part of the bonded Coulomb potential * between particle pairs. Can be used to subtract certain intramolecular @@ -98,5 +99,3 @@ inline boost::optional BondedCoulombSR::energy( return 0.; #endif } - -#endif diff --git a/src/core/bonded_interactions/bonded_interaction_data.cpp b/src/core/bonded_interactions/bonded_interaction_data.cpp index af0e876bc3..ab4750e9b5 100644 --- a/src/core/bonded_interactions/bonded_interaction_data.cpp +++ b/src/core/bonded_interactions/bonded_interaction_data.cpp @@ -17,7 +17,9 @@ * along with this program. If not, see . */ #include "bonded_interaction_data.hpp" +#include "rigid_bond.hpp" #include "system/System.hpp" +#include "thermalized_bond.hpp" #include #include @@ -59,7 +61,23 @@ double maximal_cutoff_bonded() { } void BondedInteractionsMap::on_ia_change() { + n_thermalized_bonds = 0; +#ifdef BOND_CONSTRAINT + n_rigid_bonds = 0; +#endif + for (auto &kv : *this) { + if (boost::get(&(*kv.second)) != nullptr) { + ++n_thermalized_bonds; + } +#ifdef BOND_CONSTRAINT + if (boost::get(&(*kv.second)) != nullptr) { + ++n_rigid_bonds; + } +#endif + } if (System::is_system_set()) { - System::get_system().on_short_range_ia_change(); + auto &system = System::get_system(); + system.on_short_range_ia_change(); + system.on_thermostat_param_change(); // thermalized bonds } } diff --git a/src/core/bonded_interactions/bonded_interaction_data.hpp b/src/core/bonded_interactions/bonded_interaction_data.hpp index 6cccd6749f..77e3ccd2f0 100644 --- a/src/core/bonded_interactions/bonded_interaction_data.hpp +++ b/src/core/bonded_interactions/bonded_interaction_data.hpp @@ -143,10 +143,18 @@ class BondedInteractionsMap { auto get_zero_based_type(int bond_id) const { return contains(bond_id) ? at(bond_id)->which() : 0; } + auto get_n_thermalized_bonds() const { return n_thermalized_bonds; } +#ifdef BOND_CONSTRAINT + auto get_n_rigid_bonds() const { return n_rigid_bonds; } +#endif private: container_type m_params = {}; key_type next_key = static_cast(0); + int n_thermalized_bonds = 0; +#ifdef BOND_CONSTRAINT + int n_rigid_bonds = 0; +#endif void on_ia_change(); }; diff --git a/src/core/bonded_interactions/bonded_interaction_utils.hpp b/src/core/bonded_interactions/bonded_interaction_utils.hpp index b68f2481b0..9f0f60c9a3 100644 --- a/src/core/bonded_interactions/bonded_interaction_utils.hpp +++ b/src/core/bonded_interactions/bonded_interaction_utils.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_BONDED_INTERACTION_UTILS_HPP -#define CORE_BN_IA_BONDED_INTERACTION_UTILS_HPP + +#pragma once #include "bonded_interaction_data.hpp" @@ -67,5 +67,3 @@ inline bool pair_bond_enum_exists_between(Particle const &p1, return pair_bond_enum_exists_on(p1, p2) or pair_bond_enum_exists_on(p2, p1); } - -#endif diff --git a/src/core/bonded_interactions/bonded_interactions.dox b/src/core/bonded_interactions/bonded_interactions.dox index 211500de17..a7d454ce1c 100644 --- a/src/core/bonded_interactions/bonded_interactions.dox +++ b/src/core/bonded_interactions/bonded_interactions.dox @@ -44,9 +44,9 @@ * * @subsection bondedIA_new_struct Defining the new interaction * - * Every interaction resides in its own source .cpp and .hpp files. A simple - * example for a bonded interaction is the FENE bond in @ref fene.hpp and - * @ref fene.cpp. Use these two files as templates for your interaction. + * Every interaction resides in its own source .hpp file. A simple + * example for a bonded interaction is the FENE bond in @ref fene.hpp. + * Use this file as template for your new interaction. * * The first step is to create a new @c struct which represents your new * bond type inside the .hpp file. It needs to have the following members: diff --git a/src/core/bonded_interactions/bonded_tab.cpp b/src/core/bonded_interactions/bonded_tab.cpp deleted file mode 100644 index 74762482f9..0000000000 --- a/src/core/bonded_interactions/bonded_tab.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include "bonded_interactions/bonded_tab.hpp" - -#include "errorhandling.hpp" - -#include - -#include -#include - -TabulatedBond::TabulatedBond(double min, double max, - std::vector const &energy, - std::vector const &force) { - pot = std::make_shared(min, max, force, energy); -} - -TabulatedDistanceBond::TabulatedDistanceBond(double min, double max, - std::vector const &energy, - std::vector const &force) - : TabulatedBond(min, max, energy, force) { - /* set table limits */ - this->pot->minval = min; - this->pot->maxval = max; -} - -TabulatedAngleBond::TabulatedAngleBond(double min, double max, - std::vector const &energy, - std::vector const &force) - : TabulatedBond(min, max, energy, force) { - /* set table limits */ - this->pot->minval = 0.0; - this->pot->maxval = Utils::pi() + ROUND_ERROR_PREC; -} - -TabulatedDihedralBond::TabulatedDihedralBond(double min, double max, - std::vector const &energy, - std::vector const &force) - : TabulatedBond(min, max, energy, force) { - /* set table limits */ - this->pot->minval = 0.0; - this->pot->maxval = 2.0 * Utils::pi() + ROUND_ERROR_PREC; -} diff --git a/src/core/bonded_interactions/bonded_tab.hpp b/src/core/bonded_interactions/bonded_tab.hpp index 440c6e30bc..130461b5d1 100644 --- a/src/core/bonded_interactions/bonded_tab.hpp +++ b/src/core/bonded_interactions/bonded_tab.hpp @@ -18,14 +18,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BONDED_INTERACTIONS_TABULATED_HPP -#define CORE_BONDED_INTERACTIONS_TABULATED_HPP + +#pragma once /** \file * Routines to calculate the energy and/or force for particle bonds, angles * and dihedrals via interpolation of lookup tables. - * - * Implementation in \ref bonded_tab.cpp. */ #include "config/config.hpp" @@ -35,6 +33,7 @@ #include "bonded_interactions/dihedral.hpp" #include +#include #include #include @@ -59,7 +58,9 @@ struct TabulatedBond { * @param force @copybrief TabulatedPotential::force_tab */ TabulatedBond(double min, double max, std::vector const &energy, - std::vector const &force); + std::vector const &force) { + pot = std::make_shared(min, max, force, energy); + } private: friend boost::serialization::access; @@ -77,7 +78,11 @@ struct TabulatedDistanceBond : public TabulatedBond { TabulatedDistanceBond(double min, double max, std::vector const &energy, - std::vector const &force); + std::vector const &force) + : TabulatedBond(min, max, energy, force) { + this->pot->minval = min; + this->pot->maxval = max; + } boost::optional force(Utils::Vector3d const &dx) const; boost::optional energy(Utils::Vector3d const &dx) const; @@ -90,7 +95,12 @@ struct TabulatedAngleBond : public TabulatedBond { static constexpr int num = 2; TabulatedAngleBond(double min, double max, std::vector const &energy, - std::vector const &force); + std::vector const &force) + : TabulatedBond(min, max, energy, force) { + this->pot->minval = 0.; + this->pot->maxval = Utils::pi() + ROUND_ERROR_PREC; + } + std::tuple forces(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const; double energy(Utils::Vector3d const &vec1, Utils::Vector3d const &vec2) const; @@ -104,7 +114,12 @@ struct TabulatedDihedralBond : public TabulatedBond { TabulatedDihedralBond(double min, double max, std::vector const &energy, - std::vector const &force); + std::vector const &force) + : TabulatedBond(min, max, energy, force) { + this->pot->minval = 0.; + this->pot->maxval = 2. * Utils::pi() + ROUND_ERROR_PREC; + } + boost::optional> forces(Utils::Vector3d const &v12, Utils::Vector3d const &v23, @@ -266,5 +281,3 @@ TabulatedDihedralBond::energy(Utils::Vector3d const &v12, return pot->energy(phi); } - -#endif diff --git a/src/core/bonded_interactions/dihedral.hpp b/src/core/bonded_interactions/dihedral.hpp index f5281dd006..64fa9fde84 100644 --- a/src/core/bonded_interactions/dihedral.hpp +++ b/src/core/bonded_interactions/dihedral.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef DIHEDRAL_H -#define DIHEDRAL_H + +#pragma once + /** \file * Routines to calculate the dihedral energy or/and * force for a particle quadruple. Note that usage of dihedrals @@ -210,5 +211,3 @@ DihedralBond::energy(Utils::Vector3d const &v12, Utils::Vector3d const &v23, return bend * (1. - cos(mult * phi - phase)); } - -#endif diff --git a/src/core/bonded_interactions/fene.cpp b/src/core/bonded_interactions/fene.cpp deleted file mode 100644 index 352cf03650..0000000000 --- a/src/core/bonded_interactions/fene.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** \file - * - * Implementation of \ref fene.hpp - */ - -#include "fene.hpp" - -#include - -FeneBond::FeneBond(double k, double drmax, double r0) { - this->k = k; - this->drmax = drmax; - this->r0 = r0; - - this->drmax2 = Utils::sqr(this->drmax); - this->drmax2i = 1.0 / this->drmax2; -} diff --git a/src/core/bonded_interactions/fene.hpp b/src/core/bonded_interactions/fene.hpp index 25399a1101..0866f9ea66 100644 --- a/src/core/bonded_interactions/fene.hpp +++ b/src/core/bonded_interactions/fene.hpp @@ -18,18 +18,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_FENE_HPP -#define CORE_BN_IA_FENE_HPP + +#pragma once + /** \file * Routines to calculate the FENE potential between particle pairs. - * - * Implementation in \ref fene.cpp. */ #include "config/config.hpp" #include "errorhandling.hpp" #include +#include #include @@ -52,7 +52,14 @@ struct FeneBond { static constexpr int num = 1; - FeneBond(double k, double drmax, double r0); + FeneBond(double k, double drmax, double r0) { + this->k = k; + this->drmax = drmax; + this->r0 = r0; + + this->drmax2 = Utils::sqr(this->drmax); + this->drmax2i = 1. / this->drmax2; + } boost::optional force(Utils::Vector3d const &dx) const; boost::optional energy(Utils::Vector3d const &dx) const; @@ -109,5 +116,3 @@ FeneBond::energy(Utils::Vector3d const &dx) const { return -0.5 * k * drmax2 * log(1.0 - dr * dr * drmax2i); } - -#endif diff --git a/src/core/bonded_interactions/harmonic.hpp b/src/core/bonded_interactions/harmonic.hpp index bd47c14a79..ea091a3a55 100644 --- a/src/core/bonded_interactions/harmonic.hpp +++ b/src/core/bonded_interactions/harmonic.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_HARMONIC_HPP -#define CORE_BN_IA_HARMONIC_HPP + +#pragma once + /** \file * Routines to calculate the harmonic bond potential between particle pairs. */ @@ -101,5 +102,3 @@ HarmonicBond::energy(Utils::Vector3d const &dx) const { return 0.5 * k * Utils::sqr(dist - r); } - -#endif diff --git a/src/core/bonded_interactions/quartic.hpp b/src/core/bonded_interactions/quartic.hpp index 5b9379cfb2..9d724c58d4 100644 --- a/src/core/bonded_interactions/quartic.hpp +++ b/src/core/bonded_interactions/quartic.hpp @@ -18,8 +18,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_BN_IA_QUARTIC_HPP -#define CORE_BN_IA_QUARTIC_HPP + +#pragma once + /** \file * Routines to calculate the quartic potential between particle pairs. */ @@ -102,5 +103,3 @@ QuarticBond::energy(Utils::Vector3d const &dx) const { return 0.5 * k0 * dr2 + 0.25 * k1 * Utils::sqr(dr2); } - -#endif diff --git a/src/core/bonded_interactions/rigid_bond.cpp b/src/core/bonded_interactions/rigid_bond.cpp deleted file mode 100644 index 782cdfb822..0000000000 --- a/src/core/bonded_interactions/rigid_bond.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** \file - * - * Implementation of \ref rigid_bond.hpp - */ - -#include "rigid_bond.hpp" - -int n_rigidbonds = 0; - -RigidBond::RigidBond(double d, double p_tol, double v_tol) { - this->d2 = d * d; - this->p_tol = 2.0 * p_tol; - this->v_tol = v_tol; - - n_rigidbonds++; -} diff --git a/src/core/bonded_interactions/rigid_bond.hpp b/src/core/bonded_interactions/rigid_bond.hpp index 97ab70e2ed..9767def295 100644 --- a/src/core/bonded_interactions/rigid_bond.hpp +++ b/src/core/bonded_interactions/rigid_bond.hpp @@ -18,22 +18,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef RIGID_BOND_HPP -#define RIGID_BOND_HPP + +#pragma once + /** \file - * Definition of the rigid bond data type. It is utilized by the - * Rattle algorithm. - * - * Implementation in \ref rigid_bond.cpp. + * Definition of the rigid bond data type for the Rattle algorithm. */ #include #include -/** Number of rigid bonds. */ -extern int n_rigidbonds; - /** Parameters for the rigid_bond/SHAKE/RATTLE ALGORITHM */ struct RigidBond { /** Square of the length of Constrained Bond */ @@ -51,7 +46,11 @@ struct RigidBond { static constexpr int num = 1; - RigidBond(double d, double p_tol, double v_tol); + RigidBond(double d, double p_tol, double v_tol) { + this->d2 = d * d; + this->p_tol = 2.0 * p_tol; + this->v_tol = v_tol; + } private: friend boost::serialization::access; @@ -62,5 +61,3 @@ struct RigidBond { ar &v_tol; } }; - -#endif diff --git a/src/core/bonded_interactions/thermalized_bond.cpp b/src/core/bonded_interactions/thermalized_bond.cpp deleted file mode 100644 index 8158d8bfb3..0000000000 --- a/src/core/bonded_interactions/thermalized_bond.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -/** \file - * - * Implementation of \ref thermalized_bond.hpp - */ - -#include "thermalized_bond.hpp" -#include "system/System.hpp" - -int n_thermalized_bonds = 0; - -ThermalizedBond::ThermalizedBond(double temp_com, double gamma_com, - double temp_distance, double gamma_distance, - double r_cut) { - this->temp_com = temp_com; - this->gamma_com = gamma_com; - this->temp_distance = temp_distance; - this->gamma_distance = gamma_distance; - this->r_cut = r_cut; - - pref1_com = -1.; - pref2_com = -1.; - pref1_dist = -1.; - pref2_dist = -1.; - - n_thermalized_bonds++; - System::get_system().on_thermostat_param_change(); -} diff --git a/src/core/bonded_interactions/thermalized_bond.hpp b/src/core/bonded_interactions/thermalized_bond.hpp index 4cbb9e7e91..d315fce101 100644 --- a/src/core/bonded_interactions/thermalized_bond.hpp +++ b/src/core/bonded_interactions/thermalized_bond.hpp @@ -1,4 +1,3 @@ - /* * Copyright (C) 2010-2022 The ESPResSo project * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 @@ -20,23 +19,19 @@ * along with this program. If not, see . */ -#ifndef THERMALIZED_DIST_H -#define THERMALIZED_DIST_H +#pragma once + /** \file * Routines to thermalize the center of mass and distance of a particle pair. - * - * Implementation in \ref thermalized_bond.cpp. */ -/** number of thermalized bonds */ -extern int n_thermalized_bonds; - #include "Particle.hpp" #include #include +#include #include /** Parameters for Thermalized bond */ @@ -56,7 +51,26 @@ struct ThermalizedBond { static constexpr int num = 1; ThermalizedBond(double temp_com, double gamma_com, double temp_distance, - double gamma_distance, double r_cut); + double gamma_distance, double r_cut) { + this->temp_com = temp_com; + this->gamma_com = gamma_com; + this->temp_distance = temp_distance; + this->gamma_distance = gamma_distance; + this->r_cut = r_cut; + + pref1_com = -1.; + pref2_com = -1.; + pref1_dist = -1.; + pref2_dist = -1.; + } + + void recalc_prefactors(double time_step) { + pref1_com = gamma_com; + pref2_com = std::sqrt(24. * gamma_com / time_step * temp_com); + pref1_dist = gamma_distance; + pref2_dist = std::sqrt(24. * gamma_distance / time_step * temp_distance); + } + boost::optional> forces(Particle const &p1, Particle const &p2, Utils::Vector3d const &dx) const; @@ -76,5 +90,3 @@ struct ThermalizedBond { ar &pref2_dist; } }; - -#endif diff --git a/src/core/bonded_interactions/thermalized_bond_kernel.hpp b/src/core/bonded_interactions/thermalized_bond_kernel.hpp index ef143c593a..d8585a70e5 100644 --- a/src/core/bonded_interactions/thermalized_bond_kernel.hpp +++ b/src/core/bonded_interactions/thermalized_bond_kernel.hpp @@ -19,8 +19,7 @@ * along with this program. If not, see . */ -#ifndef THERMALIZED_DIST_KERNEL_H -#define THERMALIZED_DIST_KERNEL_H +#pragma once #include "thermalized_bond.hpp" @@ -88,5 +87,3 @@ ThermalizedBond::forces(Particle const &p1, Particle const &p2, return std::make_tuple(force1, force2); } - -#endif diff --git a/src/core/bonded_interactions/thermalized_bond_utils.cpp b/src/core/bonded_interactions/thermalized_bond_utils.cpp deleted file mode 100644 index 1b87b98c06..0000000000 --- a/src/core/bonded_interactions/thermalized_bond_utils.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "thermalized_bond_utils.hpp" -#include "thermalized_bond.hpp" - -#include "bonded_interactions/bonded_interaction_data.hpp" - -#include - -void thermalized_bond_init(double time_step) { - for (auto &kv : bonded_ia_params) { - if (auto *t = boost::get(&(*kv.second))) { - t->pref1_com = t->gamma_com; - t->pref2_com = sqrt(24.0 * t->gamma_com / time_step * t->temp_com); - t->pref1_dist = t->gamma_distance; - t->pref2_dist = - sqrt(24.0 * t->gamma_distance / time_step * t->temp_distance); - } - } -} diff --git a/src/core/bonded_interactions/thermalized_bond_utils.hpp b/src/core/bonded_interactions/thermalized_bond_utils.hpp deleted file mode 100644 index d8a2da821c..0000000000 --- a/src/core/bonded_interactions/thermalized_bond_utils.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2010-2022 The ESPResSo project - * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 - * Max-Planck-Institute for Polymer Research, Theory Group - * - * This file is part of ESPResSo. - * - * ESPResSo is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ESPResSo is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef THERMALIZED_BOND_UTILS_H -#define THERMALIZED_BOND_UTILS_H -/** \file - * Initialization routine for all thermalized bonds. - * - * Implementation in \ref thermalized_bond_utils.cpp. - */ -void thermalized_bond_init(double time_step); - -#endif diff --git a/src/core/global_ghost_flags.cpp b/src/core/global_ghost_flags.cpp index ff38d61b40..3f590e700d 100644 --- a/src/core/global_ghost_flags.cpp +++ b/src/core/global_ghost_flags.cpp @@ -21,7 +21,7 @@ #include "global_ghost_flags.hpp" -#include "bonded_interactions/thermalized_bond.hpp" +#include "bonded_interactions/bonded_interaction_data.hpp" #include "collision.hpp" #include "config/config.hpp" #include "system/System.hpp" @@ -42,7 +42,7 @@ unsigned global_ghost_flags() { if (::thermo_switch & THERMO_DPD) data_parts |= Cells::DATA_PART_MOMENTUM; - if (::n_thermalized_bonds) { + if (::bonded_ia_params.get_n_thermalized_bonds()) { data_parts |= Cells::DATA_PART_MOMENTUM; data_parts |= Cells::DATA_PART_BONDS; } diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index 9b2bcd50bb..e2c944c7f1 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -39,7 +39,7 @@ #include "PropagationMode.hpp" #include "accumulators.hpp" #include "bond_breakage/bond_breakage.hpp" -#include "bonded_interactions/rigid_bond.hpp" +#include "bonded_interactions/bonded_interaction_data.hpp" #include "cell_system/CellStructure.hpp" #include "cells.hpp" #include "collision.hpp" @@ -416,6 +416,9 @@ int System::System::integrate(int n_steps, int reuse_forces) { PropagationMode::TRANS_VS_RELATIVE); }; #endif +#ifdef BOND_CONSTRAINT + auto const n_rigid_bonds = ::bonded_ia_params.get_n_rigid_bonds(); +#endif // Prepare particle structure and run sanity checks of all active algorithms propagation.update_default_propagation(); @@ -497,7 +500,7 @@ int System::System::integrate(int n_steps, int reuse_forces) { auto particles = cell_structure->local_particles(); #ifdef BOND_CONSTRAINT - if (n_rigidbonds) + if (n_rigid_bonds) save_old_position(particles, cell_structure->ghost_particles()); #endif @@ -527,7 +530,7 @@ int System::System::integrate(int n_steps, int reuse_forces) { #ifdef BOND_CONSTRAINT // Correct particle positions that participate in a rigid/constrained bond - if (n_rigidbonds) { + if (n_rigid_bonds) { correct_position_shake(*cell_structure, *box_geo); } #endif @@ -571,7 +574,7 @@ int System::System::integrate(int n_steps, int reuse_forces) { } #ifdef BOND_CONSTRAINT // SHAKE velocity updates - if (n_rigidbonds) { + if (n_rigid_bonds) { correct_velocity_shake(*cell_structure, *box_geo); } #endif diff --git a/src/core/thermostat.cpp b/src/core/thermostat.cpp index cc44101ac3..ef92a2e185 100644 --- a/src/core/thermostat.cpp +++ b/src/core/thermostat.cpp @@ -24,8 +24,8 @@ #include "config/config.hpp" +#include "bonded_interactions/bonded_interaction_data.hpp" #include "bonded_interactions/thermalized_bond.hpp" -#include "bonded_interactions/thermalized_bond_utils.hpp" #include "communication.hpp" #include "dpd.hpp" #include "errorhandling.hpp" @@ -33,6 +33,8 @@ #include "system/System.hpp" #include "thermostat.hpp" +#include + #include #include @@ -95,9 +97,11 @@ REGISTER_THERMOSTAT_CALLBACKS(dpd) REGISTER_THERMOSTAT_CALLBACKS(stokesian) #endif +static void thermalized_bond_init(double time_step); + void thermo_init(double time_step) { // initialize thermalized bond regardless of the current thermostat - if (n_thermalized_bonds) { + if (::bonded_ia_params.get_n_thermalized_bonds()) { thermalized_bond_init(time_step); } if (thermo_switch == THERMO_OFF) { @@ -140,7 +144,7 @@ void philox_counter_increment() { stokesian.rng_increment(); } #endif - if (n_thermalized_bonds) { + if (::bonded_ia_params.get_n_thermalized_bonds()) { thermalized_bond.rng_increment(); } } @@ -222,3 +226,11 @@ void mpi_set_nptiso_gammas(double gamma0, double gammav) { mpi_call_all(mpi_set_nptiso_gammas_local, gamma0, gammav); } #endif + +void thermalized_bond_init(double time_step) { + for (auto &kv : ::bonded_ia_params) { + if (auto *bond = boost::get(&(*kv.second))) { + bond->recalc_prefactors(time_step); + } + } +} diff --git a/src/script_interface/interactions/BondedInteraction.hpp b/src/script_interface/interactions/BondedInteraction.hpp index ecffe8a954..2c04ad1055 100644 --- a/src/script_interface/interactions/BondedInteraction.hpp +++ b/src/script_interface/interactions/BondedInteraction.hpp @@ -17,15 +17,14 @@ * along with this program. If not, see . */ +#pragma once + /** @file * The ScriptInterface counterparts of the bonded interactions parameters * structs from the core are defined here. * */ -#ifndef SCRIPT_INTERFACE_INTERACTIONS_BONDED_INTERACTION_HPP -#define SCRIPT_INTERFACE_INTERACTIONS_BONDED_INTERACTION_HPP - #include "core/bonded_interactions/bonded_interaction_data.hpp" #include "core/immersed_boundaries.hpp" #include "core/thermostat.hpp" @@ -114,7 +113,7 @@ class BondedInteraction : public AutoParameters { virtual void construct_bond(VariantMap const ¶ms) = 0; public: - bool operator==(BondedInteraction const &other) { + bool operator==(BondedInteraction const &other) const { return m_bonded_ia == other.m_bonded_ia; } @@ -678,5 +677,3 @@ class VirtualBond : public BondedInteractionImpl<::VirtualBond> { } // namespace Interactions } // namespace ScriptInterface - -#endif