MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RestartToData.cpp
Go to the documentation of this file.
1 //Copyright (c) 2015, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #include <iostream>
27 #include "Mercury3D.h"
28 
29 int main(int argc, char *argv[])
30 {
31  // write manual if number of arguments is not right
32  const std::string manual = "Enter the prefix of the simulation you want to restart\n"
33  " and, optionally, the prefix of the output files.\n"
34  " e.g. restart2data input output\n"
35  " reads from input.restart and writes to output.data\n";
36  if (argc<2) logger(ERROR,manual);
37 
38  // first argument is used as prefix for the input
39  std::string in = argv[1];
40  //append .restart if necessary
41  if (in.find(".restart")==-1) in += ".restart";
42  logger(INFO,"Reading from %", in);
43 
44  // if second argument is given, use it as prefix for the output; otherwise, use input prefix
45  bool prefixGiven = argc>=3 && argv[2][0]!='-';
46  char* out = prefixGiven?argv[2]:argv[1];
47  logger(INFO,"Writing to %", out);
48 
49  //read in from restart file and output data file
50  Mercury3D problem;
51  if (problem.readRestartFile(in)) {
52  problem.setName(out);
54  problem.writeXBallsScript();
55  problem.writeDataFile();
56  problem.writeFStatFile();
57  problem.writeEneFile();
58  logger(INFO,"Written to %", problem.dataFile.getFullName());
59  } else if (problem.readRestartFile(std::string(in)+".restart.0")
60  || problem.readRestartFile(std::string(in)+".restart.0000")) {
61  do {
62  problem.setName(out);
64  problem.dataFile.setCounter(problem.restartFile.getCounter() - 1);
65  problem.fStatFile.setCounter(problem.restartFile.getCounter() - 1);
66  problem.eneFile.setCounter(problem.restartFile.getCounter() - 1);
67  //problem.writeXBallsScript();
68  problem.writeDataFile();
69  problem.writeFStatFile();
70  problem.writeEneFile();
71  logger(INFO,"Written to %", problem.dataFile.getFullName());
72  problem.setName(in);
73  } while (problem.readRestartFile());
74  } else {
75  logger(ERROR,"File % not found",in);
76  }
77 }
int main(int argc, char *argv[])
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:232
const std::string getFullName() const
Also allows to access the file name, however with additional information which is the file counter...
Definition: File.cc:171
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:53
void writeFStatFile()
Definition: DPMBase.cc:2858
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
Definition: File.cc:224
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1370
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1375
CGHandler cgHandler
Object of the class cgHandler.
Definition: DPMBase.h:1365
void writeEneFile()
Definition: DPMBase.cc:2848
void computeContactPoints()
Definition: CGHandler.cc:194
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:36
virtual void writeXBallsScript() const
This writes a script which can be used to load the xballs problem to display the data just generated...
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:412
void writeDataFile()
Definition: DPMBase.cc:2839
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: DPMBase.h:1380
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1385
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition: DPMBase.cc:2896