ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
npt.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include "npt.hpp"
20
21#ifdef NPT
22
23#include "PropagationMode.hpp"
24#include "communication.hpp"
25#include "config/config.hpp"
27#include "errorhandling.hpp"
30#include "system/System.hpp"
31
32#include <utils/Vector.hpp>
33
34#include <boost/mpi/collectives/broadcast.hpp>
35
36#include <algorithm>
37#include <cmath>
38#include <stdexcept>
39
40static constexpr Utils::Vector3i nptgeom_dir{{1, 2, 4}};
41
43
45 boost::mpi::broadcast(comm_cart, nptiso.p_inst, 0);
46 boost::mpi::broadcast(comm_cart, nptiso.p_diff, 0);
47 boost::mpi::broadcast(comm_cart, nptiso.volume, 0);
48}
49
51#if defined(ELECTROSTATICS) or defined(DIPOLES)
52 auto &system = System::get_system();
53#ifdef ELECTROSTATICS
54 if (dimension < 3 and not cubic_box and system.coulomb.impl->solver) {
55 throw std::runtime_error("If electrostatics is being used you must "
56 "use the cubic box NpT.");
57 }
58#endif
59
60#ifdef DIPOLES
61 if (dimension < 3 and not cubic_box and system.dipoles.impl->solver) {
62 throw std::runtime_error("If magnetostatics is being used you must "
63 "use the cubic box NpT.");
64 }
65#endif
66#endif
67}
68
69NptIsoParameters::NptIsoParameters(double ext_pressure, double piston,
70 Utils::Vector<bool, 3> const &rescale,
71 bool cubic_box)
72 : piston{piston}, p_ext{ext_pressure}, cubic_box{cubic_box} {
73
74 if (ext_pressure < 0.0) {
75 throw std::runtime_error("The external pressure must be positive");
76 }
77 if (piston <= 0.0) {
78 throw std::runtime_error("The piston mass must be positive");
79 }
80
87
88 /* set the NpT geometry */
89 for (auto const i : {0, 1, 2}) {
90 if (rescale[i]) {
92 dimension += 1;
93 non_const_dim = i;
94 }
95 }
96
97 if (dimension == 0 or non_const_dim == -1) {
98 throw std::runtime_error(
99 "You must enable at least one of the x y z components "
100 "as fluctuating dimension(s) for box length motion");
101 }
102
104}
105
107 return {static_cast<bool>(geometry & ::nptgeom_dir[0]),
108 static_cast<bool>(geometry & ::nptgeom_dir[1]),
109 static_cast<bool>(geometry & ::nptgeom_dir[2])};
110}
111
112void npt_ensemble_init(Utils::Vector3d const &box_l, bool recalc_forces) {
114 nptiso.volume = std::pow(box_l[nptiso.non_const_dim], nptiso.dimension);
115 if (recalc_forces) {
116 nptiso.p_inst = 0.0;
119 }
120}
121
123 if (::System::get_system().propagation->used_propagations &
125 try {
127 } catch (std::runtime_error const &err) {
128 runtimeErrorMsg() << err.what();
129 }
130 }
131}
132
133/** reset virial part of instantaneous pressure */
135 if (::System::get_system().propagation->used_propagations &
138 }
139}
140
141void npt_add_virial_contribution(double energy) {
142 if (::System::get_system().propagation->used_propagations &
144 nptiso.p_vir[0] += energy;
145 }
146}
147
149 const Utils::Vector3d &d) {
150 if (::System::get_system().propagation->used_propagations &
152 nptiso.p_vir += hadamard_product(force, d);
153 }
154}
155#endif // NPT
Vector implementation and trait types for boost qvm interoperability.
__global__ float * force
boost::mpi::communicator comm_cart
The communicator.
This file contains the defaults for ESPResSo.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
#define runtimeErrorMsg()
System & get_system()
void npt_add_virial_contribution(double energy)
Definition npt.cpp:141
static constexpr Utils::Vector3i nptgeom_dir
Definition npt.cpp:40
void npt_ensemble_init(Utils::Vector3d const &box_l, bool recalc_forces)
Definition npt.cpp:112
void integrator_npt_sanity_checks()
Definition npt.cpp:122
void npt_reset_instantaneous_virials()
reset virial part of instantaneous pressure
Definition npt.cpp:134
NptIsoParameters nptiso
Definition npt.cpp:42
void synchronize_npt_state()
Synchronizes NpT state such as instantaneous and average pressure.
Definition npt.cpp:44
Exports for the NpT code.
NptIsoParameters nptiso
Definition npt.cpp:42
Parameters of the isotropic NpT-integration scheme.
Definition npt.hpp:34
double inv_piston
inverse of piston
Definition npt.hpp:41
int geometry
geometry information for the NpT integrator.
Definition npt.hpp:62
Utils::Vector3d p_vir
virial (short-range) components of p_inst
Definition npt.hpp:53
int non_const_dim
An index to one of the non-constant dimensions.
Definition npt.hpp:75
double p_diff
difference between p_ext and p_inst
Definition npt.hpp:51
double p_inst
instantaneous pressure the system currently has
Definition npt.hpp:49
Utils::Vector< bool, 3 > get_direction() const
Definition npt.cpp:106
NptIsoParameters()=default
Utils::Vector3d p_vel
ideal gas components of p_inst, derived from the velocities
Definition npt.hpp:55
int dimension
The number of dimensions in which NpT boxlength motion is coupled to particles.
Definition npt.hpp:65
double piston
mass of a virtual piston representing the shaken box
Definition npt.hpp:39
void coulomb_dipole_sanity_checks() const
Definition npt.cpp:50
double volume
isotropic volume.
Definition npt.hpp:45
static constexpr Utils::Vector3i nptgeom_dir