Loading...
Searching...
No Matches
Codes for tutorials

Particle motion in outer space (code)

Goto tutorial T1: Particle motion in outer space

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5/*
6** This file is annotated with DoxyFile comments in order to show the code on
7** the documentation - This is not needed for your real drivers.
8** Please ignore these comments.
9**
10** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T1
11*/
12
14#include <Mercury3D.h>
15#include <Species/Species.h>
18
21class Tutorial1 : public Mercury3D
22{
23
24public:
25
27 void setupInitialConditions() override {
29 // create a new particle
31 // set species (material type)
33 // set particle radius, position, velocity
34 p0.setRadius(0.01);
35 p0.setPosition(Vec3D(0.1 , 0.1, 0.1 ));
36 p0.setVelocity(Vec3D(0.1, 0.0, 0.0));
37 // pass particle to the particle handler (which contains all particles in the simulation)
40 }
41};
43
45int main(int argc, char* argv[])
46{
47 // Instantiate an object of class Tutorial1
48 Tutorial1 problem;
49
50 // Problem setup: set file name, gravity, domain size, simulation time
52 problem.setName("Tutorial1");
53 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
54 problem.setXMax(1.0);
55 problem.setYMax(1.0);
56 problem.setZMax(1.0);
57 problem.setTimeMax(1.0);
59
60 // Set the species (material properties such as density and stiffness) of particles and walls
61 // (in this case, both are assumed to consist of the same material)
64 species.setDensity(2500.0); //sets the species type_0 density in kg/m3
65 // The normal spring stiffness and normal dissipation is computed such that
66 // collision time tc=0.005 and restitution coefficient rc=1.0
67 species.setStiffness(258.5);//sets the spring stiffness in kN/m.
68 species.setDissipation(0.0); //sets the dissipation.
69 problem.speciesHandler.copyAndAddObject(species);
71
72 // Define what output gets written
74 // number of time steps skipped between saves (i.e. every 10-th time step is written to file)
75 problem.setSaveCount(50);
76 // creates file with particle positions, velocities, radii for multiple time steps (for plotting)
78 // file with contact forces, overlaps for multiple time steps (for plotting)
80 // file with all parameters of the last saved time step (for restarting)
82 // writes global properties like kinetic/potential energy and center of mass (for quick analysis)
85
87 // whether the wall geometry is written into a vtu file (either once initially or for several time steps)
89 // whether the particle positions are written into a vtu file
90 problem.particleHandler.setWriteVTK(true);
92
94 // set a time step 1/50th of collision time
95 problem.setTimeStep(0.005 / 50.0);
96 // start the solver (calls setupInitialConditions and initiates time loop)
97 problem.solve(argc, argv);
99
100 return 0;
101}
int main()
[ChuteDemo:include]
Definition ChuteDemo.cpp:13
@ NO_FILE
file will not be created/read
@ ONE_FILE
all data will be written into/ read from a single file called name_
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
Definition BaseHandler.h:360
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition BaseHandler.h:621
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
Definition BaseInteractable.cc:328
virtual void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Definition BaseInteractable.h:218
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species)
Definition BaseParticle.cc:548
virtual void setSpecies(const ParticleSpecies *species)
Definition BaseParticle.cc:798
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition DPMBase.cc:376
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition DPMBase.h:1503
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition DPMBase.h:1442
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition DPMBase.h:1498
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition DPMBase.cc:390
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition DPMBase.h:1493
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
Definition DPMBase.h:1462
void setYMax(Mdouble newYMax)
Sets the value of YMax, the upper bound of the problem domain in the y-direction.
Definition DPMBase.cc:1155
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition DPMBase.h:1508
void setXMax(Mdouble newXMax)
Sets the value of XMax, the upper bound of the problem domain in the x-direction.
Definition DPMBase.cc:1129
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created.
Definition DPMBase.h:1452
void setZMax(Mdouble newZMax)
Sets the value of ZMax, the upper bound of the problem domain in the z-direction.
Definition DPMBase.cc:1181
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition DPMBase.cc:1198
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition DPMBase.cc:850
void solve()
The work horse of the code.
Definition DPMBase.cc:4307
void setGravity(Vec3D newGravity)
Sets a new value for the gravitational acceleration.
Definition DPMBase.cc:1347
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition File.cc:193
void setDissipation(Mdouble dissipation)
Allows the normal dissipation to be changed.
Definition LinearViscoelasticNormalSpecies.cc:96
void setStiffness(Mdouble new_k)
Allows the spring constant to be changed.
Definition LinearViscoelasticNormalSpecies.cc:72
This adds on the hierarchical grid code for 3D problems.
Definition Mercury3D.h:16
void setWriteVTK(bool)
Sets whether particles are written into a VTK file.
Definition ParticleHandler.cc:1534
void setDensity(Mdouble density)
Definition ParticleSpecies.cc:88
A spherical particle is the most simple particle used in MercuryDPM.
Definition SphericalParticle.h:16
[T1:headers]
Definition Tutorial1_ParticleInOuterSpace.cpp:22
void setupInitialConditions() override
Use setupInitialConditions to define your particle and wall positions.
Definition Tutorial1_ParticleInOuterSpace.cpp:27
Definition Vector.h:30
void setWriteVTK(FileType)
Sets whether walls are written into a VTK file.
Definition WallHandler.cc:445

Return to tutorial T1: Particle motion in outer space

Particle motion on earth (code)

Goto tutorial T2: Particle motion on earth

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 2
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T2
13*/
14
17#include <Mercury3D.h>
19
21class Tutorial2 : public Mercury3D
22{
23public:
24
25 void setupInitialConditions() override {
29 p0.setRadius(0.05);
30 p0.setPosition(Vec3D(0.5 * getXMax(), 0.5 * getYMax(), getZMax()));
31 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
34 }
35
36};
38
40int main(int argc, char* argv[])
41{
42 // Problem setup
43 Tutorial2 problem;
44
46 problem.setName("Tutorial2");
47 problem.setGravity(Vec3D(0.0, 0.0, -9.81));
48 problem.setXMax(1.0);
49 problem.setYMax(1.0);
50 problem.setZMax(5.0);
51 problem.setTimeMax(1.5);
53
55 // The normal spring stiffness and normal dissipation is computed and set as
56 // For collision time tc=0.005 and restitution coefficient rc=1.0,
58 species.setDensity(2500.0); //sets the species type_0 density
59 species.setStiffness(258.5);//sets the spring stiffness.
60 species.setDissipation(0.0); //sets the dissipation.
61 problem.speciesHandler.copyAndAddObject(species);
63
65 problem.setSaveCount(50);
71
73 // whether the wall geometry is written into a vtu file (either once initially or for several time steps)
75 // whether the particle positions are written into a vtu file
76 problem.particleHandler.setWriteVTK(true);
78
79
81 problem.setTimeStep(.005 / 50.0);// (collision time)/50.0
82 problem.solve(argc, argv);
84
85 return 0;
86}
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax.
Definition DPMBase.h:616
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax.
Definition DPMBase.h:628
Mdouble getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax.
Definition DPMBase.h:640
[T2:headers]
Definition Tutorial2_ParticleUnderGravity.cpp:22
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial2_ParticleUnderGravity.cpp:25

Return to tutorial T2: Particle motion on earth

Bouncing ball - elastic (code)

Goto tutorial T3: Bouncing ball (elastic)

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 3
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T3
13*/
14
17#include <Mercury3D.h>
18#include <Walls/InfiniteWall.h>
20
25class Tutorial3 : public Mercury3D
26{
27public:
28
30 void setupInitialConditions() override {
31 // add a particle of 1cm diameter at height zMax
35 p0.setRadius(0.005);
36 p0.setPosition(Vec3D(0.5 * getXMax(), 0.5 * getYMax(), getZMax()));
37 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
40
41 // add a bottom wall at zMin
43 InfiniteWall w0;
45 w0.set(Vec3D(0.0, 0.0, -1.0), Vec3D(0, 0, getZMin()));
48 }
49
50};
52
54int main(int argc, char* argv[])
55{
56
57 // Problem setup
58 Tutorial3 problem;
59
60 // name the output files
61 problem.setName("Tutorial3");
62 // remove old output files with the same name
63 problem.removeOldFiles();
64 // set gravivational acceleration
65 problem.setGravity(Vec3D(0.0, 0.0, -9.81));
66 // set domain size (xMin = yMin = zMin = 0 by default)
67 problem.setXMax(0.5);
68 problem.setYMax(0.5);
69 problem.setZMax(0.5);
70 problem.setTimeMax(2.0);
71
73 // Sets a linear spring-damper contact law.
74 // The normal spring stiffness and normal dissipation is computed and set as
75 // For collision time tc=0.005 and restitution coefficient rc=1.0,
77 species->setDensity(2500.0);
78 double mass = species->getMassFromRadius(0.005);
79 double collisionTime = 0.005;
80 double restitution = 1.0;
81 species->setCollisionTimeAndRestitutionCoefficient(collisionTime,restitution,mass);
82 logger(INFO, "Stiffness %, dissipation %", species->getStiffness(), species->getDissipation());
84
86 problem.setSaveCount(25);
88
89 // Output vtk files for ParaView visualisation
92 problem.particleHandler.setWriteVTK(true);
94
96 // Sets time step to 1/50th of the collision time
97 problem.setTimeStep(0.005 / 50.0);
98 // Start the solver (calls setupInitialConditions and initiates time loop)
99 problem.solve(argc, argv);
101 return 0;
102}
Species< LinearViscoelasticNormalSpecies > LinearViscoelasticSpecies
Definition LinearViscoelasticSpecies.h:11
LL< Log::INFO > INFO
Info log level.
Definition Logger.cc:34
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
void setSpecies(const ParticleSpecies *species)
Defines the species of the current wall.
Definition BaseWall.cc:148
void removeOldFiles() const
Definition DPMBase.cc:4465
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin.
Definition DPMBase.h:634
A infinite wall fills the half-space {point: (position_-point)*normal_<=0}.
Definition InfiniteWall.h:27
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:97
Mdouble getStiffness() const
Allows the spring constant to be accessed.
Definition LinearViscoelasticNormalSpecies.cc:83
void setCollisionTimeAndRestitutionCoefficient(Mdouble tc, Mdouble eps, BaseParticle *p)
Sets k, disp such that it matches a given tc and eps for a collision of two copies of particle p.
Definition LinearViscoelasticNormalSpecies.cc:191
Mdouble getDissipation() const
Allows the normal dissipation to be accessed.
Definition LinearViscoelasticNormalSpecies.cc:109
Mdouble getMassFromRadius(Mdouble radius) const
Definition ParticleSpecies.cc:103
[T3:headers]
Definition Tutorial3_BouncingBallElastic.cpp:26
void setupInitialConditions() override
Use setupInitialConditions to define your particle and wall positions.
Definition Tutorial3_BouncingBallElastic.cpp:30

