How to restart MercuryDPM driver codes

Restart your code in three steps:

  • Replace the simple solve command in the main function by solve(argc, argv), so you can read in command-line arguments.
  • All DPMBase variables can be read from the restart file, but your Driver code might have new variables defined; so you have to set these variables yourself. For this there is the function DPMBase::actionsOnRestart, where you can reset your own variables in case of a restart.
  • Run your code with the command-line argument "-r" to force a restart; "-t [time]" can be used to reset final time.

Below is a simple case of how to modify your code to be restart-ready:

#include "DPMBase.h"
class FreeFall : public DPMBase{
public:
// Set species, particles, boundaries, walls here
void setupInitialConditions() override
{
s.setStiffness(1e5);
s.setDissipation(0.01);
s.setDensity(2e3);
w0.set(Vec3D(0,0,-1), Vec3D(0, 0, 0));
p0.setPosition(Vec3D(0,0,getZMax()-1e-3));
p0.setRadius(1e-3);
}
//this function replaces setupInitialConditions in case of a restart
//if you have problem-specific variables, set them here
void actionsOnRestart() override
{
}
};
int main(int argc, char *argv[])
{
//Start off my solving the default problem
FreeFall dpm;
//set FreeFall-specific parameters here
dpm.setName("FreeFallRestart");
dpm.setSaveCount(1000);
dpm.setTimeStep(1e-6);
dpm.setTimeMax(0.5);
dpm.setDomain(Vec3D(-1e-3,-1e-3,0e-3),Vec3D(1e-3,1e-3,10e-3));
dpm.setGravity(Vec3D(0,0,-9.8));
//restart and run until final time 1, using command line arguments:
// ./freeFallRestart -r -tmax 1
dpm.solve(argc,argv);
return 0;
}
int main(int argc, char *argv[])
Definition: T_protectiveWall.cpp:215
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
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
virtual void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Definition: BaseInteractable.h:239
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species)
Definition: BaseParticle.cc:553
void setSpecies(const ParticleSpecies *species)
Definition: BaseParticle.cc:818
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition: BaseWall.cc:169
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition: DPMBase.h:77
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 setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1098
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:422
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:1447
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition: DPMBase.h:1437
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 setGravity(Vec3D newGravity)
Sets a new value for the gravitational acceleration.
Definition: DPMBase.cc:1383
Mdouble getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax.
Definition: DPMBase.h:650
This code is a example on how to write a restartable mercury code.
Definition: FreeFallRestart.cpp:31
void setupInitialConditions() override
Set species, particles, boundaries, walls here.
Definition: FreeFallRestart.cpp:35
void actionsOnRestart() override
A virtual function where the users can add extra code which is executed only when the code is restart...
Definition: FreeFallRestart.cpp:55
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition: InfiniteWall.h:48
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Definition: InfiniteWall.cc:118
void setDissipation(Mdouble dissipation)
Allows the normal dissipation to be changed.
Definition: LinearViscoelasticNormalSpecies.cc:117
void setStiffness(Mdouble new_k)
Allows the spring constant to be changed.
Definition: LinearViscoelasticNormalSpecies.cc:93
void setDensity(Mdouble density)
Definition: ParticleSpecies.cc:108
A spherical particle is the most simple particle used in MercuryDPM.
Definition: SphericalParticle.h:37
Definition: Vector.h:51