37#include <boost/mpi/collectives.hpp>
52#ifdef ESPRESSO_ELECTROSTATICS
53 if (dimension < 3 and not cubic_box and system.coulomb.impl->solver) {
54 throw std::runtime_error(
"If electrostatics is being used you must "
55 "use the cubic box NpT.");
58#ifdef ESPRESSO_DIPOLES
59 if (dimension < 3 and not cubic_box and system.dipoles.impl->solver) {
60 throw std::runtime_error(
"If magnetostatics is being used you must "
61 "use the cubic box NpT.");
72 if (ext_pressure < 0.0) {
73 throw std::runtime_error(
"The external pressure must be positive");
76 throw std::runtime_error(
"The piston mass must be positive");
80 for (
auto const i : {0u, 1u, 2u}) {
89 throw std::runtime_error(
90 "You must enable at least one of the x y z components "
91 "as fluctuating dimension(s) for box length motion");
111 auto const particle_number =
cell_structure->local_particles().size();
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;
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);
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.
std::shared_ptr< InstantaneousPressure > npt_inst_pressure
void npt_add_virial_contribution(double energy)
void synchronize_npt_state()
Synchronize NpT state such as instantaneous and average pressure.
std::shared_ptr< NptIsoParameters > nptiso
std::shared_ptr< CellStructure > cell_structure
bool has_npt_enabled() const
std::shared_ptr< BoxGeometry > box_geo
boost::mpi::communicator comm_cart
The communicator.
int this_node
The number of this node.
This file contains the asynchronous MPI communication.
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.
double inv_piston
inverse of piston
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
double p_ext
desired pressure to which the algorithm strives to
bool cubic_box
Set this flag if you want all box dimensions to be identical.
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