49 std::string p4pName(name+
".p4p");
50 std::string p4cName(name+
".p4c");
51 std::string p4wName(name+
".p4w");
54 p4p.open(p4pName.c_str(), std::fstream::in);
55 p4c.open(p4cName.c_str(), std::fstream::in);
56 p4w.open(p4wName.c_str(), std::fstream::in);
58 if (
p4p.fail() ||
p4c.fail() ||
p4w.fail())
61 std::cerr <<
"ERROR: Input file " << p4pName <<
" not found" << std::endl;
63 std::cerr <<
"ERROR: Input file " << p4cName <<
" not found" << std::endl;
65 std::cerr <<
"ERROR: Input file " << p4wName <<
" not found" << std::endl;
71 std::cout <<
"Files opened: " << p4pName <<
" and " << p4cName <<
" and " << p4wName << std::endl;
80 std::cout <<
"Files closed: " <<
name_ <<
".p4p/p4w/p4c" << std::endl;
83 void copy(
double xmin,
double xmax,
double ymin,
double ymax,
double zmin,
double zmax,
double timeMin,
double timeMax,
unsigned int periodic) {
84 std::cout <<
"copy(..)" << std::endl;
95 void writeP4P(
double timeMin,
double timeMax) {
96 std::cout <<
"writeP4P(..)" << std::endl;
103 double ID, GROUP, VOLUME, MASS, VX, VY, VZ, Angular_Velocity_X, Angular_Velocity_Y, Angular_Velocity_Z;
105 unsigned int counter = 0;
110 p4p >> dummy >> dummy;
117 std::cout <<
"reading p4p (t " << time <<
" N " << N <<
"): timeMax reached; terminating" << std::endl;
120 else if (time<timeMin)
122 std::cout <<
"reading p4p (t " << time <<
" N " << N <<
"): below timeMin; skipped" << std::endl;
123 for (
unsigned int i=0; i<N; i++)
128 std::cout <<
"reading p4p (t " << time <<
" N " << N <<
" timestep #" << counter <<
")" << std::endl;
131 std::string dataName =
getName(
"data", counter);
132 data.open(dataName.c_str(), std::fstream::out);
133 std::string fstatName =
getName(
"fstat", counter);
134 fstat.open(fstatName.c_str(), std::fstream::out);
135 std::cout <<
"Files opened: " << dataName <<
" and " << fstatName << std::endl;
145 <<
zmax_ << std::endl;
149 for (
unsigned int i=0; i<N; i++) {
167 >> Angular_Velocity_X
168 >> Angular_Velocity_Y
169 >> Angular_Velocity_Z;
180 << Angular_Velocity_X <<
" "
181 << Angular_Velocity_Y <<
" "
182 << Angular_Velocity_Z <<
" "
186 std::cout <<
"written " << dataName << std::endl;
189 std::cout <<
"written " << fstatName << std::endl;
201 void writeP4C(std::fstream& fstat,
double timeData) {
206 double P1, P2, delta, deltat, fn, ft;
211 p4c >> dummy >> dummy;
216 if (time<timeData*0.999999)
218 std::cout <<
"reading p4c (t " << time <<
" N " << N <<
"): below timeMin; skipped" << std::endl;
219 for (
unsigned int i=0; i<N; i++)
224 std::cout <<
"reading p4c (t " << time <<
" N " << N <<
")" << std::endl;
227 fstat <<
"# " << time <<
" " << N << std::endl;
228 fstat <<
"# " << std::endl;
229 fstat <<
"# " << std::endl;
233 for (
unsigned int i=0; i<N; i++) {
270 else if (*c1 > 2.0*(
xmax_ - xmin_) / 3.0)
277 else if (*c1 > 2.0*(
xmax_ - xmin_) / 3.0)
318 void writeP4W(std::fstream& fstat,
double timeData)
324 double P1, delta, deltat, fn, ft;
329 p4w >> dummy >> dummy;
334 if (time<timeData*0.999999)
336 std::cout <<
"reading p4w (t " << time <<
" N " << N <<
"): below timeMin; skipped" << std::endl;
337 for (
unsigned int i=0; i<N; i++)
342 std::cout <<
"reading p4w (t " << time <<
" N " << N <<
")" << std::endl;
344 for (
unsigned int i=0; i<N; i++) {
371 std::cout <<
"restart.0000 " << timeData << std::endl;
373 std::fstream restart;
374 restart.open(
name_ +
".restart", std::fstream::out);
376 "restart_version 1.0 name " <<
name_ <<
"\n"
377 "dataFile name " <<
name_ <<
".data fileType MULTIPLE_FILES_PADDED saveCount 1 counter 1 nextSavedTimeStep 0\n"
378 "fStatFile name " <<
name_ <<
".fstat fileType MULTIPLE_FILES_PADDED saveCount 1 counter 1 nextSavedTimeStep 0\n"
379 "eneFile name " <<
name_ <<
".ene fileType ONE_FILE saveCount 1 counter 302 nextSavedTimeStep 0\n"
380 "restartFile name " <<
name_ <<
".restart fileType ONE_FILE saveCount 1 counter 1 nextSavedTimeStep 0\n"
381 "statFile name " <<
name_ <<
".stat fileType ONE_FILE saveCount 1 counter 0 nextSavedTimeStep 0\n"
388 "timeStep 0 time " << timeData <<
" ntimeSteps 0 timeMax " << timeData <<
"\n"
389 "systemDimensions 3 particleDimensions 3 gravity 0 0 -9.8\n"
391 "LinearViscoelasticSpecies id 0 density " << density <<
" stiffness 0 dissipation 0\n"
394 restart <<
"Boundaries 0\n";
397 restart <<
"Boundaries 1\n";
399 restart <<
"PeriodicBoundary id 0 normal 1 0 0 scaleFactor 1 distanceLeft " <<
xmin_ <<
" distanceRight " <<
xmax_ <<
" shift " <<
xmax_-
xmin_ <<
" 0 0\n";
401 restart <<
"PeriodicBoundary id 0 normal 0 1 0 scaleFactor 1 distanceLeft " <<
ymin_ <<
" distanceRight " <<
ymax_ <<
" shift " <<
ymax_-
ymin_ <<
" 0 0\n";
403 restart <<
"PeriodicBoundary id 0 normal 0 0 1 scaleFactor 1 distanceLeft " <<
zmin_ <<
" distanceRight " <<
zmax_ <<
" shift " <<
zmax_-
zmin_ <<
" 0 0\n";
407 "BaseParticle id 0 indSpecies 0 position 0 0 0 orientation 0 0 0 0 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 radius 0.5 invMass 1 invInertia 10\n"
413 std::string
getName(std::string type,
unsigned int counter)
416 std::stringstream name(
"");
417 name <<
name_ <<
"." << type <<
".";
441 std::vector<unsigned int>
id_;
445 int main(
int argc,
char *argv[])
451 std::cout <<
"no arguments given, so a test file is converted; to convert your own p4 files, use:" << std::endl;
452 std::cout <<
"convertP4Files.cpp name xmin xmax ymin ymax zmin zmax [timeMin [timeMax [periodic]]]" << std::endl;
455 "TIMESTEP PARTICLES\n"
457 "ID GROUP VOLUME MASS PX PY PZ VX VY VZ Angular_Velocity_X Angular_Velocity_Y Angular_Velocity_Z\n"
458 "1 1 0.52359877559 1 0.5 0.5 0.5 1 0 0 0 0 1\n"
459 "3 1 0.52359877559 1 3.5 0.5 0.5 0 0 0 0 0 0\n"
460 "TIMESTEP PARTICLES\n"
462 "ID GROUP VOLUME MASS PX PY PZ VX VY VZ Angular_Velocity_X Angular_Velocity_Y Angular_Velocity_Z\n"
463 "1 1 0.52359877559 1 0.5 0.5 0.5 1 0 0 0 0 1\n"
464 "3 1 0.52359877559 1 3.5 0.5 0.5 0 0 0 0 0 0\n"
468 "TIMESTEP CONTACTS\n"
470 "P1 P2 CX CY CZ FX FY FZ\n"
471 "1 3 0 0.5 0.5 1 1 0\n"
472 "TIMESTEP CONTACTS\n"
474 "P1 P2 CX CY CZ FX FY FZ\n"
475 "1 3 4 0.5 0.5 1 1 0\n"
479 "TIMESTEP CONTACTS\n"
481 "P1 CX CY CZ FX FY FZ\n"
482 "1 0.5 0.5 0 0 0 1\n"
483 "3 3.5 0.5 0 0 0 1\n"
484 "TIMESTEP CONTACTS\n"
486 "P1 CX CY CZ FX FY FZ\n"
487 "1 0.5 0.5 0 0 0 1\n"
488 "3 3.5 0.5 0 0 0 1\n"
492 files.
copy(0,4,0,1,0,1,-1,1e20,1);
496 std::cerr <<
"convertP4Files.cpp problem_name xmin xmax ymin ymax zmin zmax [timeMin [timeMax [periodic]]]" << std::endl;
502 std::string name(argv[1]);
503 std::cout <<
"converting " << name << std::endl;
507 timeMin = atof(argv[8]);
508 std::cout <<
"timeMin " << timeMin << std::endl;
511 double timeMax = 1e20;
513 timeMax = atof(argv[9]);
514 std::cout <<
"timeMax " << timeMax << std::endl;
517 unsigned int periodic = 0;
519 periodic = atoi(argv[10]);
520 std::cout <<
"periodic " << periodic << std::endl;
524 files.
copy(atof(argv[2]),atof(argv[3]),atof(argv[4]),atof(argv[5]),atof(argv[6]),atof(argv[7]),timeMin,timeMax,periodic);
526 std::cout <<
"finished converting " << name << std::endl;
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Mdouble X
the vector components
void writeP4P(double timeMin, double timeMax)
void writeP4W(std::fstream &fstat, double timeData)
void setZero()
Sets all elements to zero.
void writeP4C(std::fstream &fstat, double timeData)
std::string getName(std::string type, unsigned int counter)
std::string name_
These store the save file names,.
takes data and fstat files and splits them into *.data.???? and *.fstat.???? files ...
std::vector< unsigned int > id_
void copy(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, double timeMin, double timeMax, unsigned int periodic)
std::vector< Vec3D > position_
CFile(std::string name)
Constructor.
std::fstream p4p
Stream used for data files.
int main(int argc, char *argv[])
Implementation of a 3D vector (by Vitaliy).
void writeRestart(double timeData, double density)