MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FreeFallRestartUnitTest.cpp
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 
32 
33 #include "DPMBase.h"
34 #include "Particles/BaseParticle.h"
35 #include "Walls/InfiniteWall.h"
36 #include <iostream>
38 #include <Logger.h>
39 
40 class FreeFall : public DPMBase{
41 public:
42 
44  {
45  InfiniteWall w0;
46  w0.set(Vec3D(-1,0,0), Vec3D(getXMin(),0,0));
48  w0.set(Vec3D( 1,0,0), Vec3D(getXMax(),0,0));
50  w0.set(Vec3D(0,-1,0), Vec3D(0, getYMin(),0));
52  w0.set(Vec3D(0, 1,0), Vec3D(0, getYMax(),0));
54 
55  BaseParticle p0;
56  p0.setPosition(Vec3D(getXMax()/2,getYMax()/2,0.0));
57  p0.setVelocity(Vec3D(0.0,0.0,0.0));
58  p0.setRadius(0.0005);
60 
61  }
62 
64  {
65 
66  std::cout << "In this function you can add code that is run on restart" <<std::endl;
67  }
68 
69 };
70 
71 
72 void runFreeFall(int argc, char *argv[])
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 }
86 
87 int main(int argc, char *argv[])
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 }
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
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:61
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin...
Definition: DPMBase.cc:224
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:28
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
Definition: DPMBase.cc:238
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...
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
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
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax...
Definition: DPMBase.cc:231
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
int main(int argc, char *argv[])
int readRestartFile()
Reads all the particle data corresponding to the current saved time step. Which is what the restart f...
Definition: DPMBase.cc:1375
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 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 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
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax...
Definition: DPMBase.cc:245
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:883
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
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:70
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
This is a class defining walls.
Definition: InfiniteWall.h:43
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void actionsOnRestart()
A virtual function where the users can add extra code which is executed only when the code is restart...