32#include "system/System.hpp"
37#include <boost/mpi/collectives.hpp>
44 boost::mpi::broadcast(
comm_cart, nptiso->p_epsilon, 0);
45 boost::mpi::broadcast(
comm_cart, nptiso->volume, 0);
46 boost::mpi::broadcast(
comm_cart, npt_inst_pressure->p_inst, 0);
51#ifdef ESPRESSO_ELECTROSTATICS
52 if (dimension < 3 and not cubic_box and system.coulomb.impl->solver) {
53 throw std::runtime_error(
"If electrostatics is being used you must "
54 "use the cubic box NpT.");
57#ifdef ESPRESSO_DIPOLES
58 if (dimension < 3 and not cubic_box and system.dipoles.impl->solver) {
59 throw std::runtime_error(
"If magnetostatics is being used you must "
60 "use the cubic box NpT.");
68 : piston{piston}, inv_piston{piston}, p_ext{ext_pressure},
69 cubic_box{cubic_box} {
71 if (ext_pressure < 0.0) {
72 throw std::runtime_error(
"The external pressure must be positive");
75 throw std::runtime_error(
"The piston mass must be positive");
79 for (
auto const i : {0u, 1u, 2u}) {
88 throw std::runtime_error(
89 "You must enable at least one of the x y z components "
90 "as fluctuating dimension(s) for box length motion");
101 nptiso->inv_piston = 1. / nptiso->piston;
103 std::pow(box_geo->length()[nptiso->non_const_dim], nptiso->dimension);
110 auto const particle_number =
112 nptiso->particle_number =
113 boost::mpi::all_reduce(
::comm_cart, particle_number, std::plus<>());
116 nptiso->half_dt_inv_piston = 0.5 * dt * nptiso->inv_piston;
117 nptiso->half_dt_inv_piston_and_Nf = -nptiso->half_dt_inv_piston;
118 if (particle_number > 1) {
119 nptiso->half_dt_inv_piston_and_Nf *=
120 (1. + 1. /
static_cast<double>(particle_number - 1));
123 auto &mass_list = nptiso->mass_list;
125 for (
auto &p : cell_structure->local_particles()) {
126 mass_list.emplace_back(p.mass());
128 mass_list.erase(std::ranges::unique(mass_list).begin(), mass_list.end());
131 mass_list.erase(std::ranges::unique(mass_list).begin(), mass_list.end());
132 std::ranges::sort(mass_list);
138 if (has_npt_enabled()) {
139 npt_inst_pressure->p_vir[0] += energy;
Vector implementation and trait types for boost qvm interoperability.
auto get_time_step() const
Get time_step.
void npt_ensemble_init(bool recalc_forces)
Reinitialize the NpT state.
void npt_add_virial_contribution(double energy)
void synchronize_npt_state()
Synchronize NpT state such as instantaneous and average pressure.
std::shared_ptr< CellStructure > cell_structure
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
void gather_buffer(std::vector< T, Allocator > &buffer, boost::mpi::communicator const &comm, int root=0)
Gather buffer with different size on each node.
Exports for the NpT code.
void coulomb_dipole_sanity_checks(System::System const &system) const
int geometry
geometry information for the NpT integrator.
static constexpr std::array< int, 3 > nptgeom_dir
int non_const_dim
An index to one of the non-constant dimensions.
Utils::Vector< bool, 3 > get_direction() const
NptIsoParameters()=default
int dimension
The number of dimensions in which NpT boxlength motion is coupled to particles.
double piston
mass of a virtual piston representing the shaken box