10#ifndef COLVARS_SYSTEM_H
11#define COLVARS_SYSTEM_H
13#include "colvartypes.h"
48 inline COLVARS_HOST_DEVICE
void reset() {
50 type_ = types::non_periodic;
55 reciprocal_cell_y.
reset();
56 reciprocal_cell_z.
reset();
60 inline COLVARS_HOST_DEVICE
void set_boundaries(
bool periodic_x_in,
bool periodic_y_in,
75 bool periodic_x =
false, periodic_y =
false, periodic_z =
false;
80inline COLVARS_HOST_DEVICE
void
81cvm::system_boundary_conditions::set_boundaries(
bool periodic_x_in,
bool periodic_y_in,
85 constexpr double diagonal_tol2 = 1.0e-10;
88 periodic_y = periodic_y_in;
89 periodic_z = periodic_z_in;
93 reciprocal_cell_y.
reset();
94 reciprocal_cell_z.
reset();
107 bool off_diagonal =
false;
111 if ((A.y * A.y) > diagonal_tol2 || (A.z * A.z) > diagonal_tol2) {
123 if ((B.x * B.x) > diagonal_tol2 || (B.z * B.z) > diagonal_tol2) {
126 reciprocal_cell_y = unit_cell_y/unit_cell_y.norm2();
130 reciprocal_cell_y.
reset();
135 if ((C.x * C.x) > diagonal_tol2 || (C.y * C.y) > diagonal_tol2) {
138 reciprocal_cell_z = unit_cell_z/unit_cell_z.norm2();
142 reciprocal_cell_z.
reset();
150 cvm::rvector const v_yz = cvm::rvector::outer(unit_cell_y, unit_cell_z);
153 reciprocal_cell_y = v_zx / (v_zx * unit_cell_y);
155 reciprocal_cell_z = v_xy / (v_xy * unit_cell_z);
160inline COLVARS_HOST_DEVICE
166 if (
type() == types::non_periodic) {
171#if !(defined(__HIP_DEVICE_COMPILE__)) && !(defined(__CUDA_ARCH__))
172 cvm::error_static(
"Error: unsupported boundary conditions.\n", COLVARS_INPUT_ERROR);
181 diff.x -= x_shift *
unit_cell_x.x + y_shift * unit_cell_y.x + z_shift * unit_cell_z.x;
182 diff.y -= x_shift *
unit_cell_x.y + y_shift * unit_cell_y.y + z_shift * unit_cell_z.y;
183 diff.z -= x_shift *
unit_cell_x.z + y_shift * unit_cell_y.z + z_shift * unit_cell_z.z;
195cvm::system_boundary_conditions::get_triclinic_shift(
cvm::rvector const &diff)
const
201 int const ny = periodic_y ? 1 : 0;
202 int const nz = periodic_z ? 1 : 0;
205 for (
int ix = -nx; ix <= nx; ix++) {
206 for (
int iy = -ny; iy <= ny; iy++) {
207 for (
int iz = -nz; iz <= nz; iz++) {
209 cvm::real const this_dist2 = (diff + shift).norm2();
210 if (this_dist2 < min_dist2) {
212 min_dist2 = this_dist2;
vector of real numbers with three components
Definition: colvartypes.h:728
COLVARS_HOST_DEVICE void reset()
Set all components to zero.
Definition: colvartypes.h:740
Class to store the system's boundary conditions.
Definition: colvars_system.h:16
COLVARS_HOST_DEVICE void set_boundaries(bool periodic_x_in, bool periodic_y_in, bool periodic_z_in, cvm::rvector const &A, cvm::rvector const &B, cvm::rvector const &C)
Set from explicit boundary configuration.
Definition: colvars_system.h:81
system_boundary_conditions(system_boundary_conditions const &)=default
Copy constructor.
types type_
Type of boundary conditions in the current computation.
Definition: colvars_system.h:66
COLVARS_HOST_DEVICE cvm::rvector position_distance(cvm::atom_pos const &pos1, cvm::atom_pos const &pos2) const
Compute the distance between two positions.
Definition: colvars_system.h:161
cvm::rvector unit_cell_x
Bravais lattice vectors.
Definition: colvars_system.h:69
bool periodic_x
Periodic flags in each dimension.
Definition: colvars_system.h:75
COLVARS_HOST_DEVICE cvm::rvector get_triclinic_shift(cvm::rvector const &diff) const
Compute a shift vector that accounts for tilt factors up to 0.5.
Definition: colvars_system.h:195
COLVARS_HOST_DEVICE void reset()
Reset to defaults (non-periodic)
Definition: colvars_system.h:48
COLVARS_HOST_DEVICE system_boundary_conditions()
Default constructor.
Definition: colvars_system.h:29
types
Type of boundary conditions defined for the current computation.
Definition: colvars_system.h:20
@ mixed
All three dimensions are non-periodic.
@ pbc_triclinic
All three dimensions are periodic, lattice vectors are orthogonal.
@ unsupported
All three dimensions are periodic, lattice vectors are not orthogonal.
@ pbc_orthogonal
Some dimensions are periodic, but others are not.
cvm::rvector reciprocal_cell_x
Reciprocal lattice vectors.
Definition: colvars_system.h:72
COLVARS_HOST_DEVICE void set_type(types t)
Set the type of boundary explicitly.
Definition: colvars_system.h:38
COLVARS_HOST_DEVICE types type() const
Type of boundary conditions in the current computation.
Definition: colvars_system.h:35
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:99
static real floor(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:125
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:775