7 #include <boost/shared_ptr.hpp>
9 #define sptr boost::shared_ptr
11 using namespace boost;
13 typedef const unsigned int cuint;
15 inline bool to_buffer(vector<Vec*> arr,
double* buffer,
size_t sizet) {
16 if(sizet <
NDIM * arr.size()){
return false;};
17 for(
uint i=0; i < arr.size(); i++)
20 buffer[i*NDIM + j] = (double) ((*arr[i])[j]);
72 return Vec(remainder(r1[0], r2[0]), remainder(r1[1], r2[1]), remainder(r1[2], r2[2]));
77 return Vec(remainder(r1[0], r2[0]), remainder(r1[1], r2[1]));
104 return vec_mod((r1-r2), boxsize);
108 for(
uint i=0; i<
NDIM; i++) dr[i] -= boxsize[i] * boxes[i];
113 boost::array<int,NDIM> boxes;
115 for(
uint i=0; i<
NDIM; i++) boxes[i] = (
int) round(dr[i] / boxsize[i]);
120 flt V(){
return boxsize[0] * boxsize[1] * boxsize[2];};
121 flt L(){
return (boxsize[0] + boxsize[1] + boxsize[2])/3.0;};
125 flt V(){
return boxsize[0] * boxsize[1];};
126 flt L(){
return (boxsize[0] + boxsize[1])/2.0;};
133 flt resize_to(
Vec newsize);
137 flt resize_to_V(
flt newV);
142 flt resize_to_L(
flt newL);
151 return diff(v, Vec::Zero());
156 void pure_shear_to(
flt epsilon);
172 virtual Vec diff(
Vec r1,
Vec r2, boost::array<int,NDIM> boxes);
173 virtual boost::array<int,NDIM> box_round(
Vec r1,
Vec r2);
179 void shear(
flt dgamma);
183 void shear_to(
flt gamma);
187 v[0] -= gamma * v[1];
192 v[0] += gamma * v[1];
217 bool inside(
Vec r1,
flt buffer=0.0);
218 Vec rand_loc(
flt min_dist_to_wall=0.0);
253 inline Atom& operator *()
const {
return *ptr;};
279 inline uint n()
const {
return num;};
302 Atom& operator* ()
const;
317 virtual Atom& operator[](
cuint n)
const=0;
321 virtual uint size()
const=0;
329 Vec com_force()
const;
331 Vec com_velocity()
const;
340 flt kinetic_energy(
const Vec originvelocity=Vec::Zero())
const;
342 Vec momentum()
const;
344 flt gyradius()
const;
346 Vec torque(
const Vec loc)
const;
350 flt moment_about(
const Vec axis,
const Vec loc)
const;
353 Vec angular_momentum(
const Vec loc)
const;
359 Vec omega(
const Vec loc)
const;
362 void add_omega(
Vec w,
Vec origin);
366 Vec c = com(), w = omega(c);
367 if (w.squaredNorm() == 0)
return;
371 flt torque(
const Vec loc)
const;
374 flt moment(
const Vec loc)
const;
375 flt moment()
const{
return moment(com());};
377 flt angular_momentum(
const Vec loc)
const;
378 flt angular_momentum()
const {
return angular_momentum(com());};
380 flt omega(
const Vec loc)
const{
return angular_momentum(loc) / moment(loc);};
381 flt omega()
const{
return omega(com());};
383 void add_omega(
flt w,
Vec origin);
384 void add_omega(
flt w){add_omega(w, com());}
386 inline void reset_L(){
395 void add_velocity(
Vec v);
399 void randomize_velocities(
flt T);
417 for(
uint i=0; i < sz; i++){
418 atoms[i].
x = Vec::Zero();
419 atoms[i].
v = Vec::Zero();
420 atoms[i].
f = Vec::Zero();
421 atoms[i].
a = Vec::Zero();
426 atoms =
new Atom[sz];
427 for(
uint i=0; i < sz; i++) atoms[i].m = masses[i];
431 atoms =
new Atom[sz];
432 for(
uint i=0; i < sz; i++) atoms[i].m = mass;
436 atoms =
new Atom[sz];
437 for(
uint i=0; i < sz; i++) atoms[i] = other.atoms[i];
443 if (n > sz)
return AtomID();
return AtomID(atoms + n,n);};
465 std::vector<AtomID>::iterator it = std::find(ids.begin(), ids.end(), a);
467 throw std::invalid_argument(
"Cannot add AtomID to SubGroup: it already exists.");
468 return ids.push_back(a);
Vec torque() const
Definition: box.hpp:348
OriginBox(flt L)
Definition: box.hpp:119
virtual AtomIter begin()
For use in a for loop.
Definition: box.hpp:323
sptr< AtomVec > atoms
Definition: box.hpp:456
Vec vec()
A one-liner for creating a Vec object, occasionally useful from within Python.
Definition: vecrand.hpp:72
uint n() const
Definition: box.hpp:279
Vec rand_loc()
Get a random point in the box.
Definition: box.hpp:146
A spheocylinder box, also known as a capsule.
Definition: box.hpp:208
The basic class for representing each particle.
Definition: box.hpp:229
SubGroup(sptr< AtomVec > atoms)
Definition: box.hpp:459
bool operator<=(const AtomRef &other) const
Definition: box.hpp:259
Atom * operator->() const
Definition: box.hpp:254
Vec affine(Vec v)
Definition: box.hpp:191
bool operator<(const AtomRef &other) const
Definition: box.hpp:258
Atom & operator[](cuint n) const
Definition: box.hpp:462
Vec non_affine(Vec v)
Definition: box.hpp:186
AtomVec(vector< double > masses)
Definition: box.hpp:425
~AtomVec()
Definition: box.hpp:446
flt m
mass
Definition: box.hpp:243
a group of atoms, such as all of them (AtomVec), or a smaller group such as a molecule, sidebranch, etc.
Definition: box.hpp:312
Atom & operator[](cuint n)
Definition: box.hpp:461
IDPair(AtomID a, AtomID b)
Definition: box.hpp:287
The main class for representing particles.
Definition: box.hpp:412
unsigned int uint
Definition: vec.hpp:20
Vec x
location.
Definition: box.hpp:231
OriginBox(Vec size)
Definition: box.hpp:102
virtual AtomIter end()
Definition: box.hpp:324
double flt
The basic floating point type used in the simulations.
Definition: vecrand.hpp:45
void reset_L()
Reset angular momentum to 0.
Definition: box.hpp:365
Vec v
velocity
Definition: box.hpp:234
Vec angular_momentum() const
Definition: box.hpp:354
flt length()
Definition: box.hpp:219
const AtomIter & operator++()
Definition: box.hpp:303
An infinite Box, for use with, e.g., sticky conglomerations or proteins.
Definition: box.hpp:86
A rectilinear Box, with periodic boundary conditions.
Definition: box.hpp:98
bool operator==(const Atom *other) const
Definition: box.hpp:256
Atom & operator[](cuint n)
Definition: box.hpp:440
For iterating through an AtomGroup.
Definition: box.hpp:295
AtomRef()
Definition: box.hpp:251
AtomIter(AtomGroup &g, uint i)
Definition: box.hpp:300
void add(AtomID a)
Definition: box.hpp:464
Vec diff(Vec r1, Vec r2)
Distance between two points, given boundary conditions.
Definition: box.hpp:103
Lees-Edwards boundary conditions, with shear in the x-direction, relative to y.
Definition: box.hpp:165
flt V()
Returns NaN.
Definition: box.hpp:91
A pointer to an Atom, that also knows its own index in an AtomVec.
Definition: box.hpp:270
Vec a
acceleration
Definition: box.hpp:237
Vec diff(Vec r1, Vec r2)
Simply r1-r2.
Definition: box.hpp:89
virtual ~AtomGroup()
Definition: box.hpp:403
flt V()
Volume. Can return NaN.
Definition: box.hpp:120
uint size() const
Number of atoms in the group.
Definition: box.hpp:444
flt gamma
Definition: box.hpp:167
LeesEdwardsBox(Vec size, flt gamma=0.0)
Definition: box.hpp:169
void add_omega(Vec w)
Definition: box.hpp:363
AtomVec & vec()
Definition: box.hpp:460
AtomVec(AtomVec &other)
Definition: box.hpp:435
Atom & operator[](cuint n) const
Definition: box.hpp:441
vector< AtomID > ids
Definition: box.hpp:457
virtual Vec diff(Vec r1, Vec r2, boost::array< int, NDIM > boxes)
Definition: box.hpp:106
Vec f
forces
Definition: box.hpp:240
virtual boost::array< int, NDIM > box_round(Vec r1, Vec r2)
The div function to go with diff.
Definition: box.hpp:112
AtomID()
Constructor not recommended: uses UINT_MAX for number, i.e. unknown.
Definition: box.hpp:276
virtual ~Box()
Definition: box.hpp:59
bool operator!=(const AtomIter &other) const
Definition: box.hpp:301
AtomVec(uint N, flt mass)
Definition: box.hpp:430
flt L()
Definition: box.hpp:121
bool to_buffer(vector< Vec * > arr, double *buffer, size_t sizet)
Definition: box.hpp:15
AtomID first() const
Definition: box.hpp:288
AtomID get_id(cuint n)
Definition: box.hpp:442
bool operator==(const AtomRef &other) const
Definition: box.hpp:255
AtomID get_id(cuint n)
Definition: box.hpp:470
AtomID(Atom *a, uint n)
Recommended constructor.
Definition: box.hpp:278
AtomID last() const
Definition: box.hpp:289
A 3x3 matrix, with methods for adding, subtracting, dot product, etc.
Definition: vec.hpp:360
void reset_com_velocity()
Subtracts the center of mass velocity from all atoms.
Definition: box.hpp:397
Matrix moment() const
Definition: box.hpp:357
Vec vec_mod(Vec r1, Vec r2)
The modulus function for Vec.
Definition: box.hpp:71
AtomRef(Atom *a)
Definition: box.hpp:252
Atom & operator*() const
Definition: box.hpp:406
Vec box_shape()
Definition: box.hpp:153
Vec boxsize
Definition: box.hpp:100
IDPair()
Definition: box.hpp:286
bool operator>(const AtomRef &other) const
Definition: box.hpp:261
bool operator!=(const AtomRef &other) const
Definition: box.hpp:257
flt get_gamma()
The current shear amount.
Definition: box.hpp:176
bool operator>=(const AtomRef &other) const
Definition: box.hpp:260
#define NDIM
Definition: vecrand.hpp:12
uint size() const
Number of atoms in the group.
Definition: box.hpp:471
The virtual interface for the shape of the space and its boundaries.
Definition: box.hpp:50
AtomVec & vec()
Definition: box.hpp:439
Eigen::Matrix< flt, NDIM, 1 > Vec
The basic physics vector.
Definition: vecrand.hpp:53
Vec rand_vec_boxed()
Generate a random vector inside a box with sides of length 1.
Definition: vecrand.cpp:19
Vec omega() const
Definition: box.hpp:360
flt radius()
Definition: box.hpp:220
LeesEdwardsBox(flt L, flt gamma=0.0)
Definition: box.hpp:170
flt moment_about(const Vec axis) const
Definition: box.hpp:351
bool is_null()
Definition: box.hpp:262
A pointer to an Atom.
Definition: box.hpp:247
flt R
Definition: box.hpp:210
Vec diff(Vec r1, Vec r2)
Distance between two points, given boundary conditions.
Definition: box.hpp:213
const unsigned int cuint
Definition: box.hpp:13