Return to tutorial T3: Bouncing ball (elastic)

Bouncing ball - inelastic (code)

Goto tutorial T4: Bouncing ball with dissipation (inelastic)

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 4
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T4
13*/
14
17#include <Mercury3D.h>
18#include <Walls/InfiniteWall.h>
20
22class Tutorial4 : public Mercury3D
23{
24public:
25
27 void setupInitialConditions() override {
30 p0.setRadius(0.005);
31 p0.setPosition(Vec3D(0.5 * getXMax(), 0.5 * getYMax(), getZMax()));
32 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
34
35 InfiniteWall w0;
37 w0.set(Vec3D(0.0, 0.0, -1.0), Vec3D(0.0, 0.0, getZMin()));
39 }
41
42};
44
46int main(int argc, char* argv[])
47{
48
49 // Problem setup
50 Tutorial4 problem;
51
52 problem.setName("Tutorial4");
53 problem.setGravity(Vec3D(0.0, 0.0, -9.81));
54 problem.setXMax(0.25);
55 problem.setYMax(0.25);
56 problem.setZMax(0.25);
57 problem.setTimeMax(5.0);
58
60 // The normal spring stiffness and normal dissipation is computed and set as
61 // For collision time tc=0.005 and restitution coefficient rc=0.88,
63 species.setDensity(2500.0); //sets the species type_0 density
64 species.setStiffness(258.5);//sets the spring stiffness.
65 species.setDissipation(0.0334); //sets the dissipation.
66 problem.speciesHandler.copyAndAddObject(species);
68
69 problem.setSaveCount(10);
72
73 // TODO: Write vtk files (exercise 5)
74
76 //time integration parameters
77 problem.setTimeStep(0.005 / 50.0); // (collision time)/50.0
80 problem.solve(argc, argv);
82 return 0;
83}
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition DPMBase.cc:427
[T4:headers]
Definition Tutorial4_BouncingBallInelastic.cpp:23
void setupInitialConditions() override
[T4:initialConditions]
Definition Tutorial4_BouncingBallInelastic.cpp:27

Return to tutorial T4: Bouncing ball with dissipation (inelastic)

Elastic collision - 2 particles (code)

Goto tutorial T5: Elastic collision (2 particles)

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 5
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T5
13*/
14
17#include <Mercury3D.h>
19
21class Tutorial5 : public Mercury3D
22{
23public:
24
25 void setupInitialConditions() override {
28
29 p0.setRadius(0.005); //particle-1 radius
30 p0.setPosition(Vec3D(0.25 * getXMax(), 0.5 * getYMax(), 0.5 * getZMax()));
31 p0.setVelocity(Vec3D(0.25, 0.0, 0.0));
32 particleHandler.copyAndAddObject(p0); // 1st particle created
33
34 p0.setRadius(0.005); // particle-2 radius
35 p0.setPosition(Vec3D(0.75 * getXMax(), 0.5 * getYMax(), 0.5 * getZMax()));
36 p0.setVelocity(Vec3D(-0.25, 0.0, 0.0));
37 particleHandler.copyAndAddObject(p0); // 2nd particle created
38 }
39
40};
42
44int main(int argc, char* argv[])
45{
46
47 // Problem setup
48 Tutorial5 problem;
49
50 problem.setName("Tutorial5");
51 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
52 problem.setXMax(0.5);
53 problem.setYMax(0.25);
54 problem.setZMax(0.5);
55 problem.setTimeMax(2.0);
56
58 // The normal spring stiffness and normal dissipation is computed and set as
59 // For collision time tc=0.005 and restitution coefficient rc=1.0,
61 species.setDensity(2500.0); //sets the species type_0 density
62 species.setStiffness(258.5);//sets the spring stiffness.
63 species.setDissipation(0.0); //sets the dissipation.
64 problem.speciesHandler.copyAndAddObject(species);
66
67 problem.setSaveCount(10);
72
73 // TODO: Write vtk files (exercise 1)
74
75 problem.setTimeStep(.005 / 50.0); // (collision time)/50.0
76 problem.solve(argc, argv);
77
78 return 0;
79}
[T5:headers]
Definition Tutorial5_ElasticCollision.cpp:22
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial5_ElasticCollision.cpp:25

Return to tutorial T5: Elastic collision (2 particles)

Elastic collisions with periodic boundaries (code)

Goto tutorial T6: Elastic collisions with periodic boundaries

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 6
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T6
13*/
14
17#include <Mercury3D.h>
20
22class Tutorial6 : public Mercury3D
23{
24public:
25
26 void setupInitialConditions() override {
29 p0.setRadius(0.015);//particle-1
30 p0.setPosition(Vec3D(0.15 * getXMax(), 0.5 * getYMax(), 0.5 * getZMax()));
31 p0.setVelocity(Vec3D(0.25, 0.0, 0.0));
33
34 p0.setRadius(0.005);// particle-2
35 p0.setPosition(Vec3D(0.75 * getXMax(), 0.5 * getYMax(), 0.5 * getZMax()));
36 p0.setVelocity(Vec3D(-0.25, 0.0, 0.0));
38
41 b0.set(Vec3D(1.0, 0.0, 0.0), getXMin(), getXMax());
44 }
45
46};
48
49int main(int argc, char* argv[])
50{
51
52 // Problem setup
53 Tutorial6 problem; // instantiate an object of class Tutorial 6
54
55 problem.setName("Tutorial6");
56 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
57 problem.setXMax(0.5);
58 problem.setYMax(0.25);
59 problem.setZMax(0.5);
60 problem.setTimeMax(5.0);
61
63 // The normal spring stiffness and normal dissipation is computed and set as
64 // For collision time tc=0.005 and restitution coefficient rc=1.0,
66 species.setDensity(2500.0); //sets the species type_0 density
67 species.setStiffness(258.5);//sets the spring stiffness.
68 species.setDissipation(0.0); //sets the dissipation.
69 problem.speciesHandler.copyAndAddObject(species);
70
72
73 problem.setSaveCount(10);
78
79 // Write vtk files
81 problem.particleHandler.setWriteVTK(true);
82
83 problem.setTimeStep(0.005 / 50.0);// (collision time)/50.0
84 problem.solve(argc, argv);
85
86 return 0;
87}
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin.
Definition DPMBase.h:609
BoundaryHandler boundaryHandler
An object of the class BoundaryHandler which concerns insertion and deletion of particles into or fro...
Definition DPMBase.h:1467
Defines a pair of periodic walls. Inherits from BaseBoundary.
Definition PeriodicBoundary.h:20
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a PeriodicBoundary by its normal and positions.
Definition PeriodicBoundary.cc:63
[T6:headers]
Definition Tutorial6_ElasticCollisionPeriodic.cpp:23
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial6_ElasticCollisionPeriodic.cpp:26

Return to tutorial T6: Elastic collisions with periodic boundaries

Motion of a particle in a two dimensional box (code)

Goto tutorial T7: Motion of a particle in a two dimensional (2D) box

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 7
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T7
13*/
14
17#include <Mercury3D.h>
18#include <Walls/InfiniteWall.h>
20
22class Tutorial7 : public Mercury3D
23{
24public:
25
26 void setupInitialConditions() override {
29 p0.setRadius(0.005);
30 p0.setPosition(Vec3D(0.5 * getXMax(), 0.5 * getYMax(), 0.0));
31 p0.setVelocity(Vec3D(1.2, 1.3, 0.0));
33
35 InfiniteWall w0;
36
38 w0.set(Vec3D(1.0, 0.0, 0.0), Vec3D(getXMax(), 0.0, 0.0));
40
41 w0.set(Vec3D(-1.0, 0.0, 0.0), Vec3D(getXMin(), 0.0, 0.0));
43
44 w0.set(Vec3D(0.0, 1.0, 0.0), Vec3D(0.0, getYMax(), 0.0));
46
47 w0.set(Vec3D(0.0, -1.0, 0.0), Vec3D(0.0, getYMin(), 0.0));
50 }
51
52};
54
56int main(int argc, char* argv[])
57{
58 // Problem setup
59 Tutorial7 problem; // instantiate an object of class Tutorial 7
60
61 problem.setName("Tutorial7");
62 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
63 problem.setXMax(1);
64 problem.setYMax(0.5);
65 problem.setZMax(1.0);
66 problem.setTimeMax(2.5);
67
69 // The normal spring stiffness and normal dissipation is computed and set as
70 // For collision time tc=0.005 and restitution coefficient rc=1.0,
72 species.setDensity(2500.0); //sets the species type_0 density
73 species.setStiffness(258.5);//sets the spring stiffness.
74 species.setDissipation(0.0); //sets the dissipation.
75 problem.speciesHandler.copyAndAddObject(species);
77
78 problem.setSaveCount(50);
83
86 problem.particleHandler.setWriteVTK(true);
87
88 problem.setTimeStep(0.005 / 50.0);// (collision time)/50.0
89 problem.solve(argc, argv);
90
91 return 0;
92}
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin.
Definition DPMBase.h:622
[T7:headers]
Definition Tutorial7_ParticleIn2DBox.cpp:23
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial7_ParticleIn2DBox.cpp:26

