MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PeriodicWallsUnitTest.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 #include <sstream>
26 #include <iostream>
27 #include <cstdlib>
28 
29 #include "Mercury2D.h"
31 #include "Particles/BaseParticle.h"
33 #include <Logger.h>
34 
35 class periodic_walls : public Mercury2D {
36 
41  {
43  }
44 
46  {
47  BaseParticle P0,P1,P2,P3,P4,P5,P6,P7,P8,P9,P10,P11,P12,P13;
48  P0 .setPosition(Vec3D( 0e-3, 2e-3, 0.0));
49  P1 .setPosition(Vec3D( 1e-3, 2e-3, 0.0));
50  P2 .setPosition(Vec3D(10e-3, 3e-3, 0.0));
51  P3 .setPosition(Vec3D( 1e-3, 3e-3, 0.0));
52  P4 .setPosition(Vec3D( 0e-3, 4e-3, 0.0));
53  P5 .setPosition(Vec3D( 9e-3, 4e-3, 0.0));
54  P6 .setPosition(Vec3D(10e-3, 5e-3, 0.0));
55  P7 .setPosition(Vec3D( 9e-3, 5e-3, 0.0));
56  P8 .setPosition(Vec3D( 1e-3, 6e-3, 0.0));
57  P9 .setPosition(Vec3D(10e-3, 6e-3, 0.0));
58  P10.setPosition(Vec3D(10e-3,10e-3, 0.0));
59  P11.setPosition(Vec3D( 9e-3, 9e-3, 0.0));
60  P12.setPosition(Vec3D( 0e-3, 0e-3, 1e-3));
61  P13.setPosition(Vec3D( 1e-3, 1e-3, 1e-3));
62 
63  P1. setVelocity(Vec3D(-1e-2, 0e-2, 0.0));
64  P3. setVelocity(Vec3D(-1e-2, 0e-2, 0.0));
65  P5. setVelocity(Vec3D( 1e-2, 0e-2, 0.0));
66  P7. setVelocity(Vec3D( 1e-2, 0e-2, 0.0));
67  P9. setVelocity(Vec3D( 1e-2, 0e-2, 0.0));
68  P11.setVelocity(Vec3D( 1e-2, 1e-2, 0.0));
69  P13.setVelocity(Vec3D(-1e-2,-1e-2, 0.0));
70 
71  P0.setVelocity(Vec3D(0.0,0.0,0.0));
72  P2.setVelocity(Vec3D(0.0,0.0,0.0));
73  P4.setVelocity(Vec3D(0.0,0.0,0.0));
74  P6.setVelocity(Vec3D(0.0,0.0,0.0));
75  P8.setVelocity(Vec3D(0.0,0.0,0.0));
76  P10.setVelocity(Vec3D(0.0,0.0,0.0));
77  P12.setVelocity(Vec3D(0.0,0.0,0.0));
78 
79  P0.setRadius(0.45e-3);
80  P1.setRadius(0.35e-3);
81  P2.setRadius(0.45e-3);
82  P3.setRadius(0.35e-3);
83  P4.setRadius(0.45e-3);
84  P5.setRadius(0.35e-3);
85  P6.setRadius(0.45e-3);
86  P7.setRadius(0.35e-3);
87  P8.setRadius(0.45e-3);
88  P9.setRadius(0.35e-3);
89  P10.setRadius(0.45e-3);
90  P11.setRadius(0.35e-3);
91  P12.setRadius(0.45e-3);
92  P13.setRadius(0.35e-3);
93 
108 
109  PeriodicBoundary b0;
110  b0.set(Vec3D(1,0,0), getXMin(), getXMax());
112  b0.set(Vec3D(0,1,0), getYMin(), getYMax());
114  }
115 
116 };
117 
118 
119 int main(int argc UNUSED, char *argv[] UNUSED)
120 {
122  periodic_walls problem;
123  auto species = new LinearViscoelasticSpecies;
124  problem.speciesHandler.addObject(species);
125  species->setDensity(2000);
126  species->setStiffness(10000);
127  species->setDissipation(1);
128 
129  problem.setTimeMax(0.11);
130  problem.setTimeStep(1.1e-05);
131  //problem.setSaveCount(helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(1,problem.getTimeMax(),problem.getTimeStep()));
133  problem.setName("PeriodicWallsUnitTest");
134 
135  problem.solve();
136 
137  Vec3D goodPos;
138  Vec3D goodVel;
139  std::vector<BaseParticle*>::iterator pIt = problem.particleHandler.begin();
140 
141  goodPos=Vec3D(0.00950076062215577,0.002,0);
142  goodVel=Vec3D(-0.005560409816604,0,0);
143  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
144  {
145  logger(FATAL, "E0 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
146  }
147  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
148  {
149  logger(FATAL, "E0 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
150  }
151  ++pIt;
152 
153  goodPos=Vec3D(0.000725163257251641,0.002,0);
154  goodVel=Vec3D(-0.000808302139899,0,0);
155  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
156  {
157  logger(FATAL, "E1 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
158  }
159  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
160  {
161  logger(FATAL, "E1 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
162  }
163  ++pIt;
164 
165  goodPos=Vec3D(0.00950076062215577,0.003,0);
166  goodVel=Vec3D(-0.005560409816604,0,0);
167  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
168  {
169  logger(FATAL, "E2 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
170  }
171  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
172  {
173  logger(FATAL, "E2 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
174  }
175  ++pIt;
176 
177  goodPos=Vec3D(0.000725163257251641,0.003,0);
178  goodVel=Vec3D(-0.000808302139899,0,0);
179  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
180  {
181  logger(FATAL, "E3 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
182  }
183  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
184  {
185  logger(FATAL, "E3 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
186  }
187  ++pIt;
188 
189  goodPos=Vec3D(0.0004992393778432442,0.004,0);
190  goodVel=Vec3D(0.00556040981661,0,0);
191  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
192  {
193  logger(FATAL, "E4 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
194  }
195  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
196  {
197  logger(FATAL, "E4 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
198  }
199  ++pIt;
200 
201  goodPos=Vec3D(0.00927483674274562,0.004,0);
202  goodVel=Vec3D(0.0008083021398896,0,0);
203  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
204  {
205  logger(FATAL, "E5 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
206  }
207  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
208  {
209  logger(FATAL, "E5 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
210  }
211  ++pIt;
212 
213  goodPos=Vec3D(0.000499239377843248,0.005,0);
214  goodVel=Vec3D(0.00556040981661,0,0);
215  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
216  {
217  logger(FATAL, "E6 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
218  }
219  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
220  {
221  logger(FATAL, "E6 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
222  }
223  ++pIt;
224 
225  goodPos=Vec3D(0.00927483674274562,0.005,0);
226  goodVel=Vec3D(0.0008083021398892,0,0);
227  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
228  {
229  logger(FATAL, "E7 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
230  }
231  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
232  {
233  logger(FATAL, "E7 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
234  }
235  ++pIt;
236 
237  goodPos=Vec3D(0.00149923937784423,0.006,0);
238  goodVel=Vec3D(0.005560409816606,0,0);
239  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
240  {
241  logger(FATAL, "E8 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
242  }
243  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
244  {
245  logger(FATAL, "E8 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
246  }
247  ++pIt;
248 
249  goodPos=Vec3D(0.000274836742748357,0.006,0);
250  goodVel=Vec3D(0.0008083021398959,0,0);
251  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
252  {
253  logger(FATAL, "E9 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
254  }
255  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
256  {
257  logger(FATAL, "E9 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
258  }
259  ++pIt;
260 
261  goodPos=Vec3D(0.000368955529803987, 0.000368955529803987,0);
262  goodVel=Vec3D(0.005560480643586,0.005560480643586,0);
263  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
264  {
265  logger(FATAL, "E10 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
266  }
267  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
268  {
269  logger(FATAL, "E10 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
270  }
271  ++pIt;
272 
273  goodPos=Vec3D(0.0094902039201126, 0.0094902039201126 ,0);
274  goodVel=Vec3D(0.0008081850585628,0.0008081850585628,0);
275  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
276  {
277  logger(FATAL, "E11 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
278  }
279  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
280  {
281  logger(FATAL, "E11 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
282  }
283  ++pIt;
284 
285  goodPos=Vec3D(0.00963104447019111, 0.00963104447019111,0.001);
286  goodVel=Vec3D(-0.005560480643562,-0.005560480643562,0);
287  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
288  {
289  logger(FATAL, "E12 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
290  }
291  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
292  {
293  logger(FATAL, "E12 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
294  }
295  ++pIt;
296 
297  goodPos=Vec3D(0.00050979607988006, 0.00050979607988006,0.001);
298  goodVel=Vec3D(-0.0008081850586013,-0.0008081850586013,0);
299  if (!(*pIt)->getPosition().isEqualTo(goodPos, 1e-10))
300  {
301  logger(FATAL, "E13 The particle is in the wrong position. It is %, however is should be %", (*pIt)->getPosition(), goodPos);
302  }
303  if (!(*pIt)->getVelocity().isEqualTo(goodVel , 1e-10))
304  {
305  logger.log(Log::FATAL, "E13 The particle has the wrong velocity. It is %, however is should be %", (*pIt)->getVelocity(), goodVel);
306  }
307 
308 
309 }
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall.
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
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
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 setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
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 setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
int main(int argc UNUSED, char *argv[] UNUSED)
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 computeExternalForces(BaseParticle *CI)
This is were the walls are implemented.
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
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
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:878
#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
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax...
Definition: DPMBase.cc:245
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:353
virtual void computeForcesDueToWalls(BaseParticle *PI)
Computes the forces on the particles due to the walls (normals are outward normals) ...
Definition: DPMBase.cc:1465
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 getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:194
This adds on the hierarchical grid code for 2D problems.
Definition: Mercury2D.h:35