-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdat.cpp
118 lines (93 loc) · 4.5 KB
/
dat.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
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
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "dat.hpp"
/*****************
* DAT deformable *
*****************/
// CONSTRUCTORS
Dat_def::Dat_def(std::string filename, bool loadWork) :
numberParticles(), density(), systemSize(),
randomSeed(), timeStep(), framesWork(0), dumpParticles(),
dumpPeriod(),
input(filename) {
// HEADER INFORMATION
input.read<const int>(&numberParticles);
input.read<const double>(&density);
input.read<const double>(&systemSize);
input.read<const int>(&randomSeed);
input.read<const double>(&timeStep);
input.read<const bool>(&dumpParticles);
input.read<const int>(&dumpPeriod);
input.read<const int>(&framesWork); //wp # of frames in which observable is computed
//printf("\t Dat_Def After header information\n");
// FILE PARTS LENGTHS
headerLength = input.tellg();
particleLength = 3*sizeof(double)*dumpParticles;
frameLength = numberParticles*particleLength;
//wp:
workLength = 1*sizeof(double);
//printf("\t Dat_Def After lengths\n");
// ESTIMATION OF NUMBER OF COMPUTED WORK AND ORDER PARAMETER SUMS AND FRAMES
//wp: numberWork is the # of times work and order parameters were saved on file, which depends on 'framesWork*dumpPeriod' frequency
//wp: framesWork = # of frames before work/order params are saved on file; for deformable total_time/dumpPeriod e.g. 1/0.1 = at the 10th frame it is saved
numberWork =(input.getFileSize() - headerLength - frameLength)/( framesWork*frameLength + workLength);
//frames = after removing all the work/order params and header, then # of frames is size/particle frame lenght
frames = !dumpParticles ? 0 :
(input.getFileSize() - headerLength - numberWork*workLength)/frameLength;
numberWork =(input.getFileSize() - headerLength - frameLength)/( framesWork*frameLength + workLength);
// FILE CORRUPTION CHECK
if ( input.getFileSize() !=
headerLength + frames*frameLength + numberWork*workLength ) {
std::cerr << "Invalid file size." << std::endl;
exit(1);
}
//Saved variables
if ( loadWork ) {
double work; //wp: 'work' is dummy for saved observable
int test;
for (int i=0; i < numberWork; i++) {
//wp: Reads *after* whatever # input it is given
input.read<double>(&work,
headerLength // header
+ frameLength // frame with index 0 //wp initial save frame
+ (1 + i)*framesWork*frameLength // all following packs of framesWork frames //wp: all frame packs used while computing work
+ i*workLength); // previous values of the active work//wp: actual position where the quantities are dumped
//printf("\tDat::\t current: %e\n", work);
currents.push_back(work);
}
}
}
// DESTRUCTORS
Dat_def::~Dat_def() {}
// METHODS
int Dat_def::getNumberParticles() const { return numberParticles; }
double Dat_def::getDensity() const { return density; }
double Dat_def::getSystemSize() const { return systemSize; }
int Dat_def::getRandomSeed() const { return randomSeed; }
double Dat_def::getTimeStep() const { return timeStep; }
int Dat_def::getFramesWork() const { return framesWork; }
long int Dat_def::getNumberWork() const { return numberWork; }
long int Dat_def::getFrames() const { return frames; }
std::vector<double> Dat_def::getCurrents() { return currents; }
double Dat_def::getPosition(
int const& frame, int const& particle, int const& dimension) {
// Returns position of a given particle at a given frame.
return input.read<double>(
headerLength // header
+ frame*frameLength // other frames
+ particle*particleLength // other particles
+ (std::max(frame - 1, 0)/framesWork)*workLength // active work sums (taking into account the frame with index 0)
+ dimension*sizeof(double)); // dimension
}
double Dat_def::getOrientation(int const& frame, int const& particle){
// Returns position of a given particle at a given frame.
return input.read<double>(
headerLength // header
+ frame*frameLength // other frames
+ particle*particleLength // other particles
+ (std::max(frame - 1, 0)/framesWork)*workLength // active work sums (taking into account the frame with index 0)
+ 2*sizeof(double)); // positions //wp:i.e. after the x,y position
}
//end of file vile mile tile rile wile pile bile exile..