Return to tutorial T7: Motion of a particle in a two dimensional (2D) box

Motion of a particle in a box with an obstacle (code)

Goto tutorial T8: Motion of a particle in a box with an obstacle

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 8
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T8
13*/
14
17#include <Mercury3D.h>
18#include <Walls/InfiniteWall.h>
21
23class Tutorial8 : public Mercury3D
24{
25public:
26
27 void setupInitialConditions() override {
30 p0.setRadius(0.005);
31 p0.setPosition(Vec3D(0.15 * getXMax(), 0.3335 * getYMax(), 0.0));
32 p0.setVelocity(Vec3D(1.2, 0.2, 0.0));
34
36 InfiniteWall w0;
37
39 w0.set(Vec3D(1.0, 0.0, 0.0), Vec3D(getXMax(), 0.0, 0.0));
41
42 w0.set(Vec3D(-1.0, 0.0, 0.0), Vec3D(getXMin(), 0.0, 0.0));
44
45 w0.set(Vec3D(0.0, 1.0, 0.0), Vec3D(0.0, getYMax(), 0.0));
47
48 w0.set(Vec3D(0.0, -1.0, 0.0), Vec3D(0.0, getYMin(), 0.0));
51
55
56 w1.addObject(Vec3D(-1.0, 0.0, 0.0), Vec3D(0.75 * getXMax(), 0.0, 0.0));
57 w1.addObject(Vec3D(1.0, 0.0, 0.0), Vec3D(0.25 * getXMax(), 0.0, 0.0));
58 w1.addObject(Vec3D(0.0, -1.0, 0.0), Vec3D(0.0, 0.75 * getYMax(), 0.0));
59 w1.addObject(Vec3D(0.0, 1.0, 0.0), Vec3D(0.0, 0.25 * getYMax(), 0.0));
62 }
63
64};
66
67int main(int argc, char* argv[])
68{
69
70 // Problem setup
71 Tutorial8 problem; // instantiate an object of class Tutorial 8
72
73 problem.setName("Tutorial8");
74 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
75 problem.setXMax(0.5);
76 problem.setYMax(0.5);
77 problem.setZMax(0.5);
78 problem.setTimeMax(5.0);
79
81 // The normal spring stiffness and normal dissipation is computed and set as
82 // For collision time tc=0.005 and restitution coefficient rc=1.0,
84 species.setDensity(2500.0); //sets the species type_0 density
85 species.setStiffness(258.5);//sets the spring stiffness.
86 species.setDissipation(0.0); //sets the dissipation.
87 problem.speciesHandler.copyAndAddObject(species);
88
90
91 problem.setSaveCount(50);
96
99 problem.particleHandler.setWriteVTK(true);
100
101 problem.setTimeStep(.005 / 50.0); // (collision time)/50.0
102 problem.solve(argc, argv);
103
104 return 0;
105}
A IntersectionOfWalls is convex polygon defined as an intersection of InfiniteWall's.
Definition IntersectionOfWalls.h:38
void addObject(Vec3D normal, Vec3D point)
Adds a wall to the set of infinite walls, given a normal vector pointing into the wall (i....
Definition IntersectionOfWalls.cc:125
void setSpecies(const ParticleSpecies *species)
sets species of subwalls as well
Definition IntersectionOfWalls.cc:51
[T8:headers]
Definition Tutorial8_ParticleIn2DBoxWithObstacle.cpp:24
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial8_ParticleIn2DBoxWithObstacle.cpp:27

Return to tutorial T8: Motion of a particle in a box with an obstacle

Motion of a ball over an inclined plane (code)

Goto tutorial T9: Motion of a ball over an inclined plane (Sliding + Rolling)

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 9
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T9
13*/
14
17#include <Mercury3D.h>
18#include <Walls/InfiniteWall.h>
20
22class Tutorial9 : public Mercury3D
23{
24public:
25
26 void setupInitialConditions() override {
28
29 //sets the particle to species type-1
31 p0.setRadius(0.005);
32 p0.setPosition(Vec3D(0.05 * getXMax(), 0.25 * getYMax(), getZMin() + p0.getRadius()));
33 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
35
36 //sets the particle to species type-2
38 p0.setRadius(0.005);
39 p0.setPosition(Vec3D(0.05 * getXMax(), 0.5 * getYMax(), getZMin() + p0.getRadius()));
40 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
42
43 //sets the particle to species type-3
45 p0.setRadius(0.005);
46 p0.setPosition(Vec3D(0.05 * getXMax(), 0.75 * getYMax(), getZMin() + p0.getRadius()));
47 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
49
51 InfiniteWall w0;
52
54 w0.set(Vec3D(0.0, 0.0, -1.0), Vec3D(0.0, 0.0, getZMin()));
57 }
58};
60
62int main(int argc, char* argv[])
63{
64
65 // Instantiate an object of class Tutorial 9
66 Tutorial9 problem;
67
68 // Problem setup
69 problem.setName("Tutorial9");
70 problem.removeOldFiles();
71 double angle = constants::pi / 180.0 * 20.0;
72 problem.setGravity(Vec3D(sin(angle), 0.0, -cos(angle)) * 9.81);
73 problem.setXMax(0.3);
74 problem.setYMax(0.3);
75 problem.setZMax(0.05);
76 problem.setTimeMax(0.4);
77
78 // Set the species (material properties such as density and stiffness) of particles and walls
79 // (in this case, particle-0 and the wall are made from species-0, particle-1 belongs to species-1, particle-2 belongs to species-2)
80
82 // Species-0 properties
84 // The normal spring stiffness and normal dissipation is computed and set as
85 // For collision time tc=0.005 and restitution coefficient rc=0.88,
86 species0.setDensity(2500.0);//sets the species type_0 density
87 species0.setStiffness(259.018);//sets the spring stiffness.
88 species0.setDissipation(0.0334);//sets the dissipation.
89 species0.setSlidingStiffness(2.0 / 7.0 * species0.getStiffness());
90 species0.setRollingStiffness(2.0 / 5.0 * species0.getStiffness());
93 auto ptrToSp0=problem.speciesHandler.copyAndAddObject(species0);
94
95 // Species-1 properties
97 species1.setDensity(2500.0);//sets the species type-1 density
98 species1.setStiffness(259.018);//sets the spring stiffness
99 species1.setDissipation(0.0334);//sets the dissipation
100 species1.setSlidingStiffness(2.0 / 7.0 * species1.getStiffness());
101 species1.setRollingStiffness(2.0 / 5.0 * species1.getStiffness());
102 species1.setSlidingFrictionCoefficient(0.5);
103 species1.setRollingFrictionCoefficient(0.0);
104 auto ptrToSp1=problem.speciesHandler.copyAndAddObject(species1);
105
106 // Properties of contacts between species-0 and species-1
107 // (no new species is defined since the mixed species is automatically created)
108 auto species01 = problem.speciesHandler.getMixedObject(ptrToSp0,ptrToSp1);
109 species01->setStiffness(259.018);//sets the spring stiffness
110 species01->setDissipation(0.0334);//sets the dissipation
111 species01->setSlidingStiffness(2.0 / 7.0 * species01->getStiffness());
112 species01->setRollingStiffness(2.0 / 5.0 * species01->getStiffness());
113 species01->setSlidingFrictionCoefficient(0.5);
114 species01->setRollingFrictionCoefficient(0.0);
115
116 // Species 2 properties
118 species2.setDensity(2500.0);//sets the species type-2 density
119 species2.setStiffness(258.5);//sets the spring stiffness
120 species2.setDissipation(0.0);//sets the dissipation
121 species2.setSlidingStiffness(2.0 / 7.0 * species2.getStiffness());
122 species2.setRollingStiffness(2.0 / 5.0 * species2.getStiffness());
123 species2.setSlidingFrictionCoefficient(0.5);
124 species2.setRollingFrictionCoefficient(0.5);
125 auto ptrToSp2 = problem.speciesHandler.copyAndAddObject(species2);
126
127 // Properties of contacts between species-0 and species-2
128 auto species02 = problem.speciesHandler.getMixedObject(ptrToSp0, ptrToSp2);
129 species02->setStiffness(259.018);//sets the stiffness
130 species02->setDissipation(0.0334);//sets the dissipation
131 species02->setSlidingStiffness(2.0 / 7.0 * species02->getStiffness());
132 species02->setRollingStiffness(2.0 / 5.0 * species02->getStiffness());
133 species02->setSlidingFrictionCoefficient(0.5);
134 species02->setRollingFrictionCoefficient(0.5);
135
136 // Note: Properties of contacts between species-0 and species-1 are never defined, since no contacts between those
137 // two materials occurs in this simulation; note: if no properties are defined, then default properties are assumed,
138 // mostly harmonic means of the properties of both individual species
140
141 //Output
142 problem.setSaveCount(25);
147
149 // whether the wall geometry is written into a vtu file (either once initially or for several time steps)
151 // whether the particle positions are written into a vtu file
152 problem.particleHandler.setWriteVTK(true);
154
156 // set a time step 1/50th of collision time
157 problem.setTimeStep(0.005 / 50.0);
158 // start the solver (calls setupInitialConditions and initiates time loop)
159 problem.solve(argc, argv);
161 return 0;
162}
Mdouble getRadius() const
Returns the particle's radius.
Definition BaseParticle.h:339
void setRollingFrictionCoefficient(Mdouble new_mu)
Allows the (dynamic) Coulomb friction coefficient to be changed; also sets mu_s by default.
Definition FrictionSpecies.cc:165
void setRollingStiffness(Mdouble new_kt)
Allows the spring constant to be changed.
Definition FrictionSpecies.cc:128
void setSlidingStiffness(Mdouble new_kt)
Allows the spring constant to be changed.
Definition SlidingFrictionSpecies.cc:83
void setSlidingFrictionCoefficient(Mdouble new_mu)
Allows the (dynamic) Coulomb friction coefficient to be changed; also sets mu_s by default.
Definition SlidingFrictionSpecies.cc:120
std::enable_if<!std::is_pointer< typenameU::MixedSpeciesType >::value, typenameU::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition SpeciesHandler.h:52
[T9:headers]
Definition Tutorial9_InclinedPlane.cpp:23
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition Tutorial9_InclinedPlane.cpp:26
const Mdouble pi
Definition ExtendedMath.h:23

Return to tutorial T9: Motion of a ball over an inclined plane (Sliding + Rolling)

Loading data restart(code)

Goto tutorial T10: How to load restart and data files

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 10: This tutorial shows how to load restart and data files
6/*
7** This file is annotated with DoxyFile comments in order to show the code on
8** the documentation - This is not needed for your real drivers.
9** Please ignore these comments.
10**
11** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T10
12*/
13
15#include "Mercury3D.h"
16#include <Math/Helpers.h>
21
22
24int main(int argc, char* argv[])
25{
26
27 //writeToFile is used here to create a restart and a data file, which will be loaded below.
28 helpers::writeToFile("Tutorial10.ini.restart",
29 "restart_version 1.0 name Tutorial10\n"
30 "dataFile name Tutorial10.data fileType ONE_FILE saveCount 10 counter 0 nextSavedTimeStep 0\n"
31 "fStatFile name Tutorial10.fstat fileType NO_FILE saveCount 10 counter 0 nextSavedTimeStep 0\n"
32 "eneFile name Tutorial10.ene fileType ONE_FILE saveCount 10 counter 0 nextSavedTimeStep 0\n"
33 "restartFile name Tutorial10.restart fileType ONE_FILE saveCount 10 counter 0 nextSavedTimeStep 0\n"
34 "statFile name Tutorial10.stat fileType ONE_FILE saveCount 10 counter 0 nextSavedTimeStep 0\n"
35 "xMin 0 xMax 2 yMin 0 yMax 2 zMin 0 zMax 2\n"
36 "timeStep 1e-03 time 0 ntimeSteps 0 timeMax 10\n"
37 "systemDimensions 3 particleDimensions 3 gravity 0 0 -1\n"
38 "Species 1\n"
39 "LinearViscoelasticSpecies id 0 density 1.9098593 stiffness 2000 dissipation 10\n"
40 "Walls 1\n"
41 "InfiniteWall id 0 indSpecies 0 position 0 0 0 orientation 0 0 0 1 velocity 0 0 0 angularVelocity 0 0 0 0 force 0 0 0 torque 0 0 0 normal 0 0 -1 factor 1\n"
42 "Boundaries 0\n"
43 "Particles 0\n"
44 "Interactions 0\n"
45 );
46
47 helpers::writeToFile("Tutorial10.ini.data",
48 "1 0 0 0 0 2 2 2\n"
49 "1 1 1.5 0 0 0 0.5 0 0 0 0 0 0 0\n"
50 );
51
52
53 DPMBase Tutorial10;
54 //use readRestartFile to load information from a restart file
55 Tutorial10.readRestartFile("Tutorial10.ini.restart");
56
57 //use readDataFile to load information from a data file
58 Tutorial10.readDataFile("Tutorial10.ini.data");
59
60 //now start the calculations
61 Tutorial10.solve();
62
63 return 0;
64}
The DPMBase header includes quite a few header files, defining all the handlers, which are essential....
Definition DPMBase.h:56
bool readDataFile(std::string fileName="", unsigned int format=0)
This allows particle data to be reloaded from data files.
Definition DPMBase.cc:2430
bool readRestartFile(ReadOptions opt=ReadOptions::ReadAll)
Reads all the particle data corresponding to a given, existing . restart file (for more details regar...
Definition DPMBase.cc:3016
bool writeToFile(const std::string &filename, const std::string &filecontent)
Writes a string to a file.
Definition FileIOHelpers.cc:29

Return to tutorial T10: How to load restart and data files

Axisymmetric walls inside a cylindrical domain (code)

Goto tutorial T11: Axisymmetric walls inside a cylindrical domain

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5//Tutorial 11 introduces the axisymmetrical walls. Two asymmetrical walls are created into a
6//cylindrical boundary.
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T9
13*/
14
16#include "Mercury3D.h"
21
23class Tutorial11 : public Mercury3D
24{
25public:
27 Tutorial11(const Mdouble width, const Mdouble height){
28 logger(INFO, "Tutorial 11");
29 setName("Tutorial11");
36 setXBallsAdditionalArguments("-v0 -solidf");
37
38 //specify body forces
39 setGravity(Vec3D(0.0, 0.0, -9.8));
40
41 //set domain accordingly (domain boundaries are not walls!)
42 setXMin(0.0);
43 setXMax(width);
44 setYMin(0.0);
45 setYMax(width);
46 setZMin(0.0);
47 setZMax(height);
48 }
50
52 void setupInitialConditions() override {
53 Vec3D mid = {
54 (getXMin() + getXMax()) / 2.0,
55 (getYMin() + getYMax()) / 2.0,
56 (getZMin() + getZMax()) / 2.0};
57 const Mdouble halfWidth = (getXMax() - getXMin()) / 2.0;
58
60 //Cylinder
63 w1.setPosition(Vec3D(mid.X, mid.Y, 0));
64 w1.setAxis(Vec3D(0, 0, 1));
65 w1.addObject(Vec3D(1, 0, 0), Vec3D((getXMax() - getXMin()) / 2.0, 0, 0));
66 // Display the cylinder only, when not coinciding with the neck
67 std::vector<Mdouble> displayedSegmentsCylinder = {-constants::inf, mid.Z - contractionHeight, mid.Z + contractionHeight, constants::inf};
68 w1.setDisplayedSegments(displayedSegmentsCylinder);
71
73 //Cone
76 w2.setPosition(Vec3D(mid.X, mid.Y, 0));
77 w2.setAxis(Vec3D(0, 0, 1));
78 std::vector<Vec3D> points(3);
79 //define the neck as a prism through corners of your prismatic wall in clockwise direction
80 points[0] = Vec3D(halfWidth, 0.0, mid.Z + contractionHeight);
81 points[1] = Vec3D(halfWidth - contractionWidth, 0.0, mid.Z);
82 points[2] = Vec3D(halfWidth, 0.0, mid.Z - contractionHeight);
83 w2.createOpenPrism(points);
84 // Display the neck only until reaching the cylinder
85 std::vector<Mdouble> displayedSegmentsPrism = {mid.Z - contractionHeight, mid.Z + contractionHeight};
86 w2.setDisplayedSegments(displayedSegmentsPrism);
89
91 //Flat surface
92 InfiniteWall w0;
94 w0.set(Vec3D(0, 0, -1), Vec3D(0, 0, mid.Z));
97
99 const int N = 600; //maximum number of particles
102 for (Mdouble z = mid.Z + contractionHeight;
104 z += 2.0 * maxParticleRadius)
105 {
106 for (Mdouble r = halfWidth - maxParticleRadius; r > 0; r -= 1.999 * maxParticleRadius)
107 {
108 for (Mdouble c = 2.0 * maxParticleRadius; c <= 2 * constants::pi * r; c += 2.0 * maxParticleRadius)
109 {
111 p0.setPosition(Vec3D(mid.X + r * mathsFunc::sin(c / r),
112 mid.Y + r * mathsFunc::cos(c / r),
113 z + p0.getRadius()));
114 const Mdouble vz = random.getRandomNumber(-1, 0);
115 const Mdouble vx = random.getRandomNumber(-1, 1);
116 p0.setVelocity(Vec3D(vx,0.0,vz));
118 }
119 }
120 }
122 }
124
126 //Initially, a wall is inserted in the neck of the hourglass to prevent particles flowing through.
127 //This wall is moved to form the base of the hourglass at time 0.9
128 void actionsAfterTimeStep() override {
129 if (getTime() < 0.9 && getTime() + getTimeStep() > 0.9)
130 {
131 logger(INFO, "Shifting bottom wall downward");
132 dynamic_cast<InfiniteWall*>(wallHandler.getLastObject())->set(Vec3D(0, 0, -1), Vec3D(0, 0, getZMin()));
133 }
134 }
136
141
142};
144
146int main(int argc, char *argv[])
147{
149 Mdouble width = 10e-2; // 10cm
150 Mdouble height = 60e-2; // 60cm
151
152 //Point the object HG to class
153 Tutorial11 HG(width,height);
154
155 //Specify particle radius:
156 //these parameters are needed in setupInitialConditions()
157 HG.minParticleRadius = 6e-3; // 6mm
158 HG.maxParticleRadius = 10e-3; //10mm
160
162 //Specify the number of particles
163
164 //specify how big the wedge of the contraction should be
165 const Mdouble contractionWidth = 2.5e-2; //2.5cm
166 const Mdouble contractionHeight = 5e-2; //5cm
167 HG.contractionWidth = contractionWidth;
168 HG.contractionHeight = contractionHeight;
170
172 //make the species of the particle and wall
174 species.setDensity(2000);
175
176 species.setStiffness(1e5);
177 species.setDissipation(0.63);
178 HG.speciesHandler.copyAndAddObject(species);
179
181
183 //test normal forces
184 const Mdouble minParticleMass = species.getDensity() * 4.0 / 3.0 * constants::pi * mathsFunc::cubic(HG.minParticleRadius);
185 //Calculates collision time for two copies of a particle of given dissipation_, k, effective mass
186 logger(INFO, "minParticleMass = %", minParticleMass);
187 //Calculates collision time for two copies of a particle of given dissipation_, k, effective mass
188 const Mdouble tc = species.getCollisionTime(minParticleMass);
189 logger(INFO, "tc = %", tc);
190 //Calculates restitution coefficient for two copies of given dissipation_, k, effective mass
191 const Mdouble r = species.getRestitutionCoefficient(minParticleMass);
192 logger(INFO, "restitution coefficient = %", r);
194
196 //time integration parameters
197 HG.setTimeStep(tc / 10.0);
198 HG.setTimeMax(5.0);
199 HG.setSaveCount(500);
201
203 HG.solve(argc, argv);
205 return 0;
206}
double Mdouble
Definition GeneralDefine.h:13
Use AxisymmetricIntersectionOfWalls to Screw Screw::read Screw::read Screw::read define axisymmetric ...
Definition AxisymmetricIntersectionOfWalls.h:105
void setAxis(Vec3D a)
Definition AxisymmetricIntersectionOfWalls.cc:222
void setDisplayedSegments(const std::vector< Mdouble > &displayedSegments)
Sets the displayed segments.
Definition AxisymmetricIntersectionOfWalls.h:189
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
Definition BaseHandler.h:642
void setYMin(Mdouble newYMin)
Sets the value of YMin, the lower bound of the problem domain in the y-direction.
Definition DPMBase.cc:998
Mdouble getTimeStep() const
Returns the simulation time step.
Definition DPMBase.cc:1214
Mdouble getTime() const
Returns the current simulation time.
Definition DPMBase.cc:785
void setZMin(Mdouble newZMin)
Sets the value of ZMin, the lower bound of the problem domain in the z-direction.
Definition DPMBase.cc:1022
void setXBallsAdditionalArguments(std::string newXBArgs)
Set the additional arguments for xballs.
Definition DPMBase.cc:1311
RNG random
This is a random generator, often used for setting up the initial conditions etc.....
Definition DPMBase.h:1447
void setXMin(Mdouble newXMin)
Sets the value of XMin, the lower bound of the problem domain in the x-direction.
Definition DPMBase.cc:974
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,...
Definition IntersectionOfWalls.cc:454
Mdouble getCollisionTime(Mdouble mass) const
Calculates collision time for two copies of a particle of given disp, k, mass.
Definition LinearViscoelasticNormalSpecies.cc:116
Mdouble getRestitutionCoefficient(Mdouble mass) const
Calculates restitution coefficient for two copies of given disp, k, mass.
Definition LinearViscoelasticNormalSpecies.cc:147
unsigned int getNumberOfObjects() const override
Returns the number of objects in the container. In parallel code this practice is forbidden to avoid ...
Definition ParticleHandler.cc:1355
Mdouble getDensity() const
Allows density_ to be accessed.
Definition ParticleSpecies.cc:98
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition RNG.cc:123
[T11:headers]
Definition Tutorial11_AxisymmetricWalls.cpp:24
Mdouble contractionHeight
Definition Tutorial11_AxisymmetricWalls.cpp:138
Mdouble maxParticleRadius
Definition Tutorial11_AxisymmetricWalls.cpp:140
void setupInitialConditions() override
[T11:constructor]
Definition Tutorial11_AxisymmetricWalls.cpp:52
Mdouble minParticleRadius
Definition Tutorial11_AxisymmetricWalls.cpp:139
void actionsAfterTimeStep() override
[T11:initialConditions]
Definition Tutorial11_AxisymmetricWalls.cpp:128
Mdouble contractionWidth
[T11:functiontime]
Definition Tutorial11_AxisymmetricWalls.cpp:137
Mdouble Y
Definition Vector.h:45
Mdouble Z
Definition Vector.h:45
Mdouble X
the vector components
Definition Vector.h:45
int N
Definition MultiOpt.py:25
r
Definition UniformPSDSelfTest.py:20
int c
Definition calibrate.py:100
const Mdouble inf
Definition GeneralDefine.h:23
Mdouble cos(Mdouble x)
Definition ExtendedMath.cc:43
Mdouble sin(Mdouble x)
Definition ExtendedMath.cc:23
T cubic(const T val)
calculates the cube of a number
Definition ExtendedMath.h:95

Return to tutorial T11: Axisymmetric walls inside a cylindrical domain

Prismatic walls using points (code)

Goto tutorial T12: Creating objects by using Prisms

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5// Tutorial 12
6
7/*
8** This file is annotated with DoxyFile comments in order to show the code on
9** the documentation - This is not needed for your real drivers.
10** Please ignore these comments.
11**
12** For full documentation of this code, go to http://docs.mercurydpm.org/Alpha/d0/db0/BeginnerTutorials.html#T8
13*/
14
16#include <Mercury3D.h>
17#include <Walls/InfiniteWall.h>
21
23class Tutorial12 : public Mercury3D
24{
25public:
27 void setupInitialConditions() override {
31 p0.setRadius(0.005);
32 p0.setPosition(Vec3D(0.15 * getXMax(), 0.3335 * getYMax(), 0.0));
33 p0.setVelocity(Vec3D(1.2, 0.2, 0.0));
36
38 // Creating outer walls
39 InfiniteWall w0;
40
42 w0.set(Vec3D(1.0, 0.0, 0.0), Vec3D(getXMax(), 0.0, 0.0));
44
45 w0.set(Vec3D(-1.0, 0.0, 0.0), Vec3D(getXMin(), 0.0, 0.0));
47
48 w0.set(Vec3D(0.0, 1.0, 0.0), Vec3D(0.0, getYMax(), 0.0));
50
51 w0.set(Vec3D(0.0, -1.0, 0.0), Vec3D(0.0, getYMin(), 0.0));
54
56 // Defining the object in het center of the box
57 // Create an intersection of walls object w1
59 // Set the species of the wall
61 std::vector<Vec3D> Points(4);
62 // Define the vertices of the insert and ensure that points are in clockwise order
63 Points[0] = Vec3D(0.25 * getXMax(), -0.25 * getYMax(), 0.0);
64 Points[1] = Vec3D(-0.25 * getXMax(), -0.25 * getYMax(), 0.0);
65 Points[2] = Vec3D(-0.25 * getXMax(), 0.25 * getYMax(), 0.0);
66 Points[3] = Vec3D(0.25 * getXMax(), 0.25 * getYMax(), 0.0);
67 // Creating the object from the vector containing points
68 w1.createPrism(Points);
70 /* Define the angular velocity of the object (optional).
71 * Setting the angular velocity of the object results in rotation of the object around
72 * the origin (0.0,0.0,0.0). If the object is build such that the center of rotation of the object
73 * coincides with the origin the object will rotate around its own axis. */
75 w1.setAngularVelocity(Vec3D(0.0,0.0,1.0));
77 /* Define the translational velocity of the object (optional) */
79 w1.setVelocity(Vec3D(0.0,0.0,0.0));
81 /* Set the desired position of center of the object (optional).
82 * With this command you can position your object (with the set angular velocity)
83 * at a specific location in the domain.*/
85 w1.setPosition(Vec3D(0.5 * getXMax(),0.5 * getYMax(),0.0));
87 // Add the object to wall w1
89
90 }
92};
94
96int main(int argc, char* argv[])
97{
99 // Problem setup
100 Tutorial12 problem; // instantiate an object of class Tutorial 12
101
102 problem.setName("Tutorial12");
103 problem.setGravity(Vec3D(0.0, 0.0, 0.0));
104 problem.setXMax(0.5);
105 problem.setYMax(0.5);
106 problem.setZMax(0.1);
107 problem.setTimeMax(5.0);
108
110 // The normal spring stiffness and normal dissipation is computed and set as
111 // For collision time tc=0.005 and restitution coefficient rc=1.0,
113 species.setDensity(2500.0); //sets the species type_0 density
114 species.setStiffness(258.5);//sets the spring stiffness.
115 species.setDissipation(0.0); //sets the dissipation.
116 problem.speciesHandler.copyAndAddObject(species);
117
119
120 problem.setSaveCount(10);
125 problem.particleHandler.setWriteVTK(true);
127
128 problem.setTimeStep(.005 / 50.0); // (collision time)/50.0
130
132 problem.solve(argc, argv);
134
135 return 0;
136}
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Definition BaseInteractable.cc:338
void createPrism(std::vector< Vec3D > points, Vec3D prismAxis)
Creates an open prism which is a polygon between the points and extends infinitely in the PrismAxis d...
Definition IntersectionOfWalls.cc:469
[T12:headers]
Definition Tutorial12_PrismWalls.cpp:24
void setupInitialConditions() override
[T12:initialConditions]
Definition Tutorial12_PrismWalls.cpp:27

Return to tutorial T12: Creating objects by using Prisms

Particles driven by a rotating coil (code)

Goto tutorial Particles driven by a rotating coil

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
6#include "Mercury3D.h"
9#include "Walls/Coil.h"
12
14
21class CoilSelfTest : public Mercury3D
22{
23private:
24 void setupInitialConditions() override
25 {
29 //front wall
30 w.set(Vec3D(-1, 0, 0), Vec3D(getXMin(), 0, 0));
32
33 //back wall
34 w.set(Vec3D(1, 0, 0), Vec3D(getXMax(), 0, 0));
36
37 //bottom wall
38 w.set(Vec3D(0, -1, 0), Vec3D(0, getYMin(), 0));
40
41 //top wall
42 w.set(Vec3D(0, 1, 0), Vec3D(0, getYMax(), 0));
44
45 //left wall
46 w.set(Vec3D(0, 0, -1), Vec3D(0, 0, getZMin()));
48
49 //right wall
50 InfiniteWallWithHole rightWall;
52 rightWall.set(Vec3D(0, 0, 1), getZMax(), 1.0);
55
57 // creation of the coil and setting of its properties
58 Coil coil;
60 // the syntax to set the coil geometry is as follows:
61 // set(Start position, Length, Radius, Number of turns, Rotation speed, Thickness)
62 coil.set(Vec3D(0, 0, 0), 1.0, 1.0 - particleRadius, 2.0, -1.0, 0.5 * particleRadius);
63 auto pCoil = wallHandler.copyAndAddObject(coil);
65
70 p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
73 /*
74 //Single test case
75 double distance;
76 Vec3D normal;
77 p0.setPosition(Vec3D(1.0,0.0,0.0));
78 if(coil->getDistance_and_normal(p0, distance, normal))
79 std::cout<<"Collision, distance screw="<<distance<<std::endl;
80 else
81 std::cout<<"No collision, distance screw="<<distance<<std::endl;
82 */
83
85 // Nx*Ny*Nz particles are created and placed on evenly spaced positions in
86 // the domain [xMin_,xMax_]*[yMin_,yMax_]*[zMin_,zMax_] (unless their position
87 // is already occupied by the coil).
88 const unsigned int Nx = static_cast<unsigned int> (std::floor((getXMax() - getXMin()) / (2.1 * particleRadius)));
89 const unsigned int Ny = static_cast<unsigned int> (std::floor((getYMax() - getYMin()) / (2.1 * particleRadius)));
90 const unsigned int Nz = static_cast<unsigned int> (std::floor((getZMax() - getZMin()) / (2.1 * particleRadius)));
91 Mdouble distance;
92 Vec3D normal;
93
94 for (unsigned int i = 0; i < Nx; i++)
95 {
96 for (unsigned int j = 0; j < Ny; j++)
97 {
98 for (unsigned int k = 0; k < Nz; k++)
99 {
100 p0.setPosition(Vec3D(getXMin() + (getXMax() - getXMin()) * (0.5 + i) / Nx,
101 getYMin() + (getYMax() - getYMin()) * (0.5 + j) / Ny,
102 getZMin() + (getZMax() - getZMin()) * (0.5 + k) / Nz));
103 if (!pCoil->getDistanceAndNormal(p0, distance, normal)) //if there is no collision with the coil
104 {
106 }
107 else
108 {
109 logger(DEBUG, "particle at position % could not be inserted", p0.getPosition());
110 }
111 }
112 }
113 }
115 }
118 void actionsBeforeTimeStep() override
119 {
120 if (getTime() > 1)
121 {
123 }
124 }
126
127public:
129 // ! [CST:datamembers]
130 Coil* coil;
133};
135
137int main(int argc UNUSED, char* argv[] UNUSED)
138{
139
140 // create CoilSelfTest object
141 CoilSelfTest problem;
142
143 // set some basic problem properties
145 problem.setName("CoilSelfTest");
146 problem.setSystemDimensions(3);
147 problem.setGravity(Vec3D(0.0, -9.8, 0.0));
148
149 // set problem geometry
150 problem.setXMax(1.0);
151 problem.setYMax(5.0);
152 problem.setZMax(2.0);
153 problem.setXMin(-1.0);
154 problem.setYMin(-1.0);
155 problem.setTimeMax(0.5);
157 problem.particleRadius = 0.2;
158
161 species.setDensity(1000);
162 Mdouble tc = 0.05;
163 Mdouble restitutionCoefficient = 0.8;
164
165 Mdouble particleMass = pow(problem.particleRadius, 3) * constants::pi * 4.0 / 3.0 * species.getDensity();
166 species.setCollisionTimeAndRestitutionCoefficient(tc, restitutionCoefficient, particleMass);
167 problem.speciesHandler.copyAndAddObject(species);
169
171 problem.setTimeStep(0.02 * 0.05);
173 problem.getTimeStep()));
174 problem.solve();
176
177}
#define UNUSED
Definition GeneralDefine.h:18
LL< Log::DEBUG > DEBUG
Debug information.
Definition Logger.cc:37
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition BaseInteractable.h:197
[CST:headers]
Definition CoilSelfTest.cpp:22
Coil * coil
[CST:beforetime]
Definition CoilSelfTest.cpp:130
Mdouble particleRadius
Definition CoilSelfTest.cpp:131
void actionsBeforeTimeStep() override
Definition CoilSelfTest.cpp:118
void setupInitialConditions() override
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition CoilSelfTest.cpp:24
This class defines a coil in the z-direction from a (constant) starting point, a (constant) length L,...
Definition Coil.h:20
void set(Vec3D Start, Mdouble length, Mdouble radius, Mdouble numberOfRevelations, Mdouble omega, Mdouble thickness)
Set all parameters of this Coil.
Definition Coil.cc:81
void move_time(Mdouble dt)
Rotate the Coil for a period dt, so that the offset_ changes with omega_*dt.
Definition Coil.cc:193
void setSystemDimensions(unsigned int newDim)
Sets the system dimensionality.
Definition DPMBase.cc:1381
Mdouble getTimeMax() const
Returns the maximum simulation duration.
Definition DPMBase.cc:865
Definition InfiniteWallWithHole.h:17
void set(Vec3D normal, Mdouble position, Mdouble holeRadius)
Defines a standard wall, given an outward normal vector s. t. normal*x=position.
Definition InfiniteWallWithHole.cc:51
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
Definition ParticleHandler.cc:995
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 FormulaHelpers.cc:75

