MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleCreationSelfTest.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 //based on /storage2/usr/people/sluding/MDCC/C3DshearXL30/MU0_LONG2
27 #include "Mercury3D.h"
29 #include "Particles/BaseParticle.h"
32 
37 {
38 public:
39 
40  ParticleCreation(Mdouble width, Mdouble length, Mdouble height, Mdouble sizeDistribution) : sizeDistribution_(sizeDistribution)
41  {
42 
43  setXMin(0);
44  setXMax(width);
45  setYMin(0);
46  setYMax(length);
47  setZMin(0);
48  setZMax(height);
49 
50  std::cout << "Creating flat-wall box of"
51  " width [" << getXMin() << ", " << getXMax() << "],"
52  " length [" << getYMin() << ", " << getYMax() << "],"
53  " height [" << getZMin() << ", " << getZMax() << "]." << std::endl;
54 
55  //create new species
58 
59  //set inter-particle contact properties
60  species->setStiffnessAndRestitutionCoefficient(10, 0.1, 1.0);
61 
62  setTimeStep(0.02 * species->getCollisionTime(species->getMassFromRadius(0.5)));
63  std::cout << "time step used "
64  << getTimeStep() << std::endl;
65 
66  //set timestep
68 
69  //set walls
70  InfiniteWall w;
71  w.set(Vec3D(0, 0, -1), Vec3D(0, 0, getZMin()));
73  w.set(Vec3D(0, -1, 0), Vec3D(0, getYMin(), 0));
75  w.set(Vec3D(-1, 0, 0), Vec3D(getXMin(), 0, 0));
77  w.set(Vec3D(0, 0, 1), Vec3D(0, 0, getZMax()));
79  w.set(Vec3D(0, 1, 0), Vec3D(0, getYMax(), 0));
81  w.set(Vec3D(1, 0, 0), Vec3D(getXMax(), 0, 0));
83  }
84 
86  {
87  //number of particles to be inserted
88  unsigned int n = static_cast<unsigned int>((getXMax() - getXMin())*(getYMax() - getYMin())*(getZMax() - getZMin()));
89  //try to find new insertable particles
90  unsigned int i = 0;
91  BaseParticle p;
94  Mdouble rMin = cbrt(0.5 / (s * s + 1.0) / (s + 1.0));
95  std::cout << "Inserting a maximum of " << n << " particles with "
96  << 2.0*rMin << "<d<" << 2.0*s*rMin
97  << " (sizeDistribution " << s << ")" << std::endl;
98  //this already changes the largest particle (before it gets inserted into DPMBase)
99  p.setRadius(s * rMin);
100  Vec3D position;
101  unsigned int failed =0;
102  while (i < n) {
103  position.X = random.getRandomNumber(getXMin() + p.getRadius(),
104  getXMax() - p.getRadius());
105  position.Y = random.getRandomNumber(getYMin() + p.getRadius(),
106  getYMax() - p.getRadius());
107  position.Z = random.getRandomNumber(getZMin() + p.getRadius(),
108  getZMax() - p.getRadius());
109  p.setPosition(position);
111 // std::cout << "insert r=" << p.getRadius()
112 // << ", N=" << particleHandler.getNumberOfObjects()
113 // << ", R=" << particleHandler.getLargestParticle()->getRadius()
114 // << ", " << particleHandler.getLargestParticle()
115 // << ", " << &p
116 // << std::endl;
118  if (hGridNeedsRebuilding()) {
119  hGridRebuild();
120  }
121  //std::cout << "done inserting, N=" << particleHandler.getNumberOfObjects() << std::endl;
122  p.setRadius(random.getRandomNumber(rMin, s * rMin));
123  //std::cout << "next particle r=" << p.getRadius() << std::endl;
124  i++;
125  if (particleHandler.getNumberOfObjects() % 1000 == 0) {
126  std::cout << " " << particleHandler.getNumberOfObjects() / 1000 << "k";
127  std::flush(std::cout);
128  }
129  failed=0;
130  }
131  else
132  {
133  failed++;
134  if (failed>1000)
135  {
136  //std::cout << std::endl << "failed to insert 100 particles in a row; aborting" << std::endl;
137  break;
138  }
139  }
140  }
141  std::cout << std::endl << "Inserted " << particleHandler.getNumberOfObjects() << " particles" << std::endl;
142  //hGridRebuild();
143  //hGridInfo();
144  //exit(-1);
145  }
146 
149 };
150 
151 int main(int argc, char *argv[])
152 {
153  Mdouble width = 20; //in particle diameters
154  Mdouble length = 20; //in particle diameters
155  Mdouble height = 20; //in particle diameters
156  Mdouble sizeDistribution = 4;
157  ParticleCreation SC(width, length, height, sizeDistribution);
159  SC.setName("ParticleCreationSelfTest");
160  SC.solve(argc, argv);
161  //SC.hGridInfo();
162  return 0;
163 }
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
bool checkParticleForInteraction(const BaseParticle &P) override
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:609
Mdouble X
the vector components
Definition: Vector.h:52
bool hGridNeedsRebuilding()
Gets if the HGrid needs rebuilding before anything else happens.
Definition: MercuryBase.cc:520
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:179
LinearViscoelasticSpecies * species
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 getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax...
Definition: DPMBase.cc:259
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 getMassFromRadius(const Mdouble radius)
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
Definition: DPMBase.cc:238
double Mdouble
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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 setSpecies(const ParticleSpecies *species)
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
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
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:35
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 setDensity(Mdouble density)
Allows the density to be changed.
Mdouble getRadius() const
Returns the particle's radius_.
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
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Definition: BaseHandler.h:464
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
Mdouble Y
Definition: Vector.h:52
void hGridRebuild()
This sets up the parameters required for the contact model.
Definition: MercuryBase.cc:201
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition: DPMBase.h:883
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:873
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
int main(int argc, char *argv[])
This self test was written to test the speed of particle creation in MercuryDPM.
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin...
Definition: DPMBase.cc:252
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
Contains material and contact force properties.
Definition: Interaction.h:35
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
Mdouble getTimeStep() const
Allows the time step dt to be accessed.
Definition: DPMBase.cc:368
Mdouble Z
Definition: Vector.h:52
Mdouble getRandomNumber(Mdouble min, Mdouble max)
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:69
ParticleCreation(Mdouble width, Mdouble length, Mdouble height, Mdouble sizeDistribution)