MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mercury2pvd.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 "DPMBase.h"
27 
28 class Mercury2PVD : public DPMBase {
29 
30 public:
31 
33  {
34  }
35 };
36 
37 int main(int argc UNUSED, char *argv[] UNUSED)
38 {
39  Mercury2PVD m;
40 
41  //Check to see if we received one argument
42  if (argc == 2) {
43  std::string prefix = argv[1];
44  std::string::size_type pos = prefix.find(".restart");
45 
46  if (pos == std::string::npos) {
47  m.setName(argv[1]);
48  } else {
49  m.setName(prefix.substr(0,pos-1));
50  m.restartFile.setName(prefix);
51  logger(INFO, "restart file % given; prefix is %",m.restartFile.getName(),m.getName());
52  }
53 
54  } else {
55  m.setName("../Drivers/MercuryCG/NewtonsCradleSelfTest");
56  //We didn't. Print a usage and exit the program.
57  logger(WARN, "Usage: mercury2pvd [prefix] \n"
58  " This program converts MercuryDPM files into ParaView data files,\n"
59  " which can then be used to visualize your particles.\n"
60  "\n"
61  " prefix: Prefix to prepend to the i/o files.\n"
62  "\n"
63  " The following files will be generated:\n"
64  " - prefix.pvd\n"
65  " - prefix_0.vtu\n"
66  " - prefix_1.vtu\n"
67  " ( ... )\n"
68  " - prefix_987654321.vtu\n"
69  " depending on the amount of timesteps.", argv[0]);
70  }
71 
72  //Store path as it is overwritten by readRestartFile
74  std::string::size_type pos = m.getName().find_last_of("/");
75  std::string path = m.getName().substr(0,pos+1);
76  logger(INFO,"Path %",path);
77 
78  //Read restart file, and re-add path to data and fstat file name
79  logger(INFO,"Reading restart file %",m.restartFile.getName());
80  bool success = m.readRestartFile();
81  if (!success) logger(FATAL,"Reading restart file % failed",m.restartFile.getName());
82  m.dataFile.setName(path+m.dataFile.getName());
83  m.fStatFile.setName(path+m.fStatFile.getName());
84 
85  //prepare dpm class for reading in
86  m.dataFile.open(std::fstream::in);
87  m.fStatFile.open(std::fstream::in);
89  m.dataFile.setCounter(0);
90  m.fStatFile.setCounter(0);
92 
93  //read in
94  logger(INFO,"Reading data/fstat files %, %",m.dataFile.getName(), m.fStatFile.getName());
95  while (m.readNextDataFile())
96  {
97  //m.readNextFStatFile();
99  //m.writeOutputFiles()
101  //m.interactionHandler.writeVTK();
102  m.wallHandler.writeVTK();
103  }
104 }
105 
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:65
void writeVTK() const
Writes all particles into a vtk file format (unstructured grid), consisting of particle positions...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
bool readRestartFile(bool restarted=true)
Reads all the particle data corresponding to the current saved time step. Which is what the restart f...
Definition: DPMBase.cc:1629
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
void setCounter(unsigned int counter)
Allows the user to set the file counter according to his need. Sets File::counter_.
Definition: File.cc:224
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: Files.h:219
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:52
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:150
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1001
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: mercury2pvd.cpp:32
#define UNUSED
Definition: GeneralDefine.h:39
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: Files.h:209
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:50
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
bool readNextDataFile(unsigned int format=0)
Reads the next data file with default format=0. However, one can modify the format based on whether t...
Definition: DPMBase.cc:1434
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:487
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1016
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1006
void setWriteVTK(FileType f)
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
Definition: File.cc:320
each time-step will be written into/read from separate files numbered consecutively: name_...
int main(int argc UNUSED, char *argv[] UNUSED)
Definition: mercury2pvd.cpp:37
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:196
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:169
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:132
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
Definition: File.cc:163
void writeVTK() const
Writes all walls into a vtk format, consisting of points (edges) and cells (faces).
Definition: WallHandler.cc:239
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:392