Return to tutorial Particles driven by a rotating coil

Particles on an inclined chute (code)

Goto tutorial Particles on an inclined chute

#include <iostream>
#include "Chute.h"
// Creates a quasi-2D inclined plane with inflow conditions on the left boundary,
// and deletion of particles when they exit the domain on the right.
int main()
{
// Problem parameters
Chute problem;
problem.setName("ChuteDemo"); // data output file name
problem.setGravity({0,-1,0});
problem.setSaveCount(102); // number of time steps skipped between saves
Mdouble tc = 2.5e-3; // collision time
problem.setTimeStep(0.02 * tc); // actual time step
problem.setTimeMax(0.5); // maximum time
// NB: number of time steps saved to output files
// is timeMax/(timeStep*saveCount)
// Particle radii
problem.setFixedParticleRadius(0.001); // radius of fixed chute bottom particles
problem.setInflowParticleRadius(0.001); // radius of (monodisperse) inflow particles
// Particle species
LinearViscoelasticSpecies species; // initialise species
species.setHandler(&problem.speciesHandler); // assign problem species handler to species
species.setDensity(2000); // particle density
0.8, species.getMassFromRadius(problem.getInflowParticleRadius())); // material properties
problem.speciesHandler.copyAndAddObject(species); // assign species to problem species handler
// Chute properties
problem.setChuteAngle(30.0); // set angle of chute relative to horizontal
problem.setXMax(0.1); // chute length = 0.1
problem.setYMax(2.0 * problem.getInflowParticleRadius()); // chute width = 1 particle diameter
// Inflow properties
problem.setInflowHeight(0.1); // particle inflow between 0 <= Z <= 0.1
problem.setInflowVelocity(0.1); // particle inflow mean velocity
problem.setInflowVelocityVariance(0.02); // particle inflow velocity variance (in ratio of the mean velocity)
//Write paraview data
problem.wallHandler.setWriteVTK(true);
/*problem.particleHandler.setWriteVTK(true);
problem.wallHandler.setWriteVTK(true);*/
//solve
problem.solve();
} // the end
void setHandler(SpeciesHandler *handler)
Sets the pointer to the handler to which this species belongs.
Definition BaseSpecies.cc:70
Creates chutes with different bottoms. Inherits from Mercury3D (-> MercuryBase -> DPMBase).
Definition Chute.h:44
void setInflowParticleRadius(Mdouble inflowParticleRadius)
Sets the radius of the inflow particles to a single one (i.e. ensures a monodisperse inflow).
Definition Chute.cc:828
void setInflowVelocityVariance(Mdouble inflowVelocityVariance)
Sets the inflow velocity variance.
Definition Chute.cc:990
void setInflowVelocity(Mdouble inflowVelocity)
Sets the average inflow velocity.
Definition Chute.cc:963
Mdouble getInflowParticleRadius() const
Returns the average radius of inflow particles.
Definition Chute.cc:909
void setChuteAngle(Mdouble chuteAngle)
Sets gravity vector according to chute angle (in degrees)
Definition Chute.cc:748
void setInflowHeight(Mdouble inflowHeight)
Sets maximum inflow height (Z-direction)
Definition Chute.cc:937
void setFixedParticleRadius(Mdouble fixedParticleRadius)
Sets the particle radius of the fixed particles which constitute the (rough) chute bottom.
Definition Chute.cc:633

