Material.h
Go to the documentation of this file.
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 #ifndef MERCURY_MATERIAL_H
6 #define MERCURY_MATERIAL_H
7 #include "Mercury3D.h"
8 #include "Math/PSD.h"
11 
12 class Material : public Mercury3D {
13 protected:
18 
19  Material (int argc, char *argv[]) {
20  // set psd
21  setPSD(argc, argv);
22  // set species
23  setSpecies(argc, argv);
24  }
25 
26  // set psd from command line (-psd r1 p1 .. rn pn)
27  void setPSD(int argc, char *argv[]) {
28  for (unsigned i=0; i<argc-1; ++i) {
29  if (!strcmp(argv[i],"-psd")) {
30  std::vector<DistributionElements> psdVector;
32  // distribution type given
33  if (!strcmp(argv[i + 1], "logNormal"))
34  {
35  logger.assert_debug(argc > i + 5, "Error in logNormal");
36  // https://en.wikipedia.org/wiki/Log-normal_distribution
37  double meanX = std::atof(argv[i + 4]);
38  double stdX = std::atof(argv[i + 5]);
39  if (!strcmp(argv[i + 3], "radius"))
40  {
41  }
42  else if (!strcmp(argv[i + 3], "diameter"))
43  {
44  meanX /= 2;
45  stdX /= 2;
46  } else {
47  logger(ERROR,"setPSD: distribution type % not known", argv[i+3]);
48  }
49  double meanX2 = meanX*meanX;
50  double stdX2 = stdX*stdX;
51  double mean = log(meanX2/sqrt(meanX2+stdX2));
52  double std = sqrt(log(1+stdX2/meanX2));
53  double lnRMin = mean-2.5*std;
54  double lnRMax = mean+2.5*std;
55  unsigned n = 21;
56  psdVector.push_back({0.5*exp(lnRMin), 0});
57  if (std>0) {
58  for (int j = 1; j < n; ++j) {
59  double lnR = lnRMin + j / (double) n * (lnRMax - lnRMin);
60  value.internalVariable = exp(lnR);
61  value.probability = 0.5 * (1.0 + erf((lnR - mean) / (sqrt(2) * std)));
62  psdVector.push_back(value);
63  logger(INFO, "psd % %", value.internalVariable, value.probability);
64  }
65  }
66  psdVector.push_back({0.5*exp(lnRMax), 1});
67  if (!strcmp(argv[i+2],"number")) {
69  } else if (!strcmp(argv[i+2],"volume")) {
71  } else {
72  logger(ERROR,"setPSD: distribution type % not known", argv[i+2]);
73  }
74  return;
75  }
76  // distribution given
77  for (unsigned j=i+4; j<argc-1 && argv[j][0]!='-' && argv[j+1][0]!='-'; j+=2) {
78  if (!strcmp(argv[i+3],"radius")) {
79  value.internalVariable = std::atof(argv[j]);
80  } else if (!strcmp(argv[i+3],"diameter")) {
81  value.internalVariable = std::atof(argv[j]) / 2.;
82  } else {
83  logger(ERROR,"setPSD: distribution type % not known", argv[i+3]);
84  }
85  value.probability = std::atof(argv[j+1]);
86  psdVector.push_back(value);
87  }
88  if (!strcmp(argv[i+1],"cumulative")) {
89  if (!strcmp(argv[i+2],"number")) {
91  } else if (!strcmp(argv[i+2],"volume")) {
93  } else {
94  logger(ERROR,"setPSD: distribution type % not known", argv[i+1]);
95  }
96  } else if (!strcmp(argv[i+1],"probability")) {
97  if (!strcmp(argv[i+2],"number")) {
99  } else if (!strcmp(argv[i+2],"volume")) {
101  } else {
102  logger(ERROR,"setPSD: distribution type % not known", argv[i+1]);
103  }
104  } else {
105  logger(ERROR,"setPSD: distribution type % not known", argv[i+2]);
106  }
107  return;
108  }
109  }
110  //if the "-psd" is not found
111  Mdouble particleRadius = 1.5e-3;
112  psd = PSD::getDistributionNormal(particleRadius,0.025*particleRadius,50);
113  logger(WARN, "-psd argument not found; using default psd");
114  }
115 
116  // set species from command line (-species, -density, etc)
117  void setSpecies(int argc, char *argv[]) {
118  double density = readFromCommandLine(argc,argv,"-density",1000);
119  double collisionTime = readFromCommandLine(argc,argv,"-collisionTime",0.001);
120  double restitutionCoefficient = readFromCommandLine(argc,argv,"-restitutionCoefficient",0.5);
121  bool constantRestitution = readFromCommandLine(argc,argv,"-constantRestitution");
122  double slidingFriction = readFromCommandLine(argc,argv,"-slidingFriction",0.5);
123  double rollingFriction = readFromCommandLine(argc,argv,"-rollingFriction",0.0);
124  double torsionFriction = readFromCommandLine(argc,argv,"-torsionFriction",0.0);
125  double bondNumber = readFromCommandLine(argc,argv,"-bondNumber",0.0);
126 
127  //set species
129  //set density
130  species->setDensity(density);
131  //set constantRestitution
132  species->setConstantRestitution(constantRestitution);
133  //set collisionTime and restitutionCoefficient
134  double massD50 = species->getMassFromRadius(psd.getVolumeDx(50));
135  double massMin = species->getMassFromRadius(psd.getMinRadius());
136  species->setCollisionTimeAndRestitutionCoefficient(collisionTime, restitutionCoefficient, massMin);
137  // set slidingFriction, rollingFriction, torsionFriction
138  species->setSlidingFrictionCoefficient(slidingFriction);
139  species->setSlidingStiffness(2. / 7. * species->getStiffness());
140  species->setSlidingDissipation(2. / 7. * species->getDissipation());
141  species->setRollingFrictionCoefficient(rollingFriction);
142  species->setRollingStiffness(2. / 5. * species->getStiffness());
143  species->setRollingDissipation(2. / 5. * species->getDissipation());
144  species->setTorsionFrictionCoefficient(torsionFriction);
145  species->setTorsionStiffness(2. / 5. * species->getStiffness());
146  species->setTorsionDissipation(2. / 5. * species->getDissipation());
147  // set adhesion
148  species->setAdhesionStiffness(species->getStiffness());
149  species->setAdhesionForceMax(9.8*massD50*bondNumber);
150 
151  // set timeStep
152  setTimeStep(0.05 * species->getCollisionTime(massMin));
153 
154  // define side-wall species (no friction/cohesion)
155  auto frictionlessWallSpecies_ = speciesHandler.copyAndAddObject(species);
156  auto mixedSpecies = speciesHandler.getMixedObject(species, frictionlessWallSpecies_);
157  mixedSpecies->setRollingFrictionCoefficient(0.0);
158  mixedSpecies->setSlidingFrictionCoefficient(0.0);
159  mixedSpecies->setAdhesionForceMax(0.0);
160 
161  // define drum-wall species (high friction/ no cohesion)
162  auto frictionalWallSpecies_ = speciesHandler.copyAndAddObject(species);
163  mixedSpecies = speciesHandler.getMixedObject(species, frictionalWallSpecies_);
164  mixedSpecies->setRollingFrictionCoefficient(std::max(1.0,species->getSlidingFrictionCoefficient())); //\todo TW infinity does not work (anymore?)
165  mixedSpecies->setSlidingFrictionCoefficient(std::max(1.0,species->getRollingFrictionCoefficient()));
166  mixedSpecies->setAdhesionForceMax(0.0);
167  // cast down
168  particleSpecies = species;
169  frictionalWallSpecies = frictionalWallSpecies_;
170  frictionlessWallSpecies = frictionlessWallSpecies_;
171 
174  logger(INFO, "Time step %", getTimeStep());
175  }
176 
177 };
178 
179 
180 #endif //MERCURY_MATERIAL_H
AnnoyingScalar sqrt(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:134
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Species< LinearViscoelasticNormalSpecies, FrictionSpecies, ReversibleAdhesiveSpecies > LinearViscoelasticFrictionReversibleAdhesiveSpecies
Definition: LinearViscoelasticFrictionReversibleAdhesiveSpecies.h:13
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:360
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1433
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1241
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1225
class of DistributionElements which stores internalVariables and probabilities of a distribution....
Definition: DistributionElements.h:13
Definition: Material.h:12
ParticleSpecies * frictionlessWallSpecies
Definition: Material.h:17
PSD psd
Definition: Material.h:14
Material(int argc, char *argv[])
Definition: Material.h:19
void setPSD(int argc, char *argv[])
Definition: Material.h:27
ParticleSpecies * frictionalWallSpecies
Definition: Material.h:16
ParticleSpecies * particleSpecies
Definition: Material.h:15
void setSpecies(int argc, char *argv[])
Definition: Material.h:117
This adds on the hierarchical grid code for 3D problems.
Definition: Mercury3D.h:16
Contains a vector with radii and probabilities of a user defined particle size distribution (PSD)
Definition: PSD.h:47
Mdouble getMinRadius() const
Get smallest radius of the PSD.
Definition: PSD.cc:1037
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:929
static PSD getDistributionNormal(Mdouble mean, Mdouble standardDeviation, int numberOfBins)
Definition: PSD.h:145
@ PROBABILITYDENSITY_VOLUME_DISTRIBUTION
@ CUMULATIVE_VOLUME_DISTRIBUTION
@ PROBABILITYDENSITY_NUMBER_DISTRIBUTION
@ CUMULATIVE_NUMBER_DISTRIBUTION
void setPSDFromVector(std::vector< DistributionElements > psd, TYPE PSDType)
Sets the PSD from a vector with DistributionElements.
Definition: PSD.cc:513
Definition: ParticleSpecies.h:16
std::enable_if<!std::is_pointer< typename U::MixedSpeciesType >::value, typename U::MixedSpeciesType * >::type getMixedObject(const U *S, const U *T)
Definition: SpeciesHandler.h:52
#define max(a, b)
Definition: datatypes.h:23
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 exp(const bfloat16 &a)
Definition: BFloat16.h:615
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 log(const bfloat16 &a)
Definition: BFloat16.h:618
squared absolute value
Definition: GlobalFunctions.h:87
density
Definition: UniformPSDSelfTest.py:19
bool readFromCommandLine(int argc, char *argv[], const std::string &varName)
Returns true if command line arguments contain varName, false else.
Definition: CommandLineHelpers.cc:99
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2