Skip to content

Commit

Permalink
bug correction and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Iximiel committed Feb 7, 2024
1 parent 94ddc24 commit eb5dbe0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/tools/Pbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void Pbc::apply(std::vector<Vector>& dlist, unsigned max_index) const {
apply(mdMemoryView< -1,3>(&dlist[0][0],dlist.size()),max_index);
}

void Pbc::apply(mdMemoryView< -1,3>dlist, unsigned max_index) const {
void Pbc::apply(mdMemoryView< -1,3> dlist, unsigned max_index) const {
if (max_index==0) max_index=dlist.size();
if(type==unset) {
// do nothing
Expand All @@ -183,17 +183,17 @@ void Pbc::apply(mdMemoryView< -1,3>dlist, unsigned max_index) const {
} else if(type==generic) {
for(unsigned k=0; k<max_index; ++k) {
auto t =distance(Vector(0.0,0.0,0.0),
Vector(dlist[k][0],dlist[k][1],dlist[k][2]));
{dlist[k][0],dlist[k][1],dlist[k][2]});
dlist[k][0] = t[0];
dlist[k][1] = t[1];
dlist[k][2] = t[2];
}
} else plumed_merror("unknown pbc type");
}

Vector Pbc::distance(const Vector&v1, Vector d,int*nshifts)const {
Vector Pbc::distance(const Vector&v1, Vector d, int*nshifts) const {
//d is copy/move constructed
//when possible d will be RVOed
//when possible d will be RVOed
//it is equivalent to declare Vector d ad assigning it to the difference
//between the inputs
d-=v1;
Expand Down
44 changes: 26 additions & 18 deletions src/tools/Pbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,33 @@
namespace PLMD {

//this more or less mocks c++20 span with fixed size
template < int N=3>
class MemoryView {
double *ptr_;
public:
MemoryView(double* p) :ptr_(p){}
constexpr size_t size()const {return N;}
double & operator[](size_t i) { return ptr_ [i];}
};
template < std::size_t N=3>
class MemoryView {
double *ptr_;
public:
MemoryView(double* p) :ptr_(p) {}
constexpr size_t size()const {return N;}
constexpr size_t extent = N;
double & operator[](size_t i) { return ptr_[i];}
};

//this more or less mocks c++23 mdspan
template < int N=-1,int STRIDE=3>
class mdMemoryView {
double *ptr_;
size_t size_;
public:
mdMemoryView(double* p, size_t s) :ptr_(p), size_(s){}
size_t size()const {return size_;}
MemoryView<STRIDE> operator[](size_t i) { return MemoryView<STRIDE>(ptr_ + i *N);}
};
//this more or less mocks c++23 mdspan without the fancy multi-indexed operator[]
//the idea is to take an address that you know to be strided in a certain way and
//make it avaiable to any interface (like using the data from a nunmpy.ndarray in
//a function thought for a std::vector<PLMD::Vector> )
//the N=-1 is there for mocking the run time size from the span (where a
//dynamic extent is size_t(-))
template < std::size_t N=-1, std::size_t STRIDE=3>
class mdMemoryView {
double *ptr_;
size_t size_;
public:
mdMemoryView(double* p, size_t s) :ptr_(p), size_(s) {}
size_t size()const {return size_;}
constexpr size_t extent = N;
constexpr size_t stride = STRIDE;
MemoryView<STRIDE> operator[](size_t i) { return MemoryView<STRIDE>(ptr_ + i * STRIDE);}
};

/*
Tool to deal with periodic boundary conditions.
Expand Down

0 comments on commit eb5dbe0

Please sign in to comment.