Return to tutorial Particles on an inclined chute

Particles on a chute with a multilayered bottom (code)

Goto tutorial Particles on a chute with a multilayered bottom

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
6#include <sstream>
8#include "Chute.h"
10
18int main()
19{
20 //Print description
21 logger(INFO, "\nDemo of the chute flow with a rough bottom");
22
23 //Construct the problem and assign a name
24 Chute roughBottomSelfTest;
25 roughBottomSelfTest.setName("roughBottomMultiLayer");
26
27
28 //Set time stepping parameters
29 roughBottomSelfTest.setTimeStep(1e-4);
30 roughBottomSelfTest.setTimeMax(0.1);
31
32 //Set output parameter: write to the output files every 50 time steps
33 roughBottomSelfTest.setSaveCount(50);
34
35 //Set the particle radii and the type of the rough bottom
36 roughBottomSelfTest.setInflowParticleRadius(0.5);
37 roughBottomSelfTest.setFixedParticleRadius(0.5);
38 roughBottomSelfTest.setRoughBottomType(MULTILAYER);
39
40 //Set the particle properties
42 species->setDensity(6.0/constants::pi);
43 species->setStiffness(2e5);
44 species->setDissipation(25.0);
45
46 //Set the chute properties
47 roughBottomSelfTest.setChuteAngleAndMagnitudeOfGravity(24.0, 1.0);
48 roughBottomSelfTest.setChuteLength(3.0);
49 roughBottomSelfTest.setChuteWidth(3.0);
50
51 //Solve the system
52 roughBottomSelfTest.solve();
53}
@ MULTILAYER
Definition Chute.h:32
void setChuteWidth(Mdouble chuteWidth)
Sets the chute width (Y-direction)
Definition Chute.cc:1019
void setRoughBottomType(RoughBottomType roughBottomType)
Sets the type of rough bottom of the chute.
Definition Chute.cc:694
virtual void setChuteLength(Mdouble chuteLength)
Sets the chute length (X-direction)
Definition Chute.cc:1039
void setChuteAngleAndMagnitudeOfGravity(Mdouble chuteAngle, Mdouble gravity)
Sets gravity vector according to chute angle (in degrees)
Definition Chute.cc:769

