FreeFallRestartUnitTest.cpp File Reference
#include "Mercury2D.h"
#include "Walls/InfiniteWall.h"
#include <iostream>
#include <Species/LinearViscoelasticSpecies.h>
#include <Logger.h>

Classes

class  FreeFall
 This code is a example on how to write a restartable mercury code. More...
 

Functions

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

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)
78 {
79  //If code is being called with no arguments (e.g. as a selftest), it enters here and call the code again 3 times with different arguments.
80  if (argc == 1)
81  {
82  logger(INFO, "Case 1: simple run");
83  if (system("./FreeFallRestartUnitTest -name FreeFallRestart0"))
84  logger(FATAL, "code did not run");
85 
86  logger(INFO, "Case 2: restart in the middle");
87  //restarted at t=0.2
88 
89  if (system("./FreeFallRestartUnitTest -tmax 1.05 -name FreeFallRestart1"))
90  logger(FATAL, "code did not run");
91 
92  if (system("./FreeFallRestartUnitTest -r FreeFallRestart1 -tmax 2.1"))
93  logger(FATAL, "code did not run");
94 
95 
96  logger(INFO, "Case 3: restart in the middle, using separate data files");
97 
98  if (system("./FreeFallRestartUnitTest -tmax 1.05 -name FreeFallRestart2 -fileTypeData 2"))
99  logger(FATAL, "code did not run");
100 
101  if (system("./FreeFallRestartUnitTest -r FreeFallRestart2 -tmax 2.1"))
102  logger(FATAL, "code did not run");
103  }
104  else
105  {
106  runFreeFall(argc, argv);
107  return 0;
108  }
109 
110  //To compare the code using gnuplot follow the instructions below.
111  //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
112  //../sc/fpdiff.py ./free_fall_restart.fstat ./free_fall_no_restart.fstat
113 
114  //Final stage now we check what we get.
115  logger(INFO, "Finished running, now comparing");
116 
117  FreeFall dpm0;
118  FreeFall dpm1;
119  FreeFall dpm2;
120 
121  dpm0.readRestartFile("FreeFallRestart0.restart");
122  dpm1.readRestartFile("FreeFallRestart1.restart");
123  dpm2.readRestartFile("FreeFallRestart2.restart");
124 
125  auto p1 = dpm1.particleHandler.begin();
126  auto p2 = dpm2.particleHandler.begin();
127 
128  for (auto p0 = dpm0.particleHandler.begin(); p0 != dpm0.particleHandler.end(); ++p0)
129  {
130  if (!(*p0)->getPosition().isEqualTo((*p1)->getPosition(),1e-6))
131  {
132  logger(FATAL, "Particles is not in the same place after restart. Before it was % and now it is %.",
133  (*p0)->getPosition(), (*p1)->getPosition());
134  }
135  if (!(*p0)->getPosition().isEqualTo((*p2)->getPosition(),1e-10))
136  {
137  logger(FATAL, "Particles velocities are not the same place. Before it was % and now it is %.",
138  (*p0)->getVelocity(), (*p1)->getVelocity());
139  }
140  ++p1;
141  ++p2;
142  }
143 
144  return 0;
145 }
void runFreeFall(int argc, char *argv[])
Definition: FreeFallRestartUnitTest.cpp:62
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:55
LL< Log::FATAL > FATAL
Definition of the different loglevels by its wrapper class LL. These are used as tags in template met...
Definition: Logger.cc:52
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
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:3006
This code is a example on how to write a restartable mercury code.
Definition: FreeFallRestart.cpp:31

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

◆ runFreeFall()

void runFreeFall ( int  argc,
char argv[] 
)

Start off my solving the default problem

63 {
65  FreeFall dpm;
66  dpm.setName("FreeFallRestart");
67  dpm.setMax({1.0,1.5,0.0});
69  species->setDensity(4.0/constants::pi);
70  species->setCollisionTimeAndRestitutionCoefficient(0.1,1,species->getMassFromRadius(0.5));
71  dpm.setTimeStep(0.002);
72  dpm.setTimeMax(2.1);
73  dpm.setSaveCount(100);
74  dpm.solve(argc, argv);
75 }
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:33
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition: BaseHandler.h:379
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:408
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1427
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1234
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:873
void solve()
The work horse of the code.
Definition: DPMBase.cc:4270
void setMax(const Vec3D &max)
Sets the maximum coordinates of the problem domain.
Definition: DPMBase.cc:1082
const Mdouble pi
Definition: ExtendedMath.h:45

References BaseHandler< T >::copyAndAddObject(), constants::pi, DPMBase::setMax(), DPMBase::setName(), DPMBase::setSaveCount(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), DPMBase::solve(), and DPMBase::speciesHandler.

Referenced by main().