MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SquarePackingSelfTest.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 
31 #include <cmath>
32 #include <iostream>
33 #include <iomanip>
35 
36 class SquarePacking : public StatisticsVector<O> {
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  double Radius = .5;
45 
46  //set Particles' position, radius, velocity and bounding box
47  setXMin(0); setYMin(0); setZMin(0);
48 
49  setXMax(5);
50  setYMax(5);
51  BaseParticle P0;
52  for (int i=0;i<N;i++)
53  for (int j=0;j<N;j++)
54  {
55 
56  P0.setRadius(Radius);
57  P0.setVelocity(Vec3D(0.0,0.0,0.0));
58  P0.setPosition(Radius*Vec3D(1.+2.*i,1.+2.*j,0.0));
59  //setXMax(std::max(getXMax(),P0.getPosition().X+Radius));
60  //setYMax(std::max(getYMax(),P0.getPosition().Y+Radius));
62 
63  }
64  setZMax(0.1);
65 
66  //set walls
67  InfiniteWall w0;
68  w0.set(Vec3D(-1, 0, 0), Vec3D(getXMin(), 0, 0));
70  w0.set(Vec3D( 1, 0, 0), Vec3D(getXMax(), 0, 0));
72  w0.set(Vec3D( 0,-1, 0), Vec3D(0, getYMin(), 0));
74  w0.set(Vec3D( 0, 1, 0), Vec3D(0, getYMax(), 0));
76  }
77 
78  int N;
79 
80 };
81 
82 int main(int argc UNUSED, char *argv[] UNUSED)
83 {
84  SquarePacking problem;
85  problem.setName("SquarePackingSelfTest");
87  //set the number of particles
88  problem.N=5;
89  problem.setSystemDimensions(2);
90  problem.setParticleDimensions(2);
91  species->setDensity(6.0/constants::pi*2./3.);
92  //species->setDensity(1.9098593*2/3);
93  problem.setGravity(Vec3D(0.,-1,0.));
94  species->setCollisionTimeAndRestitutionCoefficient(.01,.1,1.);
95  problem.setTimeStep(.0002);
96  problem.setTimeMax(1.0);
97  problem.setSaveCount(1000);
98 
99  problem.setCGTimeMin(problem.getTimeMax()*.98);
100  problem.setTimeMaxStat(1e20);
101 
102  std::cout << "Relax the packing" << std::endl;
103  problem.solve();
104 
105  std::cout << "Get statistics" << std::endl;
106  StatisticsVector<Y> stats("SquarePackingSelfTest");
107  stats.statFile.setName("SquarePackingSelfTest.Y.stat");
108  double n = 500;
109  stats.setN(n);
110  stats.setCGWidth(.1);
111  stats.setCGTimeMin(problem.getTimeMax()*.98);
112  stats.setTimeMaxStat(1e20);
113  //stats.verbose();
114  //stats.set_boundedDomain(true);
116 
117  std::cout << "Get fully averaged statistics" << std::endl;
118  StatisticsVector<O> statsO("SquarePackingSelfTest");
119  statsO.statFile.setName("SquarePackingSelfTest.O.stat");
120  statsO.setCGTimeMin(problem.getTimeMax()*.98);
121  statsO.setTimeMaxStat(1e20);
123  // should give you Density 1
124 }
125 
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
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
int main(int argc UNUSED, char *argv[] UNUSED)
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
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin...
Definition: DPMBase.cc:224
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
Definition: DPMBase.cc:238
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 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)
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
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 setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:138
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
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.
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
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
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
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
File statFile
An instance of class File to handle in- and output into a .stat file.
Definition: Files.h:224
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:194