forked from rikigigi/analisi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
centerdiff.cpp
84 lines (76 loc) · 3.59 KB
/
centerdiff.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
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "centerdiff.h"
#include <array>
#include <cmath>
CenterDiff::CenterDiff(Traiettoria *t, unsigned int nthreads, unsigned int skip, unsigned int nit, bool sum_first_two_and_ignore_vz,bool sum_1) :
CalcolaMultiThread (nthreads,skip), t{t}, nit{nit},lista_alloc{0},starting_center{},sum_first_two_and_ignore_vz{sum_first_two_and_ignore_vz},sum_1{sum_1}
{
if (nit==0) nit=1;
}
void CenterDiff::reset(const unsigned int numeroTimestepsPerBlocco) {
lunghezza_lista=numeroTimestepsPerBlocco*3*3*nit/skip;
ntimesteps=numeroTimestepsPerBlocco;
if (lunghezza_lista> lista_alloc){
delete [] lista;
lista = new double[lunghezza_lista];
lista_alloc=lunghezza_lista;
}
}
void CenterDiff::calc_single_th(const unsigned int &start, const unsigned int &stop, const unsigned int &primo, const unsigned int &ith) noexcept {
unsigned int ilista=(start-primo)/skip;
std::array<double,3*3> dx,cn;
std::array<double,3> sums;
dx=starting_center;
for (unsigned int itimestep=start;itimestep<stop;++itimestep) {
double *box = t->scatola(itimestep);
for (unsigned int i=0;i<nit;++i) {
sums.fill(0.0);
cn.fill(0.0);
for (unsigned int iatom=0;iatom<t->get_natoms();++iatom) {
double * coord = t->posizioni(itimestep,iatom);
double * vel = t->velocita(itimestep,iatom);
for (unsigned int idim1=0;idim1<3;idim1++){
double l=box[idim1*2+1]-box[idim1*2+0];
if (sum_first_two_and_ignore_vz && idim1==2){
if (sum_1){
sums[idim1]+=1.0;
} else {
sums[idim1]+=vel[0]+vel[1];
}
} else {
sums[idim1]+=vel[idim1];
}
if (!sum_first_two_and_ignore_vz){
for (unsigned int idim2=0;idim2<3;idim2++) {
double new_coord=coord[idim1]-dx[3*idim2+idim1]; //shift of the origin
double wrapped_coord=new_coord-std::round(new_coord/l)*l; // center of the cell is in zero
cn[idim2*3+idim1]+=wrapped_coord*vel[idim2];
}
} else {
for (unsigned int idim2=0;idim2<2;idim2++) {
double new_coord=coord[idim1]-dx[3*idim2+idim1]; //shift of the origin
double wrapped_coord=new_coord-std::round(new_coord/l)*l; // center of the cell is in zero
cn[idim2*3+idim1]+=wrapped_coord*vel[idim2];
}
unsigned int idim2=2;
double new_coord=coord[idim1]-dx[3*idim2+idim1]; //shift of the origin
double wrapped_coord=new_coord-std::round(new_coord/l)*l; // center of the cell is in zero
if (sum_1){
cn[idim2*3+idim1]+=wrapped_coord;
} else {
cn[idim2*3+idim1]+=wrapped_coord*(vel[0]+vel[1]);
}
}
}
}
for (unsigned int idim1=0;idim1<3;++idim1){
for (unsigned int idim2=0;idim2<3;++idim2){
dx[idim2*3+idim1]=dx[idim2*3+idim1]+cn[idim2*3+idim1]/sums[idim2];
lista[ilista*3*3*nit+i*3*3+idim2*3+idim1]=dx[idim2*3+idim1];
}
}
}
++ilista;
}
}
CenterDiff::~CenterDiff() {
}