Return to tutorial Particles on a chute with a multilayered bottom

Isotropic compression of a cuboidal REV (code)

Goto tutorial Isotropic compression of a cuboidal REV

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5//#include <Species/Species.h>
7#include <Mercury3D.h>
12
19class StressStrainControl : public Mercury3D
20{
22public:
23 //Create the class and passing the user inputs using the constructors
24 StressStrainControl(const Matrix3D& stressGoal, const Matrix3D& strainRate, const Matrix3D& gainFactor,
25 bool isStrainRateControlled)
26 : stressGoal_(stressGoal), strainRate_(strainRate), gainFactor_(gainFactor),
27 isStrainRateControlled_(isStrainRateControlled)
28 {
29 //Define the domain size
30 setMin(Vec3D(0, 0, 0));
31 setMax(Vec3D(1, 1, 1));
32 //Calculate the mass from smallest particle
33 double mass = 2000 * constants::pi * mathsFunc::cubic(2.0 * 0.08) / 6.0;
34 //Define the species for the particles
36 species.setDensity(2000);
37 species.setStiffnessAndRestitutionCoefficient(10000, 0.4, mass);
39 }
41
43private:
44 //Here we set up the system parameters, adding particles and define boundaries
45 void setupInitialConditions() override
46 {
47 //Set up the micro parameters.
48 double rhop = 2000; //particle density
49 double K1 = 10000; //particle stiffness
50 double en = 0.4; //restitution coefficient
51 double radius = 0.08; //particle radius
52 //Calculate the mass from smallest particle
53 double mass = rhop * constants::pi * mathsFunc::cubic(2.0 * radius) / 6.0;
54 //Calculate the contact duration
55 double tc = std::sqrt(mass / 2.0 / K1 * (mathsFunc::square(constants::pi) +
56 mathsFunc::square(log(en))));
57 setSystemDimensions(3); //set the 3d simulation
58 setTimeStep(tc / 50); //set the timestep based on the shortest contact duration
59 setGravity(Vec3D(0.0, 0.0, 0.0)); //set gravity in the system
60
61 //Add particles
62 CubeInsertionBoundary insertion;
64 particle.setRadius(radius);
65 //Insert 96 particles in the subvolume = 0.8*0.8*0.8 = 0.512, if failed by 100 times, it stops
66 insertion.set(&particle, 100, 0.8 * getMin(), 0.8 * getMax(), Vec3D(0, 0, 0), Vec3D(0, 0, 0));
67 insertion.setInitialVolume(1.0);
68 insertion.checkBoundaryBeforeTimeStep(this);
69 logger(INFO,"Inserted % particles",particleHandler.getSize());
70
71 //Delete all existing boundaries
73 //Set up the deformation mode using the boundaries that are based on user's input
75 boundary.setHandler(&boundaryHandler);
78
79
80 }
82
84 //initialize the private variables for passing the user's inputs in the constructor
90};
92
94//Here we define all the control parameters and solve the problem
95int main(int argc UNUSED, char* argv[] UNUSED)
96{
97 //We want strainrate control, so here we set the target Stress to free, all to zero
98 Matrix3D stressGoal;
99 stressGoal.XX = 0.0;
100 stressGoal.YY = 0.0;
101 stressGoal.ZZ = 0.0;
102 stressGoal.XY = 0.0;
103
104 //Here we set the isotropic strainrate tensor, negative sign means compression
105 Matrix3D strainRate;
106 strainRate.XX = -0.02;
107 strainRate.YY = -0.02;
108 strainRate.ZZ = -0.02;
109 strainRate.XY = 0.0;
110
111 //This is default gainFactor, if you choose to use stress control, you might want to tune this one
112 Matrix3D gainFactor;
113 gainFactor.XY = 0.0001;
114 gainFactor.XX = 0.0001;
115 gainFactor.YY = 0.0001;
116 gainFactor.ZZ = 0.0001;
117
118 //This is by default set to true, so particles are controlled by affine movement.
119 //If set it to false, then the particles will only follow the boundary movement.
120 bool isStrainRateControlled = true;
121
122 //Define the object and problem to solve
123 StressStrainControl dpm(stressGoal, strainRate, gainFactor, isStrainRateControlled);
124
125 //Set name
126 dpm.setName("Tutorial_IsotropicCompression");
127 //Set output and time stepping properties
128 dpm.setTimeMax(10);
129 //Set the SaveCount, i.e. 100 timesteps saving one snapshot
130 dpm.setSaveCount(100);
131 //Currently all the normal file outputs are switched off, simply switch it on by replacing NO_FILE to ONE_FILE
132// dpm.dataFile.setFileType(FileType::NO_FILE);
133// dpm.restartFile.setFileType(FileType::NO_FILE);
134// dpm.fStatFile.setFileType(FileType::NO_FILE);
135// dpm.eneFile.setFileType(FileType::NO_FILE);
136 //Set output the particle information in VTK for ParaView Visualisation
137 dpm.particleHandler.setWriteVTK(true);
138 //Because of periodic boundary, out put wall files is not necessary in this case
139 //dpm.wallHandler.setWriteVTK(true);
140 //Solve the problem
141 dpm.solve();
142}
void setHandler(BoundaryHandler *handler)
Sets the boundary's BoundaryHandler.
Definition BaseBoundary.cc:113
virtual void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0.
Definition BaseHandler.h:536
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition BaseHandler.h:663
It's an insertion boundary which has cuboidal shape (yes, 'CuboidalInsertionBoundary' would have been...
Definition CubeInsertionBoundary.h:21
void set(BaseParticle *particleToCopy, unsigned int maxFailed, Vec3D posMin, Vec3D posMax, Vec3D velMin={0, 0, 0}, Vec3D velMax={0, 0, 0})
Sets the properties of the InsertionBoundary for mutliple different particle types.
Definition CubeInsertionBoundary.cc:86
Vec3D getMax() const
Returns the maximum coordinates of the problem domain.
Definition DPMBase.h:665
void setMin(const Vec3D &min)
Sets the minimum coordinates of the problem domain.
Definition DPMBase.cc:1082
Vec3D getMin() const
Returns the minimum coordinates of the problem domain.
Definition DPMBase.h:659
void setMax(const Vec3D &max)
Sets the maximum coordinates of the problem domain.
Definition DPMBase.cc:1046
void checkBoundaryBeforeTimeStep(DPMBase *md) override
Fills the boundary with particles.
Definition InsertionBoundary.cc:163
void setInitialVolume(Mdouble initialVolume)
Gets the Volume which should be inserted by the insertion routine.
Definition InsertionBoundary.cc:620
void setStiffnessAndRestitutionCoefficient(Mdouble k_, Mdouble eps, Mdouble mass)
Sets k, disp such that it matches a given tc and eps for a collision of two copies of P.
Definition LinearViscoelasticNormalSpecies.cc:165
Implementation of a 3D matrix.
Definition Matrix.h:17
Mdouble XY
Definition Matrix.h:22
Mdouble YY
Definition Matrix.h:22
Mdouble ZZ
Definition Matrix.h:22
Mdouble XX
all nine matrix elements
Definition Matrix.h:22
A cuboid box consists of periodic boundaries that can be strain/stress controlled and achieve differe...
Definition StressStrainControlBoundary.h:34
void set(const Matrix3D &stressGoal, const Matrix3D &strainRate, const Matrix3D &pGain, bool isStrainRateControlled, const Matrix3D &iGain={0, 0, 0, 0, 0, 0, 0, 0, 0})
Sets all boundary inputs at once and determines which deformation mode it is, then combine the right ...
Definition StressStrainControlBoundary.cc:288
[REV_ISO:headers]
Definition REVIsotropicCompressionDemo.cpp:20
bool isStrainRateControlled_
Definition REVIsotropicCompressionDemo.cpp:88
Matrix3D strainRate_
Definition REVIsotropicCompressionDemo.cpp:86
Matrix3D gainFactor_
Definition REVIsotropicCompressionDemo.cpp:87
Matrix3D stressGoal_
[REV_ISO:setIni]
Definition REVIsotropicCompressionDemo.cpp:85
void setupInitialConditions() override
[REV_ISO:construct]
Definition REVIsotropicCompressionDemo.cpp:45
T square(const T val)
squares a number
Definition ExtendedMath.h:86

