MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseCluster.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2020, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #include "BaseCluster.h"
27 
32  logger(DEBUG, "BaseCluster::BaseCluster() finished");
33 }
34 
39  logger(DEBUG, "BaseCluster::BaseClusterr() finished");
40 }
41 
42 /*
43  * ----------------------------------------------------------------------
44  * FUNCTIONS: setters and getters
45  * ----------------------------------------------------------------------
46  */
47 
53  return position_;
54 }
55 
61  position_ = p;
62 }
63 
64 
70 }
71 
77  if (cTOTS < 45 && cTOTS > 0)
78  logger(WARN, "collisionTimeOverTimeStep = % is too small: consider setting it greater or equal than 50.", cTOTS);
79  else if (cTOTS <= 0)
80  logger(ERROR, "collisionTimeOverTimeStep = % must be grater than zero.", cTOTS);
82 }
83 
89  return radiusParticle_;
90 }
91 
98  if (rP <= 0)
99  logger(ERROR, "radiusParticle must be greater than zero. radiusParticle = %", rP);
100  else {
101  radiusParticle_ = rP;
102  setRadiusParticle_ = true;
103  }
104 }
105 
111 }
112 
118  if (sDP < 1)
119  logger(ERROR, "sizeDispersityParticle must be greater or equal than 1. sizeDispersityParticle = %", sDP);
120  else sizeDispersityParticle_ = sDP;
121 }
122 
127  return nParticles_;
128 }
129 
135  if (nP < 0)
136  logger(ERROR, "nParticles must be grater than zero. nParticles = %", nP);
137  else {
138  nParticles_ = nP;
139  setNumberOfParticles_ = true;
140  }
141 }
142 
150  if (rCR <= 0)
151  logger(ERROR,
152  "relativeClusterRadius is smaller than 0. relativeClusterRadius = %",
153  rCR);
154  else
155  radiusCluster_ = rCR;
156 
157  setRadiusCluster_ = true;
158 }
159 
168  else
169  return solidFraction_;
170 }
171 
175 unsigned int BaseCluster::getClusterId() const {
176  return idCluster_;
177 }
178 
183 void BaseCluster::setClusterId(unsigned int iC) {
184  if (iC < 0)
185  logger(WARN, "idCluster = % is less than zero.", iC);
186  idCluster_ = iC;
187 }
188 
194 }
195 
201  if (vDM < 0 || vDM > 1)
202  logger(ERROR, "velocityDampingModulus must be grater than zero and less than 1. velocityDampingModulus = %", vDM);
204 }
205 
211 }
212 
218  if (gL <= 0)
219  logger(ERROR, "nInternalStructurePoints_ must be grater than zero. nInternalStructurePoints_ = %", gL);
221 }
222 
227  return energyRatioTolerance_;
228 }
229 
235  if (eRT <= 0)
236  logger(ERROR, "energyRatioTolerance must be grater than zero. energyRatioTolerance = %", eRT);
237  energyRatioTolerance_ = eRT;
238 }
239 
244  return particleSpecies_;
245 }
246 
251  particleSpecies_ = pS;
252 }
253 
258  return clusterVelocity_;
259 }
260 
265  clusterVelocity_ = v;
266 }
267 
272  return isCdatOutputOn_;
273 }
274 
278 void BaseCluster::doCdatOutput(bool iCOO) {
279  isCdatOutputOn_ = iCOO;
280 }
281 
286  return isOverlOutputOn_;
287 }
288 
292 void BaseCluster::doOverlOutput(bool iOOO) {
293  isOverlOutputOn_ = iOOO;
294 }
295 
300  return isAmatOutputOn_;
301 }
302 
306 void BaseCluster::doAmatOutput(bool iAOO) {
307  isAmatOutputOn_ = iAOO;
308 }
309 
314  return isIntStrucOutputOn_;
315 }
316 
321  isIntStrucOutputOn_ = iISOO;
322 }
323 
328  return isVtkOutputOn_;
329 }
330 
334 void BaseCluster::doVtkOutput(bool iVOO) {
335  isVtkOutputOn_ = iVOO;
336 }
337 
342  return isRestartOutputOn_;
343 }
344 
349  isRestartOutputOn_ = r;
350 }
351 
356  return isFStatOutputOn_;
357 }
358 
363  isFStatOutputOn_ = fS;
364 }
365 
370  return isEneOutputOn_;
371 }
372 
377  isEneOutputOn_ = e;
378 }
379 
384  return meanClusterRadius_;
385 }
386 
391  return meanRelativeOverlap_;
392 }
393 
394 /*
395  * ----------------------------------------------------------------------
396  * FUNCTIONS: overridden mercury3D functions
397  * ----------------------------------------------------------------------
398  */
399 
426 {
427  logger(VERBOSE, "CREATING CLUSTER");
428 
429  if (particleHandler.getSize()>0){
430  logger(WARN, "ParticleHandler was not empty");
432  }
433 
434  if (speciesHandler.getSize()>0){
435  logger(WARN, "speciesHandler was not empty");
437  }
438  // Defining cluster parameters starting from the user input.
439  // In order to use this class the user has to set exactly 2 values among radiusParticle,
440  // radiusCluster and numberOfParticles.
442  logger(ERROR, "Please set exactly two values among radiusParticle, radiusCluster and numberOfParticles."
443  " radiusParticle = %, radiusCluster = %, numberOfParticles = %.",
445 
446  // If the user sets the cluster radius and the radius of a single particle,
447  // the number of particles has to be computed:
450  logger(VERBOSE, "clusterRadius is small compared to the radius of a single particle:"
451  " consider setting clusterRadius >= 2 * radiusParticle."
452  "clusterRadius = %, radiusParticle = %.", radiusCluster_, radiusParticle_);
453  // relative cluster radius
455  // mass fraction of the cluster in the limit of phi = 0.
456  Mdouble eps0 = 0.58;
457  // The number of particles (N) per cluster given the relative cluster radius (hatR) and penetration depth max (phi)
458  // can be computed as: N = ( hatR / (1 - eps0*phi) )^3 * eps0.
459  // It is very important to notice that this formula is accurate only if sliding friction is set to 0.5 and relative
460  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
461 
462  nParticles_ =
463  round (std::pow( hatR / (1.0 - eps0 * particleSpecies_->getPenetrationDepthMax() ), 3) * eps0);
464  logger(VERBOSE, "Number of particles: %.\n", nParticles_);
465  }
466 
467  // If the user sets the cluster radius and the number of particles,
468  // the radius of a single particle has to be computed:
470  // mass fraction of the cluster in the limit of phi = 0.
471  Mdouble eps0 = 0.58;
472  // The radius of a single particle (r) composig the cluster given the cluster radius (R), penetration depth max (phi)
473  // and the number of particles (N) can be obtained as: r = R / ( cbrt(N/eps0) * (1-eps0*phi) ).
474  // It is very important to notice that this formula is accurate only if sliding friction is set to 0.5 and relative
475  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
476  radiusParticle_ = radiusCluster_ / (cbrt(nParticles_/eps0) * (1-eps0*particleSpecies_->getPenetrationDepthMax()));
477 
478  logger(VERBOSE, "radius particle: %.\n", radiusParticle_);
479  }
480 
481  logger(VERBOSE, "SETTING RADII");
482  setRadii();
483 
484  logger(VERBOSE, "SETTING SPECIES");
485  setSpecies();
486 
487  logger(VERBOSE, "SETTING DOMAIN LIMITS");
488  setDomainLimits();
489 
490  logger(VERBOSE, "COMPUTING TIME STEP");
492 
493  logger(VERBOSE, "PARTICLE INSERTION");
494  insertParticles();
495 
496  logger(VERBOSE, "Number of particles: %.", particleHandler.getSize());
497 
498  t0_ = getTime();
499 
500  // \details deltaStar
501  Mdouble deltaStar = particleSpecies_->getPenetrationDepthMax() * particleSpecies_->getUnloadingStiffnessMax()
502  / (particleSpecies_->getUnloadingStiffnessMax() - particleSpecies_->getLoadingStiffness());
503 
504  /*
505  * \brief maximum force modulus applied on particles (this value is then multiplied by the relative distance from
506  * force center d, which is d = D/r).
507  * It is the force necessary to get a overlap of deltaStar (computed above this description).
508  * If constant restitution is true then it is also multiplied by the mass of the biggest particle,
509  * or if MERCURY_USE_MPI it is the biggest possible mass computed taking into account particle dispersity,
510  * i.e. the mass of a particle having radius
511  * r = radiusParticle_ * 2 * sizeDispersityParticle_ / (1 + sizeDispersityParticle_).
512  * (In order to get the right value of loading stiffness it should be multiplied by the mass of the smallest
513  * particle; multiplying it for the biggest mass here, instead, is for safety).
514  */
515 
516 #ifdef MERCURY_USE_MPI
518  particleSpecies_->getLoadingStiffness()
519  * (particleSpecies_->getConstantRestitution() ?
521  :
522  1);
523 #else
525  particleSpecies_->getLoadingStiffness()
526  * (particleSpecies_->getConstantRestitution() ?
528  :
529  1);
530 #endif
531 
532  /*
533  * \details
534  * The time needed for a particle to cover a distance of x is sqrt(2 * x * m / F), when a constant force F is applied.
535  * In order to hit another particle, a single particle has to travel a distance of about boxSize/4 (boxSize is the domain length).
536  * As a value for x it is used boxSize_ (instead of boxSize_/4 as a safety factor).
537  * As a value for F it is used maximumForceModulus/50 which is half of maximumForceModulus/25 (in this way it is calculated
538  * a measure of the time needed with a force which linearly increases from 0 to maximumForceModulus/25, again dividing for 25
539  * is done for safety). As a value for m it is used the mass of the biggest particle, or if MERCURY_USE_MPI it is
540  * the mass computed taking into account size dispersity, so the mass
541  * of a particle having radius r = radiusParticle_ * 2 * sizeDispersityParticle_ / (1 + sizeDispersityParticle_), for safety.
542  * The factor 5* outside the sqrt is another safety factor empirically determined: with this values the computation is fast
543  * and the obtained results are very similar to the ones obtained if longer times would be set.
544  * All this safety factors are needed because this is not the exact value of time needed but a measure of it: the problem
545  * indeed is quite complicated given that particles can also rearrange during compression and so they will eventually
546  * move in a non radial direction and for this reason they will need more time to settle.
547  */
548 #ifdef MERCURY_USE_MPI
552 #else
555 #endif
556 
557  //\details Maximum possible time duration of dissipation (i.e. duration of dissipation if energy ration tollerance not reached).
558  dissipationDuration_ = forceTuningDuration_/2;
559 
560  // Compression + Decompression + Dissipation = 2 * Compression + Dissipation
561  clusterTimeMax_ = 2 * forceTuningDuration_ + dissipationDuration_;
563 
564  fileOutputTimeInterval_ = forceTuningDuration_ / 100;
565 
567 
569 
570  forceDampingModulus_ = 0.95;
571 
573 
574  setXBallsAdditionalArguments("-v0 -p 10");
575 
577 
579 
581 
582  fStatFile.setFileType(isFStatOutputOn() ? FileType::ONE_FILE : FileType::NO_FILE);
583 
584  eneFile.setFileType(isEneOutputOn() ? FileType::ONE_FILE : FileType::NO_FILE);
585 
586  // Name setting
587  std::ostringstream name;
588  name << "Cluster_ID_" << idCluster_;
589  setName(name.str());
590 
591  if (isCdatOutputOn()) {
592  logger(VERBOSE, "CREATING .cdat FILE\n");
593  makeCdatFile();
594  }
595 
596  if (isOverlOutputOn()) {
597  logger(VERBOSE, "CREATING .overl FILE\n");
598  makeOverlFile();
599  }
600 
601  logger(VERBOSE, "ACTIVATING CENTRAL FORCES\n");
602 
603  /*
604  * \details
605  * Stage defines in which phase of the calculation the program is:
606  * stage = 1: compressing particles and increasing force
607  * stage = 2: releasing force
608  * stage = 3: waiting for the system to be static.
609  */
610  stage_ = 1;
611 }
612 
622 {
624 
626  writeToCdatFile();
627 
630 
631  /*
632  * \brief If stage == 1 force is linearly increased and velocities are damped for a time T = forceTuningDuration.
633  * If t > T, stage is set to 2.
634  */
635  if (stage_ == 1)
636  {
637  if (getTime() - t0_ < forceTuningDuration_)
638  {
639  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
640  increaseForce();
641 
642  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
643  dampVelocities();
644 
646  }
647  else
648  {
649  logger(VERBOSE, "DECREASING CENTRAL FORCE");
650 
651  t0_ = getTime();
652  stage_++;
653  }
654  }
655 
656  /*
657  * \brief If stage == 2 force is linearly decreased and velocities are damped for a time duration of T = forceTuningDuration.
658  * If t > T, stage is set to 3.
659  */
660  if (stage_ == 2)
661  {
662  if (getTime() - t0_ < forceTuningDuration_)
663  {
664  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
665  decreaseForce();
666 
667  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
668  dampVelocities();
669 
671  }
672  else
673  {
674  logger(VERBOSE, "DISSIPATING ENERGY");
675 
676  t0_ = getTime();
679  stage_++;
680  }
681  }
682 
683  /*
684  * \details If stage == 3 force is exponentially decreased and velocities are damped for a time duration of T = dissipationDuration_.
685  * If t>T or if the energy ratio is below the minimum threshold calculation is concluded and a few last operation are computed.
686  * They are:
687  * -timeMax is set to getTime(), in order to stop the calculation,
688  * -stage is set to 4 (if the energy threshold is not reached stage will remain 3 (because the simulation is stopped by the previous
689  * definition of timeMax): if this happens the user gets a warning, see actionsAfterSolve()).
690  * If MERCURY_USE_MPI this process lasts for a time T = dissipationDuration_ - getTimeStep().
691  */
692  if (stage_ == 3)
693  {
694  // \brief Now force is damped and not decreased.
695  if (fmod(getTime() - t0_, forceTuningInterval_) < getTimeStep())
696  dampForce();
697 
698  if (fmod(getTime() - t0_, velocityDampingInterval_) < getTimeStep())
699  dampVelocities();
700 
702 #ifdef MERCURY_USE_MPI
704 #else
707 #endif
708  {
709  printTime();
710  logger(VERBOSE, "ENERGY DISSIPATED\n");
711 
712  // stage++ now is a flag used to understand if the dissipation procedure has been completed.
713  stage_++;
714 
715  setTimeMax(getTime());
716  }
717  }
718 
719 }
720 
734 {
735 
737 
738  if ( isCdatOutputOn() )
739  writeToCdatFile();
740 
741  if ( isOverlOutputOn() )
743 
744  if (stage_ == 3)
745  logger(WARN, "Dissipation process not completed: final energyRatioTollerance_ = %."
746  "Try to increase energyRatioTollerance_ or decreasing velocityDampingModulus.",
748 
749  if (isAmatOutputOn())
750  {
751  logger(VERBOSE, "CREATING ADJACENCY MATRIX FILE\n");
753  makeAmatFile();
754  writeAmatFile();
755  }
756 
757  if (isIntStrucOutputOn())
758  {
759  logger(VERBOSE, "COMPUTING INTERNAL STRUCTURE FILE\n");
761  }
762 
763  if(isOverlOutputOn())
764  {
765  logger(VERBOSE, "COMPUTING GNUPLOT FILE\n");
766  makeGnuplotFile();
767  }
768 
769 
770  /*
771  * \brief with this loop all particles are moved so that center of mass == position_ and their velocity is set.
772  */
773  for (auto i = particleHandler.begin(); i != particleHandler.end(); ++i){
774  (*i)->setPosition( (*i)->getPosition() + position_ - centerOfMass_ );
775  (*i)->setVelocity( clusterVelocity_ );
776  }
777 
778  logger(VERBOSE, "CLUSTER CREATED.\n");
779 
780  if (isCdatOutputOn())
781  cdatFile_.close();
782 
783  if (isOverlOutputOn())
784  overlFile_.close();
785 }
786 
791 void BaseCluster::write(std::ostream& os, bool writeAllParticles) const
792 {
793  writeAllParticles = true;
794  MercuryBase::write(os, writeAllParticles);
795 
796  os <<
797  "position " << position_ << " " <<
798  "stage " << stage_ << " " <<
799  "t0 " << t0_
800  << "\n" <<
801  "idCluster " << idCluster_ << " " <<
802  "nParticles " << nParticles_ << " " <<
803  "radiusParticle " << radiusParticle_ << " " <<
804  "massParticle " << massParticle_ << " " <<
805  "sizeDispersityParticle " << sizeDispersityParticle_ << " " <<
806  "totalParticleVolume " << totalParticleVolume_
807  << "\n" <<
808  "maximumForceModulus " << maximumForceModulus_ << " " <<
809  "forceTuningInterval " << forceTuningInterval_ << " " <<
810  "forceTuningDuration " << forceTuningDuration_ << " " <<
811  "velocityDampingInterval " << velocityDampingInterval_ << " " <<
812  "velocityDampingModulus " << velocityDampingModulus_ << " " <<
813  "energyRatioTolerance " << energyRatioTolerance_ << " " <<
814  "forceDampingModulus " << forceDampingModulus_ << " " <<
815  "forceModulus " << forceModulus_
816  << "\n" <<
817  "isCdatOutputON " << isCdatOutputOn_ << " " <<
818  "isOverlOutputOn " << isOverlOutputOn_ << " " <<
819  "isAmatOutputOn " << isAmatOutputOn_ << " " <<
820  "isIntStrucOutputOn " << isIntStrucOutputOn_
821  << "\n";
822  if (isIntStrucOutputOn())
823  {
824  os << "nInternalStructurePoints " << nInternalStructurePoints_ << "\n";
825  }
826 
827  os << "isRestartOutputOn " << isRestartOutputOn_ << " " << //This is obviously on because otherwise restart
828  // process would not take place.
829  //For now it is saved but could eventually be removed.
830  "isFStatOutputOn " << isFStatOutputOn_ << " " <<
831  "isEneOutputOn " << isEneOutputOn_ << std::endl;
832 }
833 
838 void BaseCluster::read(std::istream& is, ReadOptions opt)
839 {
840  MercuryBase::read(is);
841 
842  std::stringstream line;
843  std::string dummy;
844 
846  line >> dummy >> position_
847  >> dummy >> stage_
848  >> dummy >> t0_;
850  line >> dummy >> idCluster_
851  >> dummy >> nParticles_
852  >> dummy >> radiusParticle_
853  >> dummy >> massParticle_
854  >> dummy >> sizeDispersityParticle_
855  >> dummy >> totalParticleVolume_;
857  line >> dummy >> maximumForceModulus_
858  >> dummy >> forceTuningInterval_
859  >> dummy >> forceTuningDuration_
860  >> dummy >> velocityDampingInterval_
861  >> dummy >> velocityDampingModulus_
862  >> dummy >> energyRatioTolerance_
863  >> dummy >> forceDampingModulus_
864  >> dummy >> forceModulus_;
866  line >> dummy >> isCdatOutputOn_
867  >> dummy >> isOverlOutputOn_
868  >> dummy >> isAmatOutputOn_
869  >> dummy >> isIntStrucOutputOn_;
870  if(isIntStrucOutputOn() )
871  {
873  line >> dummy >> nInternalStructurePoints_;
874  }
875  line >> dummy >> isRestartOutputOn_
876  >> dummy >> isFStatOutputOn_
877  >> dummy >> isEneOutputOn_;
878 }
879 
885 {
886  readRestartFile();
887 
889 
891 
893 
895 
897 
898  setXBallsAdditionalArguments("-v0 -p 10");
899 
901 
903 
905 
907 
909 
910  if (isCdatOutputOn())
911  {
912  std::ostringstream cdatName;
913  cdatName << getName() << ".cdat";
914  cdatFile_.open(cdatName.str(), std::ios::app);
915  }
916 
917  if (isOverlOutputOn())
918  {
919  std::ostringstream overlName;
920  overlName << getName() << ".overl";
921  overlFile_.open(overlName.str(), std::ios::app);
922  }
923 
924  logger(VERBOSE, "CALCULATION RESTARTED\n");
925 }
926 
945 {
946  std::ostringstream printTime;
947  switch (stage_)
948  {
949  case 1: printTime << "Compression progress: " << std::setw(3) << int( ceil( 100 * (getTime() - t0_) / forceTuningDuration_ ) ) << "%, ";
950  break;
951 
952  case 2: printTime << "Decompression progress: " << std::setw(3) << int( ceil( 100 * (getTime() - t0_) / forceTuningDuration_ ) )<< "%, ";
953  break;
954 
955  case 3: printTime << "Dissipating energy: ";
956  break;
957 
958  default: printTime << "Final values: ";
959  break;
960  }
961  printTime <<
962  "E_ratio = " << std::scientific << std::setprecision(2) << std::setw(8) << getKineticEnergy()/getElasticEnergy() <<
963  ", cN = " << std::fixed << std::setw(5) << meanCoordinationNumber_ << ", rMean = " << std::scientific << meanClusterRadius_ <<
964  ", mF = " << std::fixed << std::setprecision(3) << solidFraction_ << ", Force Modulus = " << std::scientific << forceModulus_ <<
965  ", dMin = " << std::fixed << std::setw(7) << std::setprecision(5) << minRelativeOverlap_ << ", dMean = " << std::setw(7) << meanRelativeOverlap_ <<
966  ", dMax = " << maxRelativeOverlap_ << ", centerOfMass = " << std::scientific << std::setprecision(5) << std::setw(13) << centerOfMass_.X
967  << std::setw(14) << centerOfMass_.Y << std::setw(14) << centerOfMass_.Z <<
968  " nParticles: " << particleHandler.getSize();
969  logger(VERBOSE, printTime.str());
970 }
971 
972 
973 
974 /*
975  * ----------------------------------------------------------------------
976  * FUNCTIONS: functions inside setupInitialConditions
977  * ----------------------------------------------------------------------
978  */
979 
984 {
987  for (int i = 0; i < nParticles_; ++i)
988  {
989  // This is the actual radius of the i-th particle
991  // Computing totalParticleVolume (this is done because this value is needed before particle insertion).
992  totalParticleVolume_ += 4.0*constants::pi*pow(radii_[i],3.0)/3.0;
993  //computing the smallest radius (needed in computeTimeStep(), which is needed before particle insertion)
995  }
996 }
997 
1003 {
1004  if (particleSpecies_ == nullptr)
1005  {
1006  logger(ERROR, "Species not set.");
1007  }
1009  /*
1010  * \brief mass of the particle which has radius radiusParticle if constantRestitution(false) or
1011  * radiusParticle_*2/(1+sizeDispersityParticle_) otherwise.
1012  * It is set now and used various time in the code (for example for stiffnesses, collision time
1013  * and restitution coefficient below).
1014  */
1015  massParticle_ = particleSpecies_ -> getConstantRestitution()?
1016  speciesHandler.getObject(0) -> getMassFromRadius(radiusParticle_*2/(1+sizeDispersityParticle_))
1017  :
1018  speciesHandler.getObject(0) -> getMassFromRadius(radiusParticle_);
1019 
1020  std::ostringstream printSpecies;
1021  /*
1022  * If constantRestitution(true) loading, unloading, and cohesion stiffness are multiplied by the mass of a particle
1023  * whose radius is radiusParticle_*2/(1+sizeDispersityParticle_),
1024  * which is the mass that should be used to compute collision time.
1025  */
1026  printSpecies << "loadingStiffness: " << std::scientific << particleSpecies_ -> getLoadingStiffness()
1027  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1028  << "unloadingStiffnessMax: " << particleSpecies_ -> getUnloadingStiffnessMax()
1029  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1030  << "cohesionStiffness: " << particleSpecies_ -> getCohesionStiffness()
1031  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl
1032  << "restitutionCoefficient: " << std::fixed << particleSpecies_ -> getRestitutionCoefficient(massParticle_) << std::endl
1033  << "collisionTime: " << std::scientific << std::setprecision(3) << particleSpecies_ -> getCollisionTime(massParticle_) << std::endl;
1034  logger(VERBOSE, printSpecies.str());
1035 }
1036 
1045 {
1046  Mdouble initialSolidFraction = 0.1;
1047  boxSize_ = cbrt(totalParticleVolume_/initialSolidFraction);
1048  std::ostringstream printDomainLimits;
1049  printDomainLimits << "Cubic size " << boxSize_ << std::endl;
1050  logger(VERBOSE, printDomainLimits.str());
1051 
1052  setDomain(-0.5*boxSize_*Vec3D(1,1,1) + position_, 0.5*boxSize_*Vec3D(1,1,1) + position_);
1053 }
1054 
1060 {
1061  // if constantRestitution(true) mass for collision time will be automatically set to 1, otherwise the smallest particle's mass will be used
1063 
1064  // printing values of timeStep and ratio between collisionTime and timeStep
1065  std::ostringstream printTimeStep;
1066  printTimeStep << "timeStep: " << std::setprecision(4) << getTimeStep() << std::endl
1067  << "cT/tS, at least: " << std::fixed << std::setprecision(1)
1069  << std::endl;
1070  logger(VERBOSE, printTimeStep.str());
1071 }
1072 
1073 
1078 {
1079  int nParticlesInserted = 0;
1080 
1081  while (nParticlesInserted < nParticles_)
1082  {
1083  /* nParticleInserted corresponds to the index of the particle which is being inserted:
1084  * for example if no particle has been inserted yet nParticlesInserted=0 which is the
1085  * index of the first particle, and so on. For this reason this variable is the input
1086  * for particleInsertionSuccessful.
1087  */
1088  if (particleInsertionSuccessful(nParticlesInserted))
1089  {
1090  nParticlesInserted++;
1091  }
1092  else
1093  {
1094  logger(ERROR, "Cannot insert all particles, try to decrase the value of initialSolidFraction in "
1095  "BaseCluster::setDomainLimits();\n"
1096  "Inserted %/% particles.", nParticlesInserted, nParticles_);
1097  }
1098  }
1099  logger(VERBOSE, "PARTICLE INSERTION TERMINATED SUCCESSFULLY\n");
1100 }
1101 
1137 {
1138  std::ostringstream cdatName;
1139  cdatName << getName() << ".cdat";
1140 
1141  cdatFile_.open(cdatName.str(), std::ios::out);
1142 
1143  cdatFile_ << "CLUSTER DATA AND INFORMATION" << std::endl << std::endl;
1144  cdatFile_ << "position: " << position_ << std::endl;
1145  cdatFile_ << "collisionTimeOverTimeStep: " << getCollisionTimeOverTimeStep() << std::endl;
1146  cdatFile_ << "radiusParticle: " << std:: scientific << std::setprecision(2) << getRadiusParticle() << std::endl;
1147  cdatFile_ << "sizeDispersityParticle: " << std::defaultfloat << getSizeDispersityParticle() << std::endl;
1148  cdatFile_ << "densityParticle: " << std:: scientific << particleSpecies_ -> getDensity() << std::endl;
1149  cdatFile_ << "nParticles: " << std::defaultfloat << getNumberOfParticles() << std::endl;
1150  cdatFile_ << "idCluster: " << getClusterId() << std::endl;
1151  cdatFile_ << "slidingFrictionCoeff: " << particleSpecies_ -> getSlidingFrictionCoefficient() << std::endl;
1152  cdatFile_ << "rollingFrictionCoeff: " << particleSpecies_ -> getRollingFrictionCoefficient() << std::endl;
1153  cdatFile_ << "torsionFrictionCoeff: " << particleSpecies_ -> getTorsionFrictionCoefficient() << std::endl;
1154  // If constantRestitution(true) loading, unloading, and cohesion stiffness are multiplied by the mass of a particle (massParticle_) whose radius is radiusParticle_*2/(1+sizeDispersityParticle_),
1155  // which is the mass that should be used to compute collision time.
1156  cdatFile_ << "loadingStiffness: " << std::scientific << particleSpecies_ -> getLoadingStiffness()
1157  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1158  cdatFile_ << "unloadingStiffnessMax: " << particleSpecies_ -> getUnloadingStiffnessMax()
1159  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1160  cdatFile_ << "cohesionStiffness: " << particleSpecies_ -> getCohesionStiffness()
1161  * (particleSpecies_->getConstantRestitution()?massParticle_:1) << std::endl;
1162  cdatFile_ << "restitutionCoefficient: " << particleSpecies_ -> getRestitutionCoefficient(massParticle_) << std::endl;
1163  cdatFile_ << "collisionTime: " << std::scientific << std::setprecision(3) << particleSpecies_ -> getCollisionTime(massParticle_) << std::endl;
1165  cdatFile_ << "nInternalStructurePoints: " << getNumberOfInternalStructurePoints() << std::endl;
1166  cdatFile_ << "energyRatioTolerance: " << getEnergyRatioTolerance() << std::endl;
1167  cdatFile_ << "velocityDampingModulus: " << std::defaultfloat << getVelocityDampingModulus() << std::endl << std::endl;
1168 
1169  cdatFile_ << "progress" << std::setw(16) << "ElastEne" << std::setw(23) << "Ekin/ElastEne" << std::setw(18) << "coord_number" << std::setw(14) << "meanRadius"
1170  << std::setw(19) << "solidFraction" << std::setw(16) << "forceModulus" << std::setw(22) << "AveFOnOverl" << std::setw(15) << "dMin" << std::setw(17) << "dMean"
1171  << std::setw(14) << "dMax" << std::setw(24) << "Mass Centre" << std::endl;
1172 }
1173 
1180 {
1181  std::ostringstream overlName;
1182  overlName << getName() << ".overl";
1183 
1184  overlFile_.open(overlName.str(), std::ios::out);
1185  overlFile_ << "Overlap Vs Normal Force" << std::endl;
1186 }
1187 
1199 
1200  int insertionFailCounter = 0;
1201  Mdouble rad, theta, phi;
1202  Vec3D particlePosition;
1203  SphericalParticle p0;
1204 
1205  // setup of particle properties and initial conditions (besides position)
1206  p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
1207  p0.setRadius(radii_[n]);
1209  p0.setGroupId(idCluster_);
1210 
1211  while (insertionFailCounter < 1000)
1212  {
1213  theta = constants::pi * random.getRandomNumber(0, 2.0);
1214  phi = acos(random.getRandomNumber(-1.0, 1.0));
1215  rad = p0.getRadius() + cbrt( random.getRandomNumber( 0, 1 ) ) * ( 0.5 * boxSize_ - 2.01 * p0.getRadius() );
1216 
1217  particlePosition.X = position_.X + rad * sin(phi) * cos(theta);
1218  particlePosition.Y = position_.Y + rad * sin(phi) * sin(theta);
1219  particlePosition.Z = position_.Z + rad * cos(phi);
1220 
1221  p0.setPosition(particlePosition);
1222 
1224  {
1226  return true;
1227  }
1228 
1229  insertionFailCounter++;
1230  }
1231 
1232  return false;
1233 }
1234 
1235 
1236 
1237 /*
1238  * ----------------------------------------------------------------------
1239  * FUNCTIONS: functions inside actionsAfterTimeStep
1240  * ----------------------------------------------------------------------
1241  */
1242 
1256 {
1257  // resetting counters and variables
1258  Mdouble solidVolumeInsideRadius = 0;
1259  Vec3D localMin;
1260  Vec3D localMax;
1261  localMin.setZero();
1262  localMax.setZero();
1264  //\brief vector in which it is saved the relative position of a particle from the center of mass
1265  Vec3D distanceFromCenterOfMass;
1266  //\brief distance from the center of mass of the furthest particle
1267  Mdouble furthestParticleDistance = 0;
1268  // number of particles whose distance d from the center of mass is d > furthestParticleDistance - radiusParticle_
1269  int counter = 0;
1270  Mdouble relativeOverlap = 0;
1271 
1272  meanClusterRadius_ = 0.0;
1274  maxRelativeOverlap_ = 0.0;
1275  meanRelativeOverlap_ = 0.0;
1277 
1278  // loops over each particle to compute mean coordination number and center of mass.
1279  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1280 
1281  meanCoordinationNumber_ += ((*p)->getInteractions()).size();
1282 
1283  centerOfMass_ += ((*p)->getVolume()) * ((*p)->getPosition());
1284  }
1285 
1288 
1289 
1290  // loops over each particle to compute the furthest particle from the center of mass.
1291  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1292 
1293  distanceFromCenterOfMass = (*p)->getPosition() - centerOfMass_;
1294 
1295  if (distanceFromCenterOfMass.getLength() > furthestParticleDistance)
1296  furthestParticleDistance = distanceFromCenterOfMass.getLength();
1297 
1298  }
1299 
1300  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p) {
1301 
1302  distanceFromCenterOfMass = (*p)->getPosition() - centerOfMass_;
1303 
1304  if (distanceFromCenterOfMass.getLength() > furthestParticleDistance - radiusParticle_) {
1305  meanClusterRadius_ += distanceFromCenterOfMass.getLength();
1306  counter++;
1307  }
1308 
1309  }
1310 
1311  meanClusterRadius_ /= counter;
1313 
1314 
1315  /*
1316  * \details This is the radius used to compute solid fraction: it is smaller than the meanClusterRadius.
1317  */
1319 
1320  /*
1321  * \details With a for cycle the volume of the particles inside radiusForSolidFraction is computed and after this the value of solid
1322  * fraction is calculated. This value is less precise as the maximum penetration depth increases and more precise as the
1323  * number of particle increases.
1324  */
1325  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1326  {
1327  distanceFromCenterOfMass = (*p) -> getPosition() - centerOfMass_;
1328 
1329  if( distanceFromCenterOfMass.getLength() < radiusForSolidFraction_ )
1330  solidVolumeInsideRadius += (*p) -> getVolume();
1331  }
1332 
1333  solidFraction_ = 3 * solidVolumeInsideRadius / ( 4 * constants::pi * pow(radiusForSolidFraction_, 3) );
1334 
1335  // loops over every interaction to compute mean force acting on interaction, maximum, mean and minimum relative particle overlap.
1336  for (std::vector<BaseInteraction*>::const_iterator i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1337  {
1338 
1339  /*
1340  * \details the relative overlap is computed as an average of the relative overlap on the two particles.
1341  * rO = ( O/R1 + O/R2 ) / 2.
1342  */
1343  relativeOverlap = ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getP() -> getIndex()) -> getRadius()) +
1344  ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getI() -> getIndex()) -> getRadius());
1345  relativeOverlap /= 2;
1346  meanRelativeOverlap_ += relativeOverlap;
1347  if (relativeOverlap > maxRelativeOverlap_)
1348  maxRelativeOverlap_ = relativeOverlap;
1349 
1350  if (relativeOverlap < minRelativeOverlap_)
1351  minRelativeOverlap_ = relativeOverlap;
1352  }
1354 }
1355 
1371 {
1372  switch (stage_)
1373  {
1374  case 1:
1375  cdatFile_ << "C, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1376  break;
1377 
1378  case 2:
1379  cdatFile_ << "D, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1380  break;
1381 
1382  case 3:
1383  cdatFile_ << "D-energy: ";
1384  break;
1385 
1386  default:
1387  cdatFile_ << "Final v: ";
1388  }
1389 
1390  cdatFile_ <<
1391  std::scientific <<
1392  std::setprecision(2)<<
1393  std::setw(14) <<
1394  getElasticEnergy() <<
1395  std::setw(18) <<
1397  std::fixed <<
1398  std::setprecision(2) <<
1399  std::setw(15) <<
1401  std::scientific <<
1402  std::setw(20) <<
1404  std::fixed <<
1405  std::setprecision(2) <<
1406  std::setw(13) <<
1407  solidFraction_ <<
1408  std::scientific <<
1409  std::setprecision(3) <<
1410  std::setw(24) <<
1411  forceModulus_ <<
1412  std::setw(22) <<
1413  std::fixed <<
1414  std::setprecision(5) <<
1415  std::setw(18) <<
1417  std::setw(16) <<
1419  std::setw(15) <<
1421  std::scientific <<
1422  std::setprecision(2) <<
1423  std::setw(19) <<
1424  centerOfMass_.X <<
1425  std::setw(12) <<
1426  centerOfMass_.Y <<
1427  std::setw(12) <<
1428  centerOfMass_.Z <<
1429  " " <<
1430  std::endl;
1431 }
1432 
1438 {
1439  //\brief force acting on overlap.
1440  Mdouble forceOnOverlap = 0;
1441  Mdouble relativeOverlap = 0;
1442  switch (stage_)
1443  {
1444  case 1:
1445  overlFile_ << "C, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1446  break;
1447 
1448  case 2:
1449  overlFile_ << "D, " << std::fixed << std::setprecision(0) << std::setw(4) << 100 * (getTime() - t0_) / forceTuningDuration_ << "%: ";
1450  break;
1451 
1452  case 3:
1453  overlFile_ << "D energy: ";
1454  break;
1455 
1456  default:
1457  overlFile_ << "Final v: ";
1458  }
1459 
1460  for (std::vector<BaseInteraction*>::const_iterator i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1461  {
1462  forceOnOverlap = ((*i) -> getForce()).getLength();
1463  relativeOverlap = ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getP() -> getIndex()) -> getRadius()) +
1464  ((*i) -> getOverlap())/(particleHandler.getObject((*i) -> getI() -> getIndex()) -> getRadius());
1465  relativeOverlap = relativeOverlap / 2;
1466  overlFile_ << std::setprecision(2) << std::scientific << std::setw(18) << forceOnOverlap
1467  << std::defaultfloat << std::fixed << std::setprecision(4) << std::setw(9) << relativeOverlap;
1468  }
1469 
1470  overlFile_ << " " << std::endl;
1471 }
1472 
1481 {
1482  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1483  {
1484  //\brief distance from the center of forces (which is position_).
1485  Vec3D distanceFromForceCenter = (*p) -> getPosition() - position_;
1486 
1487  //\brief norm of distanceFromForceCenter vector
1488  Mdouble norm = distanceFromForceCenter.getLength();
1489 
1490  (*p) -> addForce( -forceModulus_ * distanceFromForceCenter * (2*radiusParticle_ + norm) / (2*radiusParticle_*norm) );
1491 
1492  }
1493 }
1494 
1500 {
1502 }
1503 
1509 {
1510  for (auto p = particleHandler.begin(); p != particleHandler.end(); ++p)
1511  {
1512  (*p) -> setVelocity(velocityDampingModulus_*( (*p) -> getVelocity() ));
1513  }
1514 }
1515 
1522 {
1524 }
1525 
1530 {
1532 }
1533 
1540 {
1541  for (int i = 0; i < particleHandler.getSize(); i++)
1542  {
1543  std::vector<int> temporaryRowVector;
1544  temporaryRowVector.reserve(particleHandler.getSize());
1545 
1546  for (int j = 0; j < particleHandler.getSize(); j++)
1547  temporaryRowVector.push_back(0);
1548 
1549  adjacencyMatrix_.push_back(temporaryRowVector);
1550  }
1551 
1552  for (auto i = interactionHandler.begin(); i != interactionHandler.end(); ++i)
1553  {
1554  adjacencyMatrix_[(*i) -> getP() -> getIndex()][(*i) -> getI() -> getIndex()] = 1;
1555  adjacencyMatrix_[(*i) -> getI() -> getIndex()][(*i) -> getP() -> getIndex()] = 1;
1556  }
1557 }
1558 
1563 {
1564  std::ostringstream amatName;
1565  amatName << getName() << ".amat";
1566 
1567  amatFile_.open(amatName.str(), std::ios::out);
1568  amatFile_ << "ADJACENCY MATRIX" << std::endl << std::endl;
1569 }
1570 
1577 {
1578  for(int i=0; i < particleHandler.getSize(); i++)
1579  {
1580  for(int j=0; j < particleHandler.getSize(); j++)
1581  {
1582  amatFile_ << adjacencyMatrix_[i][j] << " ";
1583  }
1584  amatFile_ << std::endl;
1585  }
1587  amatFile_ << std::endl;
1588  amatFile_ << "THE TOTAL NUMBER OF INTRACLUSTER BONDS IS: " << nIntraClusterBonds_ << std::endl;
1589  amatFile_ << "THE MEAN COORDINATION NUMBER IS: " << meanCoordinationNumber_ << std::endl;
1590 
1591  amatFile_.close();
1592 }
1593 
1603 {
1604 
1605 
1606 
1607  Vec3D mcPoint;
1608  SphericalParticle p0;
1609  Mdouble fictitiousGridPointRadiusRatio = 1.0e-5;
1611  p0.setRadius(radiusParticle_*fictitiousGridPointRadiusRatio);
1612  p0.setVelocity(Vec3D(0.0, 0.0, 0.0));
1613  int nMonteCarloSamplingPoints = nInternalStructurePoints_;
1614  Mdouble nPointsInsideComponentsForMCTest = 0;
1615 
1617 
1618  for (int i = 0; i < nMonteCarloSamplingPoints; ++i)
1619  {
1620 
1621  Mdouble theta = constants::pi * random.getRandomNumber(0, 2.0);
1622  Mdouble phi = acos(random.getRandomNumber(-1.0, 1.0));
1623  Mdouble rad = radiusForSolidFraction_*cbrt( random.getRandomNumber( 0, 1 ) );
1624 
1625  mcPoint.X = rad * sin(phi) * cos(theta);
1626  mcPoint.Y = rad * sin(phi) * sin(theta);
1627  mcPoint.Z = rad * cos(phi);
1628  mcPoint += centerOfMass_;
1629 
1630  p0.setPosition(mcPoint);
1631 
1632  if (!checkParticleForInteraction(p0)) // collision -> the counter goes to the mass fraction
1633  {
1634  nPointsInsideComponentsForMCTest++;
1635  intStructFile_ << std::scientific << std::setprecision(5) << std::setw(12) << mcPoint.X
1636  << std::setw(13) << mcPoint.Y << std::setw(13) << mcPoint.Z << std::setw(6) << 0 << std::endl;
1637  }
1638 
1639  }
1640 
1641  // Solid fraction (accordance between theoretical values and penetration depth max).
1642  // It is very important to notice that this value is accurate only if sliding friction is set to 0.5 and relative
1643  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
1644  solidFractionIntStruct_ = nPointsInsideComponentsForMCTest/nMonteCarloSamplingPoints;
1645  Mdouble theoVal = 0.58 + 3*pow(0.58,2)*particleSpecies_->getPenetrationDepthMax();
1646  Mdouble diff = fabs(theoVal-solidFractionIntStruct_);
1647  Mdouble accordance = (theoVal - diff)/theoVal;
1648  // Solid fraction (accordance between theoretical values and average overlap).
1649  // It is very important to notice that this value is accurate only if sliding friction is set to 0.5 and relative
1650  // tangential stiffness is set to 0.3 while creating the cluster. Different values do not guarantee accuracy.
1651  solidFractionIntStruct_ = nPointsInsideComponentsForMCTest/nMonteCarloSamplingPoints;
1652  Mdouble theoValAvOverl = 0.58 + 3*pow(0.58,2)*meanRelativeOverlap_;
1653  Mdouble diffAvOverl = fabs(theoValAvOverl-solidFractionIntStruct_);
1654  Mdouble accordanceAvOverl = (theoValAvOverl - diffAvOverl)/theoValAvOverl;
1655 
1656  intStructFile_ << "n_points_inside_boundary: " << std::scientific << nMonteCarloSamplingPoints << std::endl;
1657  intStructFile_ << "n_points_inside_components: " << nPointsInsideComponentsForMCTest << std::endl;
1658  intStructFile_ << "solidFractionIntStruct_: " << std::fixed << std::setprecision(6) << solidFractionIntStruct_
1659  << ", accordance with theoretical values: " << 100*accordance << "%." << std::endl
1660  << "Accordance with average overlap: " << 100*accordanceAvOverl << "%." << std::endl
1661  << "It is very important to notice that this formula is accurate only if sliding friction" << std::endl
1662  << "is set to 0.5 and relative tangential stiffness is set to 0.3 while creating the cluster." << std::endl
1663  << "Different values do not guarantee accuracy." << std::endl << std::endl;
1664 
1665  /*
1666  * computeInternalStructure output is set to VERBOSE in order not to have too much output. If the user needs it,
1667  * it is enough to set it to INFO.
1668  */
1669 
1670  std::ostringstream printResults;
1671  printResults << "n_points_inside_boundary: " << std::scientific << nMonteCarloSamplingPoints << std::endl;
1672  printResults << "n_points_inside_components: " << nPointsInsideComponentsForMCTest << std::endl;
1673  printResults << "solidFractionIntStruct_: " << std::fixed << std::setprecision(6) << solidFractionIntStruct_
1674  << ", accordance with theoretical values: " << 100*accordance << "%." << std::endl
1675  << "Accordance with average overlap: " << 100*accordanceAvOverl << "%." << std::endl
1676  << "It is very important to notice that this formula is accurate only if sliding friction" << std::endl
1677  << "is set to 0.5 and relative tangential stiffness is set to 0.3 while creating the cluster." << std::endl
1678  << "Different values do not guarantee accuracy." << std::endl << std::endl;
1679  logger(VERBOSE, printResults.str());
1680 }
1681 
1689 {
1690  std::ostringstream gnuplotname;
1691  gnuplotname << getName() << ".gnuplot";
1692 
1693  gnuplotFile_.open(gnuplotname.str(), std::ios::out);
1694  gnuplotFile_ << "set terminal jpeg" << std::endl;
1695  gnuplotFile_ << "set output \"" << getName() << "_overlaps" << ".jpeg\"" << std::endl;
1696  std::string titleLine=R"(set title "Overlap Vs Force")";// font ",14"
1697  std::string xLabel=R"(set xlabel "Overlap")";
1698  std::string yLabel=R"(set ylabel "Force")";
1699  gnuplotFile_ << titleLine << std::endl;
1700  gnuplotFile_ << xLabel << std::endl;
1701  gnuplotFile_ << yLabel << std::endl;
1702  gnuplotFile_ << "set grid" << std::endl;
1703  gnuplotFile_ << "plot ";
1704  for (int i = 0; i < interactionHandler.getSize(); ++i)
1705  {
1706  gnuplotFile_ << "\"" << getName() << ".overl" << "\"" << " using " << 2*i+4 << ":" << 2*i+3 << " title \"\" with lines lt 1 dashtype 2, ";
1707  }
1708 
1709  gnuplotFile_.close();
1710 
1711 }
1712 
1720 {
1721  std::ostringstream intStructName;
1722  intStructName << getName() << ".struct";
1723 
1724  intStructFile_.open(intStructName.str(), std::ios::out);
1725  intStructFile_ << "Number of Montecarlo points: " << nInternalStructurePoints_ << std::endl;
1726 }
std::vector< std::vector< int > > adjacencyMatrix_
Definition: BaseCluster.h:560
Vec3D getPosition() const
This returns the value of position_, which is the position in which the cluster will be inserted...
Definition: BaseCluster.cc:52
void setSpecies()
Sets species of particles.
BaseParticle * getLargestParticle() const
Returns the pointer of the largest particle in the particle handler. When mercury is running in paral...
void computeInternalStructure()
This computes the internal structure of the cluster.
void setCollisionTimeOverTimeStep(Mdouble cTOTS)
This sets the collisionTimeOverTimeStep number (which is the ratio between collision time and time st...
Definition: BaseCluster.cc:76
Mdouble minRelativeOverlap_
Definition: BaseCluster.h:568
Mdouble getCollisionTimeOverTimeStep() const
This returns the value of the ratio between collision time and time step.
Definition: BaseCluster.cc:68
Mdouble X
the vector components
Definition: Vector.h:65
void makeDataAnalysis()
This functions computes some important cluster information needed by the program. ...
bool isEneOutputOn() const
This returns the bool variable that defines whether the cluster ene output is written or not...
Definition: BaseCluster.cc:369
Mdouble t0_
Definition: BaseCluster.h:598
void writeToCdatFile()
This writes on the cluster data output file.
A spherical particle is the most simple particle used in MercuryDPM.
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
LinearPlasticViscoelasticFrictionSpecies * particleSpecies_
Definition: BaseCluster.h:513
unsigned int getSize() const
Gets the size of the particleHandler (including mpi and periodic particles)
Definition: BaseHandler.h:655
void setTimeMax(Mdouble newTMax)
Sets a new value for the maximum simulation duration.
Definition: DPMBase.cc:863
void setNumberOfInternalStructurePoints(int gL)
This sets the value of the number of particles used to compute the internal structure.
Definition: BaseCluster.cc:217
LinearPlasticViscoelasticFrictionSpecies * getParticleSpecies() const
This returns the species of the particle.
Definition: BaseCluster.cc:243
void actionsAfterSolve() override
Overrides DPMBase actionsAfterSolve(): in this cluster data file and cluster overlap file are closed ...
Definition: BaseCluster.cc:733
void createAdjacencyMatrix()
This calculates the adjacency matrix of the cluster.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here...
double Mdouble
Definition: GeneralDefine.h:34
bool isCdatOutputOn_
Definition: BaseCluster.h:518
virtual void setRadius(Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
void doOverlOutput(bool iOOO)
This sets the bool variable that defines whether the cluster overlap output will be written or not...
Definition: BaseCluster.cc:292
Mdouble velocityDampingInterval_
Definition: BaseCluster.h:610
void doIntStrucOutput(bool iISOO)
This sets the bool variable that defines whether the cluster internal structure output will be writte...
Definition: BaseCluster.cc:320
void doAmatOutput(bool iAOO)
This sets the bool variable that defines whether the cluster adjacency matrix output will be written ...
Definition: BaseCluster.cc:306
unsigned int getClusterId() const
This returns the value of the cluster ID.
Definition: BaseCluster.cc:175
void doEneOutput(bool isEneOutputOn)
This sets the bool variable that defines whether the cluster ene output will be written or not...
Definition: BaseCluster.cc:376
void insertParticles()
Inserts particles inside the domain.
Mdouble radiusParticle_
Definition: BaseCluster.h:481
void setParticlesWriteVTK(bool writeParticlesVTK)
Sets whether particles are written in a VTK file.
Definition: DPMBase.cc:927
void writeToOverlFile()
This writes on the cluster overlap output file.
void decreaseForce()
This linearly decreases values of forceModulus (stage = 2).
bool isVtkOutputOn_
Definition: BaseCluster.h:526
const std::complex< Mdouble > i
Definition: ExtendedMath.h:50
Mdouble meanRelativeOverlap_
Definition: BaseCluster.h:566
Vec3D clusterVelocity_
Definition: BaseCluster.h:499
void setRadii()
Sets all radii according to particleRadius and sizeDispersityParticle.
Definition: BaseCluster.cc:983
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
Definition: BaseHandler.h:704
void setSizeDispersityParticle(Mdouble sDP)
This sets the value of particles' dispersity in size.
Definition: BaseCluster.cc:117
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
Definition: DPMBase.cc:390
Mdouble boxSize_
Definition: BaseCluster.h:554
bool isVtkOutputOn() const
This returns the bool variable that defines whether the cluster vtk output is written or not...
Definition: BaseCluster.cc:327
void setZero()
Sets all elements to zero.
Definition: Vector.cc:43
void dampForce()
This damps values of forceModulus (stage = 3).
bool setNumberOfParticles_
Definition: BaseCluster.h:489
bool isIntStrucOutputOn_
Definition: BaseCluster.h:524
Mdouble maxRelativeOverlap_
Definition: BaseCluster.h:564
bool isIntStrucOutputOn() const
This returns the bool variable that defines whether the cluster internal structure output is written ...
Definition: BaseCluster.cc:313
int getNumberOfInternalStructurePoints() const
This returns the value of the number of particles used to compute internal structure.
Definition: BaseCluster.cc:209
void setSpecies(const ParticleSpecies *species)
Mdouble dissipationDuration_
Definition: BaseCluster.h:615
Mdouble getRandomNumber()
This is a random generating routine can be used for initial positions.
Definition: RNG.cc:143
Mdouble getMassFromRadius(Mdouble radius) const
bool particleInsertionSuccessful(int n)
This function tries to insert the n-th particle (returns true if it manage to do that). It is inside insertParticles().
Mdouble getMeanClusterRadius()
this returns meanClusterRadius (radius of an ideal perfectly spherical cluster, there's no setter)...
Definition: BaseCluster.cc:383
bool isAmatOutputOn() const
This returns the bool variable that defines whether the cluster adjacency matrix output is written or...
Definition: BaseCluster.cc:299
std::ofstream gnuplotFile_
Definition: BaseCluster.h:578
void increaseForce()
This linearly increases the value of forceModulus (stage = 1).
void clear() override
Empties the whole ParticleHandler by removing all BaseParticle.
void doCdatOutput(bool iCOO)
This sets the bool variable that defines whether the cluster data output will be written or not...
Definition: BaseCluster.cc:278
void makeAmatFile()
This creates the adjacency matrix file.
const Mdouble inf
Definition: GeneralDefine.h:44
bool isOverlOutputOn_
Definition: BaseCluster.h:520
bool isCdatOutputOn() const
This returns the bool variable that defines whether the cluster data output (which is NOT the mercury...
Definition: BaseCluster.cc:271
static Mdouble getLength(const Vec3D &a)
Calculates the length of a Vec3D: .
Definition: Vector.cc:331
std::ofstream overlFile_
Definition: BaseCluster.h:576
void read(std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
Overrides DPMBase read(): in this all variables needed by the program for restarting are read...
Definition: BaseCluster.cc:838
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:64
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
Definition: BaseHandler.h:690
Mdouble getSizeDispersityParticle() const
This returns the value of particles' dispersity in size.
Definition: BaseCluster.cc:109
Mdouble radiusCluster_
Definition: BaseCluster.h:495
bool isFStatOutputOn_
Definition: BaseCluster.h:530
void setVelocity(Vec3D v)
This sets the value of velocity after creation.
Definition: BaseCluster.cc:264
bool checkParticleForInteraction(const BaseParticle &P) final
Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle.
Definition: MercuryBase.cc:594
Mdouble meanCoordinationNumber_
Definition: BaseCluster.h:562
void setDomain(const Vec3D &min, const Vec3D &max)
Sets the minimum coordinates of the problem domain.
Definition: DPMBase.cc:1082
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Definition: DPMBase.cc:1514
void setDomainLimits()
Sets domain limits.
File dataFile
An instance of class File to handle in- and output into a .data file.
Definition: DPMBase.h:1417
Mdouble clusterTimeMax_
Definition: BaseCluster.h:600
file will not be created/read
void makeCdatFile()
Creates the cluster data output file.
Mdouble maximumForceModulus_
Definition: BaseCluster.h:604
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:44
bool setRadiusParticle_
Definition: BaseCluster.h:483
void write(std::ostream &os, bool writeAllParticles=true) const override
Writes all data into a restart file.
Definition: MercuryBase.cc:147
Mdouble fileOutputTimeInterval_
Definition: BaseCluster.h:584
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
Definition: DPMBase.h:1422
void write(std::ostream &os, bool writeAllParticles) const override
Overrides DPMBase write(): in this all variables needed by the program for restarting are written...
Definition: BaseCluster.cc:791
std::ofstream intStructFile_
Definition: BaseCluster.h:582
Mdouble getFinalMassFraction()
This gets the final value obtained for the mass fraction;.
Definition: BaseCluster.cc:165
unsigned int idCluster_
Definition: BaseCluster.h:493
Mdouble getMass() const
Returns the particle's mass.
Definition: BaseParticle.h:322
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
Definition: Helpers.cc:423
const Mdouble pi
Definition: ExtendedMath.h:45
std::ofstream amatFile_
Definition: BaseCluster.h:580
void actionsOnRestart() override
Overrides DPMBase actionsOnRestart(): in this all variables needed by the program for restarting are ...
Definition: BaseCluster.cc:884
void setVelocityDampingModulus(Mdouble vDM)
This sets the value of the velocity damping modulus.
Definition: BaseCluster.cc:200
void makeOverlFile()
Creates the cluster overlap output file.
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
Definition: DPMBase.h:1376
all data will be written into/ read from a single file called name_
void makeGnuplotFile()
This creates the gnuplot file needed for printing force vs overlaps values.
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
Definition: BaseHandler.h:613
void doVtkOutput(bool iVOO)
This sets the bool variable that defines whether the cluster vtk output will be written or not...
Definition: BaseCluster.cc:334
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
Definition: DPMBase.cc:1528
void printTime() const override
Overrides DPMBase printTime(): this way variables of interest are shown.
Definition: BaseCluster.cc:944
void doFStatOutput(bool isfStatOutputOn)
This sets the bool variable that defines whether the cluster fStat output will be written or not...
Definition: BaseCluster.cc:362
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:399
Mdouble collisionTimeOverTimeStep_
Definition: BaseCluster.h:475
Mdouble solidFraction_
Definition: BaseCluster.h:590
Mdouble energyRatioTolerance_
Definition: BaseCluster.h:477
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
Mdouble radiusForSolidFraction_
Definition: BaseCluster.h:588
void writeAmatFile()
This writes on the adjacency matrix file.
Vec3D position_
Definition: BaseCluster.h:471
Mdouble forceDampingModulus_
Definition: BaseCluster.h:617
Mdouble getRadius() const
Returns the particle's radius.
Definition: BaseParticle.h:345
Mdouble getAverageOverlap()
this returns the average overlap.
Definition: BaseCluster.cc:390
void clear() override
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
Mdouble sizeDispersityParticle_
Definition: BaseCluster.h:485
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc.
Definition: DPMBase.h:1366
InteractionHandler interactionHandler
An object of the class InteractionHandler.
Definition: DPMBase.h:1406
Mdouble forceModulus_
Definition: BaseCluster.h:606
Mdouble totalParticleVolume_
Definition: BaseCluster.h:550
void setXBallsAdditionalArguments(std::string newXBArgs)
Set the additional arguments for xballs.
Definition: DPMBase.cc:1331
std::ofstream cdatFile_
Definition: BaseCluster.h:574
bool isAmatOutputOn_
Definition: BaseCluster.h:522
Mdouble Y
Definition: Vector.h:65
~BaseCluster() final
Default destructor.
Definition: BaseCluster.cc:38
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
Definition: File.cc:215
RNG random
This is a random generator, often used for setting up the initial conditions etc...
Definition: DPMBase.h:1371
Vec3D getVelocity()
This gets the value of velocity after creation.
Definition: BaseCluster.cc:257
Mdouble solidFractionIntStruct_
Definition: BaseCluster.h:592
void setGroupId(unsigned groupId)
Definition: BaseObject.h:131
bool isEneOutputOn_
Definition: BaseCluster.h:532
void dampVelocities()
This damps values of each particle velocity (stage = 1, stage = 2, stage = 3).
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
Mdouble round(const Mdouble value, unsigned precision)
Definition: Helpers.cc:598
Mdouble massParticle_
Definition: BaseCluster.h:548
void setNumberOfParticles(int nP)
This sets the value of the number of particles in the cluster.
Definition: BaseCluster.cc:134
Vec3D centerOfMass_
Definition: BaseCluster.h:556
Mdouble smallestRadius_
Definition: BaseCluster.h:546
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Definition: DPMBase.cc:413
void applyCentralForce()
This applies force on each particle.
Mdouble meanClusterRadius_
Definition: BaseCluster.h:501
bool isRestartOutputOn() const
This returns the bool variable that defines whether the cluster restart output is written or not...
Definition: BaseCluster.cc:341
Mdouble velocityDampingModulus_
Definition: BaseCluster.h:505
Mdouble getEnergyRatioTolerance() const
This returns the value of the value of the energy ratio threshold under which the process can be cons...
Definition: BaseCluster.cc:226
Mdouble forceTuningDuration_
Definition: BaseCluster.h:612
void makeIntenalStructureFile()
This creates the file needed for writing down datas from computeInternalStructure().
void setParticleSpecies(LinearPlasticViscoelasticFrictionSpecies *particleSpecies)
This sets the species of the particle.
Definition: BaseCluster.cc:250
void setTimeStep(Mdouble newDt)
Sets a new value for the simulation time step.
Definition: DPMBase.cc:1218
Mdouble getRadiusParticle() const
This returns the value of particles' radius if there's no dispersity in size. In case of dispersity !...
Definition: BaseCluster.cc:88
File eneFile
An instance of class File to handle in- and output into a .ene file.
Definition: DPMBase.h:1427
File restartFile
An instance of class File to handle in- and output into a .restart file.
Definition: DPMBase.h:1432
int nInternalStructurePoints_
Definition: BaseCluster.h:509
void setEnergyRatioTolerance(Mdouble eRT)
This sets the value of the value of the energy ratio threshold under which the process can be conside...
Definition: BaseCluster.cc:234
Contains material and contact force properties.
Definition: Interaction.h:42
void doRestartOutput(bool isRestartOutputOn)
This sets the bool variable that defines whether the cluster restart output will be written or not...
Definition: BaseCluster.cc:348
Definition: Vector.h:49
void setRadiusParticle(Mdouble rP)
This sets the value of particles' radius if there's no dispersity in size.
Definition: BaseCluster.cc:97
void actionsAfterTimeStep() override
Overrides DPMBase actionsAfterTimeStep(): in this compression and decompression are computed...
Definition: BaseCluster.cc:621
int nIntraClusterBonds_
Definition: BaseCluster.h:570
void calculateTimeStep()
Calculates the time step.
Mdouble getTimeStep() const
Returns the simulation time step.
Definition: DPMBase.cc:1234
Mdouble getVelocityDampingModulus() const
This returns the value of the velocity damping modulus.
Definition: BaseCluster.cc:192
bool isFStatOutputOn() const
This returns the bool variable that defines whether the cluster fStat output is written or not...
Definition: BaseCluster.cc:355
void read(std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
Reads the MercuryBase from an input stream, for example a restart file.
Definition: MercuryBase.cc:104
bool isRestartOutputOn_
Definition: BaseCluster.h:528
Mdouble Z
Definition: Vector.h:65
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:2914
void setupInitialConditions() override
Overrides DPMBase setupInitialConditions(): in this initial conditions for the problem are set...
Definition: BaseCluster.cc:425
Mdouble getTime() const
Returns the current simulation time.
Definition: DPMBase.cc:798
Mdouble forceTuningInterval_
Definition: BaseCluster.h:608
bool isOverlOutputOn() const
This returns the bool variable that defines whether the cluster overlap output is written or not...
Definition: BaseCluster.cc:285
void setPosition(Vec3D p)
This sets the value of position_, which is the position in which the cluster will be inserted...
Definition: BaseCluster.cc:60
void setClusterId(unsigned int iC)
This sets the value of the cluster ID.
Definition: BaseCluster.cc:183
BaseCluster()
Default constructor.
Definition: BaseCluster.cc:31
int getNumberOfParticles() const
This returns the value of the number of particles in the cluster.
Definition: BaseCluster.cc:126
ReadOptions
Definition: DPMBase.h:241
bool setRadiusCluster_
Definition: BaseCluster.h:497
void setRadiusCluster(Mdouble rCR)
This sets the desired value of the cluster radius (there is no getter of this value, but there is a getter of the actual mean cluster radius obtained, getMeanClusterRadius)
Definition: BaseCluster.cc:149
std::vector< Mdouble > radii_
Definition: BaseCluster.h:544