MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NewtonsCradleSelfTest.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 #include "Mercury3D.h"
27 #include "StatisticsVector.h"
28 #include "Particles/BaseParticle.h"
29 #include "Walls/InfiniteWall.h"
30 #include <cmath>
31 #include <iostream>
32 #include <iomanip>
34 
35 
37 
38 public:
39 
41  {
42  // make sure the number of particles is right
43  std::cout << "Creating a cubic packing of " << N << "^3 particles" << std::endl;
44  //set_N(mathsFunc::cubic(N));
45  double Radius = 1;
46 
47  //set Particles' position, radius, velocity and bounding box
48  setXMin(0);
49  setYMin(0);
50  setZMin(0);
51 
52  setXMax(2.*Radius);
53  setYMax(2.*Radius);
54  setZMax(N*2.*Radius+.5);
55 
56  BaseParticle P0;
57  for (int i=0;i<1;i++)
58  for (int j=0;j<1;j++)
59  for (int k=0;k<N;k++)
60  {
61  P0.setRadius(Radius);
62  P0.setVelocity(Vec3D(0.0,0.0,0.0));
63  P0.setPosition(Radius*Vec3D(1.+2.*i,1.+2.*j,1.+2.*k));
65  }
66 
67  //set walls
68  InfiniteWall w;
69  w.set(Vec3D(0.0,0.0,-1.0),Vec3D(0, 0, getZMin()));
71  }
72 
73  int N;
74 };
75 
76 int main(int argc UNUSED, char *argv[] UNUSED)
77 {
78  NewtonsCradleSelfTest problem;
79  problem.setName("NewtonsCradleSelfTest");
81  problem.N=5; //set the number of particles
82  problem.setSystemDimensions(3);
83  problem.setParticleDimensions(3);
84  species->setDensity(6./constants::pi/8*(2*problem.N+.5)*1.05*1.05);
85  problem.setGravity(Vec3D(0.,0.,-1.));
86  species->setCollisionTimeAndRestitutionCoefficient(.01,.1,1.);
87  problem.setTimeStep(.0001);
88  problem.setTimeMax(8.0);
89  problem.setSaveCount(1000);
90  std::cout << "Relax the packing" << std::endl;
91  problem.solve();
92 
93  std::cout << "Get statistics" << std::endl;
94  std::string str[3];
95  str[0]="Gaussian";
96  str[1]="HeavisideSphere";
97  str[2]="Lucy";
98 
99  int i=0;
100  double w=0.46/3.;
101  StatisticsVector<Z> stats1("NewtonsCradleSelfTest");
102  stats1.setZMinStat(-.5);
103  stats1.setZMaxStat(2*problem.N);
104  stats1.setXMinStat(0.5);
105  stats1.setXMaxStat(1.55);
106  stats1.setYMinStat(0.5);
107  stats1.setYMaxStat(1.55);
108  std::cout << stats1.getName() + "_" + str[i] + "T_XYZ.stat" << std::endl;
109  stats1.statFile.setName(stats1.getName() + "_" + str[i] + "T_XYZ.stat");
110  stats1.set_h(0.0005);
111  stats1.setCGWidth(w);
112  stats1.setSuperExact(false);
113  stats1.setCGShape(str[i].c_str());
114  stats1.setCGTimeMin(problem.getTimeMax()*1.00000999999);
115  stats1.setTimeMaxStat(1e20);
117 
118  for (int i=0; i<3; i++) {
119  double w=0.125;
120  if (i==1) w*=2;
121  if (i==2) w*=2*sqrt(3);
122 
123  StatisticsVector<Z> stats0("NewtonsCradleSelfTest");
124  stats0.setZMinStat(-0.5);
125  stats0.statFile.setName(stats0.getName() + "_" + str[i] + "T_XYZ.stat");
126  stats0.set_h(0.02);
127  stats0.setCGWidth(w);
128  stats0.setSuperExact(true);
129  stats0.setCGShape(str[i].c_str());
130  stats0.setCGTimeMin(problem.getTimeMax()*.999999);
131  stats0.setTimeMaxStat(1e20);
133 
134  StatisticsVector<XYZ> stats2("NewtonsCradleSelfTest");
135  stats2.setZMinStat(-0.5);
136  stats2.statFile.setName(stats2.getName() + "_" + str[i] + "T_XYZ.stat");
137  stats2.set_h(0.02);
138  stats2.setNY(1);
139  stats2.setCGWidth(w);
140  stats2.setSuperExact(true);
141  stats2.setCGShape(str[i].c_str());
142  stats2.setCGTimeMin(problem.getTimeMax()*.999999);
143  stats2.setTimeMaxStat(1e20);
145 
146  /* Current the 2D statistics is not implement this tets will be added when it is.
147  StatisticsVector<XZ> stats1("NewtonsCradleSelfTest");
148  stats1.setZMinStat(-0.5);
149  stats1.statFile.setName(str[i] + "T_XZ.stat");
150  stats1.set_h(0.02);
151  stats1.setCGWidth(w);
152  stats1.setSuperExact(true);
153  stats1.setCGShape(str[i].c_str());
154  stats1.setCGTimeMin(problem.getTimeMax()*.999999);
155  stats1.setTimeMaxStat(1e20);
156  stats1.statistics_from_fstat_and_data();
157  */
158  // should give you Density 5
159  }
160 
161  return(0);
162 }
163 
void setYMaxStat(Mdouble ymaxStat_)
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.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:179
void set_h(Mdouble h)
void setYMin(Mdouble newYMin)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMin...
Definition: DPMBase.cc:280
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setXMaxStat(Mdouble xmaxStat_)
void setXMinStat(Mdouble xminStat_)
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:474
void setZMax(Mdouble newZMax)
If the length of the problem domain in z-direction is XMax - XMin, this method sets ZMax...
Definition: DPMBase.cc:338
void setCGShape(const char *new_)
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:453
void setGravity(Vec3D newGravity)
Allows to modify the gravity vector.
Definition: DPMBase.cc:431
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
void setCGTimeMin(Mdouble t)
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
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
const Mdouble pi
Definition: ExtendedMath.h:42
void setXMin(Mdouble newXMin)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMin...
Definition: DPMBase.cc:266
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
void statistics_from_fstat_and_data()
get StatisticsPoint
void setTimeMaxStat(Mdouble t)
#define UNUSED
Definition: GeneralDefine.h:37
void setNY(int new_)
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
void setYMinStat(Mdouble yminStat_)
void setZMin(Mdouble newZMin)
If the length of the problem domain in z-direction is ZMax - ZMin, this method sets ZMin...
Definition: DPMBase.cc:295
void setSuperExact(bool new_)
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 setCGWidth(Mdouble w)
Set CG variables w2 and CG_invvolume.
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
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin...
Definition: DPMBase.cc:252
This class is used to extract statistical data from MD simulations.
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
void setZMinStat(Mdouble zminStat_)
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
Definition: File.cc:195
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
int main(int argc UNUSED, char *argv[] UNUSED)
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: Files.cc:131
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:194
void setZMaxStat(Mdouble zmaxStat_)