-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdat.cpp
364 lines (303 loc) · 13.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include "dat.hpp"
/*******
* DAT *
*******/
// CONSTRUCTORS
Dat::Dat(std::string filename, bool loadWork) :
numberParticles(), persistenceLength(), packingFraction(), systemSize(),
torqueParameter(), randomSeed(), timeStep(), framesWork(), dumpParticles(),
dumpPeriod(),
input(filename) {
// HEADER INFORMATION
input.read<const int>(&numberParticles);
input.read<const double>(&persistenceLength);
input.read<const double>(&packingFraction);
input.read<const double>(&systemSize);
input.read<const double>(&torqueParameter);
input.read<const int>(&randomSeed);
input.read<const double>(&timeStep);
input.read<const int>(&framesWork);
input.read<const bool>(&dumpParticles);
input.read<const int>(&dumpPeriod);
// FILE PARTS LENGTHS
headerLength = input.tellg();
particleLength = 5*sizeof(double)*dumpParticles;
frameLength = numberParticles*particleLength;
workLength = 8*sizeof(double);
// ESTIMATION OF NUMBER OF COMPUTED WORK AND ORDER PARAMETER SUMS AND FRAMES
numberWork = (input.getFileSize() - headerLength - frameLength)/(
framesWork*frameLength + workLength);
frames = !dumpParticles ? 0 :
(input.getFileSize() - headerLength - numberWork*workLength)/frameLength;
// FILE CORRUPTION CHECK
if ( input.getFileSize() !=
headerLength + frames*frameLength + numberWork*workLength ) {
std::cerr << "Invalid file size." << std::endl;
exit(1);
}
// ACTIVE WORK AND ORDER PARAMETER
if ( loadWork ) {
double work;
for (int i=0; i < numberWork; i++) {
input.read<double>(&work,
headerLength // header
+ frameLength // frame with index 0
+ (1 + i)*framesWork*frameLength // all following packs of framesWork frames
+ i*workLength); // previous values of the active work
activeWork.push_back(work);
input.read<double>(&work);
activeWorkForce.push_back(work);
input.read<double>(&work);
activeWorkOri.push_back(work);
input.read<double>(&work);
orderParameter.push_back(work);
input.read<double>(&work);
orderParameter0.push_back(work);
input.read<double>(&work);
orderParameter1.push_back(work);
input.read<double>(&work);
torqueIntegral1.push_back(work);
input.read<double>(&work);
torqueIntegral2.push_back(work);
}
}
}
// DESTRUCTORS
Dat::~Dat() {}
// METHODS
int Dat::getNumberParticles() const { return numberParticles; }
double Dat::getPersistenceLength() const { return persistenceLength; }
double Dat::getPackingFraction() const { return packingFraction; }
double Dat::getSystemSize() const { return systemSize; }
double Dat::getTorqueParameter() const { return torqueParameter; }
int Dat::getRandomSeed() const { return randomSeed; }
double Dat::getTimeStep() const { return timeStep; }
int Dat::getFramesWork() const { return framesWork; }
long int Dat::getNumberWork() const { return numberWork; }
long int Dat::getFrames() const { return frames; }
std::vector<double> Dat::getActiveWork() { return activeWork; }
std::vector<double> Dat::getActiveWorkForce() { return activeWorkForce; }
std::vector<double> Dat::getActiveWorkOri() { return activeWorkOri; }
std::vector<double> Dat::getOrderParameter() { return orderParameter; }
std::vector<double> Dat::getOrderParameter0() { return orderParameter0; }
std::vector<double> Dat::getOrderParameter1() { return orderParameter1; }
std::vector<double> Dat::getTorqueIntegral1() { return torqueIntegral1; }
std::vector<double> Dat::getTorqueIntegral2() { return torqueIntegral2; }
double Dat::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::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
}
double Dat::getVelocity(
int const& frame, int const& particle, int const& dimension) {
// Returns velocity 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)
+ 3*sizeof(double) // positions and orientation
+ dimension*sizeof(double)); // dimension
}
/********
* DAT0 *
********/
// CONSTRUCTORS
Dat0::Dat0(std::string filename, bool loadWork) :
numberParticles(), potentialParameter(), propulsionVelocity(),
transDiffusivity(), rotDiffusivity(), persistenceLength(),
packingFraction(), systemSize(), randomSeed(), timeStep(), framesWork(),
dumpParticles(), dumpPeriod(),
input(filename) {
// HEADER INFORMATION
input.read<const int>(&numberParticles);
input.read<const double>(&potentialParameter);
input.read<const double>(&propulsionVelocity);
input.read<const double>(&transDiffusivity);
input.read<const double>(&rotDiffusivity);
input.read<const double>(&persistenceLength);
input.read<const double>(&packingFraction);
input.read<const double>(&systemSize);
input.read<const int>(&randomSeed);
input.read<const double>(&timeStep);
input.read<const int>(&framesWork);
input.read<const bool>(&dumpParticles);
input.read<const int>(&dumpPeriod);
// DIAMETERS
double diameter;
for (int i=0; i < numberParticles; i++) {
input.read<double>(&diameter);
diameters.push_back(diameter);
}
// FILE PARTS LENGTHS
headerLength = input.tellg();
particleLength = 5*sizeof(double)*dumpParticles;
frameLength = numberParticles*particleLength;
workLength = 4*sizeof(double);
// ESTIMATION OF NUMBER OF COMPUTED WORK AND ORDER PARAMETER SUMS AND FRAMES
numberWork = (input.getFileSize() - headerLength - frameLength)/(
framesWork*frameLength + workLength);
frames = !dumpParticles ? 0 :
(input.getFileSize() - headerLength - numberWork*workLength)/frameLength;
// FILE CORRUPTION CHECK
if ( input.getFileSize() !=
headerLength + frames*frameLength + numberWork*workLength ) {
std::cerr << "Invalid file size." << std::endl;
exit(1);
}
// ACTIVE WORK AND ORDER PARAMETER
if ( loadWork ) {
double work;
for (int i=0; i < numberWork; i++) {
input.read<double>(&work,
headerLength // header
+ frameLength // frame with index 0
+ (1 + i)*framesWork*frameLength // all following packs of framesWork frames
+ i*workLength); // previous values of the active work
activeWork.push_back(work);
input.read<double>(&work);
activeWorkForce.push_back(work);
input.read<double>(&work);
activeWorkOri.push_back(work);
input.read<double>(&work);
orderParameter.push_back(work);
}
}
}
// DESTRUCTORS
Dat0::~Dat0() {}
// METHODS
int Dat0::getNumberParticles() const { return numberParticles; }
double Dat0::getPotentialParameter() const { return potentialParameter; }
double Dat0::getPropulsionVelocity() const { return propulsionVelocity; }
double Dat0::getTransDiffusivity() const { return transDiffusivity; }
double Dat0::getRotDiffusivity() const { return rotDiffusivity; }
double Dat0::getPersistenceLength() const { return persistenceLength; }
double Dat0::getPackingFraction() const { return packingFraction; }
double Dat0::getSystemSize() const { return systemSize; }
int Dat0::getRandomSeed() const { return randomSeed; }
double Dat0::getTimeStep() const { return timeStep; }
int Dat0::getFramesWork() const { return framesWork; }
long int Dat0::getNumberWork() const { return numberWork; }
long int Dat0::getFrames() const { return frames; }
std::vector<double> Dat0::getDiameters() { return diameters; }
std::vector<double> Dat0::getActiveWork() { return activeWork; }
std::vector<double> Dat0::getActiveWorkForce() { return activeWorkForce; }
std::vector<double> Dat0::getActiveWorkOri() { return activeWorkOri; }
std::vector<double> Dat0::getOrderParameter() { return orderParameter; }
double Dat0::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 Dat0::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
}
double Dat0::getVelocity(
int const& frame, int const& particle, int const& dimension) {
// Returns velocity 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)
+ 3*sizeof(double) // positions and orientation
+ dimension*sizeof(double)); // dimension
}
/********
* DATR *
********/
// CONSTRUCTORS
DatR::DatR(std::string filename, bool loadOrder) :
numberParticles(), rotDiffusivity(), torqueParameter(), timeStep(),
framesOrder(), dumpRotors(), dumpPeriod(), randomSeed(),
input(filename) {
// HEADER INFORMATION
input.read<const int>(&numberParticles);
input.read<const double>(&rotDiffusivity);
input.read<const double>(&torqueParameter);
input.read<const double>(&timeStep);
input.read<const int>(&framesOrder);
input.read<const bool>(&dumpRotors);
input.read<const int>(&dumpPeriod);
input.read<const int>(&randomSeed);
// FILE PARTS LENGTHS
headerLength = input.tellg();
rotorLength = 1*sizeof(double);
frameLength = numberParticles*rotorLength;
orderLength = 2*sizeof(double);
// ESTIMATION OF NUMBER OF COMPUTED ORDER PARAMETER SUMS AND FRAMES
numberOrder = (input.getFileSize() - headerLength - frameLength)/(
framesOrder*frameLength + orderLength);
frames = !dumpRotors ? 0 :
(input.getFileSize() - headerLength - numberOrder*orderLength)/frameLength;
// FILE CORRUTION CHECK
if ( input.getFileSize() !=
headerLength + frames*frameLength + numberOrder*orderLength ) {
std::cerr << "Invalid file size." << std::endl;
exit(1);
}
// ORDER PARAMETER
if ( loadOrder ) {
double order;
for (int i=0; i < numberOrder; i++) {
input.read<double>(&order,
headerLength // header
+ frameLength // frame with index 0
+ (1 + i)*framesOrder*frameLength // all following packs of framesOrder frames
+ i*orderLength); // previous values of the order parameter
orderParameter.push_back(order);
input.read<double>(&order);
orderParameterSq.push_back(order);
}
}
}
// DESTRUCTORS
DatR::~DatR() {}
// METHODS
int DatR::getNumberParticles() const { return numberParticles; }
double DatR::getRotDiffusivity() const { return rotDiffusivity; }
double DatR::getTorqueParameter() const { return torqueParameter; }
double DatR::getTimeStep() const { return timeStep; }
int DatR::getDumpPeriod() const { return dumpPeriod; }
int DatR::getRandomSeed() const { return randomSeed; }
long int DatR::getFrames() const { return frames; }
std::vector<double> DatR::getOrderParameter() { return orderParameter; }
std::vector<double> DatR::getOrderParameterSq() { return orderParameterSq; }
double DatR::getOrientation(int const& frame, int const& rotor) {
// Returns position of a given rotor at a given frame.
return input.read<double>(
headerLength // header
+ frame*frameLength // other frames
+ rotor*rotorLength // other rotors
+ (std::max(frame - 1, 0)/framesOrder)*orderLength); // order parameter sums (taking into account the frame with index 0)
}