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[] 
)
56 {
57  //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.
58  if (argc == 1)
59  {
60  logger(INFO, "Case 1: simple run");
61  if (system("./FreeFallRestartUnitTest -name FreeFallRestart0"))
62  logger(FATAL, "code did not run");
63 
64  logger(INFO, "Case 2: restart in the middle");
65  //restarted at t=0.2
66 
67  if (system("./FreeFallRestartUnitTest -tmax 1.05 -name FreeFallRestart1"))
68  logger(FATAL, "code did not run");
69 
70  if (system("./FreeFallRestartUnitTest -r FreeFallRestart1 -tmax 2.1"))
71  logger(FATAL, "code did not run");
72 
73 
74  logger(INFO, "Case 3: restart in the middle, using separate data files");
75 
76  if (system("./FreeFallRestartUnitTest -tmax 1.05 -name FreeFallRestart2 -fileTypeData 2"))
77  logger(FATAL, "code did not run");
78 
79  if (system("./FreeFallRestartUnitTest -r FreeFallRestart2 -tmax 2.1"))
80  logger(FATAL, "code did not run");
81  }
82  else
83  {
84  runFreeFall(argc, argv);
85  return 0;
86  }
87 
88  //To compare the code using gnuplot follow the instructions below.
89  //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
90  //../sc/fpdiff.py ./free_fall_restart.fstat ./free_fall_no_restart.fstat
91 
92  //Final stage now we check what we get.
93  logger(INFO, "Finished running, now comparing");
94 
95  FreeFall dpm0;
96  FreeFall dpm1;
97  FreeFall dpm2;
98 
99  dpm0.readRestartFile("FreeFallRestart0.restart");
100  dpm1.readRestartFile("FreeFallRestart1.restart");
101  dpm2.readRestartFile("FreeFallRestart2.restart");
102 
103  auto p1 = dpm1.particleHandler.begin();
104  auto p2 = dpm2.particleHandler.begin();
105 
106  for (auto p0 = dpm0.particleHandler.begin(); p0 != dpm0.particleHandler.end(); ++p0)
107  {
108  if (!(*p0)->getPosition().isEqualTo((*p1)->getPosition(),1e-6))
109  {
110  logger(FATAL, "Particles is not in the same place after restart. Before it was % and now it is %.",
111  (*p0)->getPosition(), (*p1)->getPosition());
112  }
113  if (!(*p0)->getPosition().isEqualTo((*p2)->getPosition(),1e-10))
114  {
115  logger(FATAL, "Particles velocities are not the same place. Before it was % and now it is %.",
116  (*p0)->getVelocity(), (*p1)->getVelocity());
117  }
118  ++p1;
119  ++p2;
120  }
121 
122  return 0;
123 }
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void runFreeFall(int argc, char *argv[])
Definition: FreeFallRestartUnitTest.cpp:40
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:31
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
Vector3f p0
Definition: MatrixBase_all.cpp:2
Vector3f p1
Definition: MatrixBase_all.cpp:2
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:698
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:712
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1443
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:3043
This code is a example on how to write a restartable mercury code.
Definition: FreeFallRestart.cpp:9
#define INFO(i)
Definition: mumps_solver.h:54

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

◆ runFreeFall()

void runFreeFall ( int  argc,
char argv[] 
)

Start off my solving the default problem

41 {
43  FreeFall dpm;
44  dpm.setName("FreeFallRestart");
45  dpm.setMax({1.0,1.5,0.0});
47  species->setDensity(4.0/constants::pi);
48  species->setCollisionTimeAndRestitutionCoefficient(0.1,1,species->getMassFromRadius(0.5));
49  dpm.setTimeStep(0.002);
50  dpm.setTimeMax(2.1);
51  dpm.setSaveCount(100);
52  dpm.solve(argc, argv);
53 }
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition: LinearViscoelasticSpecies.h:11
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:360
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:386
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:400
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1225
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:864
void solve()
The work horse of the code.
Definition: DPMBase.cc:4334
void setMax(const Vec3D &max)
Sets the maximum coordinates of the problem domain.
Definition: DPMBase.cc:1073
const Mdouble pi
Definition: ExtendedMath.h:23

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

Referenced by main().