MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FreeFallRestartUnitTest.cpp File Reference
#include "DPMBase.h"
#include "Particles/BaseParticle.h"
#include "Walls/InfiniteWall.h"
#include <iostream>
#include <Species/LinearViscoelasticSpecies.h>
#include <Logger.h>

Go to the source code of this file.

Classes

class  FreeFall
 This code tests: 1) Restarting 2) Saving arcoss multiple files 3) and accepting command line argument. More...
 

Functions

void runFreeFall (int argc, char *argv[])
 
int main (int argc, char *argv[])
 

Function Documentation

int main ( int argc  ,
char *  argv[] 
)

Definition at line 87 of file FreeFallRestartUnitTest.cpp.

References BaseHandler< T >::begin(), BaseHandler< T >::end(), FATAL, INFO, logger, DPMBase::particleHandler, DPMBase::readRestartFile(), and runFreeFall().

88 {
89 
90  //On first pass i.e. code being called as a selftest, it enters here and call the code again 3 times with different arguments.
91  if (argc==1)
92  {
93  logger(INFO,"Case 1: not restarted");
94  if (system("./FreeFallRestartUnitTest -tmax 0.4 -name FreeFallRestartUnitTest_NoRestart"))
95  logger(FATAL, "code did not run");
96 
97  logger(INFO,"Case 2: restarted at t=0.2");
98  //restarted at t=0.2
99 
100  if (system("./FreeFallRestartUnitTest -tmax 0.2 -name FreeFallRestartUnitTest_Restarted"))
101  logger(FATAL, "code did not run");
102 
103  if (system("./FreeFallRestartUnitTest -r FreeFallRestartUnitTest_Restarted -tmax 0.4"))
104  logger(FATAL,"code did not run");
105 
106 
107  logger(INFO,"Case 3: restarted at t=0.2; using separate data files");
108 
109 
110  if (system("./FreeFallRestartUnitTest -tmax 0.2 -name FreeFallRestartUnitTest_SeparateFiles -fileTypeData 2"))
111  logger(FATAL,"code did not run");
112  if (system("./FreeFallRestartUnitTest -r FreeFallRestartUnitTest_SeparateFiles -tmax 0.4 "))
113  logger(FATAL,"code did not run");
114  } else
115  {
116  runFreeFall(argc, argv);
117  return 0;
118  }
119 
120  //To compare the code using gnuplot follow the instructions below.
121  //gnuplot> plot 'free_fall_restart/free_fall_restart.ene' u 1:3 w l, 'free_fall_restart/free_fall_no_restart.ene' u 1:3 w l
122  //../sc/fpdiff.py ./free_fall_restart.fstat ./free_fall_no_restart.fstat
123 
124  //Final stage now we check what we get.
125  logger(INFO,"Finished running, now comparing");
126 
127  FreeFall FreeFallProblemReload;
128  FreeFall FreeFallProblemReloadRestart;
129  FreeFall FreeFallProblemReloadSplitFiles;
130 
131  FreeFallProblemReload.readRestartFile("FreeFallRestartUnitTest_NoRestart.restart");
132  FreeFallProblemReloadRestart.readRestartFile("FreeFallRestartUnitTest_Restarted.restart");
133  FreeFallProblemReloadSplitFiles.readRestartFile("FreeFallRestartUnitTest_SeparateFiles.restart");
134 
135  auto FreeFallProblemReloadRestartIt = FreeFallProblemReloadRestart.particleHandler.begin();
136  auto FreeFallProblemReloadSplitFilesIt = FreeFallProblemReloadSplitFiles.particleHandler.begin();
137 
138  for (auto FreeFallProblemReloadIt = FreeFallProblemReload.particleHandler.begin(); FreeFallProblemReloadIt != FreeFallProblemReload.particleHandler.end(); ++FreeFallProblemReloadIt)
139  {
140  // if (!(*FreeFallProblemReloadIt))->getTimeMax()
141 
142  if (!(*FreeFallProblemReloadIt)->getPosition().isEqualTo((*FreeFallProblemReloadRestartIt)->getPosition(),1e-6))
143  {
144  logger(FATAL,"Particles is not in the same place after restart. Before it was % and now it is %.",(*FreeFallProblemReloadIt)->getPosition(),(*FreeFallProblemReloadRestartIt)->getPosition());
145  }
146  if (!(*FreeFallProblemReloadIt)->getPosition().isEqualTo((*FreeFallProblemReloadSplitFilesIt)->getPosition(), 1e-10))
147  {
148  logger(FATAL,"Particles velocities are not the same place. Before it was % and now it is %.",(*FreeFallProblemReloadIt)->getVelocity(),(*FreeFallProblemReloadRestartIt)->getVelocity());
149  }
150  ++FreeFallProblemReloadRestartIt;
151  ++FreeFallProblemReloadSplitFilesIt;
152  }
153 
154  return 0;
155 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:28
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:494
This code tests: 1) Restarting 2) Saving arcoss multiple files 3) and accepting command line argument...
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:482
int readRestartFile()
Reads all the particle data corresponding to the current saved time step. Which is what the restart f...
Definition: DPMBase.cc:1375
void runFreeFall(int argc, char *argv[])
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
LL< Log::FATAL > FATAL
Fatal log level.
Definition: Logger.cc:25
void runFreeFall ( int  argc,
char *  argv[] 
)

Start off my solving the default problem

Definition at line 72 of file FreeFallRestartUnitTest.cpp.

References BaseHandler< T >::copyAndAddObject(), Files::dataFile, File::getFstream(), Files::setName(), Files::setSaveCount(), DPMBase::setTimeStep(), DPMBase::setXMax(), DPMBase::setYMax(), DPMBase::solve(), and DPMBase::speciesHandler.

Referenced by main().

73 {
75  FreeFall FreeFallProblem;
76  auto species = FreeFallProblem.speciesHandler.copyAndAddObject(LinearViscoelasticSpecies());
77  species->setDensity(2000);
78  FreeFallProblem.setName("FreeFallRestartUnitTest");
79  FreeFallProblem.setSaveCount(10000);
80  FreeFallProblem.setTimeStep(1e-6);
81  FreeFallProblem.setYMax(0.1);
82  FreeFallProblem.setXMax(0.01);
83  FreeFallProblem.dataFile.getFstream().precision(10);
84  FreeFallProblem.solve(argc,argv);
85 }
void setXMax(Mdouble newXMax)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMax...
Definition: DPMBase.cc:309
void solve()
The work horse of the code.
Definition: DPMBase.cc:1895
This code tests: 1) Restarting 2) Saving arcoss multiple files 3) and accepting command line argument...
void setYMax(Mdouble newYMax)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMax...
Definition: DPMBase.cc:324
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
Definition: File.cc:150
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: Files.cc:149
U * copyAndAddObject(const U &O)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:268
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: Files.h:204
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
Definition: DPMBase.h:868
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353