Return to tutorial Isotropic compression of a cuboidal REV

Pure shear (constant volume) of a cuboidal REV (code)

Goto tutorial Pure shear (constant volume) of a cuboidal REV

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5//#include <Species/Species.h>
7#include <Mercury3D.h>
12
20class StressStrainControl : public Mercury3D
21{
23public:
24 //Create the class and passing the user inputs using the constructors
25 StressStrainControl(const Matrix3D& stressGoal, const Matrix3D& strainRate, const Matrix3D& gainFactor,
26 bool isStrainRateControlled)
27 : stressGoal_(stressGoal), strainRate_(strainRate), gainFactor_(gainFactor),
28 isStrainRateControlled_(isStrainRateControlled)
29 {
30 //Define the domain size
31 setMin(Vec3D(0, 0, 0));
32 setMax(Vec3D(1, 1, 1));
33 //Calculate the mass from smallest particle
34 double mass = 2000 * constants::pi * mathsFunc::cubic(2.0 * 0.08) / 6.0;
35 //Define the species for the particles
37 species.setDensity(2000);
38 species.setStiffnessAndRestitutionCoefficient(10000, 0.4, mass);
40 }
42
44private:
45 //Here we set up the system parameters, adding particles and define boundaries
46 void setupInitialConditions() override
47 {
48 //Set up the micro parameters.
49 double rhop = 2000; //particle density
50 double K1 = 10000; //particle stiffness
51 double en = 0.4; //restitution coefficient
52 double radius = 0.05; //particle radius
53 //Calculate the mass from smallest particle
54 double mass = rhop * constants::pi * mathsFunc::cubic(2.0 * radius) / 6.0;
55 //Calculate the contact duration
56 double tc = std::sqrt(mass / 2.0 / K1 * (mathsFunc::square(constants::pi) +
57 mathsFunc::square(log(en))));
58 setSystemDimensions(3); //set the 3d simulation
59 setTimeStep(tc / 50); //set the timestep based on the shortest contact duration
60 setGravity(Vec3D(0.0, 0.0, 0.0)); //set gravity in the system
61
62 //Add particles
63 CubeInsertionBoundary insertion;
65 //Insert 96 particles in the subvolume = 1.0*1.0*1.0 = 1.0, if failed by 100 times, it stops
66 insertion.set(&particle, 100, getMin(), getMax(), Vec3D(0, 0, 0), Vec3D(0, 0, 0));
67 insertion.setInitialVolume(1.0);
68 insertion.checkBoundaryBeforeTimeStep(this);
69 logger(INFO,"Inserted % particles",particleHandler.getSize());
70
71 //Set up the deformation mode using the boundaries that are based on user's input
72 boundaryHandler.clear(); // Delete all exist boundaries
74 boundary.setHandler(&boundaryHandler);
77
78
79 }
81
83 //Initialize the private variables for passing the user's inputs in the constructor
89};
91
93//Here we define all the control parameters and solve the problem
94int main(int argc UNUSED, char* argv[] UNUSED)
95{
96 //We want strainrate control, so here we set the target Stress to free, all to zero
97 Matrix3D stressGoal;
98 stressGoal.XX = 0.0;
99 stressGoal.YY = 0.0;
100 stressGoal.ZZ = 0.0;
101 stressGoal.XY = 0.0;
102
103 //Here we set the pure shear strainrate tensor, negative sign means compression
104 Matrix3D strainRate;
105 strainRate.XX = 0.4;
106 strainRate.YY = -0.4;
107 strainRate.ZZ = 0.0;
108 strainRate.XY = 0.0;
109
110 //This is default gainFactor, if you choose to use stress control, you might want to tune this one
111 Matrix3D gainFactor;
112 gainFactor.XY = 0.0001;
113 gainFactor.XX = 0.0001;
114 gainFactor.YY = 0.0001;
115 gainFactor.ZZ = 0.0001;
116
117 //This is by default set to true, so particles are controlled by affine movement.
118 //If set it to false, then the particles will only follow the boundary movement.
119 bool isStrainRateControlled = true;
120
121 //Define the object and problem to solve
122 StressStrainControl dpm(stressGoal, strainRate, gainFactor, isStrainRateControlled);
123
124 //Set name
125 dpm.setName("Tutorial_PureShear");
126 //Set output and time stepping properties
127 dpm.setTimeMax(1);
128 //Set the SaveCount, i.e. 100 timesteps saving one snapshot
129 dpm.setSaveCount(10);
130 //Currently all the normal file outputs are switched off, simply switch it on by replacing NO_FILE to ONE_FILE
131 dpm.dataFile.setFileType(FileType::NO_FILE);
132 dpm.restartFile.setFileType(FileType::NO_FILE);
133 dpm.fStatFile.setFileType(FileType::NO_FILE);
134 dpm.eneFile.setFileType(FileType::NO_FILE);
135 //Set output the particle information in VTK for ParaView Visualisation
136 dpm.particleHandler.setWriteVTK(true);
137 //Because of periodic boundary, out put wall files is not necessary in this case
138 //dpm.wallHandler.setWriteVTK(true);
139 //Solve the problem
140 dpm.solve();
141}

