MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MovingIntersectionOfWallsUnitTest.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 <cmath>
27 #include <iostream>
28 #include <iomanip>
29 
30 #include "Logger.h"
31 #include "DPMBase.h"
32 #include "Particles/BaseParticle.h"
35 
39 
41 {
42 public:
43 
45  {
47 
48  }
49 
51  {
54  setXMin(-2.0);
55  setXMax(2.0);
56  setYMin(-2.0);
57  setYMax(2.0);
59  setGravity(Vec3D(0.0, 0.0, 0.0));
60  species->setCollisionTimeAndRestitutionCoefficient(0.01, 1.0, 1.0);
61  setTimeStep(0.0002);
62  setTimeMax(1.0);
64 
72  std::vector<Vec3D> points={Vec3D(0.5,-std::sqrt(3)/6.0,0.0),Vec3D(0.0,std::sqrt(3)/3.0,0.0),Vec3D(-0.5,-std::sqrt(3)/6.0,0.0),Vec3D(0.5,-std::sqrt(3)/6.0,0.0)};
73  triangle->createOpenPrism(points,Vec3D(0.0,0.0,1.0));
74 
75  p1f->setRadius(0.1);
76  p2f->setRadius(0.1);
77  p3f->setRadius(0.1);
78  p1f->setPosition(Vec3D(-0.5, std::sqrt(3)/6.0,0.0));
79  p2f->setPosition(Vec3D(-0.0,-std::sqrt(3)/3.0,0.0));
80  p3f->setPosition(Vec3D( 0.5, std::sqrt(3)/6.0,0.0));
81  p1f->setVelocity(Vec3D( 0.5,-std::sqrt(3)/6.0,0.0));
82  p2f->setVelocity(Vec3D( 0.0, std::sqrt(3)/3.0,0.0));
83  p3f->setVelocity(Vec3D(-0.5,-std::sqrt(3)/6.0,0.0));
84  p1e->setRadius(0.1);
85  p2e->setRadius(0.1);
86  p3e->setRadius(0.1);
87  p1e->setPosition(1.5*Vec3D( 0.5,-std::sqrt(3)/6.0,0.0));
88  p2e->setPosition(1.5*Vec3D( 0.0, std::sqrt(3)/3.0,0.0));
89  p3e->setPosition(1.5*Vec3D(-0.5,-std::sqrt(3)/6.0,0.0));
90  p1e->setVelocity(Vec3D(-0.5, std::sqrt(3)/6.0,0.0));
91  p2e->setVelocity(Vec3D( 0.0,-std::sqrt(3)/3.0,0.0));
92  p3e->setVelocity(Vec3D( 0.5, std::sqrt(3)/6.0,0.0));
93  }
94 
102 
103 private:
105 };
106 
107 
109 {
110 public:
112  {
121  }
122  Vec3D velocity=Vec3D(1.0,0.0,0.0);
123 };
124 void compareParticles(BaseParticle* Ptest, BaseParticle* Pref, double absError, Vec3D positionDifference, Vec3D velocityDifference, Vec3D orientationDifference, Vec3D AngularVelocityDifference)
125 {
126  if (!mathsFunc::isEqual(Ptest->getPosition(), Pref->getPosition() + positionDifference, absError))
127  {
128  logger(FATAL, "The particle has the wrong position. It is %, however is should be %, the difference is %", Ptest->getPosition(), Pref->getPosition() + positionDifference, Ptest->getPosition() - Pref->getPosition() - positionDifference);
129  }
130  if (!mathsFunc::isEqual(Ptest->getVelocity(), Pref->getVelocity() + velocityDifference, absError))
131  {
132  logger(FATAL, "The particle has the wrong velocity. It is %, however is should be %, the difference is %", Ptest->getVelocity(), Pref->getVelocity() + velocityDifference, Ptest->getVelocity() - Pref->getVelocity() - velocityDifference);
133  }
134  if (!mathsFunc::isEqual(Ptest->getOrientation(), Pref->getOrientation() + orientationDifference, absError))
135  {
136  logger(FATAL, "The particle has the wrong orientation. It is %, however is should be %, the difference is %", Ptest->getOrientation(), Pref->getOrientation() + orientationDifference, Ptest->getOrientation() - Pref->getOrientation() - orientationDifference);
137  }
138  if (!mathsFunc::isEqual(Ptest->getAngularVelocity(), Pref->getAngularVelocity() + AngularVelocityDifference, absError))
139  {
140  logger(FATAL, "The particle has the wrong angular velocity. It is %, however is should be %, the difference is %", Ptest->getAngularVelocity(), Pref->getAngularVelocity() + AngularVelocityDifference, Ptest->getAngularVelocity() - Pref->getAngularVelocity() - AngularVelocityDifference);
141  }
142 }
143 int main(int argc UNUSED, char *argv[] UNUSED)
144 {
147  basic.setName("MovingIntersectionOfWallsUnitTest_Basic");
148  movingReferenceFrame.setName("MovingIntersectionOfWallsUnitTest_MovingReferenceFrame");
149  basic.solve();
150  movingReferenceFrame.solve();
151  compareParticles(movingReferenceFrame.p1f,basic.p1f, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
152  compareParticles(movingReferenceFrame.p2f,basic.p2f, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
153  compareParticles(movingReferenceFrame.p3f,basic.p3f, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
154  compareParticles(movingReferenceFrame.p1e,basic.p1e, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
155  compareParticles(movingReferenceFrame.p2e,basic.p2e, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
156  compareParticles(movingReferenceFrame.p3e,basic.p3e, 1e-10, movingReferenceFrame.velocity*movingReferenceFrame.getTime(), movingReferenceFrame.velocity, Vec3D(0.0,0.0,0.0), Vec3D(0.0,0.0,0.0));
157 }
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.
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:179
void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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
int main(int argc UNUSED, char *argv[] UNUSED)
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
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:453
void accelerate(const Vec3D &vel)
Increases the particle's velocity_ by the given vector.
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) ...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
const Vec3D & getOrientation() const
Returns the orientation of this BaseInteractable.
void createOpenPrism(std::vector< Vec3D > points, Vec3D prismAxis)
Creates an open prism which is a polygon between the points, except the first and last point...
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 setDensity(Mdouble density)
Allows the density to be changed.
#define UNUSED
Definition: GeneralDefine.h:37
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
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
bool isEqual(Mdouble v1, Mdouble v2, double absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
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 setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
This tests if moving walls also works with IntersectionOfWalls.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
Contains material and contact force properties.
Definition: Interaction.h:35
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
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
unsigned int getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(unsigned int numberOfSaves, Mdouble timeMax, Mdouble timestep)
Returns the correct saveCount if the total number of saves, the final time and the time step is known...
Definition: Helpers.cc:343
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:158
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:194
void compareParticles(BaseParticle *Ptest, BaseParticle *Pref, double absError, Vec3D positionDifference, Vec3D velocityDifference, Vec3D orientationDifference, Vec3D AngularVelocityDifference)