MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HGridUnitTest.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 
27 #include "Mercury3D.h"
28 #include "DPMBase.h"
30 #include "Particles/BaseParticle.h"
31 
32 class MD_demo : public DPMBase
33 {
34 public:
35 
37  {
40  }
41 
43  {
45  {
48 
49  double VP = constants::pi * 4.0 / 3.0;
50  L = pow(N * VP * DistInt(1, omega) / nu, 1.0 / 3.0);
51 
52  setXMin(0);
53  setYMin(0);
54  setZMin(0);
55  setXMax(L);
56  setYMax(L);
57  setZMax(L);
58 
60  b0.set(Vec3D(1, 0, 0), getXMin(), getXMax());
62  b0.set(Vec3D(0, 1, 0), getYMin(), getYMax());
64  b0.set(Vec3D(0, 0, 1), getZMin(), getZMax());
66 
68  BaseParticle p0;
69  p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
70 
71  double V = 0;
72 
73  //Use at least particles with maximum and minimum size
74  p0.setRadius(1.0);
75  Vec3D position;
76  position.Z = random.getRandomNumber(0, getZMax());
77  position.Y = random.getRandomNumber(0, getYMax());
78  position.X = random.getRandomNumber(0, getXMax());
79  p0.setPosition(position);
81  V += VP * pow(p0.getRadius(), 3);
82 
83  p0.setRadius(omega);
84  position.Z = random.getRandomNumber(0, getZMax());
85  position.Y = random.getRandomNumber(0, getYMax());
86  position.X = random.getRandomNumber(0, getXMax());
87  p0.setPosition(position);
89  V += VP * pow(p0.getRadius(), 3);
90 
91  //For other particles use a random distribution
92  for (unsigned int i = 2; i < N; i++)
93  {
94  p0.setRadius(RandomRadius());
95  position.Z = random.getRandomNumber(0, getZMax());
96  position.Y = random.getRandomNumber(0, getYMax());
97  position.X = random.getRandomNumber(0, getXMax());
98  p0.setPosition(position);
100  V += VP * pow(p0.getRadius(), 3);
101  }
102  }
103  }
104 
105  double RandomRadius()
106  {
107  double rand = random.getRandomNumber(0, 1);
108  if (alpha == -1)
109  {
110  return pow(omega, rand);
111  }
112  else
113  {
114  return pow(rand * (pow(omega, 1.0 + alpha) - 1.0) + 1.0, 1.0 / (1.0 + alpha));
115  }
116  }
117 
118  double DistInt(double s, double e)
119  {
120  if (omega == 1)
121  {
122  return 1;
123  }
124  double numerator;
125  double denominator;
126  if (alpha == -1)
127  {
128  denominator = log(omega);
129  }
130  else
131  {
132  denominator = (pow(omega, 1.0 + alpha) - 1.0) / (1.0 + alpha);
133  }
134 
135  if (alpha == -4)
136  {
137  numerator = log(e) - log(s);
138  }
139  else
140  {
141  numerator = (pow(e, 4.0 + alpha) - pow(s, 4.0 + alpha)) / (4.0 + alpha);
142  }
143  return numerator / denominator;
144  }
145 
146  double L;
147  double omega;
148  double alpha;
149  double nu;
150  unsigned int N;
152 };
153 
154 class HGrid_demo : public Mercury3D
155 {
156 public:
158  : DPMBase(other)
159  {
160  }
161 };
162 
163 int main(int argc UNUSED, char *argv[] UNUSED)
164 {
165  MD_demo MD_problem;
166  MD_problem.species->setDensity(2000);
167 
168  MD_problem.omega = 40;
169  MD_problem.alpha = -2;
170  MD_problem.nu = 0.7;
171  MD_problem.N = 1000;
172  MD_problem.setSystemDimensions(3);
173  MD_problem.setParticleDimensions(3);
174  MD_problem.setName("HGridUnitTest_MD");
175  MD_problem.setTimeStep(0.1);
176  MD_problem.setTimeMax(0.09);
177  MD_problem.setSaveCount(1);
178  MD_problem.setupInitialConditions();
179 
180  HGrid_demo HGrid_problem1(MD_problem);
181  HGrid_problem1.setHGridMethod(TOPDOWN);
182  HGrid_problem1.setHGridMaxLevels(3);
183  HGrid_problem1.setHGridDistribution(EXPONENTIAL);
184  HGrid_problem1.setName("HGridUnitTest_HGrid1");
185 
186  HGrid_demo HGrid_problem2(MD_problem);
187  HGrid_problem2.setHGridMethod(BOTTOMUP);
188  HGrid_problem2.setHGridMaxLevels(8);
189  HGrid_problem2.setHGridDistribution(LINEAR);
190  HGrid_problem2.setName("HGridUnitTest_HGrid2");
191 
192  std::cout << "Solving the MD problem" << std::endl;
193  MD_problem.solve();
194  std::cout << "Solving the first HGrid problem" << std::endl;
195  HGrid_problem1.solve();
196  std::cout << "Solving the second HGrid problem" << std::endl;
197  HGrid_problem2.solve();
198 
199  // Check the particles are in the same place for all three problem i.e. no HGrid and two different HGrid settings
200  std::vector<BaseParticle*>::iterator hGrid1It = HGrid_problem1.particleHandler.begin();
201  std::vector<BaseParticle*>::iterator hGrid2It = HGrid_problem2.particleHandler.begin();
202  for (std::vector<BaseParticle*>::iterator mdIt = MD_problem.particleHandler.begin(); mdIt != MD_problem.particleHandler.end(); ++mdIt)
203  {
204  if (!(*mdIt)->getPosition().isEqualTo((*hGrid1It)->getPosition(),1e-10))
205  {
206  exit(-1);
207  }
208  if (!(*mdIt)->getPosition().isEqualTo((*hGrid2It)->getPosition(), 1e-10))
209  {
210  exit(-1);
211  }
212  ++hGrid1It;
213  ++hGrid2It;
214  }
215 }
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall.
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
Mdouble X
the vector components
Definition: Vector.h:52
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 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
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
Definition: BaseHandler.h:476
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
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
int main(int argc UNUSED, char *argv[] UNUSED)
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:453
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
double RandomRadius()
double DistInt(double s, double e)
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
Defines a pair of periodic walls. Inherits from BaseBoundary.
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 clear()
Empties the whole ParticleHandler by removing all BaseParticle.
void setHGridMethod(HGridMethod hGridMethod)
Sets the HGridMethod to either BOTTOMUP or TOPDOWN.
Definition: MercuryBase.cc:447
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
virtual void addObject(ParticleSpecies *const S)
Adds a new ParticleSpecies to the SpeciesHandler.
BoundaryHandler boundaryHandler
An object of the class BoundaryHandler which concerns insertion and deletion of particles into or fro...
Definition: DPMBase.h:888
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 setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setDensity(Mdouble density)
Allows the density to be changed.
#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
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
double alpha
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
void setHGridMaxLevels(unsigned int HGridMaxLevels)
Sets the maximum number of levels of the HGrid in this MercuryBase.
Definition: MercuryBase.cc:500
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
HGrid_demo(DPMBase &other)
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
unsigned int N
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.
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
double omega
Contains material and contact force properties.
Definition: Interaction.h:35
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setHGridDistribution(HGridDistribution hGridDistribution)
Sets how the sizes of the cells of different levels are distributed.
Definition: MercuryBase.cc:464
LinearViscoelasticSpecies * species
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
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Definition: BaseHandler.h:360