Return to tutorial Pure shear (constant volume) of a cuboidal REV

(Rigid_clumps) (code)

Goto tutorial (Rigid_clumps) (code)

Return to tutorial (Rigid_clumps) (code)

or Dzhanibekov theorem (code)

Goto tutorial Tennisracket or Dzhanibekov theorem

Return to tutorial Tennisracket or Dzhanibekov theorem

effect (code)

Goto tutorial Domino effect

Return to tutorial Domino effect

(code)

Goto tutorial Simple shear (constant stress) of a cuboidal REV

1// This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2// Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3// License: BSD 3-Clause License; see the LICENSE file in the root directory.
4
5//#include <Species/Species.h>
7#include <Mercury3D.h>
12
21class StressStrainControl : public Mercury3D
22{
24public:
25 //Create the class and passing the user inputs using the constructors
26 StressStrainControl(const Matrix3D& stressGoal, const Matrix3D& strainRate, const Matrix3D& gainFactor,
27 bool isStrainRateControlled)
28 : stressGoal_(stressGoal), strainRate_(strainRate), gainFactor_(gainFactor),
29 isStrainRateControlled_(isStrainRateControlled)
30 {
31 //Define the domain size
32 setMin(Vec3D(0, 0, 0));
33 setMax(Vec3D(1, 1, 1));
34 //Calculate the mass from smallest particle
35 double mass = 2000 * constants::pi * mathsFunc::cubic(2.0 * 0.05) / 6.0;
36 //Define the species for the particles
38 species.setDensity(2000);
39 species.setStiffnessAndRestitutionCoefficient(10000, 0.4, mass);
41 }
43
45private:
46 //Here we set up the system parameters, adding particles and define boundaries
47 void setupInitialConditions() override
48 {
49 //Set up the micro parameters.
50 double rhop = 2000; //particle density
51 double K1 = 10000; //particle stiffness
52 double en = 0.4; //restitution coefficient
53 double radius = 0.05; //particle radius
54 //Calculate the mass from smallest particle
55 double mass = rhop * constants::pi * mathsFunc::cubic(2.0 * radius) / 6.0;
56 //Calculate the contact duration
57 double tc = std::sqrt(mass / 2.0 / K1 * (mathsFunc::square(constants::pi) +
58 mathsFunc::square(log(en))));
59 setSystemDimensions(3); //set the 3d simulation
60 setTimeStep(tc / 50); //set the timestep based on the shortest contact duration
61 setGravity(Vec3D(0.0, 0.0, 0.0)); //set gravity in the system
62
63 //Add particles
64 CubeInsertionBoundary insertion;
66 //Insert 96 particles in the subvolume = 1.0*1.0*1.0 = 1.0, if failed by 100 times, it stops
67 insertion.set(&particle, 100, getMin(), getMax(), Vec3D(0, 0, 0), Vec3D(0, 0, 0));
68 insertion.setInitialVolume(1.0);
69 insertion.checkBoundaryBeforeTimeStep(this);
70 logger(INFO,"Inserted % particles",particleHandler.getSize());
71
72 //Set up the deformation mode using the boundaries that are based on user's input
73 boundaryHandler.clear(); // Delete all exist boundaries
75 boundary.setHandler(&boundaryHandler);
78
79
80 }
82
84 //Initialize the private variables for passing the user's inputs in the constructor
90};
92
94//Here we define all the control parameters and solve the problem
95int main(int argc UNUSED, char* argv[] UNUSED)
96{
97 //Here we want to set stress in y direction to constant, 100 is just an example,
98 //if you would like to keep the volume constant, then everything here should be set to zero
99 Matrix3D stressGoal;
100 stressGoal.XX = 0.0;
101 stressGoal.YY = 100.0;
102 stressGoal.ZZ = 0.0;
103 stressGoal.XY = 0.0;
104
105 //Here we set the simple shear strainrate tensor, negative sign means compression
106 Matrix3D strainRate;
107 strainRate.XX = 0.0;
108 strainRate.YY = 0.0;
109 strainRate.ZZ = 0.0;
110 strainRate.XY = 1.0;
111
112 //This is default gainFactor, if you choose to use stress control, you might want to tune this one
113 Matrix3D gainFactor;
114 gainFactor.XY = 0.0001;
115 gainFactor.XX = 0.0001;
116 gainFactor.YY = 0.0001;
117 gainFactor.ZZ = 0.0001;
118
119 //This is by default set to true, so particles are controlled by affine movement.
120 //If set it to false, then the particles will only follow the boundary movement.
121 bool isStrainRateControlled = true;
122
123 //Define the object and problem to solve
124 StressStrainControl dpm(stressGoal, strainRate, gainFactor, isStrainRateControlled);
125
126 //Set name
127 dpm.setName("Tutorial_SimpleShear");
128 //Set output and time stepping properties
129 dpm.setTimeMax(10);
130 //Set the SaveCount, i.e. 100 timesteps saving one snapshot
131 dpm.setSaveCount(100);
132 //Currently all the normal file outputs are switched off, simply switch it on by replacing NO_FILE to ONE_FILE
133 dpm.dataFile.setFileType(FileType::NO_FILE);
134 dpm.restartFile.setFileType(FileType::NO_FILE);
135 dpm.fStatFile.setFileType(FileType::NO_FILE);
136 dpm.eneFile.setFileType(FileType::NO_FILE);
137 //Set output the particle information in VTK for ParaView Visualisation
138 dpm.particleHandler.setWriteVTK(true);
139 //Because of periodic boundary, out put wall files is not necessary in this case
140 //dpm.wallHandler.setWriteVTK(true);
141 //Solve the problem
142 dpm.solve();
143}

Return to tutorial Simple shear (constant stress) of a cuboidal REV