-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnapshot.h
More file actions
143 lines (126 loc) · 2.82 KB
/
snapshot.h
File metadata and controls
143 lines (126 loc) · 2.82 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef __SNAPSHOT__
#define __SNAPSHOT__
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include <map>
#include<list>
#include<cmath>
#include "kh_math_fourier.h"
#define MAXLINE 512
static char line[MAXLINE];
struct atom {
int id,type;
real x,y,z;
real mux,muy,muz;
real mu1;
atom& operator = (const atom & p){
id = p.id;
type=p.type;
x=p.x;y=p.y;z=p.z;
mux=p.mux;muy=p.muy;muz=p.muz;
}
atom() {}
bool operator< (const atom & rhs) {
return type < rhs.type;
}
atom(int id, int type,
real x, real y, real z,
real mux,real muy, real muz) {
init( id, type, x, y, z, mux, muy, muz);
}
void init(int id, int type,
real x, real y, real z,
real mux,real muy, real muz) {
this->id=id; this->type=type;
this->x=x;this->y=y;this->z=z;
mu1 = sqrt(mux*mux+muy*muy+muz*muz);
if (mu1>0.) {
this->mux=mux/mu1;this->muy=muy/mu1;this->muz=muz/mu1;
}
}
};
struct box3 {
real xlow,xhigh;
real ylow,yhigh;
real zlow,zhigh;
bool pbc[3];
real getVol() {
return (xhigh-xlow)*(yhigh-ylow)*(zhigh-zlow);
};
};
typedef struct Snapshot {
long timestep;
int n_atoms;
int n_types;
long bytes;
struct atom* atoms;
struct box3 box;
Snapshot(){
}
Snapshot(long _ts,int _n_atoms){
init(_ts,_n_atoms);
}
/* Snapshot(const Snaptshot &T) {
* timestep = T.timestep;
* n_atoms = T.n_atoms;
* box = T.box;
* atoms = T.atoms;
* n_types = T.n_types;
* }
*/
void init(long _ts,int _n_atoms){
this->timestep = _ts;
n_atoms = _n_atoms;
atoms = new struct atom[n_atoms];
bytes = sizeof(Snapshot) + sizeof(atom) * n_atoms;
}
void setBox(real xl,real xh, real yl,real yh, real zl,real zh) {
box.xlow=xl;box.xhigh=xh;
box.ylow=yl;box.yhigh=yh;
box.zlow=zl;box.zhigh=zh;
}
void setBox(box3 otherbox){
memcpy(&box,&otherbox,sizeof(otherbox));
}
int get_n_ptls (int type){
int _n_types = calc_n_type () ;
if( type<_n_types) return 0;
int n_ptls=0;
for( int i =0; i<n_atoms; i++ ) {
if (type == atoms[i].type)
n_ptls ++ ;
}
return n_ptls;
}
real getVol() {
return (box.xhigh-box.xlow)*(box.yhigh-box.ylow)*(box.zhigh-box.zlow);
};
int calc_n_type (){
if(flag_calc_n_type) return n_types;
std::list<int> unique_type_list;
for( int i =0; i<n_atoms; i++ ) {
unique_type_list.push_back(atoms[i].type);
}
unique_type_list.sort();
unique_type_list.unique();
n_types = unique_type_list.size();
flag_calc_n_type = true;
return n_types;
}
~Snapshot() {
delete [] atoms;
}
protected:
bool flag_calc_n_type=false;
} Snapshot;
int compare_atom_type(const void *, const void *);
struct Snapshot* read_dump(FILE*);
typedef enum {
SUCCESS, ERR1,ERR2,ERR3,ERR4
} ENUM_DUMP;
ENUM_DUMP get_dump(FILE*,Snapshot*);
void read_lines(int n,FILE*);
void* error( const char *);
typedef std::list<Snapshot*> l_snapshot;
#endif