Material.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MERCURY_MATERIAL_H
27 #define MERCURY_MATERIAL_H
28 #include "Mercury3D.h"
29 #include "Math/PSD.h"
32 
33 class Material : public Mercury3D {
34 protected:
39 
40  Material (int argc, char *argv[]) {
41  // set psd
42  setPSD(argc, argv);
43  // set species
44  setSpecies(argc, argv);
45  }
46 
47  // set psd from command line (-psd r1 p1 .. rn pn)
48  void setPSD(int argc, char *argv[]) {
49  for (unsigned i=0; i<argc-1; ++i) {
50  if (!strcmp(argv[i],"-psd")) {
51  std::vector<DistributionElements> psdVector;
53  // distribution type given
54  if (!strcmp(argv[i + 1], "logNormal"))
55  {
56  logger.assert_debug(argc > i + 5, "Error in logNormal");
57  // https://en.wikipedia.org/wiki/Log-normal_distribution
58  double meanX = std::atof(argv[i + 4]);
59  double stdX = std::atof(argv[i + 5]);
60  if (!strcmp(argv[i + 3], "radius"))
61  {
62  }
63  else if (!strcmp(argv[i + 3], "diameter"))
64  {
65  meanX /= 2;
66  stdX /= 2;
67  } else {
68  logger(ERROR,"setPSD: distribution type % not known", argv[i+3]);
69  }
70  double meanX2 = meanX*meanX;
71  double stdX2 = stdX*stdX;
72  double mean = log(meanX2/sqrt(meanX2+stdX2));
73  double std = sqrt(log(1+stdX2/meanX2));
74  double lnRMin = mean-2.5*std;
75  double lnRMax = mean+2.5*std;
76  unsigned n = 21;
77  psdVector.push_back({0.5*exp(lnRMin), 0});
78  if (std>0) {
79  for (int j = 1; j < n; ++j) {
80  double lnR = lnRMin + j / (double) n * (lnRMax - lnRMin);
81  value.internalVariable = exp(lnR);
82  value.probability = 0.5 * (1.0 + erf((lnR - mean) / (sqrt(2) * std)));
83  psdVector.push_back(value);
84  logger(INFO, "psd % %", value.internalVariable, value.probability);
85  }
86  }
87  psdVector.push_back({0.5*exp(lnRMax), 1});
88  if (!strcmp(argv[i+2],"number")) {
90  } else if (!strcmp(argv[i+2],"volume")) {
92  } else {
93  logger(ERROR,"setPSD: distribution type % not known", argv[i+2]);
94  }
95  return;
96  }
97  // distribution given
98  for (unsigned j=i+4; j<argc-1 && argv[j][0]!='-' && argv[j+1][0]!='-'; j+=2) {
99  if (!strcmp(argv[i+3],"radius")) {
100  value.internalVariable = std::atof(argv[j]);
101  } else if (!strcmp(argv[i+3],"diameter")) {
102  value.internalVariable = std::atof(argv[j]) / 2.;
103  } else {
104  logger(ERROR,"setPSD: distribution type % not known", argv[i+3]);
105  }
106  value.probability = std::atof(argv[j+1]);
107  psdVector.push_back(value);
108  }
109  if (!strcmp(argv[i+1],"cumulative")) {
110  if (!strcmp(argv[i+2],"number")) {
112  } else if (!strcmp(argv[i+2],"volume")) {
114  } else {
115  logger(ERROR,"setPSD: distribution type % not known", argv[i+1]);
116  }
117  } else if (!strcmp(argv[i+1],"probability")) {
118  if (!strcmp(argv[i+2],"number")) {
120  } else if (!strcmp(argv[i+2],"volume")) {
122  } else {
123  logger(ERROR,"setPSD: distribution type % not known", argv[i+1]);
124  }
125  } else {
126  logger(ERROR,"setPSD: distribution type % not known", argv[i+2]);
127  }
128  return;
129  }
130  }
131  //if the "-psd" is not found
132  Mdouble particleRadius = 1.5e-3;
133  psd = PSD::getDistributionNormal(particleRadius,0.025*particleRadius,50);
134  logger(WARN, "-psd argument not found; using default psd");
135  }
136 
137  // set species from command line (-species, -density, etc)
138  void setSpecies(int argc, char *argv[]) {
139  double density = readFromCommandLine(argc,argv,"-density",1000);
140  double collisionTime = readFromCommandLine(argc,argv,"-collisionTime",0.001);
141  double restitutionCoefficient = readFromCommandLine(argc,argv,"-restitutionCoefficient",0.5);
142  bool constantRestitution = readFromCommandLine(argc,argv,"-constantRestitution");
143  double slidingFriction = readFromCommandLine(argc,argv,"-slidingFriction",0.5);
144  double rollingFriction = readFromCommandLine(argc,argv,"-rollingFriction",0.0);
145  double torsionFriction = readFromCommandLine(argc,argv,"-torsionFriction",0.0);
146  double bondNumber = readFromCommandLine(argc,argv,"-bondNumber",0.0);
147 
148  //set species
150  //set density
151  species->setDensity(density);
152  //set constantRestitution
153  species->setConstantRestitution(constantRestitution);
154  //set collisionTime and restitutionCoefficient
155  double massD50 = species->getMassFromRadius(psd.getVolumeDx(50));
156  double massMin = species->getMassFromRadius(psd.getMinRadius());
157  species->setCollisionTimeAndRestitutionCoefficient(collisionTime, restitutionCoefficient, massMin);
158  // set slidingFriction, rollingFriction, torsionFriction
159  species->setSlidingFrictionCoefficient(slidingFriction);
160  species->setSlidingStiffness(2. / 7. * species->getStiffness());
161  species->setSlidingDissipation(2. / 7. * species->getDissipation());
162  species->setRollingFrictionCoefficient(rollingFriction);
163  species->setRollingStiffness(2. / 5. * species->getStiffness());
164  species->setRollingDissipation(2. / 5. * species->getDissipation());
165  species->setTorsionFrictionCoefficient(torsionFriction);
166  species->setTorsionStiffness(2. / 5. * species->getStiffness());
167  species->setTorsionDissipation(2. / 5. * species->getDissipation());
168  // set adhesion
169  species->setAdhesionStiffness(species->getStiffness());
170  species->setAdhesionForceMax(9.8*massD50*bondNumber);
171 
172  // set timeStep
173  setTimeStep(0.05 * species->getCollisionTime(massMin));
174 
175  // define side-wall species (no friction/cohesion)
176  auto frictionlessWallSpecies_ = speciesHandler.copyAndAddObject(species);
177  auto mixedSpecies = speciesHandler.getMixedObject(species, frictionlessWallSpecies_);
178  mixedSpecies->setRollingFrictionCoefficient(0.0);
179  mixedSpecies->setSlidingFrictionCoefficient(0.0);
180  mixedSpecies->setAdhesionForceMax(0.0);
181 
182  // define drum-wall species (high friction/ no cohesion)
183  auto frictionalWallSpecies_ = speciesHandler.copyAndAddObject(species);
184  mixedSpecies = speciesHandler.getMixedObject(species, frictionalWallSpecies_);
185  mixedSpecies->setRollingFrictionCoefficient(std::max(1.0,species->getSlidingFrictionCoefficient())); //\todo TW infinity does not work (anymore?)
186  mixedSpecies->setSlidingFrictionCoefficient(std::max(1.0,species->getRollingFrictionCoefficient()));
187  mixedSpecies->setAdhesionForceMax(0.0);
188  // cast down
189  particleSpecies = species;
190  frictionalWallSpecies = frictionalWallSpecies_;
191  frictionlessWallSpecies = frictionlessWallSpecies_;
192 
195  logger(INFO, "Time step %", getTimeStep());
196  }
197 
198 };
199 
200 
201 #endif //MERCURY_MATERIAL_H
const unsigned n
Definition: CG3DPackingUnitTest.cpp:32
Species< LinearViscoelasticNormalSpecies, FrictionSpecies, ReversibleAdhesiveSpecies > LinearViscoelasticFrictionReversibleAdhesiveSpecies
Definition: LinearViscoelasticFrictionReversibleAdhesiveSpecies.h:35
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ WARN
@ INFO
@ ERROR
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:379
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1427
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1250
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1234
class of DistributionElements which stores internalVariables and probabilities of a distribution....
Definition: DistributionElements.h:34
Mdouble internalVariable
Definition: DistributionElements.h:36
Mdouble probability
Definition: DistributionElements.h:37
Definition: Material.h:33
ParticleSpecies * frictionlessWallSpecies
Definition: Material.h:38
PSD psd
Definition: Material.h:35
Material(int argc, char *argv[])
Definition: Material.h:40
void setPSD(int argc, char *argv[])
Definition: Material.h:48
ParticleSpecies * frictionalWallSpecies
Definition: Material.h:37
ParticleSpecies * particleSpecies
Definition: Material.h:36
void setSpecies(int argc, char *argv[])
Definition: Material.h:138
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:37
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD)
Definition: PSD.h:65
Mdouble getMinRadius() const
Get smallest radius of the PSD.
Definition: PSD.cc:886
Mdouble getVolumeDx(Mdouble x) const
Calculate a certain diameter (e.g. D10, D50, D90, etc.) from a percentile x of the volume based PSD.
Definition: PSD.cc:777
static PSD getDistributionNormal(Mdouble mean, Mdouble standardDeviation, int numberOfBins)
Definition: PSD.h:153
@ PROBABILITYDENSITY_VOLUME_DISTRIBUTION
@ CUMULATIVE_VOLUME_DISTRIBUTION
@ PROBABILITYDENSITY_NUMBER_DISTRIBUTION
@ CUMULATIVE_NUMBER_DISTRIBUTION
MERCURYDPM_DEPRECATED void setPSDFromVector(std::vector< DistributionElements > psd, TYPE PSDType)
Deprecated version of reading in PSDs from a vector.
Definition: PSD.cc:396
Definition: ParticleSpecies.h:37
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:74
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51
bool readFromCommandLine(int argc, char *argv[], std::string varName)
Returns true if command line arguments contain varName, false else.
Definition: CommandLineHelpers.cc:103
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:104
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:84