forked from rikigigi/analisi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atomicdensity.cpp
72 lines (62 loc) · 2.78 KB
/
atomicdensity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "atomicdensity.h"
#include "config.h"
template <class T, class Hist>
AtomicDensity<T,Hist>::AtomicDensity(T *t, std::array<size_t, 3> nbin, unsigned int nthreads, unsigned int skip) : CalcolaMultiThread<This> {nthreads, skip}, nbin{nbin},t{t}, ntypes{t->get_ntypes()}
{
lunghezza_lista=nbin[0]*nbin[1]*nbin[2]*ntypes;
lista=new Hist [lunghezza_lista];
hist=new Hist [ lunghezza_lista*(nthreads-1)];
azzera();
}
template <class T, class Hist>
AtomicDensity<T,Hist>::~AtomicDensity() {
delete [] hist; // lista deleted in OperazioniSuLista
}
template <class T, class Hist>
void AtomicDensity<T, Hist>::calc_single_th(const unsigned int &start, const unsigned int & stop, const unsigned int & primo, const unsigned int & ith) {
if (ntimesteps+primo > t->get_ntimesteps()){
throw std::runtime_error("trajectory is too short for this kind of calculation. Select a different starting timestep or lower the size of the block");
}
Hist * hist_=0;
if (ith>0) hist_= hist+lunghezza_lista*(ith-1);
else hist_= lista;
unsigned int natoms=t->get_natoms();
for (unsigned int i=start;i<stop; i+=skip) {
for (unsigned int iatom=0; iatom<natoms;++iatom) {
int itype=t->get_type(iatom);
auto * pos = t->posizioni(i,iatom);
auto * l = t->scatola(i);
bool in_range=false;
auto ih=idx_(pos,l,in_range,itype);
if (in_range){
hist_[ih]+=1;
}
}
}
}
template <class T, class Hist>
void AtomicDensity<T,Hist>::join_data() {
for (unsigned int ith=0;ith<nthreads-1;++ith) {
for (size_t i=0;i<lunghezza_lista;++i){
lista[i]+=hist[i+ith*lunghezza_lista];
}
}
}
template <class T, class Hist>
unsigned int AtomicDensity<T,Hist>::numeroTimestepsOltreFineBlocco(unsigned int n_b) {return 0;}
template <class T, class Hist>
void AtomicDensity<T,Hist>::reset(const unsigned int numeroTimestepsPerBlocco) { ntimesteps=numeroTimestepsPerBlocco; azzera(); }
template <class T, class Hist>
std::vector<ssize_t> AtomicDensity<T,Hist>::get_shape() const{
return {static_cast<long>(ntypes),static_cast<long>(nbin[0]),static_cast<long>(nbin[1]),static_cast<long>(nbin[2])};
}
template <class T, class Hist>
std::vector<ssize_t> AtomicDensity<T,Hist>::get_stride() const {
return {sizeof (Hist)*static_cast<long>(nbin[0]*nbin[1]*nbin[2]),static_cast<long>(nbin[1]*nbin[2]*sizeof (Hist)),static_cast<long>(nbin[2]*sizeof (Hist)),static_cast<long>(sizeof (Hist))};
}
#include "traiettoria.h"
template class AtomicDensity<Traiettoria,long>;
#ifdef PYTHON_SUPPORT
#include "traiettoria_numpy.h"
template class AtomicDensity<Traiettoria_numpy,long>;
#endif